Пример #1
0
        private static IEnumerator SendAndWait <T>(this UnityWebRequest self, Response <T> resp)
        {
            var timer = Stopwatch.StartNew();

            try {
                SetupDownloadAndUploadHanders(self, resp);
                resp.duration = Stopwatch.StartNew();
                self.ApplyAllCookiesToRequest();
                resp.debugInfo = self.method + " " + self.url;
                // Log.d("Sending: " + resp);
            }
            catch (Exception ex) { resp.onError(self, ex); throw; }
            var req = self.SendWebRequest();

            timer.AssertUnderXms(40);
            while (!req.isDone)
            {
                try {
                    var currentProgress = req.progress * 100;
                    if (resp.progressInPercent.SetNewValue(currentProgress))
                    {
                        timer.Restart();
                        resp.onProgress.InvokeIfNotNull(resp.progressInPercent.value);
                    }
                }
                catch (Exception ex) { resp.onError(self, ex); throw; }
                yield return(resp.wait);

                if (timer.ElapsedMilliseconds > resp.maxMsWithoutProgress)
                {
                    self.Abort();
                }
            }
            try {
                resp.duration.Stop();
                // Log.d("   > Finished " + resp);
                AssertResponseLooksNormal(self, resp);
                self.SaveAllNewCookiesFromResponse();
                if (self.error.IsNullOrEmpty())
                {
                    resp.progressInPercent.SetNewValue(100);
                }
                resp.getResult = () => { return(self.GetResult <T>()); };
                ProcessServerDate(self.uri, self.GetResponseHeader("date"));
            }
            catch (Exception ex) { resp.onError(self, ex); throw; }
        }
Пример #2
0
        private static IEnumerator SendAndWait <T>(this UnityWebRequest self, Response <T> resp)
        {
            SetupDownloadAndUploadHanders(self, resp);
            resp.duration = Stopwatch.StartNew();
            var timer = Stopwatch.StartNew();

            self.ApplyAllCookiesToRequest();
            if (self.downloadHandler == null)
            {
                self.downloadHandler = resp.createDownloadHandler();
            }
            resp.debugInfo = self.method + " " + self.url + " with cookies=[" + self.GetRequestHeader("Cookie") + "]";
            Log.d("Sending: " + resp);
            var req = self.SendWebRequest();

            timer.AssertUnderXms(40);
            while (!req.isDone)
            {
                var currentProgress = req.progress * 100;
                if (resp.progressInPercent.setNewValue(currentProgress))
                {
                    timer.Restart();
                    resp.onProgress.InvokeIfNotNull(resp.progressInPercent.value);
                }
                yield return(resp.wait);

                if (timer.ElapsedMilliseconds > resp.maxMsWithoutProgress)
                {
                    self.Abort();
                }
            }
            resp.duration.Stop();
            Log.d("   > Finished " + resp);
            AssertResponseLooksNormal(self, resp);
            self.SaveAllNewCookiesFromResponse();
            if (self.error.IsNullOrEmpty())
            {
                resp.progressInPercent.setNewValue(100);
            }
            resp.getResult = () => { return(self.GetResult <T>()); };
        }