private static void DownloadDynamoPackageByIdTest() { var nv = new HeaderDownload("51eccaac7fa5b0146b000005"); var pkgResponse = pmc.ExecuteAndDeserializeWithContent<PackageHeader>(nv); //var pkgResponse = pmc.Execute(nv); Console.WriteLine(pkgResponse.content.name); // the package }
/// <summary> /// Asynchronously download a specific user-defined node from the server /// </summary> /// <param name="id"> The id that uniquely defines the package, usually obtained from a PackageHeader </param> /// <param name="version"> A version name for the download </param> /// <param name="callback"> Delegate to execute upon receiving the package </param> public void Download(string id, string version, Action<Guid> callback) { ThreadStart start = () => { // download the package var m = new HeaderDownload(id); ResponseWithContentBody<PackageHeader> p = Client.ExecuteAndDeserializeWithContent<PackageHeader>(m); // then save it to a file in packages var d = new XmlDocument(); d.LoadXml(p.content.versions[p.content.versions.Count-1].contents); // obtain the funcDefGuid Guid funcDefGuid = ExtractFunctionDefinitionGuid(p.content, 0); if (Guid.Empty == funcDefGuid) { return; } // for which we need to create path string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (directory == null) { throw new DirectoryNotFoundException(); } string pluginsPath = Path.Combine(directory, "definitions"); try { if (!Directory.Exists(pluginsPath)) Directory.CreateDirectory(pluginsPath); // now save it string path = Path.Combine(pluginsPath, p.content.name + ".dyf"); d.Save(path); SavePackageHeader(p.content); dynSettings.Bench.Dispatcher.BeginInvoke((Action) (() => { Controller.DynamoViewModel.OpenDefinition(path); dynSettings.Controller.DynamoViewModel.Log("Successfully imported package " + p.content.name); callback(funcDefGuid); })); } catch { dynSettings.Bench.Dispatcher.BeginInvoke( (Action) (() => dynSettings.Controller.DynamoViewModel.Log("Failed to load package " + p.content.name))); } }; new Thread(start).Start(); }
/// <summary> /// Synchronously download a package header /// </summary> /// <param name="id"></param> /// <param name="header"></param> /// <returns></returns> public PackageManagerResult DownloadPackageHeader(string id, out PackageHeader header) { var pkgDownload = new HeaderDownload(id); try { var response = Client.ExecuteAndDeserializeWithContent<PackageHeader>(pkgDownload); if (!response.success) throw new Exception(response.message); header = response.content; } catch (Exception e) { var a = PackageManagerResult.Failed(e.Message); header = null; return a; } return new PackageManagerResult("", true); }
private static void DownloadDynamoPackageByEngineAndNameTest() { var nv = new HeaderDownload("dynamo", "Third .NET Package"); var pkgResponse = pmc.ExecuteAndDeserializeWithContent<PackageHeader>(nv); Console.WriteLine(pkgResponse.content); // the package }