IEnumerator Fetch() { bool shouldRetry = true; int retryCount = 0; string url = API_URL_ASSETS + assetContractAddress; do { if (OpenSeaRequestController.VERBOSE) { Debug.Log($"RequestGroup: Request to OpenSea {url}"); } // NOTE(Santi): In this case, as this code is implementing a very specific retries system (including delays), we use our // custom WebRequest system without retries (requestAttemps = 1) and let the current code to apply the retries. WebRequestAsyncOperation requestOp = WebRequestController.i.Get(url: url, requestAttemps: 1, disposeOnCompleted: false); yield return(requestOp); AssetsResponse response = null; if (requestOp.isSucceded) { response = Utils.FromJsonWithNulls <AssetsResponse>(requestOp.webRequest.downloadHandler.text); } if (OpenSeaRequestController.VERBOSE) { Debug.Log($"RequestGroup: Request resolving {response != null} {requestOp.webRequest.error} {url}"); } if (response != null) { shouldRetry = false; OnSuccess?.Invoke(response); requestOp.Dispose(); } else { shouldRetry = retryCount < REQUEST_RETRIES; if (!shouldRetry) { OnError?.Invoke("Error " + requestOp.webRequest.downloadHandler.text); requestOp.Dispose(); } else { retryCount++; if (OpenSeaRequestController.VERBOSE) { Debug.Log($"RequestGroup: Request retrying {url}"); } yield return(new WaitForSeconds(GetRetryDelay())); requestOp.Dispose(); } } } while (shouldRetry); }
private void Hide() { content.SetActive(false); if (fetchParcelImageOp != null) { fetchParcelImageOp.Dispose(); } if (downloadedBanner != null) { UnityEngine.Object.Destroy(downloadedBanner); downloadedBanner = null; } }
private IEnumerator UniGifProcessorLoad(string url, Action<GifFrameData[]> OnSuccess, Action OnFail) { webRequestOp = DCL.Environment.i.platform.webRequest.Get(url: url, disposeOnCompleted: false); yield return webRequestOp; if (webRequestOp.isSucceded) { var bytes = webRequestOp.webRequest.downloadHandler.data; yield return UniGif.GetTextureListCoroutine(bytes, (frames, loopCount, width, height) => { if (frames != null) { OnSuccess?.Invoke(frames); } else { OnFail?.Invoke(); } }); } else { OnFail?.Invoke(); } webRequestOp.Dispose(); }
public void LoadAsset(string url = "", bool loadEvenIfAlreadyLoaded = false) { if (alreadyLoadedAsset && !loadEvenIfAlreadyLoaded) { return; } if (!string.IsNullOrEmpty(url)) { OBJUrl = url; } if (asyncOp != null) { asyncOp.Dispose(); } LoadAsset(); }
/// <summary> /// Notify processor that the gif is disposed. /// If using UniGif plugin we just cancel the download if pending /// If using webworker we send a message to kernel to cancel download and/or remove created texture from memory /// </summary> public void DisposeGif() { if (jsGIFProcessingEnabled) { DCL.GIFProcessingBridge.i.DeleteGIF(url); } else if (webRequestOp != null) { webRequestOp.Dispose(); } }
private IEnumerator CreateHTTPRequest(string rootUri, string httpRequestPath) { string finalUrl = httpRequestPath; if (!string.IsNullOrEmpty(rootUri)) { finalUrl = Path.Combine(rootUri, httpRequestPath); } WebRequestAsyncOperation asyncOp = webRequestController.Get( url: finalUrl, downloadHandler: new DownloadHandlerBuffer(), timeout: 5000, disposeOnCompleted: false); yield return(asyncOp); if (!asyncOp.isSucceded) { Debug.LogError($"{asyncOp.webRequest.error} - {finalUrl}"); yield break; } if (asyncOp.webRequest.downloadedBytes > int.MaxValue) { Debug.LogError("Stream is too big for a byte array"); yield break; } if (asyncOp.webRequest.downloadHandler.data == null) { yield break; } //NOTE(Brian): Caution, webRequestResult.downloadHandler.data returns a COPY of the data, if accessed twice, // 2 copies will be performed for the entire file (and then discarded by GC, introducing hiccups). // The correct fix is by using DownloadHandler.ReceiveData. But this is in version > 2019.3. byte[] data = asyncOp.webRequest.downloadHandler.data; if (data != null) { LoadedStream = new MemoryStream(data, 0, data.Length, true, true); } asyncOp.Dispose(); }
IEnumerator Fetch(float delayRequest) { yield return(new WaitForSeconds(delayRequest)); CloseGroup(); bool shouldRetry = false; int retryCount = 0; string url = API_URL_ASSETS + requestUrl; do { if (OpenSeaRequestController.VERBOSE) { Debug.Log($"RequestGroup: Request to OpenSea {url}"); } // NOTE(Santi): In this case, as this code is implementing a very specific retries system (including delays), we use our // custom WebRequest system without retries (requestAttemps = 1) and let the current code to apply the retries. WebRequestAsyncOperation asyncOp = WebRequestController.i.Get(url: url, requestAttemps: 1, disposeOnCompleted: false); yield return(asyncOp); AssetsResponse response = null; if (asyncOp.isSucceded) { response = Utils.FromJsonWithNulls <AssetsResponse>(asyncOp.webRequest.downloadHandler.text); } if (OpenSeaRequestController.VERBOSE) { Debug.Log($"RequestGroup: Request resolving {response != null} {asyncOp.webRequest.error} {url}"); } if (response != null) { shouldRetry = false; //if we have one element in the group, is the one failing and we dont group it again if (response.assets.Length != 0 || requests.Count <= 1) { using (var iterator = requests.GetEnumerator()) { while (iterator.MoveNext()) { iterator.Current.Value.Resolve(response); } } } else { //There are invalids NFTs to fetch, we split the request into 2 smaller groups to find the ofender SplitGroup(); } asyncOp.Dispose(); } else { shouldRetry = retryCount < REQUEST_RETRIES; if (!shouldRetry) { using (var iterator = requests.GetEnumerator()) { while (iterator.MoveNext()) { iterator.Current.Value.Resolve(asyncOp.webRequest.error); } } asyncOp.Dispose(); } else { retryCount++; if (OpenSeaRequestController.VERBOSE) { Debug.Log($"RequestGroup: Request retrying {url}"); } asyncOp.Dispose(); yield return(new WaitForSeconds(GetRetryDelay())); } } } while (shouldRetry); }