public override void Prepare([NotNull] UpdaterStatus status, CancellationToken cancellationToken) { if (status == null) { throw new ArgumentNullException("status"); } try { _logger.LogDebug("Preparing diff installation..."); base.Prepare(status, cancellationToken); _localData.PrepareForWriting(); _previousContentSummary = _remoteMetaData.GetContentSummary(_versionId - 1, cancellationToken); _contentSummary = _remoteMetaData.GetContentSummary(_versionId, cancellationToken); _diffSummary = _remoteMetaData.GetDiffSummary(_versionId, cancellationToken); double unarchivePackageWeight = StatusWeightHelper.GetUnarchivePackageWeight(_diffSummary.Size); _logger.LogTrace("unarchivePackageWeight = " + unarchivePackageWeight); _unarchivePackageStatusReporter = new OperationStatus { Weight = { Value = unarchivePackageWeight } }; status.RegisterOperation(_unarchivePackageStatusReporter); double addFilesWeight = StatusWeightHelper.GetAddDiffFilesWeight(_diffSummary); _logger.LogTrace("addFilesWeight = " + addFilesWeight); _addFilesStatusReporter = new OperationStatus { Weight = { Value = addFilesWeight } }; status.RegisterOperation(_addFilesStatusReporter); double modifiedFilesWeight = StatusWeightHelper.GetModifyDiffFilesWeight(_diffSummary); _logger.LogTrace("modifiedFilesWeight = " + modifiedFilesWeight); _modifiedFilesStatusReporter = new OperationStatus { Weight = { Value = modifiedFilesWeight } }; status.RegisterOperation(_modifiedFilesStatusReporter); double removeFilesWeight = StatusWeightHelper.GetRemoveDiffFilesWeight(_diffSummary); _logger.LogTrace("removeFilesWeight = " + removeFilesWeight); _removeFilesStatusReporter = new OperationStatus { Weight = { Value = removeFilesWeight } }; status.RegisterOperation(_removeFilesStatusReporter); _logger.LogDebug("Diff installation prepared."); } catch (Exception e) { _logger.LogError("Failed to prepare diff installation.", e); throw; } }
private void ClearCachedBanner() { _logger.LogDebug(string.Format("Clearning the cached banner at {0}", CachedBannerPath)); if (!File.Exists(CachedBannerPath)) { _logger.LogError("The cached banner doesn't exist."); return; } FileOperations.Delete(CachedBannerPath, CancellationToken.Empty); CachedBannerPath = ""; }
private void EnforceCorrectScreenSize() { string screenSizeFilePath = Path.Combine(Application.dataPath, ScreenSizeFilename); _logger.LogDebug("Reading correct screen size from " + screenSizeFilePath); if (!File.Exists(screenSizeFilePath)) { _logger.LogWarning(screenSizeFilePath + " file does not exist."); return; } var screenResolutionText = File.ReadAllText(screenSizeFilePath).Split(' '); try { int width = int.Parse(screenResolutionText[0]); int height = int.Parse(screenResolutionText[1]); PlayerPrefs.SetInt("Screenmanager Resolution Width", width); PlayerPrefs.SetInt("Screenmanager Resolution Height", height); PlayerPrefs.SetInt("Screenmanager Is Fullscreen mode", 0); Screen.SetResolution(width, height, false); } catch (System.Exception e) { _logger.LogError("Failed to correct screen sizing due to an exception.", e); } }
public void Download(CancellationToken cancellationToken) { try { Assert.MethodCalledOnlyOnce(ref _downloadHasBeenCalled, "Download"); if (AreMetaAvailable()) { _logger.LogDebug("Resource meta are available."); try { DownloadMeta(cancellationToken); } catch (DownloadFailureException e) { throw new ResourceMetaDownloadFailureException("Failed to download resource meta.", e); } } else { _logger.LogDebug("Resource meta are not available."); } if (AreChunksAvailable()) { _logger.LogDebug("Chunks are available."); try { DownloadWithChunkedHttp(cancellationToken); return; } catch (DownloadFailureException e) { throw new ResourceDownloadFailureException("Failed to download resource.", e); } } _logger.LogDebug("Chunks are not available."); try { DownloadWithHttp(cancellationToken); } catch (DownloadFailureException e) { throw new ResourceDownloadFailureException("Failed to download resource.", e); } } catch (Exception e) { _logger.LogError("Downloading resource has failed.", e); throw; } }
public IHttpResponse Get(HttpGetRequest getRequest) { try { _logger.LogDebug("Sending GET request to " + getRequest.Address); if (getRequest.Range != null) { throw new NotImplementedException(); } _logger.LogTrace("timeout = " + getRequest.Timeout); var result = new WWWResult(); var waitHandle = UnityDispatcher.InvokeCoroutine(GetWWW(getRequest, result)); waitHandle.WaitOne(TimeSpan.FromMilliseconds(getRequest.Timeout)); lock (result) { if (!result.IsDone) { throw new WebException("Timeout.", WebExceptionStatus.Timeout); } var statusCode = ReadStatusCode(result); _logger.LogDebug("Successfuly received response."); return(new UnityHttpResponse(result.Text, statusCode, ResponseEncoding)); } } catch (Exception e) { _logger.LogError("Failed to get response.", e); throw; } }
private IApiResponse SendRequest(Func <Request> requestBuilder) { try { var request = requestBuilder(); IApiResponse apiResponse; bool retry; do { if (!TrySendRequest(_connectionSettings.MainServer, request, ServerType.MainServer, out apiResponse)) { if (_connectionSettings.CacheServers != null && request.Method == RequestMethod.Get) { foreach (var cacheServer in _connectionSettings.CacheServers) { if (TrySendRequest(cacheServer, request, ServerType.CacheServer, out apiResponse)) { break; } } } } if (apiResponse == null) { Logger.LogWarning( "Connection attempt to every server has failed. Checking whether retry is possible..."); RequestTimeoutCalculator.OnRequestFailure(); RequestRetryStrategy.OnRequestFailure(); retry = RequestRetryStrategy.ShouldRetry; if (!retry) { Logger.LogError("Retry is not possible."); throw new ApiConnectionException(request.MainServerExceptions, request.CacheServersExceptions); } Logger.LogDebug( string.Format( "Retry is possible. Waiting {0}ms before next attempt...", RequestRetryStrategy.DelayBeforeNextTry)); Thread.Sleep(RequestRetryStrategy.DelayBeforeNextTry); Logger.LogDebug("Trying to get response from servers once again..."); } else { retry = false; } } while (retry); Logger.LogDebug("Successfully got response."); Logger.LogTrace( string.Format("Response body: {0}", apiResponse.Body)); RequestTimeoutCalculator.OnRequestSuccess(); RequestRetryStrategy.OnRequestSuccess(); return(apiResponse); } catch (Exception e) { Logger.LogError("Failed to get response.", e); throw; } }