예제 #1
0
        public async Task <ActionResult> InstallPackage(
            [FromRoute, Required] string name,
            [FromQuery] string?assemblyGuid,
            [FromQuery] string?version,
            [FromQuery] string?repositoryUrl)
        {
            var packages = await _installationManager.GetAvailablePackages().ConfigureAwait(false);

            if (!string.IsNullOrEmpty(repositoryUrl))
            {
                packages = packages.Where(p => p.repositoryUrl.Equals(repositoryUrl, StringComparison.OrdinalIgnoreCase))
                           .ToList();
            }

            var package = _installationManager.GetCompatibleVersions(
                packages,
                name,
                string.IsNullOrEmpty(assemblyGuid) ? Guid.Empty : Guid.Parse(assemblyGuid),
                specificVersion: string.IsNullOrEmpty(version) ? null : Version.Parse(version))
                          .FirstOrDefault();

            if (package == null)
            {
                return(NotFound());
            }

            await _installationManager.InstallPackage(package).ConfigureAwait(false);

            return(NoContent());
        }
예제 #2
0
        public async void Install(PackageVersionInfo version)
        {
            _installationManager.InstallPackage(version, new Progress <double>(), CancellationToken.None);

            await _nav.NavigateToSettingsPage();

            _nav.RemovePagesFromHistory(3);
        }
        async void BtnInstall_Click(object sender, RoutedEventArgs e)
        {
            var version = _packageInfo.versions.First(i => string.Equals(i.versionStr, SelectVersion.SelectedValue));

            _installationManager.InstallPackage(version, new Progress <double>(), CancellationToken.None);

            await _nav.NavigateToSettingsPage();

            _nav.RemovePagesFromHistory(3);
        }
예제 #4
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(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);
        }
예제 #5
0
        /// <summary>
        /// Posts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <exception cref="ResourceNotFoundException"></exception>
        public async Task Post(InstallPackage request)
        {
            var package = string.IsNullOrEmpty(request.Version) ?
                          await _installationManager.GetLatestCompatibleVersion(request.Name, request.AssemblyGuid, typeof(PackageService).Assembly.GetName().Version, request.UpdateClass).ConfigureAwait(false) :
                          await _installationManager.GetPackage(request.Name, request.AssemblyGuid, request.UpdateClass, Version.Parse(request.Version)).ConfigureAwait(false);

            if (package == null)
            {
                throw new ResourceNotFoundException(string.Format("Package not found: {0}", request.Name));
            }

            await _installationManager.InstallPackage(package, new SimpleProgress <double>(), CancellationToken.None);
        }
예제 #6
0
        /// <summary>
        /// Posts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <exception cref="ResourceNotFoundException"></exception>
        public void Post(InstallPackage request)
        {
            var package = string.IsNullOrEmpty(request.Version) ?
                          _installationManager.GetLatestCompatibleVersion(request.Name, request.AssemblyGuid, _appHost.ApplicationVersion, request.UpdateClass).Result :
                          _installationManager.GetPackage(request.Name, request.AssemblyGuid, request.UpdateClass, Version.Parse(request.Version)).Result;

            if (package == null)
            {
                throw new ResourceNotFoundException(string.Format("Package not found: {0}", request.Name));
            }

            Task.Run(() => _installationManager.InstallPackage(package, new Progress <double>(), CancellationToken.None));
        }
예제 #7
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);
        }
        /// <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;

            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.ErrorException("Error downloading {0}", ex, package.name);
                }
                catch (IOException ex)
                {
                    _logger.ErrorException("Error updating {0}", ex, package.name);
                }

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

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

            progress.Report(100);
        }
예제 #9
0
        /// <summary>
        /// Posts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <exception cref="ResourceNotFoundException"></exception>
        public async Task Post(InstallPackage request)
        {
            var packages = await _installationManager.GetAvailablePackages().ConfigureAwait(false);

            var package = _installationManager.GetCompatibleVersions(
                packages,
                request.Name,
                string.IsNullOrEmpty(request.AssemblyGuid) ? Guid.Empty : Guid.Parse(request.AssemblyGuid),
                string.IsNullOrEmpty(request.Version) ? null : Version.Parse(request.Version)).FirstOrDefault();

            if (package == null)
            {
                throw new ResourceNotFoundException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              "Package not found: {0}",
                              request.Name));
            }

            await _installationManager.InstallPackage(package);
        }
예제 #10
0
        public async Task <ActionResult> InstallPackage(
            [FromRoute][Required] string?name,
            [FromQuery] string?assemblyGuid,
            [FromQuery] string?version)
        {
            var packages = await _installationManager.GetAvailablePackages().ConfigureAwait(false);

            var package = _installationManager.GetCompatibleVersions(
                packages,
                name,
                string.IsNullOrEmpty(assemblyGuid) ? Guid.Empty : Guid.Parse(assemblyGuid),
                string.IsNullOrEmpty(version) ? null : Version.Parse(version)).FirstOrDefault();

            if (package == null)
            {
                return(NotFound());
            }

            await _installationManager.InstallPackage(package).ConfigureAwait(false);

            return(NoContent());
        }