< Summary

Class:DeployedScenesFetcher
Assembly:DeployedScenesFetcher
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/DeployedScenesFetcher/DeployedScenesFetcher.cs
Covered lines:21
Uncovered lines:25
Coverable lines:46
Total lines:106
Line coverage:45.6% (21 of 46)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FetchScenes(...)0%2100%
FetchLandsFromOwner(...)0%110100%
GetLands(...)0%2.152066.67%
ProcessLand(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/DeployedScenesFetcher/DeployedScenesFetcher.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using DCL;
 4using DCL.Builder;
 5using DCL.Helpers;
 6
 7public static class DeployedScenesFetcher
 8{
 9    private const float DEFAULT_SCENES_CACHE_TIME = 3 * 60;
 10    private const float DEFAULT_LAND_CACHE_TIME = 5 * 60;
 11
 12    public static Promise<Scene[]> FetchScenes(ICatalyst catalyst, string[] parcels, float cacheMaxAgeSeconds = DEFAULT_
 13    {
 014        Promise<Scene[]> promise = new Promise<Scene[]>();
 015        catalyst.GetDeployedScenes(parcels, cacheMaxAgeSeconds)
 16                .Then(result =>
 17                {
 018                    promise.Resolve(result.Select(deployment => new Scene(deployment, catalyst.contentUrl)).ToArray());
 019                })
 020                .Catch(err => promise.Reject(err));
 021        return promise;
 22    }
 23
 24    public static Promise<LandWithAccess[]> FetchLandsFromOwner(ICatalyst catalyst, ITheGraph theGraph, string ethAddres
 25        float cacheMaxAgeSecondsLand = DEFAULT_LAND_CACHE_TIME, float cacheMaxAgeSecondsScenes = DEFAULT_SCENES_CACHE_TI
 26    {
 627        Promise<LandWithAccess[]> resultPromise = new Promise<LandWithAccess[]>();
 28
 629        List<Land> lands = new List<Land>();
 30
 631        Promise<string[]> getOwnedParcelsPromise = new Promise<string[]>();
 632        Promise<Scene[]> getDeployedScenesPromise = new Promise<Scene[]>();
 633        theGraph.QueryLands(network, ethAddress, cacheMaxAgeSecondsLand)
 34                .Then(landsReceived =>
 35                {
 236                    lands = landsReceived;
 37
 238                    List<string> parcels = new List<string>();
 439                    for (int i = 0; i < landsReceived.Count; i++)
 40                    {
 041                        if (landsReceived[i].parcels == null)
 42                            continue;
 43
 044                        parcels.AddRange(landsReceived[i].parcels.Select(parcel => $"{parcel.x},{parcel.y}"));
 45                    }
 46
 247                    getOwnedParcelsPromise.Resolve(parcels.ToArray());
 248                })
 049                .Catch(err => getOwnedParcelsPromise.Reject(err));
 50
 651        getOwnedParcelsPromise.Then(parcels =>
 52                              {
 253                                  if (parcels.Length > 0)
 54                                  {
 055                                      FetchScenes(catalyst, parcels, cacheMaxAgeSecondsScenes)
 056                                          .Then(scenes => getDeployedScenesPromise.Resolve(scenes))
 057                                          .Catch(err => getDeployedScenesPromise.Reject(err));
 058                                  }
 59                                  else
 60                                  {
 261                                      getDeployedScenesPromise.Resolve(new Scene[] { });
 62                                  }
 263                              })
 064                              .Catch(err => getDeployedScenesPromise.Reject(err));
 65
 666        getDeployedScenesPromise.Then(scenes =>
 67                                {
 268                                    resultPromise.Resolve(GetLands(lands, scenes));
 269                                })
 070                                .Catch(err => resultPromise.Reject(err));
 71
 672        return resultPromise;
 73    }
 74
 75    private static LandWithAccess[] GetLands(List<Land> lands, Scene[] scenes)
 76    {
 277        LandWithAccess[] result = new LandWithAccess[lands.Count];
 78
 479        for (int i = 0; i < lands.Count; i++)
 80        {
 081            result[i] = ProcessLand(lands[i], scenes);
 82        }
 83
 284        return result;
 85    }
 86
 87    private static LandWithAccess ProcessLand(Land land, Scene[] scenes)
 88    {
 089        List<Scene> scenesInLand = new List<Scene>();
 90
 091        LandWithAccess result = new LandWithAccess(land);
 092        for (int i = 0; i < result.parcels.Length; i++)
 93        {
 094            Scene sceneInParcel = scenes.FirstOrDefault(scene => scene.parcels.Contains(result.parcels[i]) && !scenesInL
 095            if (sceneInParcel != null)
 96            {
 097                sceneInParcel.SetScene(result);
 098                scenesInLand.Add(sceneInParcel);
 99            }
 100        }
 101
 0102        result.scenes = scenesInLand;
 103
 0104        return result;
 105    }
 106}