public void UpdateInstallationInfo(InstallationInfo info, CancellationTokenSource cancellationToken) { CancellationTokenSource = cancellationToken; InstallationInfo = info; TxtName.Text = InstallationInfo.Name + " " + InstallationInfo.Version; }
/// <summary> /// Initializes a new instance of the <see cref="SystemInfo"/> class. /// </summary> public SystemInfo() { InProgressInstallations = new InstallationInfo[] { }; CompletedInstallations = new InstallationInfo[] { }; FailedPluginAssemblies = new string[] { }; }
public InProgressInstallation(InstallationInfo installationInfo, CancellationTokenSource cancellationToken) { CancellationTokenSource = cancellationToken; InstallationInfo = installationInfo; InitializeComponent(); }
/// <summary> /// Installs the package. /// </summary> /// <param name="package">The package.</param> /// <param name="progress">The progress.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> /// <exception cref="System.ArgumentNullException">package</exception> public async Task InstallPackage(PackageVersionInfo package, IProgress<double> progress, CancellationToken cancellationToken) { if (package == null) { throw new ArgumentNullException("package"); } if (progress == null) { throw new ArgumentNullException("progress"); } if (cancellationToken == null) { throw new ArgumentNullException("cancellationToken"); } var installationInfo = new InstallationInfo { Id = Guid.NewGuid(), Name = package.name, UpdateClass = package.classification, Version = package.versionStr }; var innerCancellationTokenSource = new CancellationTokenSource(); var tuple = new Tuple<InstallationInfo, CancellationTokenSource>(installationInfo, innerCancellationTokenSource); // Add it to the in-progress list lock (CurrentInstallations) { CurrentInstallations.Add(tuple); } var innerProgress = new ActionableProgress<double>(); // Whenever the progress updates, update the outer progress object and InstallationInfo innerProgress.RegisterAction(percent => { progress.Report(percent); installationInfo.PercentComplete = percent; }); var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationTokenSource.Token).Token; var installationEventArgs = new InstallationEventArgs { InstallationInfo = installationInfo, PackageVersionInfo = package }; EventHelper.QueueEventIfNotNull(PackageInstalling, this, installationEventArgs, _logger); try { await InstallPackageInternal(package, innerProgress, linkedToken).ConfigureAwait(false); lock (CurrentInstallations) { CurrentInstallations.Remove(tuple); } CompletedInstallations.Add(installationInfo); EventHelper.QueueEventIfNotNull(PackageInstallationCompleted, this, installationEventArgs, _logger); } catch (OperationCanceledException) { lock (CurrentInstallations) { CurrentInstallations.Remove(tuple); } _logger.Info("Package installation cancelled: {0} {1}", package.name, package.versionStr); EventHelper.QueueEventIfNotNull(PackageInstallationCancelled, this, installationEventArgs, _logger); throw; } catch (Exception ex) { _logger.ErrorException("Package installation failed", ex); lock (CurrentInstallations) { CurrentInstallations.Remove(tuple); } EventHelper.QueueEventIfNotNull(PackageInstallationFailed, this, new InstallationFailedEventArgs { InstallationInfo = installationInfo, Exception = ex }, _logger); throw; } finally { // Dispose the progress object and remove the installation from the in-progress list innerProgress.Dispose(); tuple.Item2.Dispose(); } }