Esempio n. 1
0
        public async Task <UpdateResult> UpdateAsync(UpdateRequest updateRequest, IManagedTemplatePackageProvider provider, CancellationToken cancellationToken)
        {
            _ = updateRequest ?? throw new ArgumentNullException(nameof(updateRequest));
            _ = provider ?? throw new ArgumentNullException(nameof(provider));

            if (string.IsNullOrWhiteSpace(updateRequest.Version))
            {
                throw new ArgumentException("Version cannot be null or empty", nameof(updateRequest.Version));
            }

            //ensure uninstall is performed
            UninstallResult uninstallResult = await UninstallAsync(updateRequest.TemplatePackage, provider, cancellationToken).ConfigureAwait(false);

            if (!uninstallResult.Success)
            {
                if (uninstallResult.ErrorMessage is null)
                {
                    throw new InvalidOperationException($"{nameof(uninstallResult.ErrorMessage)} cannot be null when {nameof(uninstallResult.Success)} is 'true'");
                }
                return(UpdateResult.CreateFailure(updateRequest, uninstallResult.Error, uninstallResult.ErrorMessage));
            }

            var nuGetManagedSource = updateRequest.TemplatePackage as NuGetManagedTemplatePackage;
            Dictionary <string, string> installationDetails = new Dictionary <string, string>();

            if (nuGetManagedSource != null && !string.IsNullOrWhiteSpace(nuGetManagedSource.NuGetSource))
            {
                installationDetails.Add(InstallerConstants.NuGetSourcesKey, nuGetManagedSource.NuGetSource !);
            }
            InstallRequest installRequest = new InstallRequest(updateRequest.TemplatePackage.Identifier, updateRequest.Version, details: installationDetails);

            return(UpdateResult.FromInstallResult(updateRequest, await InstallAsync(installRequest, provider, cancellationToken).ConfigureAwait(false)));
        }
Esempio n. 2
0
        private async Task <UpdateResult> UpdateAsync(List <TemplatePackageData> packages, UpdateRequest updateRequest, CancellationToken cancellationToken)
        {
            (InstallerErrorCode result, string message) = await EnsureInstallPrerequisites(packages, updateRequest.TemplatePackage.Identifier, updateRequest.Version, updateRequest.TemplatePackage.Installer, cancellationToken, update : true).ConfigureAwait(false);

            if (result != InstallerErrorCode.Success)
            {
                return(UpdateResult.CreateFailure(updateRequest, result, message));
            }

            UpdateResult updateResult = await updateRequest.TemplatePackage.Installer.UpdateAsync(updateRequest, provider : this, cancellationToken).ConfigureAwait(false);

            if (!updateResult.Success)
            {
                return(updateResult);
            }

            if (updateResult.TemplatePackage is null)
            {
                throw new InvalidOperationException($"{nameof(updateResult.TemplatePackage)} cannot be null when {nameof(updateResult.Success)} is 'true'");
            }

            lock (packages)
            {
                packages.Add(((ISerializableInstaller)updateRequest.TemplatePackage.Installer).Serialize(updateResult.TemplatePackage));
            }
            return(updateResult);
        }