< 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:105
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.Helpers;
 5
 6public static class DeployedScenesFetcher
 7{
 8    private const float DEFAULT_SCENES_CACHE_TIME = 3 * 60;
 9    private const float DEFAULT_LAND_CACHE_TIME = 5 * 60;
 10
 11    public static Promise<DeployedScene[]> FetchScenes(ICatalyst catalyst, string[] parcels, float cacheMaxAgeSeconds = 
 12    {
 013        Promise<DeployedScene[]> promise = new Promise<DeployedScene[]>();
 014        catalyst.GetDeployedScenes(parcels, cacheMaxAgeSeconds)
 15                .Then(result =>
 16                {
 017                    promise.Resolve(result.Select(deployment => new DeployedScene(deployment, catalyst.contentUrl)).ToAr
 018                })
 019                .Catch(err => promise.Reject(err));
 020        return promise;
 21    }
 22
 23    public static Promise<LandWithAccess[]> FetchLandsFromOwner(ICatalyst catalyst, ITheGraph theGraph, string ethAddres
 24        float cacheMaxAgeSecondsLand = DEFAULT_LAND_CACHE_TIME, float cacheMaxAgeSecondsScenes = DEFAULT_SCENES_CACHE_TI
 25    {
 826        Promise<LandWithAccess[]> resultPromise = new Promise<LandWithAccess[]>();
 27
 828        List<Land> lands = new List<Land>();
 29
 830        Promise<string[]> getOwnedParcelsPromise = new Promise<string[]>();
 831        Promise<DeployedScene[]> getDeployedScenesPromise = new Promise<DeployedScene[]>();
 832        theGraph.QueryLands(network, ethAddress, cacheMaxAgeSecondsLand)
 33                .Then(landsReceived =>
 34                {
 435                    lands = landsReceived;
 36
 437                    List<string> parcels = new List<string>();
 838                    for (int i = 0; i < landsReceived.Count; i++)
 39                    {
 040                        if (landsReceived[i].parcels == null)
 41                            continue;
 42
 043                        parcels.AddRange(landsReceived[i].parcels.Select(parcel => $"{parcel.x},{parcel.y}"));
 44                    }
 45
 446                    getOwnedParcelsPromise.Resolve(parcels.ToArray());
 447                })
 048                .Catch(err => getOwnedParcelsPromise.Reject(err));
 49
 850        getOwnedParcelsPromise.Then(parcels =>
 51                              {
 452                                  if (parcels.Length > 0)
 53                                  {
 054                                      FetchScenes(catalyst, parcels, cacheMaxAgeSecondsScenes)
 055                                          .Then(scenes => getDeployedScenesPromise.Resolve(scenes))
 056                                          .Catch(err => getDeployedScenesPromise.Reject(err));
 057                                  }
 58                                  else
 59                                  {
 460                                      getDeployedScenesPromise.Resolve(new DeployedScene[] { });
 61                                  }
 462                              })
 063                              .Catch(err => getDeployedScenesPromise.Reject(err));
 64
 865        getDeployedScenesPromise.Then(scenes =>
 66                                {
 467                                    resultPromise.Resolve(GetLands(lands, scenes));
 468                                })
 069                                .Catch(err => resultPromise.Reject(err));
 70
 871        return resultPromise;
 72    }
 73
 74    private static LandWithAccess[] GetLands(List<Land> lands, DeployedScene[] scenes)
 75    {
 476        LandWithAccess[] result = new LandWithAccess[lands.Count];
 77
 878        for (int i = 0; i < lands.Count; i++)
 79        {
 080            result[i] = ProcessLand(lands[i], scenes);
 81        }
 82
 483        return result;
 84    }
 85
 86    private static LandWithAccess ProcessLand(Land land, DeployedScene[] scenes)
 87    {
 088        List<DeployedScene> scenesInLand = new List<DeployedScene>();
 89
 090        LandWithAccess result = new LandWithAccess(land);
 091        for (int i = 0; i < result.parcels.Length; i++)
 92        {
 093            DeployedScene sceneInParcel = scenes.FirstOrDefault(scene => scene.parcels.Contains(result.parcels[i]) && !s
 094            if (sceneInParcel != null)
 95            {
 096                sceneInParcel.SetScene(result);
 097                scenesInLand.Add(sceneInParcel);
 98            }
 99        }
 100
 0101        result.scenes = scenesInLand;
 102
 0103        return result;
 104    }
 105}