private static void InstallPackage(string value) { if (string.IsNullOrEmpty(value)) { throw new ArgumentNullException("value", "Package to install must not be an empty string."); } if (!System.IO.File.Exists(value)) { throw new ArgumentException("Package file to install must exist.", "value"); } PackagesToInstall.Add(value); }
private void GetDependencies(dynamic version, out List <Tuple <dynamic, dynamic> > packageVersionData) { packageVersionData = new List <Tuple <dynamic, dynamic> >(); // get all of the headers PackageManagerRequest req; string[] depends = version["dependencies"].Split(','); foreach (string depend in depends) { string[] temp = depend.Split('|'); req = new PackageManagerRequest((string.Format("assets/{0}/customdata", temp[0])).Trim(), Method.GET); ResponseWithContentBody <dynamic> response = Client.ExecuteAndDeserializeDynamoRequest(req); var customData = response.content; req = new PackageManagerRequest(("assets/" + temp[0]).Trim(), Method.GET); response = Client.ExecuteAndDeserializeDynamoRequest(req); var depAsset = response.content; if (customData.custom_data.Count > 0) { dynamic versionData; string json; for (int i = 0; i < customData.custom_data.Count; i++) { if (customData.custom_data[i].key == string.Format("version:{0}", temp[1])) { json = System.Uri.UnescapeDataString(customData.custom_data[i].data.ToString()); versionData = JsonConvert.DeserializeObject <dynamic>(json); packageVersionData.Add(new Tuple <dynamic, dynamic>(depAsset, versionData)); PackagesToInstall.Add(string.Format("{0},{1},{2}", temp[0], versionData.file_id.Value, depAsset.asset_name)); } } } } }
/// <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 = MessageBox.Show(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 = Loader.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()) { MessageBox.Show(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)); MessageBox.Show(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 (MessageBox.Show(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)); }