Exemplo n.º 1
0
        private MessageBoxResult CheckForNewerDynamoVersion(List <Tuple <dynamic, dynamic> > packageVersionData)
        {
            // Determine if there are any dependencies that are made with a newer version
            // of Dynamo (this includes the root package)
            var dynamoVersion       = Model.Version;
            var dynamoVersionParsed = VersionUtilities.PartialParse(dynamoVersion, 3);
            var futureDeps          = FilterFuturePackages(packageVersionData, 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.ToList());

                if (PkgMgrCommands.ShowMessageBox(MessageTypes.PackageNewerDynamo, string.Format(Resources.MessagePackageNewerDynamo, ProductName, versionList),
                                                  string.Format(Resources.PackageUseNewerDynamoMessageBoxTitle,
                                                                ProductName),
                                                  MessageBoxButton.OKCancel,
                                                  MessageBoxImage.Warning) == MessageBoxResult.Cancel)
                {
                    return(MessageBoxResult.Cancel);
                }
            }
            return(MessageBoxResult.OK);
        }
Exemplo n.º 2
0
        private MessageBoxResult CheckForBinariesPythonScripts(dynamic version, List <Tuple <dynamic, dynamic> > packageVersionData)
        {
            var containsBinaries =
                packageVersionData.Any(
                    x => x.Item2.contents.ToString().Contains(Dynamo.PackageManager.PackageManagerClient.PackageContainsBinariesConstant) || (bool)x.Item2.contains_binaries);

            containsBinaries = containsBinaries || (version["contents"].ToString().Contains(Dynamo.PackageManager.PackageManagerClient.PackageContainsBinariesConstant) || (bool)version["contains_binaries"]);

            var containsPythonScripts =
                packageVersionData.Any(
                    x => x.Item2.contents.ToString().Contains(Dynamo.PackageManager.PackageManagerClient.PackageContainsPythonScriptsConstant));

            containsPythonScripts = containsPythonScripts || (version["contents"].ToString().Contains(Dynamo.PackageManager.PackageManagerClient.PackageContainsPythonScriptsConstant));

            // if any do, notify user and allow cancellation
            if (containsBinaries || containsPythonScripts)
            {
                var res = PkgMgrCommands.ShowMessageBox(MessageTypes.PackageContainPythinScript, string.Format(Resources.MessagePackageContainPythonScript),
                                                        Resources.PackageDownloadMessageBoxTitle,
                                                        MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);

                return(res);
            }

            return(MessageBoxResult.OK);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Uninstall Dynamo Package
        /// </summary>
        /// <returns></returns>
        public bool Uninstall()
        {
            Package localPkg = PkgMgrCommands.LocalPackages.Where(a => a.Name == this.PkgRequest.asset_name.ToString()).First();

            if (localPkg.LoadedAssemblies.Any())
            {
                var resAssem =
                    PkgMgrCommands.ShowMessageBox(MessageTypes.NeedToRestart, string.Format(Resources.MessageNeedToRestart, ProductName),
                                                  Resources.UninstallingPackageMessageBoxTitle,
                                                  MessageBoxButton.OKCancel,
                                                  MessageBoxImage.Exclamation);
                if (resAssem == MessageBoxResult.Cancel)
                {
                    return(false);
                }
            }

            var res = PkgMgrCommands.ShowMessageBox(MessageTypes.ConfirmToUninstall, string.Format(Resources.MessageConfirmToUninstallPackage, localPkg.Name),
                                                    Resources.UninstallingPackageMessageBoxTitle,
                                                    MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (res == MessageBoxResult.No)
            {
                return(false);
            }

            try
            {
                var dynModel = Model;
                PkgMgrCommands.UnloadPackage(localPkg);
                return(true);
            }
            catch (Exception)
            {
                PkgMgrCommands.ShowMessageBox(MessageTypes.FailedToUninstall, string.Format(Resources.MessageFailedToUninstall, ProductName),
                                              Resources.UninstallFailureMessageBoxTitle,
                                              MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Install Dynamo Package
        /// </summary>
        /// <param name="downloadPath"></param>
        public void InstallPackage(string downloadPath)
        {
            var firstOrDefault = PkgMgrCommands.LocalPackages.FirstOrDefault(pkg => pkg.ID == DownloadRequest.asset_id.ToString());

            if (firstOrDefault != null)
            {
                var dynModel = Model;
                try
                {
                    firstOrDefault.UninstallCore(dynModel.CustomNodeManager, Loader, dynModel.PreferenceSettings);
                }
                catch
                {
                    PkgMgrCommands.ShowMessageBox(MessageTypes.FailToUninstallPackage, string.Format(Resources.MessageFailToUninstallPackage, ProductName, DownloadRequest.asset_name.ToString()), Resources.UninstallFailureMessageBoxTitle,
                                                  MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            var settings = Model.PreferenceSettings;
            PackageDownloadHandle packageDownloadHandle = new PackageDownloadHandle();

            packageDownloadHandle.Name = DownloadRequest.asset_name;

            packageDownloadHandle.Done(downloadPath);

            //string installedPkgPath = string.Empty;
            Package dynPkg = null;

            if (packageDownloadHandle.Extract(Model, this.PackageInstallPath, out dynPkg))
            {
                var p = Package.FromDirectory(dynPkg.RootDirectory, Model.Logger);
                p.ID = DownloadRequest.asset_id;

                PkgMgrCommands.LoadPackage(p);

                packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Installed;
                this.PackageInstallPath             = string.Empty;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Install button click event
        /// </summary>
        /// <param name="asset"></param>
        /// <param name="version"></param>
        /// <returns>If "cencel" returned to webclient halt the installation. If not cancel then this method returns the | delimitted list of package and its version to be installed</returns>
        /// TODO: Rename this method to OnInstallPackage
        public string PackageOnExecuted(dynamic asset, dynamic version)
        {
            string downloadPath = this.PackageInstallPath;

            List <Tuple <dynamic, dynamic> > packageVersionData = new List <Tuple <dynamic, dynamic> >();

            string msg = String.IsNullOrEmpty(downloadPath) ?
                         String.Format(Resources.MessageConfirmToInstallPackage, asset["asset_name"], version["version"]) :
                         String.Format(Resources.MessageConfirmToInstallPackageToFolder, asset["asset_name"], version["version"], downloadPath);


            var result = String.IsNullOrEmpty(downloadPath) ? PkgMgrCommands.ShowMessageBox(MessageTypes.ConfirmToInstallPackage, msg,
                                                                                            Resources.PackageDownloadConfirmMessageBoxTitle,
                                                                                            MessageBoxButton.OKCancel, MessageBoxImage.Question) :
                         PkgMgrCommands.ShowMessageBox(MessageTypes.ConfirmToInstallPackageFolder, msg,
                                                       Resources.PackageDownloadConfirmMessageBoxTitle,
                                                       MessageBoxButton.OKCancel, MessageBoxImage.Question);

            if (PackagesToInstall == null)
            {
                PackagesToInstall = new List <string>();
            }
            else
            {
                PackagesToInstall.Clear();
            }

            if (result == MessageBoxResult.OK)
            {
                if (!string.IsNullOrEmpty(version["dependencies"]))
                {
                    GetDependencies(version, out packageVersionData);
                }

                //Add selected package to the list of packges to install
                PackagesToInstall.Add(string.Format("{0},{1},{2}", asset["asset_id"], version["file_id"], asset["asset_name"]));

                // determine if any of the packages contain binaries or python scripts.
                result = CheckForBinariesPythonScripts(version, packageVersionData);
                if (result == MessageBoxResult.Cancel)
                {
                    return("cancel");
                }

                result = CheckForNewerDynamoVersion(packageVersionData);
                if (result == MessageBoxResult.Cancel)
                {
                    return("cancel");
                }


                var localPkgs = PkgMgrCommands.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 packageVersionData.Select(x => localPkgs.FirstOrDefault(v => v.Name == x.Item1.asset_name.ToString())))
                {
                    if (localPkg == null)
                    {
                        continue;
                    }

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

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

                    immediateUninstalls.Add(localPkg);
                }

                if (uninstallRequiringUserModifications.Any())
                {
                    PkgMgrCommands.ShowMessageBox(MessageTypes.UnistallToContinue, string.Format(Resources.MessageUninstallToContinue, ProductName,
                                                                                                 JoinPackageNames(uninstallRequiringUserModifications)), Resources.CannotDownloadPackageMessageBoxTitle,
                                                  MessageBoxButton.OK, MessageBoxImage.Error);
                    return("cancel");
                }

                var settings = Model.PreferenceSettings;

                if (uninstallsRequiringRestart.Any())
                {
                    // mark for uninstallation
                    uninstallsRequiringRestart.ForEach(
                        x => x.MarkForUninstall(settings));

                    PkgMgrCommands.ShowMessageBox(MessageTypes.UnistallToContinue2, string.Format(Resources.MessageUninstallToContinue2, ProductName,
                                                                                                  JoinPackageNames(uninstallsRequiringRestart)),
                                                  Resources.CannotDownloadPackageMessageBoxTitle,
                                                  MessageBoxButton.OK, MessageBoxImage.Error);
                    return("cancel");
                }

                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 (PkgMgrCommands.ShowMessageBox(MessageTypes.AlreadyInstalledDynamo, string.Format(Resources.MessageAlreadyInstallDynamo, ProductName,
                                                                                                         JoinPackageNames(immediateUninstalls)),
                                                      Resources.DownloadWarningMessageBoxTitle,
                                                      MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.Cancel)
                    {
                        return("cancel");
                    }
                }

                // add custom path to custom package folder list
                if (!String.IsNullOrEmpty(downloadPath))
                {
                    if (!settings.CustomPackageFolders.Contains(downloadPath))
                    {
                        settings.CustomPackageFolders.Add(downloadPath);
                    }
                }
            }
            else
            {
                return("cancel");
            }
            return(String.Join("|", PackagesToInstall));
        }