< Summary

Class:DependencyMapLoadHelper
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/AssetBundles/DependencyMapLoadHelper.cs
Covered lines:25
Uncovered lines:4
Coverable lines:29
Total lines:70
Line coverage:86.2% (25 of 29)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DependencyMapLoadHelper()0%110100%
WaitUntilDepMapIsResolved()0%550100%
GetDepMap()0%9.367063.64%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/AssetBundles/DependencyMapLoadHelper.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using System.Linq;
 4using UnityEngine;
 5
 6public static class DependencyMapLoadHelper
 7{
 18    static bool VERBOSE = false;
 9    private const string MAIN_SHADER_FILENAME = "mainshader";
 10
 111    public static Dictionary<string, List<string>> dependenciesMap = new Dictionary<string, List<string>>();
 12
 113    static HashSet<string> failedRequests = new HashSet<string>();
 114    static HashSet<string> downloadingDepmap = new HashSet<string>();
 15
 16    [System.Serializable]
 17    public class AssetDependencyMap
 18    {
 19        public string[] dependencies;
 20    }
 21
 22    public static IEnumerator WaitUntilDepMapIsResolved(string hash)
 23    {
 524        while (true)
 25        {
 2426            bool depmapBeingDownloaded = downloadingDepmap.Contains(hash);
 2427            bool depmapRequestIsDone = dependenciesMap.ContainsKey(hash) || failedRequests.Contains(hash);
 28
 2429            if (!depmapBeingDownloaded && depmapRequestIsDone)
 30                break;
 31
 532            yield return null;
 33        }
 1934    }
 35
 36    public static IEnumerator GetDepMap(string baseUrl, string hash)
 37    {
 538        if (dependenciesMap.ContainsKey(hash))
 039            yield break;
 40
 541        if (failedRequests.Contains(hash))
 042            yield break;
 43
 544        if (downloadingDepmap.Contains(hash))
 45        {
 046            yield return WaitUntilDepMapIsResolved(hash);
 047            yield break;
 48        }
 49
 550        string url = baseUrl + hash + ".depmap";
 51
 552        downloadingDepmap.Add(hash);
 553        yield return DCL.Environment.i.platform.webRequest.Get(
 54            url: url,
 55            OnSuccess: (depmapRequest) =>
 56            {
 257                AssetDependencyMap map = JsonUtility.FromJson<AssetDependencyMap>(depmapRequest.downloadHandler.text);
 358                map.dependencies = map.dependencies.Where(x => !x.Contains(MAIN_SHADER_FILENAME)).ToArray();
 59
 260                dependenciesMap.Add(hash, new List<string>(map.dependencies));
 61
 262                downloadingDepmap.Remove(hash);
 263            },
 64            OnFail: (depmapRequest) =>
 65            {
 366                failedRequests.Add(hash);
 367                downloadingDepmap.Remove(hash);
 368            });
 569    }
 70}