public List<PackageManagerSearchElement> ListAll()
        {
            CachedPackageList = new List<PackageManagerSearchElement>();

            foreach (var header in Model.ListAll())
            {
                var ele = new PackageManagerSearchElement(header);

                ele.UpvoteRequested += this.Model.Upvote;
                ele.DownvoteRequested += this.Model.Downvote;

                CachedPackageList.Add( ele );
            }

            return CachedPackageList;
        }
        private void PackageOnExecuted(PackageManagerSearchElement element, PackageVersion version, string downloadPath)
        {
            string msg = String.IsNullOrEmpty(downloadPath) ?
                         String.Format(Resources.MessageConfirmToInstallPackage, element.Name, version.version) :
                         String.Format(Resources.MessageConfirmToInstallPackageToFolder, element.Name, version.version, downloadPath);

            var result = MessageBox.Show(msg,
                                         Resources.PackageDownloadConfirmMessageBoxTitle,
                                         MessageBoxButton.OKCancel, MessageBoxImage.Question);

            var pmExt = PackageManagerClientViewModel.DynamoViewModel.Model.GetPackageManagerExtension();

            if (result == MessageBoxResult.OK)
            {
                // get all of the headers
                var headers = version.full_dependency_ids.Select(dep => dep._id).Select((id) =>
                {
                    PackageHeader pkgHeader;
                    var res = pmExt.PackageManagerClient.DownloadPackageHeader(id, out pkgHeader);

                    if (!res.Success)
                    {
                        MessageBox.Show(String.Format(Resources.MessageFailedToDownloadPackage, id),
                                        Resources.PackageDownloadErrorMessageBoxTitle,
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                    return(pkgHeader);
                }).ToList();

                // if any header download fails, abort
                if (headers.Any(x => x == null))
                {
                    return;
                }

                var allPackageVersions = PackageManagerSearchElement.ListRequiredPackageVersions(headers, version);

                // determine if any of the packages contain binaries or python scripts.
                var containsBinaries =
                    allPackageVersions.Any(
                        x => x.Item2.contents.Contains(PackageManagerClient.PackageContainsBinariesConstant) || x.Item2.contains_binaries);

                var containsPythonScripts =
                    allPackageVersions.Any(
                        x => x.Item2.contents.Contains(PackageManagerClient.PackageContainsPythonScriptsConstant));

                // if any do, notify user and allow cancellation
                if (containsBinaries || containsPythonScripts)
                {
                    var res = MessageBox.Show(Resources.MessagePackageContainPythonScript,
                                              Resources.PackageDownloadMessageBoxTitle,
                                              MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);

                    if (res == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }

                // Determine if there are any dependencies that are made with a newer version
                // of Dynamo (this includes the root package)
                var dynamoVersion       = this.PackageManagerClientViewModel.DynamoViewModel.Model.Version;
                var dynamoVersionParsed = VersionUtilities.PartialParse(dynamoVersion, 3);
                var futureDeps          = allPackageVersions.FilterFuturePackages(dynamoVersionParsed);

                // If any of the required packages use a newer version of Dynamo, show a dialog to the user
                // allowing them to cancel the package download
                if (futureDeps.Any())
                {
                    var versionList = FormatPackageVersionList(futureDeps);

                    if (MessageBox.Show(String.Format(Resources.MessagePackageNewerDynamo,
                                                      PackageManagerClientViewModel.DynamoViewModel.BrandingResourceProvider.ProductName,
                                                      versionList),
                                        string.Format(Resources.PackageUseNewerDynamoMessageBoxTitle,
                                                      PackageManagerClientViewModel.DynamoViewModel.BrandingResourceProvider.ProductName),
                                        MessageBoxButton.OKCancel,
                                        MessageBoxImage.Warning) == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }

                var localPkgs = pmExt.PackageLoader.LocalPackages;

                var uninstallsRequiringRestart          = new List <Package>();
                var uninstallRequiringUserModifications = new List <Package>();
                var immediateUninstalls = new List <Package>();

                // if a package is already installed we need to uninstall it, allowing
                // the user to cancel if they do not want to uninstall the package
                foreach (var localPkg in headers.Select(x => localPkgs.FirstOrDefault(v => v.Name == x.name)))
                {
                    if (localPkg == null)
                    {
                        continue;
                    }

                    if (localPkg.LoadedAssemblies.Any())
                    {
                        uninstallsRequiringRestart.Add(localPkg);
                        continue;
                    }

                    if (localPkg.InUse(this.PackageManagerClientViewModel.DynamoViewModel.Model))
                    {
                        uninstallRequiringUserModifications.Add(localPkg);
                        continue;
                    }

                    immediateUninstalls.Add(localPkg);
                }

                if (uninstallRequiringUserModifications.Any())
                {
                    MessageBox.Show(String.Format(Resources.MessageUninstallToContinue,
                                                  PackageManagerClientViewModel.DynamoViewModel.BrandingResourceProvider.ProductName,
                                                  JoinPackageNames(uninstallRequiringUserModifications)),
                                    Resources.CannotDownloadPackageMessageBoxTitle,
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                var settings = PackageManagerClientViewModel.DynamoViewModel.Model.PreferenceSettings;

                if (uninstallsRequiringRestart.Any())
                {
                    var message = string.Format(Resources.MessageUninstallToContinue2,
                                                PackageManagerClientViewModel.DynamoViewModel.BrandingResourceProvider.ProductName,
                                                JoinPackageNames(uninstallsRequiringRestart),
                                                element.Name + " " + version.version);
                    var dialogResult = MessageBox.Show(message,
                                                       Resources.CannotDownloadPackageMessageBoxTitle,
                                                       MessageBoxButton.YesNo, MessageBoxImage.Error);

                    if (dialogResult == MessageBoxResult.Yes)
                    {
                        // mark for uninstallation
                        uninstallsRequiringRestart.ForEach(x => x.MarkForUninstall(settings));
                    }
                    return;
                }

                if (immediateUninstalls.Any())
                {
                    // if the package is not in use, tell the user we will be uninstall it and give them the opportunity to cancel
                    if (MessageBox.Show(String.Format(Resources.MessageAlreadyInstallDynamo,
                                                      PackageManagerClientViewModel.DynamoViewModel.BrandingResourceProvider.ProductName,
                                                      JoinPackageNames(immediateUninstalls)),
                                        Resources.DownloadWarningMessageBoxTitle,
                                        MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }

                // add custom path to custom package folder list
                if (!String.IsNullOrEmpty(downloadPath))
                {
                    if (!settings.CustomPackageFolders.Contains(downloadPath))
                    {
                        settings.CustomPackageFolders.Add(downloadPath);
                    }
                }

                // form header version pairs and download and install all packages
                allPackageVersions
                .Select(x => new PackageDownloadHandle(x.Item1, x.Item2))
                .ToList()
                .ForEach(x => this.PackageManagerClientViewModel.DownloadAndInstall(x, downloadPath));
            }
        }
        private void PackageOnExecuted(PackageManagerSearchElement element, PackageVersion version, string downloadPath)
        {
            string msg = String.IsNullOrEmpty(downloadPath) ?
                String.Format(Resources.MessageConfirmToInstallPackage, element.Name, version.version) :
                String.Format(Resources.MessageConfirmToInstallPackageToFolder, element.Name, version.version, downloadPath);

            var result = MessageBox.Show(msg, 
                Resources.PackageDownloadConfirmMessageBoxTitle,
                MessageBoxButton.OKCancel, MessageBoxImage.Question);

            var pmExt = PackageManagerClientViewModel.DynamoViewModel.Model.GetPackageManagerExtension();
            if (result == MessageBoxResult.OK)
            {
                // get all of the headers
                var headers = version.full_dependency_ids.Select(dep => dep._id).Select((id) =>
                {
                    PackageHeader pkgHeader;
                    var res = pmExt.PackageManagerClient.DownloadPackageHeader(id, out pkgHeader);

                    if (!res.Success)
                        MessageBox.Show(String.Format(Resources.MessageFailedToDownloadPackage, id),
                            Resources.PackageDownloadErrorMessageBoxTitle,
                            MessageBoxButton.OK, MessageBoxImage.Error);

                    return pkgHeader;
                }).ToList();

                // if any header download fails, abort
                if (headers.Any(x => x == null))
                {
                    return;
                }

                var allPackageVersions = PackageManagerSearchElement.ListRequiredPackageVersions(headers, version);

                // determine if any of the packages contain binaries or python scripts.  
                var containsBinaries =
                    allPackageVersions.Any(
                        x => x.Item2.contents.Contains(PackageManagerClient.PackageContainsBinariesConstant) || x.Item2.contains_binaries);

                var containsPythonScripts =
                    allPackageVersions.Any(
                        x => x.Item2.contents.Contains(PackageManagerClient.PackageContainsPythonScriptsConstant));

                // if any do, notify user and allow cancellation
                if (containsBinaries || containsPythonScripts)
                {
                    var res = MessageBox.Show(Resources.MessagePackageContainPythonScript,
                        Resources.PackageDownloadMessageBoxTitle,
                        MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);

                    if (res == MessageBoxResult.Cancel) return;
                }

                // Determine if there are any dependencies that are made with a newer version
                // of Dynamo (this includes the root package)
                var dynamoVersion = this.PackageManagerClientViewModel.DynamoViewModel.Model.Version;
                var dynamoVersionParsed = VersionUtilities.PartialParse(dynamoVersion, 3);
                var futureDeps = allPackageVersions.FilterFuturePackages(dynamoVersionParsed);

                // If any of the required packages use a newer version of Dynamo, show a dialog to the user
                // allowing them to cancel the package download
                if (futureDeps.Any())
                {
                    var versionList = FormatPackageVersionList(futureDeps);

                    if (MessageBox.Show(String.Format(Resources.MessagePackageNewerDynamo,
                        PackageManagerClientViewModel.DynamoViewModel.BrandingResourceProvider.ProductName,
                        versionList),
                        string.Format(Resources.PackageUseNewerDynamoMessageBoxTitle,
                        PackageManagerClientViewModel.DynamoViewModel.BrandingResourceProvider.ProductName),
                        MessageBoxButton.OKCancel,
                        MessageBoxImage.Warning) == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }

                var localPkgs = pmExt.PackageLoader.LocalPackages;

                var uninstallsRequiringRestart = new List<Package>();
                var uninstallRequiringUserModifications = new List<Package>();
                var immediateUninstalls = new List<Package>();

                // if a package is already installed we need to uninstall it, allowing
                // the user to cancel if they do not want to uninstall the package
                foreach (var localPkg in headers.Select(x => localPkgs.FirstOrDefault(v => v.Name == x.name)))
                {
                    if (localPkg == null) continue;

                    if (localPkg.LoadedAssemblies.Any())
                    {
                        uninstallsRequiringRestart.Add(localPkg);
                        continue;
                    }

                    if (localPkg.InUse(this.PackageManagerClientViewModel.DynamoViewModel.Model))
                    {
                        uninstallRequiringUserModifications.Add(localPkg);
                        continue;
                    }

                    immediateUninstalls.Add(localPkg);
                }

                if (uninstallRequiringUserModifications.Any())
                {
                    MessageBox.Show(String.Format(Resources.MessageUninstallToContinue,
                        PackageManagerClientViewModel.DynamoViewModel.BrandingResourceProvider.ProductName,
                        JoinPackageNames(uninstallRequiringUserModifications)),
                        Resources.CannotDownloadPackageMessageBoxTitle, 
                        MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                var settings = PackageManagerClientViewModel.DynamoViewModel.Model.PreferenceSettings;

                if (uninstallsRequiringRestart.Any())
                {
                    var message = string.Format(Resources.MessageUninstallToContinue2,
                        PackageManagerClientViewModel.DynamoViewModel.BrandingResourceProvider.ProductName,
                        JoinPackageNames(uninstallsRequiringRestart),
                        element.Name + " " + version.version);
                    var dialogResult = MessageBox.Show(message, 
                        Resources.CannotDownloadPackageMessageBoxTitle,
                        MessageBoxButton.YesNo, MessageBoxImage.Error);

                    if (dialogResult == MessageBoxResult.Yes)
                    {
                        // mark for uninstallation
                        uninstallsRequiringRestart.ForEach(x => x.MarkForUninstall(settings));
                    }
                    return;
                }

                if (immediateUninstalls.Any())
                {
                    // if the package is not in use, tell the user we will be uninstall it and give them the opportunity to cancel
                    if (MessageBox.Show(String.Format(Resources.MessageAlreadyInstallDynamo, 
                        PackageManagerClientViewModel.DynamoViewModel.BrandingResourceProvider.ProductName,
                        JoinPackageNames(immediateUninstalls)),
                        Resources.DownloadWarningMessageBoxTitle, 
                        MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.Cancel)
                        return;
                }

                // add custom path to custom package folder list
                if (!String.IsNullOrEmpty(downloadPath))
                {
                    if (!settings.CustomPackageFolders.Contains(downloadPath))
                        settings.CustomPackageFolders.Add(downloadPath);
                }

                // form header version pairs and download and install all packages
                allPackageVersions
                        .Select(x => new PackageDownloadHandle(x.Item1, x.Item2))
                        .ToList()
                        .ForEach(x => this.PackageManagerClientViewModel.DownloadAndInstall(x, downloadPath));

            }
        }
 internal void PackageOnExecuted(PackageManagerSearchElement element, PackageVersion version, string downloadPath)
 {
     this.PackageManagerClientViewModel.ExecutePackageDownload(element.Name, version, downloadPath);
 }
Пример #5
0
        private void PackageOnExecuted(PackageManagerSearchElement element, PackageVersion version)
        {
            string message = "Are you sure you want to install " + element.Name + " " + version.version + "?";

            var result = MessageBox.Show(message, "Package Download Confirmation",
                                         MessageBoxButton.OKCancel, MessageBoxImage.Question);

            if (result == MessageBoxResult.OK)
            {
                // get all of the headers
                var headers = version.full_dependency_ids.Select(dep => dep._id).Select((id) =>
                {
                    PackageHeader pkgHeader;
                    var res = this.PackageManagerClientViewModel.DynamoViewModel.Model.PackageManagerClient.DownloadPackageHeader(id, out pkgHeader);

                    if (!res.Success)
                    {
                        MessageBox.Show("Failed to download package with id: " + id + ".  Please try again and report the package if you continue to have problems.", "Package Download Error",
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                    return(pkgHeader);
                }).ToList();

                // if any header download fails, abort
                if (headers.Any(x => x == null))
                {
                    return;
                }

                var allPackageVersions = PackageManagerSearchElement.ListRequiredPackageVersions(headers, version);

                // determine if any of the packages contain binaries or python scripts.
                var containsBinaries =
                    allPackageVersions.Any(
                        x => x.Item2.contents.Contains(PackageManagerClient.PackageContainsBinariesConstant) || x.Item2.contains_binaries);

                var containsPythonScripts =
                    allPackageVersions.Any(
                        x => x.Item2.contents.Contains(PackageManagerClient.PackageContainsPythonScriptsConstant));

                // if any do, notify user and allow cancellation
                if (containsBinaries || containsPythonScripts)
                {
                    var res = MessageBox.Show("The package or one of its dependencies contains Python scripts or binaries. " +
                                              "Do you want to continue?", "Package Download",
                                              MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);

                    if (res == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }

                // Determine if there are any dependencies that are made with a newer version
                // of Dynamo (this includes the root package)
                var dynamoVersion       = this.PackageManagerClientViewModel.DynamoViewModel.Model.Version;
                var dynamoVersionParsed = VersionUtilities.PartialParse(dynamoVersion, 3);
                var futureDeps          = allPackageVersions.FilterFuturePackages(dynamoVersionParsed);

                // If any of the required packages use a newer version of Dynamo, show a dialog to the user
                // allowing them to cancel the package download
                if (futureDeps.Any())
                {
                    var sb = new StringBuilder();

                    sb.AppendLine(
                        "The following packages use a newer version of Dynamo than you are currently using: ");
                    sb.AppendLine();

                    foreach (var elem in futureDeps)
                    {
                        sb.AppendLine(elem.Item1.name + " " + elem.Item2);
                    }

                    sb.AppendLine();
                    sb.AppendLine("Do you want to continue?");

                    // If the user
                    if (MessageBox.Show(
                            sb.ToString(),
                            "Package Uses Newer Version of Dynamo!",
                            MessageBoxButton.OKCancel,
                            MessageBoxImage.Warning) == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }

                var localPkgs = this.PackageManagerClientViewModel.DynamoViewModel.Model.PackageLoader.LocalPackages;

                var uninstallsRequiringRestart          = new List <Package>();
                var uninstallRequiringUserModifications = new List <Package>();
                var immediateUninstalls = new List <Package>();

                // if a package is already installed we need to uninstall it, allowing
                // the user to cancel if they do not want to uninstall the package
                foreach (var localPkg in headers.Select(x => localPkgs.FirstOrDefault(v => v.Name == x.name)))
                {
                    if (localPkg == null)
                    {
                        continue;
                    }

                    if (localPkg.LoadedAssemblies.Any())
                    {
                        uninstallsRequiringRestart.Add(localPkg);
                        continue;
                    }

                    if (localPkg.InUse(this.PackageManagerClientViewModel.DynamoViewModel.Model))
                    {
                        uninstallRequiringUserModifications.Add(localPkg);
                        continue;
                    }

                    immediateUninstalls.Add(localPkg);
                }

                string msg;

                if (uninstallRequiringUserModifications.Any())
                {
                    msg = "Dynamo needs to uninstall " + JoinPackageNames(uninstallRequiringUserModifications) +
                          " to continue, but cannot as one of its types appears to be in use.  Try restarting Dynamo.";
                    MessageBox.Show(msg, "Cannot Download Package", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    return;
                }

                if (uninstallsRequiringRestart.Any())
                {
                    // mark for uninstallation
                    uninstallsRequiringRestart.ForEach(
                        x =>
                        x.MarkForUninstall(
                            this.PackageManagerClientViewModel.DynamoViewModel.Model.PreferenceSettings));

                    msg = "Dynamo needs to uninstall " + JoinPackageNames(uninstallsRequiringRestart) +
                          " to continue but it contains binaries already loaded into Dynamo.  It's now marked " +
                          "for removal, but you'll need to first restart Dynamo.";
                    MessageBox.Show(msg, "Cannot Download Package", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    return;
                }

                if (immediateUninstalls.Any())
                {
                    // if the package is not in use, tell the user we will be uninstall it and give them the opportunity to cancel
                    msg = "Dynamo has already installed " + JoinPackageNames(immediateUninstalls) +
                          ".  \n\nDynamo will attempt to uninstall this package before installing.  ";
                    if (MessageBox.Show(msg, "Download Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }

                // form header version pairs and download and install all packages
                allPackageVersions
                .Select(x => new PackageDownloadHandle(x.Item1, x.Item2))
                .ToList()
                .ForEach(x => this.PackageManagerClientViewModel.DownloadAndInstall(x));
            }
        }