Exemple #1
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, 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 = packageManagerClient.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);
                                downloadPkg.LoadIntoDynamo(this.dynamoViewModel.Model.Loader, this.dynamoViewModel.Model.Logger);

                                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);
                }
            });
        }
Exemple #2
0
        /// <summary>
        /// Check Dynamo package install state
        /// </summary>
        /// <param name="packageDownloadHandle">package download handle</param>
        /// <param name="downloadPath">package download path</param>
        internal void SetPackageState(PackageDownloadHandle packageDownloadHandle, string downloadPath)
        {
            Package dynPkg;

            if (packageDownloadHandle.Extract(DynamoViewModel.Model, downloadPath, out dynPkg))
            {
                PackageManagerExtension.PackageLoader.LoadPackages(new List <Package> {
                    dynPkg
                });
                packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Installed;
            }
            else
            {
                packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Error;
                packageDownloadHandle.Error(Resources.MessageInvalidPackage);
            }
        }
Exemple #3
0
        /// <summary>
        /// Install Dynamo Package
        /// </summary>
        /// <param name="downloadPath"></param>
        private void InstallPackage(string downloadPath)
        {
            var firstOrDefault = Loader.LocalPackages.FirstOrDefault(pkg => pkg.ID == DownloadRequest.asset_id.ToString());

            if (firstOrDefault != null)
            {
                var dynModel = Model;
                try
                {
                    firstOrDefault.UninstallCore(dynModel.CustomNodeManager, Loader, dynModel.PreferenceSettings);
                }
                catch
                {
                    MessageBox.Show(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;
                Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    Loader.Load(p);
                }));
                packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Installed;
                this.PackageInstallPath             = string.Empty;
            }
        }
Exemple #4
0
        /// <summary>
        /// Check Dynamo package install state
        /// </summary>
        /// <param name="packageDownloadHandle">package download handle</param>
        /// <param name="downloadPath">package download path</param>
        internal void SetPackageState(PackageDownloadHandle packageDownloadHandle, string downloadPath)
        {
            Package dynPkg;

            if (packageDownloadHandle.Extract(DynamoViewModel.Model, downloadPath, out dynPkg))
            {
                PackageManagerExtension.PackageLoader.LoadPackages(new List <Package> {
                    dynPkg
                });
                packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Installed;

                if (DebugModes.IsEnabled("DynamoPackageStates"))
                {
                    // Temporary location for setting the package state.
                    // Should be moved somewhere with more visibility into possible errors.
                    dynPkg.PackageState = Package.PackageStates.Loaded;
                }
            }
            else
            {
                packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Error;
                packageDownloadHandle.Error(Resources.MessageInvalidPackage);
            }
        }
Exemple #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, 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);
                    }
                }));
            });
        }
        /// <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)
        {
            Downloads.Add(packageDownloadHandle);

            packageDownloadHandle.DownloadState = PackageDownloadHandle.State.Downloading;

            Task.Factory.StartNew(() =>
            {
                try
                {
                    var pathDl = Model.DownloadPackage(packageDownloadHandle.Header._id,
                                                       packageDownloadHandle.VersionName);

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

                            Package dynPkg;

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

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

                                var loader = DynamoViewModel.Model.Loader;
                                var logger = DynamoViewModel.Model.Logger;
                                var libraryServices = DynamoViewModel.EngineController.LibraryServices;

                                var loadPackageParams = new LoadPackageParams
                                {
                                    Loader = loader,
                                    LibraryServices = libraryServices,
                                    Context = DynamoViewModel.Model.Context,
                                    IsTestMode = DynamoModel.IsTestMode,
                                    CustomNodeManager = DynamoViewModel.Model.CustomNodeManager
                                };

                                downloadPkg.LoadIntoDynamo(loadPackageParams, logger);

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