Ejemplo n.º 1
0
 private static string DownloadPackageByIdTest()
 {
     var nv = new PackageDownload("5225e7dde2f476ca05000057");
     var response = pmc.Execute(nv);
     var pathDl = PackageDownload.GetFileFromResponse(response);
     var output = FileUtilities.UnZip(pathDl);
     return pathDl;
 }
Ejemplo n.º 2
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);
                }
            });
        }
Ejemplo n.º 3
0
 internal PackageManagerResult DownloadPackage(string packageId, string version, out string pathToPackage)
 {
     try
     {
         var response = this.client.Execute(new PackageDownload(packageId, version));
         pathToPackage = PackageDownload.GetFileFromResponse(response);
         return(PackageManagerResult.Succeeded());
     }
     catch (Exception e)
     {
         pathToPackage = null;
         return(PackageManagerResult.Failed(e.Message));
     }
 }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
        internal string DownloadPackage(string packageId, string version)
        {
            var response = this.client.Execute(new PackageDownload(packageId, version));

            return(PackageDownload.GetFileFromResponse(response));
        }