Exemple #1
0
 /// <summary>
 /// Gets the Greg PackageVersion object for a specific version of a package
 /// </summary>
 /// <param name="header"></param>
 /// <param name="version"></param>
 /// <returns></returns>
 internal PackageVersion GetGregPackageVersion(PackageHeader header, Version version)
 {
     foreach (var v in header.versions)
     {
         if (new Version(v.version) == version)
         {
             return(v);
         }
     }
     return(null);
 }
 /// <summary>
 /// The class constructor. </summary>
 /// <param name="header">The PackageHeader object describing the element</param>
 public PackageManagerSearchElement(PackageHeader header)
 {
     this.Header = header;
     this.Guid = PackageManagerClient.ExtractFunctionDefinitionGuid(header, 0);
     this.Weight = 1;
     if (header.keywords.Count > 0)
     {
         this.Keywords = String.Join(" ", header.keywords);
     }
     else
     {
         this.Keywords = "";
     }
 }
        /// <summary>
        ///     The class constructor
        /// </summary>
        /// <param name="header">The PackageHeader object describing the element</param>
        public PackageManagerSearchElement(PackageHeader header)
        {
            this.IsExpanded = false;
            this.Header     = header;
            this.Weight     = header.deprecated ? 0.1 : 1;

            if (header.keywords != null && header.keywords.Count > 0)
            {
                this.Keywords = String.Join(" ", header.keywords);
            }
            else
            {
                this.Keywords = "";
            }
            this.Votes = header.votes;
        }
        public void FilterFuturePackages_IEnumerableTuplePackageHeaderPackageVersion_ReturnsCorrectResults()
        {
            var pkgVersion063 = new PackageVersion()
            {
                engine_version = "0.6.3"
            };

            var pkgVersion080 = new PackageVersion()
            {
                engine_version = "0.8.0"
            };

            var pkg063 = new PackageHeader()
            {
                name     = "063",
                versions = new List <PackageVersion>()
                {
                    pkgVersion063
                }
            };

            var pkg080 = new PackageHeader()
            {
                name     = "080",
                versions = new List <PackageVersion>()
                {
                    pkgVersion080
                }
            };

            var pkgList = new List <Tuple <PackageHeader, PackageVersion> >()
            {
                new Tuple <PackageHeader, PackageVersion>(pkg063, pkgVersion063),
                new Tuple <PackageHeader, PackageVersion>(pkg080, pkgVersion080),
            };

            var dynamoVersion   = Version.Parse("0.7.1");
            var filteredPkgList = pkgList.FilterFuturePackages(dynamoVersion);

            Assert.AreEqual(1, filteredPkgList.Count());
            Assert.AreEqual("080", filteredPkgList.First().Item1.name);
        }
        public void FilterFuturePackages_IEnumerableTuplePackageHeaderPackageVersion_ReturnsCorrectResults()
        {
            var pkgVersion063 = new PackageVersion()
            {
                engine_version = "0.6.3"
            };

            var pkgVersion080 = new PackageVersion()
            {
                engine_version = "0.8.0"
            };

            var pkg063 = new PackageHeader()
            {
                name = "063",
                versions = new List<PackageVersion>()
                {
                    pkgVersion063
                }
            };

            var pkg080 = new PackageHeader()
            {
                name = "080",
                versions = new List<PackageVersion>()
                {
                    pkgVersion080
                }
            };

            var pkgList = new List<Tuple<PackageHeader, PackageVersion>>()
            {
                new Tuple<PackageHeader, PackageVersion>(pkg063, pkgVersion063),
                new Tuple<PackageHeader, PackageVersion>(pkg080, pkgVersion080),
            };

            var dynamoVersion = Version.Parse("0.7.1");
            var filteredPkgList = pkgList.FilterFuturePackages(dynamoVersion);

            Assert.AreEqual(1, filteredPkgList.Count());
            Assert.AreEqual("080", filteredPkgList.First().Item1.name);
        }
        internal PackageManagerResult DownloadPackageHeader(string id, out PackageHeader header)
        {
            var pkgDownload = new HeaderDownload(id);

            try
            {
                var response = this.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));
        }
        public bool IsNewestVersion(string packageId, string currentVersion, ref string newerVersion)
        {
            var searchEle = CachedPackageList.FirstOrDefault(x => x.Id == packageId);

            PackageHeader header = null;

            if (searchEle != null)
            {
                header = searchEle.Header;
            }

            if (header == null)
            {
                DownloadPackageHeader(packageId, out header);
            }

            if (header == null)
            {
                return(false);
            }

            return(!PackageUtilities.IsNewerVersion(currentVersion, header._id));
        }
        /// <summary>
        ///     Serialize and save a PackageHeader to the "Packages" directory
        /// </summary>
        /// <param name="pkgHeader"> The PackageHeader object </param>
        public void SavePackageHeader(PackageHeader pkgHeader)
        {
            try
            {
                var m2 = new JsonSerializer();
                string s = m2.Serialize(pkgHeader);

                string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string pluginsPath = Path.Combine(directory, "packages");

                if (!Directory.Exists(pluginsPath))
                    Directory.CreateDirectory(pluginsPath);

                // now save it
                string path = Path.Combine(pluginsPath, pkgHeader.name + ".json");
                File.WriteAllText(path, s);
            }
            catch
            {
                dynSettings.Bench.Dispatcher.BeginInvoke(
                    (Action)
                    (() => dynSettings.Controller.DynamoViewModel.Log(
                        "Failed to write package header information, won't be under source control.")));
            }
        }
        /// <summary>
        ///     Create a PackageVersionUpload object from the given data
        /// </summary>
        /// <param name="funDef"> The function definition for the user-defined node </param>
        /// <param name="packageHeader"> The PackageHeader object </param>
        /// <param name="version"> The version, specified in X.Y.Z form</param>
        /// <param name="description"> A description of the user-defined node </param>
        /// <param name="keywords"> Keywords to describe the user-defined node </param>
        /// <param name="license"> A license string (e.g. "MIT") </param>
        /// <param name="group"> The "group" for the package (e.g. DynamoTutorial) </param>
        /// <returns>Returns null if it fails to get the xmlDoc, otherwise a valid PackageVersionUpload  </returns>
        public PackageVersionUpload GetPackageVersionUpload(FunctionDefinition funDef, PackageHeader packageHeader,
                                                            string version,
                                                            string description, List<string> keywords, string license,
                                                            string group)
        {
            // var group = ((FuncWorkspace) funDef.Workspace).Category;
            string name = funDef.Workspace.Name;
            var xml = dynWorkspaceModel.GetXmlDocFromWorkspace(funDef.Workspace, false);
            if (xml == null) return null;
            var contents = xml.OuterXml;
            string engineVersion = "0.1.0"; //nope
            string engineMetadata = "FunctionDefinitionGuid:" + funDef.FunctionId.ToString();

            var pkg = new PackageVersionUpload(name, version, description, keywords, contents, "dynamo",
                                                engineVersion,
                                                engineMetadata);
            return pkg;
        }
 /// <summary>
 ///     Extract a guid from the engine-meta data string from a PackageHeader
 /// </summary>
 /// <param name="header"> The package header </param>
 /// <param name="versionIndex"> The index of the version to obtain </param>
 /// <returns> Returns the guid if the guid was found, otherwise Guid.Empty. </returns>
 public static Guid ExtractFunctionDefinitionGuid(PackageHeader header, int versionIndex)
 {
     if (versionIndex < 0 || versionIndex >= header.versions.Count)
         return Guid.Empty;
     return ExtractFunctionDefinitionGuid(header.versions[versionIndex].engine_metadata);
 }
 public void Done(PackageHeader ph)
 {
     this.CompletedHeader = ph;
     this.UploadState = State.Uploaded;
 }
        /// <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);
        }
Exemple #13
0
 /// <summary>
 ///     Adds a PackageHeader, recently downloaded from the Package Manager, to Search
 /// </summary>
 /// <param name="packageHeader">A PackageHeader object</param>
 public void Add(PackageHeader packageHeader)
 {
     var searchEle = new PackageManagerSearchElement(packageHeader);
     SearchDictionary.Add(searchEle, searchEle.Name);
     if (packageHeader.keywords != null && packageHeader.keywords.Count > 0)
         SearchDictionary.Add(searchEle, packageHeader.keywords);
     SearchDictionary.Add(searchEle, searchEle.Description);
     SearchAndUpdateResultsSync(SearchText);
 }
 public DynamoPackageDownload(PackageHeader header, string version)
 {
     this.Header = header;
     this.DownloadPath = "";
 }
 public void Done(PackageHeader ph)
 {
     this.CompletedHeader = ph;
     this.UploadState     = State.Uploaded;
 }
        /// <summary>
        ///     The class constructor
        /// </summary>
        /// <param name="header">The PackageHeader object describing the element</param>
        public PackageManagerSearchElement(PackageHeader header)
        {
            this.IsExpanded = false;
            this.Header = header;
            this.Weight = header.deprecated ? 0.1 : 1;

            if (header.keywords != null && header.keywords.Count > 0)
            {
                this.Keywords = String.Join(" ", header.keywords);
            } 
            else
            {
                this.Keywords = "";
            }
            this.Votes = header.votes;
        }
 public DynamoPackageDownload(PackageHeader header, string version)
 {
     this.Header       = header;
     this.DownloadPath = "";
 }