Beispiel #1
0
        public void Open(string contractName)
        {
            _catalog = AppExtensionCatalog.Open(contractName);

            _catalog.PackageInstalled     += (s, e) => PackageInstalled?.Invoke(this, new AppExtensionPackageInstalledEventArgsWrapper(e));
            _catalog.PackageUpdated       += (s, e) => PackageUpdated?.Invoke(this, new AppExtensionPackageUpdatedEventArgsWrapper(e));
            _catalog.PackageUninstalling  += (s, e) => PackageUninstalling?.Invoke(this, new AppExtensionPackageUninstallingEventArgsWrapper(e));
            _catalog.PackageUpdating      += (s, e) => PackageUpdating?.Invoke(this, new AppExtensionPackageUpdatingEventArgsWrapper(e));
            _catalog.PackageStatusChanged += (s, e) => PackageStatusChanged?.Invoke(this, new AppExtensionPackageStatusChangedEventArgsWrapper(e));
        }
Beispiel #2
0
        private async Task InstallPackagesInternalAsync(
            IEnumerable <ProjectInstallActionSummaryModel> summaries,
            INuGetProjectContext projectContext,
            bool shouldThrow,
            CancellationToken token)
        {
            projectContext.ActionType  = NuGetActionType.Install;
            projectContext.OperationId = Guid.NewGuid();

            List <NuGetProject>    projects = summaries.Select(t => t.Project).ToList();
            List <PackageIdentity> packages = summaries.SelectMany(t => t.NeedInstall).Distinct().ToList();

            using (SourceCacheContext sourceCacheContext = new SourceCacheContext())
            {
                foreach (PackageIdentity packageIdentity in packages)
                {
                    IReadOnlyList <ResolvedAction> actions = await GetActionsForInstallAsync(projects,
                                                                                             packageIdentity,
                                                                                             projectContext,
                                                                                             sourceCacheContext,
                                                                                             token);

                    if (actions.Count != 0)
                    {
                        PackageInstalling?.Invoke(packageIdentity.Id, packageIdentity.Version.ToNormalizedString());

                        try
                        {
                            await ExecuteActionsAsync(actions, packageIdentity, projectContext, sourceCacheContext, token);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex);
                            if (shouldThrow)
                            {
                                throw;
                            }
                        }
                        finally
                        {
                            PackageInstalled?.Invoke(packageIdentity.Id, packageIdentity.Version.ToNormalizedString());
                        }
                    }
                }
            }
        }
Beispiel #3
0
 private void OnPackageInstalled(PackageData package)
 {
     PackageInstalled?.Invoke(package);
 }
Beispiel #4
0
 private void OnPackageInstalled(NuGetInstallResult result)
 {
     PackageInstalled?.Invoke(result);
 }
Beispiel #5
0
 private void NuGetPackageInstalled(string packageId, string version)
 {
     PackageInstalled?.Invoke(packageId, version);
 }
 protected void OnPackageInstalled(string packageName)
 {
     PackageInstalled?.Invoke(this, new PackageEventArgs(packageName));
 }
 public void OnPackageInstalled(IDotNetProject project, NuGet.ProjectManagement.PackageEventArgs e)
 {
     PackageInstalled?.Invoke(this, new PackageManagementEventArgs(project, e));
 }
Beispiel #8
0
        /// <summary>
        ///     Installs the specified <paramref name="packageArchive"/> with the specified <paramref name="options"/>.
        /// </summary>
        /// <param name="packageArchive">The <see cref="IPackageArchive"/> to install.</param>
        /// <param name="options">The <see cref="PackageInstallationOptions"/> for the installation.</param>
        /// <returns>A Result containing the result of the operation and the installed <see cref="IPackage"/>.</returns>
        public IResult <IPackage> InstallPackage(IPackageArchive packageArchive, PackageInstallationOptions options)
        {
            Guid guid = logger.EnterMethod(xLogger.Params(packageArchive, options), true);

            logger.Info($"Installing Package '{packageArchive?.FQN}' from '{packageArchive?.FileName}'...");

            IResult <IPackage> retVal      = new Result <IPackage>();
            string             destination = default(string);

            if (packageArchive == default(IPackageArchive))
            {
                retVal.AddError($"The specified Package Archive is null.");
            }
            else if (string.IsNullOrEmpty(packageArchive.FileName))
            {
                retVal.AddError($"The specified Package Archive contains a null or empty FileName.");
            }
            else if (!Platform.FileExists(packageArchive.FileName))
            {
                retVal.AddError($"The specified Package Archive file '{packageArchive.FileName}' can not be found.");
            }
            else if (options == default(PackageInstallationOptions))
            {
                retVal.AddError($"Installation options were specified but are null.");
            }
            else if (options?.PublicKey != default(string) && options.PublicKey == string.Empty)
            {
                retVal.AddError($"The PGP installation key is specified but is empty.");
            }
            else
            {
                PackageExtractor extractor = new PackageExtractor();
                extractor.Updated += (sender, e) => logger.Debug($"    PackageExtractor: {e.Message}");

                // determine the installation directory; should look like \path\to\Plugins\FQN\
                destination = ReplaceInvalidCharacters(packageArchive.FQN);
                destination = Path.Combine(PlatformManager.Directories.Packages, destination);

                logger.Debug($"Install directory: '{destination}'; overwrite={options.Overwrite}, skipVerification={options.SkipVerification}");

                try
                {
                    extractor.ExtractPackage(packageArchive.FileName, destination, options?.PublicKey, options.Overwrite, options.SkipVerification);
                }
                catch (Exception ex)
                {
                    logger.Exception(LogLevel.Debug, ex);
                    retVal.AddError(ex.Message);
                }

                ScanPackages();

                retVal.ReturnValue = FindPackage(packageArchive.FQN);
            }

            if (retVal.ResultCode != ResultCode.Failure)
            {
                logger.Debug($"Package {retVal.ReturnValue.FQN} installed successfully. Sending PackageInstalled Event...");
                Task.Run(() => PackageInstalled?.Invoke(this, new PackageInstallEventArgs(retVal.ReturnValue, destination)));
            }

            retVal.LogResult(logger);
            logger.ExitMethod(guid);
            return(retVal);
        }
Beispiel #9
0
 private void OnPackageInstalled(IPackage package, NuGetInstallResult result)
 {
     PackageInstalled?.Invoke(package, result);
 }
Beispiel #10
0
        private async Task UpdatePackagesInternalAsync(
            IEnumerable <ProjectInstallActionSummaryModel> summaries,
            INuGetProjectContext projectContext,
            bool shouldThrow,
            CancellationToken token)
        {
            projectContext.ActionType  = NuGetActionType.UpdateAll;
            projectContext.OperationId = Guid.NewGuid();

            List <NuGetProject>    projects = summaries.Select(t => t.Project).ToList();
            List <PackageIdentity> packages = summaries.SelectMany(t => t.NeedInstall).Distinct().ToList();

            using (SourceCacheContext sourceCacheContext = new SourceCacheContext())
            {
                foreach (PackageIdentity packageIdentity in packages)
                {
                    IReadOnlyList <ResolvedAction> actions = await GetActionsForUpdateAsync(projects,
                                                                                            packageIdentity,
                                                                                            projectContext,
                                                                                            sourceCacheContext,
                                                                                            token);

                    if (actions.Count != 0)
                    {
                        PackageInstalling?.Invoke(packageIdentity.Id, packageIdentity.Version.ToNormalizedString());

                        try
                        {
                            await ExecuteActionsAsync(actions, packageIdentity, projectContext, sourceCacheContext, token);
                        }
                        catch (PackageReferenceRollbackException rollbackException)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(rollbackException.Message);

                            if (rollbackException.LogMessages != null)
                            {
                                foreach (var item in rollbackException.LogMessages)
                                {
                                    sb.AppendLine(item.FormatWithCode());
                                }
                            }

                            throw new Exception(sb.ToString());
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex);
                            if (shouldThrow)
                            {
                                throw;
                            }
                        }
                        finally
                        {
                            PackageInstalled?.Invoke(packageIdentity.Id, packageIdentity.Version.ToNormalizedString());
                        }
                    }
                }
            }
        }