Inheritance: Microsoft.Practices.Prism.ViewModel.NotificationObject
Beispiel #1
0
        internal void DownloadAndInstall(PackageDownloadHandle packageDownloadHandle)
        {
            var pkgDownload = new PackageDownload(packageDownloadHandle.Header._id, packageDownloadHandle.VersionName);

            Downloads.Add(packageDownloadHandle);

            ThreadStart start = () =>
            {
                try
                {
                    var response = Client.Execute(pkgDownload);
                    var pathDl   = PackageDownload.GetFileFromResponse(response);

                    dynSettings.Controller.UIDispatcher.BeginInvoke((Action)(() =>
                    {
                        try
                        {
                            packageDownloadHandle.Done(pathDl);

                            Package dynPkg;

                            var firstOrDefault = dynSettings.PackageLoader.LocalPackages.FirstOrDefault(pkg => pkg.Name == packageDownloadHandle.Name);
                            if (firstOrDefault != null)
                            {
                                firstOrDefault.UninstallCommand.Execute();
                            }

                            if (packageDownloadHandle.Extract(out dynPkg))
                            {
                                var downloadPkg = Package.FromDirectory(dynPkg.RootDirectory);
                                downloadPkg.Load();
                                dynSettings.PackageLoader.LocalPackages.Add(downloadPkg);
                                packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Installed;
                            }
                        }
                        catch (Exception e)
                        {
                            packageDownloadHandle.Error(e.Message);
                        }
                    }));
                }
                catch (Exception e)
                {
                    packageDownloadHandle.Error(e.Message);
                }
            };

            new Thread(start).Start();
        }
        /// <summary>
        /// Checks if the package corresponding to the PackageDownloadHandle can be installed.
        /// </summary>
        /// <param name="dh"></param>
        /// <returns></returns>
        internal bool CanInstallPackage(PackageDownloadHandle dh)
        {
            switch (dh.DownloadState)
            {
            case PackageDownloadHandle.State.Uninitialized:
            case PackageDownloadHandle.State.Error:
                return(true);   // Allowed if Download/Install not yet begun or if in Error state.

            case PackageDownloadHandle.State.Downloaded:
            case PackageDownloadHandle.State.Downloading:
            case PackageDownloadHandle.State.Installing:
                return(false);

            default:
                return(CanInstallPackage(dh.Name));   // All other states need to check with PackageLoader's LocalPackages
            }
        }
        /// <summary>
        /// When the user downloads new package via the package search manager, a toast notification
        /// appears at the base of the window. This command fires when the user clicks to dismiss
        /// one of these toast notifications.
        /// </summary>
        /// <param name="obj"></param>
        public void ClearDownloadToastNotification(object obj)
        {
            if (!(obj is PackageDownloadHandle packageDownloadHandle))
            {
                return;
            }

            PackageDownloadHandle packageDownloadHandleToRemove = PackageManagerClientViewModel.Downloads
                                                                  .FirstOrDefault(x => x.Id == packageDownloadHandle.Id);

            if (packageDownloadHandleToRemove == null)
            {
                return;
            }

            PackageManagerClientViewModel.Downloads.Remove(packageDownloadHandleToRemove);
            RaisePropertyChanged(nameof(Downloads));
        }
        /// <summary>
        /// This method downloads the package represented by the PackageDownloadHandle,
        /// uninstalls its current installation if necessary, and installs the package.
        /// 
        /// Note that, if the package is already installed, it must be uninstallable
        /// </summary>
        internal void DownloadAndInstall(PackageDownloadHandle packageDownloadHandle, string downloadPath)
        {
            Downloads.Add(packageDownloadHandle);

            packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Downloading;

            Task.Factory.StartNew(() =>
            {
                // Attempt to download package
                string pathDl;
                var res = Model.DownloadPackage(packageDownloadHandle.Header._id, packageDownloadHandle.VersionName, out pathDl);

                // if you fail, update download handle and return
                if (!res.Success)
                {
                    packageDownloadHandle.Error(res.Error);
                    return;
                }

                // if success, proceed to install the package
                DynamoViewModel.UIDispatcher.BeginInvoke((Action)(() =>
                {
                    try
                    {
                        packageDownloadHandle.Done(pathDl);

                        Package dynPkg;

                        var pmExtension = DynamoViewModel.Model.GetPackageManagerExtension();
                        var firstOrDefault = pmExtension.PackageLoader.LocalPackages.FirstOrDefault(pkg => pkg.Name == packageDownloadHandle.Name);
                        if (firstOrDefault != null)
                        {
                            var dynModel = DynamoViewModel.Model;
                            try
                            {
                                firstOrDefault.UninstallCore(dynModel.CustomNodeManager, pmExtension.PackageLoader, dynModel.PreferenceSettings);
                            }
                            catch
                            {
                                MessageBox.Show(String.Format(Resources.MessageFailToUninstallPackage, 
                                    DynamoViewModel.BrandingResourceProvider.ProductName,
                                    packageDownloadHandle.Name),
                                    Resources.UninstallFailureMessageBoxTitle, 
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }

                        if (packageDownloadHandle.Extract(DynamoViewModel.Model, downloadPath, out dynPkg))
                        {
                            var p = Package.FromDirectory(dynPkg.RootDirectory, DynamoViewModel.Model.Logger);
                            pmExtension.PackageLoader.Load(p);

                            packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Installed;
                        }
                    }
                    catch (Exception e)
                    {
                        packageDownloadHandle.Error(e.Message);
                    }
                }));

            });

        }
Beispiel #5
0
        /// <summary>
        /// This method downloads the package represented by the PackageDownloadHandle,
        /// uninstalls its current installation if necessary, and installs the package.
        /// 
        /// Note that, if the package is already installed, must be uninstallable
        /// </summary>
        /// <param name="packageDownloadHandle"></param>
        internal void DownloadAndInstall(PackageDownloadHandle packageDownloadHandle)
        {
            var pkgDownload = new PackageDownload(packageDownloadHandle.Header._id, packageDownloadHandle.VersionName);
            Downloads.Add( packageDownloadHandle );

            Task.Factory.StartNew(() =>
            {
                try
                {
                    var response = Client.Execute(pkgDownload);
                    var pathDl = PackageDownload.GetFileFromResponse(response);

                    dynSettings.Controller.UIDispatcher.BeginInvoke((Action) (() =>
                        {
                            try
                            {
                                packageDownloadHandle.Done(pathDl);

                                Package dynPkg;

                                var firstOrDefault = dynSettings.PackageLoader.LocalPackages.FirstOrDefault(pkg => pkg.Name == packageDownloadHandle.Name);
                                if (firstOrDefault != null)
                                {
                                    try { firstOrDefault.UninstallCore(); }
                                    catch
                                    {
                                        MessageBox.Show("Dynamo failed to uninstall the package: " + packageDownloadHandle.Name + 
                                            "  The package may need to be reinstalled manually.", "Uninstall Failure", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                    
                                } 

                                if (packageDownloadHandle.Extract(out dynPkg))
                                {

                                    var downloadPkg = Package.FromDirectory(dynPkg.RootDirectory);
                                    downloadPkg.Load();
                                    dynSettings.PackageLoader.LocalPackages.Add(downloadPkg);
                                    packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Installed;

                                }
                            }
                            catch (Exception e)
                            {
                                packageDownloadHandle.Error(e.Message);
                            }
                        }));
                    
                }
                catch (Exception e)
                {
                    packageDownloadHandle.Error(e.Message);
                }
            });

        }
        internal void DownloadAndInstall(PackageDownloadHandle packageDownloadHandle)
        {
            var pkgDownload = new PackageDownload(packageDownloadHandle.Header._id, packageDownloadHandle.VersionName);
            Downloads.Add( packageDownloadHandle );

            Task.Factory.StartNew(() =>
            {
                try
                {
                    var response = Client.Execute(pkgDownload);
                    var pathDl = PackageDownload.GetFileFromResponse(response);

                    dynSettings.Controller.UIDispatcher.BeginInvoke((Action) (() =>
                        {
                            try
                            {
                                packageDownloadHandle.Done(pathDl);

                                Package dynPkg;

                                var firstOrDefault = dynSettings.PackageLoader.LocalPackages.FirstOrDefault(pkg => pkg.Name == packageDownloadHandle.Name);
                                if (firstOrDefault != null)
                                    firstOrDefault.UninstallCommand.Execute();

                                if (packageDownloadHandle.Extract(out dynPkg))
                                {

                                    var downloadPkg = Package.FromDirectory(dynPkg.RootDirectory);
                                    downloadPkg.Load();
                                    dynSettings.PackageLoader.LocalPackages.Add(downloadPkg);
                                    packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Installed;

                                }
                            }
                            catch (Exception e)
                            {
                                packageDownloadHandle.Error(e.Message);
                            }
                        }));

                }
                catch (Exception e)
                {
                    packageDownloadHandle.Error(e.Message);
                }
            });
        }
        /// <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;
            }
        }
        /// <summary>
        /// This method downloads the package represented by the PackageDownloadHandle,
        /// uninstalls its current installation if necessary, and installs the package.
        /// 
        /// Note that, if the package is already installed, it must be uninstallable
        /// </summary>
        /// <param name="packageDownloadHandle"></param>
        internal void DownloadAndInstall(PackageDownloadHandle packageDownloadHandle)
        {
            var pkgDownload = new PackageDownload(packageDownloadHandle.Header._id, packageDownloadHandle.VersionName);
            this.Downloads.Add(packageDownloadHandle);

            Task.Factory.StartNew(() =>
            {
                try
                {
                    var response = Model.Client.Execute(pkgDownload);
                    var pathDl = PackageDownload.GetFileFromResponse(response);

                    dynamoViewModel.UIDispatcher.BeginInvoke((Action)(() =>
                    {
                        try
                        {
                            packageDownloadHandle.Done(pathDl);

                            Package dynPkg;

                            var firstOrDefault = dynamoViewModel.Model.Loader.PackageLoader.LocalPackages.FirstOrDefault(pkg => pkg.Name == packageDownloadHandle.Name);
                            if (firstOrDefault != null)
                            {
                                var dynModel = this.dynamoViewModel.Model;
                                try
                                {
                                    firstOrDefault.UninstallCore(dynModel.CustomNodeManager, dynModel.Loader.PackageLoader, dynModel.PreferenceSettings, dynModel.Logger);
                                }
                                catch
                                {
                                    MessageBox.Show("Dynamo failed to uninstall the package: " + packageDownloadHandle.Name +
                                        "  The package may need to be reinstalled manually.", "Uninstall Failure", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                            }

                            if (packageDownloadHandle.Extract(out dynPkg))
                            {
                                var downloadPkg = Package.FromDirectory(dynPkg.RootDirectory, this.dynamoViewModel.Model.Logger);

                                var loader = dynamoViewModel.Model.Loader;
                                var logger = dynamoViewModel.Model.Logger;
                                var libraryServices = dynamoViewModel.Model.EngineController.LibraryServices;
                                downloadPkg.LoadIntoDynamo(loader, logger, libraryServices);

                                dynamoViewModel.Model.Loader.PackageLoader.LocalPackages.Add(downloadPkg);
                                packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Installed;
                            }
                        }
                        catch (Exception e)
                        {
                            packageDownloadHandle.Error(e.Message);
                        }
                    }));

                }
                catch (Exception e)
                {
                    packageDownloadHandle.Error(e.Message);
                }
            });

        }