示例#1
0
        /// <summary>
        /// Update installed plugins
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="progress">The progress.</param>
        /// <returns>Task.</returns>
        public async Task Execute(CancellationToken cancellationToken, IProgress <double> progress)
        {
            progress.Report(0);

            var packagesToInstall = (await _installationManager.GetAvailablePluginUpdates(_appHost.ApplicationVersion, true, cancellationToken).ConfigureAwait(false)).ToList();

            progress.Report(10);

            var numComplete = 0;

            // Create tasks for each one
            var tasks = packagesToInstall.Select(i => Task.Run(async() =>
            {
                cancellationToken.ThrowIfCancellationRequested();

                try
                {
                    await _installationManager.InstallPackage(i, new Progress <double>(), cancellationToken).ConfigureAwait(false);
                }
                catch (OperationCanceledException)
                {
                    // InstallPackage has it's own inner cancellation token, so only throw this if it's ours
                    if (cancellationToken.IsCancellationRequested)
                    {
                        throw;
                    }
                }
                catch (HttpException ex)
                {
                    _logger.ErrorException("Error downloading {0}", ex, i.name);
                }
                catch (IOException ex)
                {
                    _logger.ErrorException("Error updating {0}", ex, i.name);
                }

                // Update progress
                lock (progress)
                {
                    numComplete++;
                    double percent = numComplete;
                    percent       /= packagesToInstall.Count;

                    progress.Report((90 * percent) + 10);
                }
            }));

            cancellationToken.ThrowIfCancellationRequested();

            await Task.WhenAll(tasks).ConfigureAwait(false);

            progress.Report(100);
        }
示例#2
0
        /// <inheritdoc />
        public async Task ExecuteAsync(IProgress <double> progress, CancellationToken cancellationToken)
        {
            progress.Report(0);

            var packageFetchTask  = _installationManager.GetAvailablePluginUpdates(cancellationToken);
            var packagesToInstall = (await packageFetchTask.ConfigureAwait(false)).ToList();

            progress.Report(10);

            var numComplete = 0;

            foreach (var package in packagesToInstall)
            {
                cancellationToken.ThrowIfCancellationRequested();

                try
                {
                    await _installationManager.InstallPackage(package, cancellationToken).ConfigureAwait(false);
                }
                catch (OperationCanceledException)
                {
                    // InstallPackage has it's own inner cancellation token, so only throw this if it's ours
                    if (cancellationToken.IsCancellationRequested)
                    {
                        throw;
                    }
                }
                catch (HttpRequestException ex)
                {
                    _logger.LogError(ex, "Error downloading {0}", package.Name);
                }
                catch (IOException ex)
                {
                    _logger.LogError(ex, "Error updating {0}", package.Name);
                }
                catch (InvalidDataException ex)
                {
                    _logger.LogError(ex, "Error updating {0}", package.Name);
                }

                // Update progress
                lock (progress)
                {
                    progress.Report((90.0 * ++numComplete / packagesToInstall.Count) + 10);
                }
            }

            progress.Report(100);
        }
示例#3
0
        /// <summary>
        /// Update installed plugins
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="progress">The progress.</param>
        /// <returns>Task.</returns>
        public async Task Execute(CancellationToken cancellationToken, IProgress <double> progress)
        {
            progress.Report(0);

            var packagesToInstall = (await _installationManager.GetAvailablePluginUpdates(typeof(PluginUpdateTask).Assembly.GetName().Version, true, cancellationToken).ConfigureAwait(false)).ToList();

            progress.Report(10);

            var numComplete = 0;

            foreach (var package in packagesToInstall)
            {
                cancellationToken.ThrowIfCancellationRequested();

                try
                {
                    await _installationManager.InstallPackage(package, true, new SimpleProgress <double>(), cancellationToken).ConfigureAwait(false);
                }
                catch (OperationCanceledException)
                {
                    // InstallPackage has it's own inner cancellation token, so only throw this if it's ours
                    if (cancellationToken.IsCancellationRequested)
                    {
                        throw;
                    }
                }
                catch (HttpException ex)
                {
                    _logger.LogError(ex, "Error downloading {0}", package.name);
                }
                catch (IOException ex)
                {
                    _logger.LogError(ex, "Error updating {0}", package.name);
                }

                // Update progress
                lock (progress)
                {
                    numComplete++;
                    progress.Report(90.0 * numComplete / packagesToInstall.Count + 10);
                }
            }

            progress.Report(100);
        }
示例#4
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetPackageVersionUpdates request)
        {
            var result = new List <PackageVersionInfo>();

            if (request.PackageType == PackageType.UserInstalled || request.PackageType == PackageType.All)
            {
                result.AddRange(_installationManager.GetAvailablePluginUpdates(_appHost.ApplicationVersion, false, CancellationToken.None).Result.ToList());
            }

            else if (request.PackageType == PackageType.System || request.PackageType == PackageType.All)
            {
                var updateCheckResult = _appHost.CheckForApplicationUpdate(CancellationToken.None, new Progress <double>()).Result;

                if (updateCheckResult.IsUpdateAvailable)
                {
                    result.Add(updateCheckResult.Package);
                }
            }

            return(ToOptimizedResult(result));
        }
示例#5
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetPackageVersionUpdates request)
        {
            var result = new List <PackageVersionInfo>();

            if (string.Equals(request.PackageType, "UserInstalled", StringComparison.OrdinalIgnoreCase) || string.Equals(request.PackageType, "All", StringComparison.OrdinalIgnoreCase))
            {
                result.AddRange(_installationManager.GetAvailablePluginUpdates(_appHost.ApplicationVersion, false, CancellationToken.None).Result.ToList());
            }

            else if (string.Equals(request.PackageType, "System", StringComparison.OrdinalIgnoreCase) || string.Equals(request.PackageType, "All", StringComparison.OrdinalIgnoreCase))
            {
                var updateCheckResult = _appHost.CheckForApplicationUpdate(CancellationToken.None, new SimpleProgress <double>()).Result;

                if (updateCheckResult.IsUpdateAvailable)
                {
                    result.Add(updateCheckResult.Package);
                }
            }

            return(ToOptimizedResult(result));
        }
示例#6
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public async Task <object> Get(GetPackageVersionUpdates request)
        {
            PackageVersionInfo[] result = null;

            if (string.Equals(request.PackageType, "UserInstalled", StringComparison.OrdinalIgnoreCase) || string.Equals(request.PackageType, "All", StringComparison.OrdinalIgnoreCase))
            {
                result = (await _installationManager.GetAvailablePluginUpdates(_appHost.ApplicationVersion, false, CancellationToken.None).ConfigureAwait(false)).ToArray();
            }

            else if (string.Equals(request.PackageType, "System", StringComparison.OrdinalIgnoreCase) ||
                     string.Equals(request.PackageType, "All", StringComparison.OrdinalIgnoreCase))
            {
                var updateCheckResult = await _appHost
                                        .CheckForApplicationUpdate(CancellationToken.None, new SimpleProgress <double>()).ConfigureAwait(false);

                if (updateCheckResult.IsUpdateAvailable)
                {
                    result = new PackageVersionInfo[] { updateCheckResult.Package };
                }
            }

            return(ToOptimizedResult(result ?? new PackageVersionInfo[] { }));
        }