/// <summary> /// Searches for updates. /// </summary> /// <returns>Returns <c>true</c> if updates were found; otherwise, <c>false</c>.</returns> public bool SearchForUpdates() { // It may be that this is not the first search call and previously saved data needs to be disposed. Cleanup(); OnUpdateSearchStarted(this, EventArgs.Empty); if (!ConnectionManager.IsConnectionAvailable()) { return(false); } ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; var configuration = UpdateConfiguration.Download(UpdateConfigurationFileUri, HttpAuthenticationCredentials, Proxy, SearchTimeout); var result = new UpdateResult(configuration, CurrentVersion, IncludeAlpha, IncludeBeta, Conditions); if (!result.UpdatesFound) { return(false); } PackageConfigurations = result.NewestConfigurations; double updatePackageSize = 0; foreach (var updateConfiguration in PackageConfigurations) { updateConfiguration.UpdatePackageUri = ConvertPackageUri(updateConfiguration.UpdatePackageUri); updateConfiguration.UpdatePhpFileUri = ConvertStatisticsUri(updateConfiguration.UpdatePhpFileUri); var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri); if (newPackageSize == null) { throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText); } updatePackageSize += newPackageSize.Value; if (updateConfiguration.Operations == null) { continue; } if (_packageOperations == null) { _packageOperations = new Dictionary <UpdateVersion, IEnumerable <Operation> >(); } _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion), updateConfiguration.Operations); } TotalSize = updatePackageSize; return(true); }
/// <summary> /// Searches for updates, asynchronously. /// </summary> /// <seealso cref="SearchForUpdates" /> /// <exception cref="SizeCalculationException" /> /// <exception cref="OperationCanceledException" /> public Task <bool> SearchForUpdatesAsync() { return(Task.Run(async() => { // It may be that this is not the first search call and previously saved data needs to be disposed. Cleanup(); _searchCancellationTokenSource?.Dispose(); _searchCancellationTokenSource = new CancellationTokenSource(); if (!ConnectionManager.IsConnectionAvailable()) { return false; } _searchCancellationTokenSource.Token.ThrowIfCancellationRequested(); // Check for SSL and ignore it ServicePointManager.ServerCertificateValidationCallback += delegate { return true; }; var configuration = await UpdateConfiguration.DownloadAsync(UpdateConfigurationFileUri, HttpAuthenticationCredentials, Proxy, _searchCancellationTokenSource, SearchTimeout); _searchCancellationTokenSource.Token.ThrowIfCancellationRequested(); var result = new UpdateResult(configuration, CurrentVersion, IncludeAlpha, IncludeBeta, Conditions); if (!result.UpdatesFound) { return false; } PackageConfigurations = result.NewestConfigurations; double updatePackageSize = 0; foreach (var updateConfiguration in PackageConfigurations) { updateConfiguration.UpdatePackageUri = ConvertPackageUri(updateConfiguration.UpdatePackageUri); updateConfiguration.UpdatePhpFileUri = ConvertStatisticsUri(updateConfiguration.UpdatePhpFileUri); _searchCancellationTokenSource.Token.ThrowIfCancellationRequested(); var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri); if (newPackageSize == null) { throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText); } updatePackageSize += newPackageSize.Value; } TotalSize = updatePackageSize; if (!_searchCancellationTokenSource.Token.IsCancellationRequested) { return true; } throw new OperationCanceledException(); })); }
/// <summary> /// Searches for updates. /// </summary> /// <returns>Returns <c>true</c> if updates were found; otherwise, <c>false</c>.</returns> /// <exception cref="SizeCalculationException">The calculation of the size of the available updates has failed.</exception> /// <exception cref="OperationCanceledException">The update search was canceled.</exception> public bool SearchForUpdates() { if (_searchCancellationTokenSource != null) { _searchCancellationTokenSource.Dispose(); } _searchCancellationTokenSource = new CancellationTokenSource(); if (!ConnectionChecker.IsConnectionAvailable()) { return(false); } // Check for SSL and ignore it ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); }; var configuration = UpdateConfiguration.Download(_updateConfigurationFileUri, Proxy); var result = new UpdateResult(configuration, CurrentVersion, IncludeAlpha, IncludeBeta); if (!result.UpdatesFound) { return(false); } _updateConfigurations = _configurationUpdateCallback == null ? result.NewestConfigurations : _configurationUpdateCallback.Invoke(result.NewestConfigurations); double updatePackageSize = 0; foreach (var updateConfiguration in _updateConfigurations) { var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri); if (newPackageSize == null) { throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText); } updatePackageSize += newPackageSize.Value; _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion), updateConfiguration.Operations); } TotalSize = updatePackageSize; if (_searchCancellationTokenSource.Token.IsCancellationRequested) { _packageOperations.Clear(); _packageFilePaths.Clear(); throw new OperationCanceledException(); } return(true); }
/// <summary> /// Searches for updates. /// </summary> /// <returns>Returns <c>true</c> if updates were found; otherwise, <c>false</c>.</returns> /// <exception cref="SizeCalculationException">The calculation of the size of the available updates has failed.</exception> /// <exception cref="OperationCanceledException">The update search was canceled.</exception> public bool SearchForUpdates() { // It may be that this is not the first search call and previously saved data needs to be disposed. Cleanup(); _searchCancellationTokenSource?.Dispose(); _searchCancellationTokenSource = new CancellationTokenSource(); if (!ConnectionChecker.IsConnectionAvailable()) { return(false); } // Check for SSL and ignore it ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); }; var configuration = UpdateConfiguration.Download(UpdateConfigurationFileUri, Proxy); var result = new UpdateResult(configuration, CurrentVersion, IncludeAlpha, IncludeBeta); if (!result.UpdatesFound) { return(false); } PackageConfigurations = result.NewestConfigurations; double updatePackageSize = 0; foreach (var updateConfiguration in PackageConfigurations) { var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri); if (newPackageSize == null) { throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText); } updatePackageSize += newPackageSize.Value; _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion), updateConfiguration.Operations); } TotalSize = updatePackageSize; if (_searchCancellationTokenSource.Token.IsCancellationRequested) { Cleanup(); throw new OperationCanceledException(); } return(true); }
/// <summary> /// Searches for updates. /// </summary> /// <returns>Returns <c>true</c> if updates were found; otherwise, <c>false</c>.</returns> public bool SearchForUpdates() { // It may be that this is not the first search call and previously saved data needs to be disposed. Cleanup(); OnUpdateSearchStarted(this, EventArgs.Empty); if (!ConnectionManager.IsConnectionAvailable()) { return(false); } // Check for SSL and ignore it ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); }; var configuration = UpdateConfiguration.Download(UpdateConfigurationFileUri, HttpAuthenticationCredentials, Proxy, SearchTimeout); var result = new UpdateResult(configuration, CurrentVersion, IncludeAlpha, IncludeBeta); if (!result.UpdatesFound) { return(false); } PackageConfigurations = result.NewestConfigurations; double updatePackageSize = 0; foreach (var updateConfiguration in PackageConfigurations) { updateConfiguration.UpdatePackageUri = ConvertPackageUri(updateConfiguration.UpdatePackageUri); updateConfiguration.UpdatePhpFileUri = ConvertStatisticsUri(updateConfiguration.UpdatePhpFileUri); var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri); if (newPackageSize == null) { throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText); } updatePackageSize += newPackageSize.Value; _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion), updateConfiguration.Operations); } TotalSize = updatePackageSize; return(true); }
/// <summary> /// Searches for updates. /// </summary> /// <exception cref="InvalidOperationException">There is already a search process running.</exception> /// <exception cref="NetworkException">There is no network connection available.</exception> /// <seealso cref="SearchForUpdatesAsync"/> public void SearchForUpdates() { if (_searchWebClient.IsBusy) { throw new InvalidOperationException(_lp.SearchProcessRunningExceptionText); } if (!ConnectionChecker.IsConnectionAvailable()) { throw new NetworkException(_lp.NetworkConnectionExceptionText); } // Check for SSL and ignore it ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); }; var configurations = UpdateConfiguration.Download(UpdateConfigurationFileUri, Proxy); var result = new UpdateResult(configurations, CurrentVersion, IncludeAlpha, IncludeBeta); if (!result.UpdatesFound) { OnUpdateSearchFinished(false); } else { _updateConfiguration = result.NewestConfiguration; NewestVersion = new UpdateVersion(_updateConfiguration.LiteralVersion); Changelog = _updateConfiguration.Changelog.ContainsKey(LanguageCulture) ? _updateConfiguration.Changelog.First(item => item.Key.Name == LanguageCulture.Name).Value : _updateConfiguration.Changelog.First(item => item.Key.Name == new CultureInfo("en").Name).Value; Signature = Convert.FromBase64String(_updateConfiguration.Signature); MustUpdate = _updateConfiguration.MustUpdate; Operations = _updateConfiguration.Operations; var updatePackageSize = GetUpdatePackageSize(_updateConfiguration.UpdatePackageUri); if (updatePackageSize == null) { throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText); } PackageSize = updatePackageSize.Value; OnUpdateSearchFinished(true); } }
/// <summary> /// Searches for updates, asynchronously. /// </summary> /// <seealso cref="SearchForUpdates" /> public void SearchForUpdatesAsync() { OnUpdateSearchStarted(this, EventArgs.Empty); Task.Factory.StartNew(() => { // It may be that this is not the first search call and previously saved data needs to be disposed. Cleanup(); // Reinitialize the cancellation tokens and wait handles _searchCancellationTokenSource?.Dispose(); _searchCancellationTokenSource = new CancellationTokenSource(); _searchManualResetEvent.Reset(); if (!ConnectionManager.IsConnectionAvailable()) { return(false); } ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; IEnumerable <UpdateConfiguration> configurations = null; Exception exception = null; UpdateConfiguration.DownloadAsync(UpdateConfigurationFileUri, HttpAuthenticationCredentials, Proxy, (c, e) => { configurations = c; exception = e; _searchManualResetEvent.Set(); }, _searchCancellationTokenSource, SearchTimeout); _searchManualResetEvent.WaitOne(); // Check for cancellation before throwing any errors if (_searchCancellationTokenSource.IsCancellationRequested) { return(false); } if (exception != null) { throw exception; } var result = new UpdateResult(configurations, CurrentVersion, IncludeAlpha, IncludeBeta, Conditions); if (!result.UpdatesFound) { return(false); } PackageConfigurations = result.NewestConfigurations; double updatePackageSize = 0; foreach (var updateConfiguration in PackageConfigurations) { updateConfiguration.UpdatePackageUri = ConvertPackageUri(updateConfiguration.UpdatePackageUri); updateConfiguration.UpdatePhpFileUri = ConvertStatisticsUri(updateConfiguration.UpdatePhpFileUri); if (_searchCancellationTokenSource.IsCancellationRequested) { return(false); } var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri); if (newPackageSize == null) { throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText); } updatePackageSize += newPackageSize.Value; if (updateConfiguration.Operations == null) { continue; } if (_packageOperations == null) { _packageOperations = new Dictionary <UpdateVersion, IEnumerable <Operation> >(); } _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion), updateConfiguration.Operations); } TotalSize = updatePackageSize; return(true); }).ContinueWith(SearchTaskCompleted); }
/// <summary> /// Searches for updates, asynchronously. /// </summary> /// <seealso cref="SearchForUpdates" /> /// <exception cref="SizeCalculationException" /> /// <exception cref="OperationCanceledException" /> public Task <bool> SearchForUpdatesAsync() { return(TaskEx.Run(async() => { // It may be that this is not the first search call and previously saved data needs to be disposed. Cleanup(); _searchCancellationTokenSource?.Dispose(); _searchCancellationTokenSource = new CancellationTokenSource(); if (!ConnectionManager.IsConnectionAvailable()) { return false; } _searchCancellationTokenSource.Token.ThrowIfCancellationRequested(); ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; var configuration = await UpdateConfiguration.DownloadAsync(UpdateConfigurationFileUri, HttpAuthenticationCredentials, Proxy, _searchCancellationTokenSource, SearchTimeout); _searchCancellationTokenSource.Token.ThrowIfCancellationRequested(); var result = new UpdateResult(configuration, CurrentVersion, IncludeAlpha, IncludeBeta, Conditions); if (!result.UpdatesFound) { return false; } PackageConfigurations = result.NewestConfigurations; double updatePackageSize = 0; foreach (var updateConfiguration in PackageConfigurations) { updateConfiguration.UpdatePackageUri = ConvertPackageUri(updateConfiguration.UpdatePackageUri); updateConfiguration.UpdatePhpFileUri = ConvertStatisticsUri(updateConfiguration.UpdatePhpFileUri); _searchCancellationTokenSource.Token.ThrowIfCancellationRequested(); var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri); if (newPackageSize == null) { throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText); } updatePackageSize += newPackageSize.Value; if (updateConfiguration.Operations == null) { continue; } if (_packageOperations == null) { _packageOperations = new Dictionary <UpdateVersion, IEnumerable <Operation> >(); } _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion), updateConfiguration.Operations); } TotalSize = updatePackageSize; if (!_searchCancellationTokenSource.Token.IsCancellationRequested) { return true; } throw new OperationCanceledException(); })); }