< Summary

Class:DeployedScenesFetcher
Assembly:DeployedScenesFetcher
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/DeployedScenesFetcher/DeployedScenesFetcher.cs
Covered lines:8
Uncovered lines:38
Coverable lines:46
Total lines:105
Line coverage:17.3% (8 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%6200%
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.Helpers;
 4
 5public static class DeployedScenesFetcher
 6{
 7    private const float DEFAULT_SCENES_CACHE_TIME = 3 * 60;
 8    private const float DEFAULT_LAND_CACHE_TIME = 5 * 60;
 9
 10    public static Promise<DeployedScene[]> FetchScenes(ICatalyst catalyst, string[] parcels, float cacheMaxAgeSeconds = 
 11    {
 012        Promise<DeployedScene[]> promise = new Promise<DeployedScene[]>();
 013        catalyst.GetDeployedScenes(parcels, cacheMaxAgeSeconds)
 14            .Then(result =>
 15            {
 016                promise.Resolve(result.Select(deployment => new DeployedScene(deployment, catalyst.contentUrl)).ToArray(
 017            })
 018            .Catch(err => promise.Reject(err));
 019        return promise;
 20    }
 21
 22    public static Promise<LandWithAccess[]> FetchLandsFromOwner(ICatalyst catalyst, ITheGraph theGraph, string ethAddres
 23        float cacheMaxAgeSecondsLand = DEFAULT_LAND_CACHE_TIME, float cacheMaxAgeSecondsScenes = DEFAULT_SCENES_CACHE_TI
 24    {
 425        Promise<LandWithAccess[]> resultPromise = new Promise<LandWithAccess[]>();
 26
 427        List<Land> lands = new List<Land>();
 28
 429        Promise<string[]> getOwnedParcelsPromise = new Promise<string[]>();
 430        Promise<DeployedScene[]> getDeployedScenesPromise = new Promise<DeployedScene[]>();
 31
 432        theGraph.QueryLands(tld, ethAddress, cacheMaxAgeSecondsLand)
 33            .Then(landsReceived =>
 34            {
 035                lands = landsReceived;
 36
 037                List<string> parcels = new List<string>();
 038                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
 046                getOwnedParcelsPromise.Resolve(parcels.ToArray());
 047            })
 048            .Catch(err => getOwnedParcelsPromise.Reject(err));
 49
 450        getOwnedParcelsPromise.Then(parcels =>
 51            {
 052                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                {
 060                    getDeployedScenesPromise.Resolve(new DeployedScene[] { });
 61                }
 062            })
 063            .Catch(err => getDeployedScenesPromise.Reject(err));
 64
 465        getDeployedScenesPromise.Then(scenes =>
 66            {
 067                resultPromise.Resolve(GetLands(lands, scenes));
 068            })
 069            .Catch(err => resultPromise.Reject(err));
 70
 471        return resultPromise;
 72    }
 73
 74    private static LandWithAccess[] GetLands(List<Land> lands, DeployedScene[] scenes)
 75    {
 076        LandWithAccess[] result = new LandWithAccess[lands.Count];
 77
 078        for (int i = 0; i < lands.Count; i++)
 79        {
 080            result[i] = ProcessLand(lands[i], scenes);
 81        }
 82
 083        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.sceneLand = result;
 097                scenesInLand.Add(sceneInParcel);
 98            }
 99        }
 100
 0101        result.scenes = scenesInLand;
 102
 0103        return result;
 104    }
 105}