< Summary

Class:DCL.GLTFast.Wrappers.GltFastDownloadProvider
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTFast/Wrappers/GLTFastDownloadProvider.cs
Covered lines:0
Uncovered lines:27
Coverable lines:27
Total lines:78
Line coverage:0% (0 of 27)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GltFastDownloadProvider(...)0%2100%
Request()0%42600%
RequestTexture()0%30500%
Dispose()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTFast/Wrappers/GLTFastDownloadProvider.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Threading.Tasks;
 4using GLTFast.Loading;
 5using UnityEngine;
 6using UnityEngine.Networking;
 7
 8namespace DCL.GLTFast.Wrappers
 9{
 10    /// <summary>
 11    /// With this class we replace all of GLTFast web requests with our own
 12    /// </summary>
 13    internal class GltFastDownloadProvider : IDownloadProvider, IDisposable
 14    {
 15        private readonly IWebRequestController webRequestController;
 16        private readonly AssetIdConverter fileToUrl;
 017        private List<IDisposable> disposables = new ();
 18
 019        public GltFastDownloadProvider(IWebRequestController webRequestController, AssetIdConverter fileToUrl)
 20        {
 021            this.webRequestController = webRequestController;
 022            this.fileToUrl = fileToUrl;
 023        }
 24
 25        public async Task<IDownload> Request(Uri uri)
 26        {
 027            string finalUrl = uri.OriginalString;
 28
 029            string fileName = uri.AbsolutePath.Substring(uri.AbsolutePath.LastIndexOf('/') + 1);
 30
 031            if (fileToUrl(fileName, out string url)) { finalUrl = url; }
 32
 033            WebRequestAsyncOperation asyncOp = (WebRequestAsyncOperation)webRequestController.Get(
 34                url: finalUrl,
 35                downloadHandler: new DownloadHandlerBuffer(),
 36                timeout: 30,
 37                disposeOnCompleted: false,
 38                requestAttemps: 3);
 39
 040            GltfDownloaderWrapper wrapper = new GltfDownloaderWrapper(asyncOp);
 041            disposables.Add(wrapper);
 42
 043            while (wrapper.MoveNext()) { await Task.Yield(); }
 44
 045            if (!wrapper.success) { Debug.LogError($"<color=Red>[GLTFast WebRequest Failed]</color> {asyncOp.asyncOp.web
 46
 047            return wrapper;
 048        }
 49
 50        public async Task<ITextureDownload> RequestTexture(Uri uri, bool nonReadable)
 51        {
 052            string fileName = uri.AbsolutePath.Substring(uri.AbsolutePath.LastIndexOf('/') + 1);
 053            fileToUrl(fileName, out string url);
 54
 055            WebRequestAsyncOperation asyncOp = webRequestController.GetTexture(
 56                url: url,
 57                timeout: 30,
 58                disposeOnCompleted: false,
 59                requestAttemps: 3);
 60
 061            GltfTextureDownloaderWrapper wrapper = new GltfTextureDownloaderWrapper(asyncOp);
 062            disposables.Add(wrapper);
 63
 064            while (wrapper.MoveNext()) { await Task.Yield(); }
 65
 066            if (!wrapper.success) { Debug.LogError("[GLTFast Texture WebRequest Failed] " + asyncOp.asyncOp.webRequest.u
 67
 068            return wrapper;
 069        }
 70
 71        public void Dispose()
 72        {
 073            foreach (IDisposable disposable in disposables) { disposable.Dispose(); }
 74
 075            disposables = null;
 076        }
 77    }
 78}