Esempio n. 1
0
        private static void HandleResult(WwwCallResult result, string log, byte[] bytes, Uri uri, StringBuilder timeoutLogs, int numAttempts, Action <LoadAssetResult> callback, Action <Uri, Action <LoadAssetResult>, StringBuilder, int> retry, AbstractLogger logger)
        {
            switch (result)
            {
            case WwwCallResult.Success:
                logger.Debug(log);
                callback(new LoadAssetResult(success: true, bytes));
                break;

            case WwwCallResult.TooManyTimeoutsError:
                logger.Critical("Too many timeouts: " + uri.AbsoluteUri + "\nPrevious logs:\n" + timeoutLogs);
                callback(new LoadAssetResult(success: false, null));
                break;

            case WwwCallResult.TooManyServerErrors:
                logger.Critical("Too many server errors:\n" + log);
                callback(new LoadAssetResult(success: false, null));
                break;

            case WwwCallResult.RetryTimeout:
                logger.Error(log);
                timeoutLogs.Append(log);
                timeoutLogs.Append("\n\n");
                retry(uri, callback, timeoutLogs, numAttempts + 1);
                break;

            case WwwCallResult.RetryServerError:
                logger.Error(log);
                retry(uri, callback, timeoutLogs, numAttempts + 1);
                break;

            case WwwCallResult.OfflineError:
                logger.Error(log);
                callback(new LoadAssetResult(success: false, null));
                break;

            case WwwCallResult.ClientError:
                logger.Critical(log);
                callback(new LoadAssetResult(success: false, null));
                break;
            }
        }
Esempio n. 2
0
        private void Load(Uri uri, Action <LoadAssetResult> callback, StringBuilder timeoutLogs, int numAttempts)
        {
            IWwwCall wwwCall = wwwCallFactory.Create(uri, HttpMethod.GET, null, emptyHeaders, 10000L, 30000L);

            logger.Debug(BuildRequestLog(uri, wwwCall.RequestId));
            EventHandler <WwwDoneEventArgs> handleOnDone = null;

            handleOnDone = delegate
            {
                wwwCall.OnDone -= handleOnDone;
                Dictionary <string, string> responseHeaders = wwwCall.ResponseHeaders;
                uint          statusCode   = wwwCall.StatusCode;
                WwwCallResult result       = GetResult(wwwCall.Error, statusCode, numAttempts);
                string        log          = BuildResponseLog(uri, result, responseHeaders, statusCode, wwwCall);
                byte[]        responseBody = wwwCall.ResponseBody;
                HandleResult(result, log, responseBody, uri, timeoutLogs, numAttempts, callback, Load, logger);
                wwwCall.Dispose();
            };
            wwwCall.OnDone += handleOnDone;
            wwwCall.Execute();
        }
Esempio n. 3
0
 private static string BuildResponseLog(Uri uri, WwwCallResult result, Dictionary <string, string> headers, uint statusCode, IWwwCall wwwCall)
 {
     return((result == WwwCallResult.RetryTimeout) ? HttpLogBuilder.BuildTimeoutLog(wwwCall.RequestId, uri, HttpMethod.GET, headers, string.Empty, wwwCall.TimeToStartUpload, wwwCall.TimeToFinishUpload, wwwCall.PercentUploaded, wwwCall.TimeToStartDownload, wwwCall.TimeToFinishDownload, wwwCall.PercentDownloaded, wwwCall.TimeoutReason, wwwCall.TimeoutTime) : HttpLogBuilder.BuildResponseLog(wwwCall.RequestId, uri, HttpMethod.GET, headers, string.Empty, statusCode));
 }