Example #1
0
        private static PackageInstance.PackageInstance ConvertXmlToPackage(XmlNode n)
        {
            PackageInstance.PackageInstance retVal = new PackageInstance.PackageInstance();

            if (n != null)
            {
                retVal.Id             = int.Parse(SafeAttribute("id", n));
                retVal.Name           = SafeAttribute("name", n);
                retVal.Folder         = SafeAttribute("folder", n);
                retVal.PackagePath    = SafeAttribute("packagepath", n);
                retVal.Version        = SafeAttribute("version", n);
                retVal.Url            = SafeAttribute("url", n);
                retVal.RepositoryGuid = SafeAttribute("repositoryGuid", n);
                retVal.PackageGuid    = SafeAttribute("packageGuid", n);
                retVal.HasUpdate      = bool.Parse(SafeAttribute("hasUpdate", n));

                retVal.IconUrl = SafeAttribute("iconUrl", n);
                var     umbVersion = SafeAttribute("umbVersion", n);
                Version parsedVersion;
                if (umbVersion.IsNullOrWhiteSpace() == false && Version.TryParse(umbVersion, out parsedVersion))
                {
                    retVal.UmbracoVersion = parsedVersion;
                }

                retVal.License    = SafeNodeValue(n.SelectSingleNode("license"));
                retVal.LicenseUrl = n.SelectSingleNode("license").Attributes.GetNamedItem("url").Value;

                retVal.Author    = SafeNodeValue(n.SelectSingleNode("author"));
                retVal.AuthorUrl = SafeAttribute("url", n.SelectSingleNode("author"));

                retVal.Readme  = SafeNodeValue(n.SelectSingleNode("readme"));
                retVal.Actions = SafeNodeInnerXml(n.SelectSingleNode("actions"));

                retVal.ContentNodeId         = SafeAttribute("nodeId", n.SelectSingleNode("content"));
                retVal.ContentLoadChildNodes = bool.Parse(SafeAttribute("loadChildNodes", n.SelectSingleNode("content")));

                retVal.Macros          = new List <string>(SafeNodeValue(n.SelectSingleNode("macros")).Trim(',').Split(','));
                retVal.Macros          = new List <string>(SafeNodeValue(n.SelectSingleNode("macros")).Trim(',').Split(','));
                retVal.Templates       = new List <string>(SafeNodeValue(n.SelectSingleNode("templates")).Trim(',').Split(','));
                retVal.Stylesheets     = new List <string>(SafeNodeValue(n.SelectSingleNode("stylesheets")).Trim(',').Split(','));
                retVal.Documenttypes   = new List <string>(SafeNodeValue(n.SelectSingleNode("documenttypes")).Trim(',').Split(','));
                retVal.Languages       = new List <string>(SafeNodeValue(n.SelectSingleNode("languages")).Trim(',').Split(','));
                retVal.DictionaryItems = new List <string>(SafeNodeValue(n.SelectSingleNode("dictionaryitems")).Trim(',').Split(','));
                retVal.DataTypes       = new List <string>(SafeNodeValue(n.SelectSingleNode("datatypes")).Trim(',').Split(','));

                XmlNodeList xmlFiles = n.SelectNodes("files/file");
                retVal.Files = new List <string>();

                for (int i = 0; i < xmlFiles.Count; i++)
                {
                    retVal.Files.Add(xmlFiles[i].InnerText);
                }

                retVal.LoadControl = SafeNodeValue(n.SelectSingleNode("loadcontrol"));
            }

            return(retVal);
        }
        /// <summary>
        /// Creates a package manifest containing name, license, version and other meta data.
        /// </summary>
        /// <param name="pack">The packinstance.</param>
        /// <param name="doc">The xml document.</param>
        /// <returns></returns>
        public static XmlNode PackageInfo(PackageInstance pack, XmlDocument doc)
        {
            XmlNode info = doc.CreateElement("info");

            //Package info
            XmlNode package = doc.CreateElement("package");

            package.AppendChild(CreateNode("name", pack.Name, doc));
            package.AppendChild(CreateNode("version", pack.Version, doc));
            package.AppendChild(CreateNode("iconUrl", pack.IconUrl, doc));

            XmlNode license = CreateNode("license", pack.License, doc);

            license.Attributes.Append(CreateAttribute("url", pack.LicenseUrl, doc));
            package.AppendChild(license);

            package.AppendChild(CreateNode("url", pack.Url, doc));

            XmlNode requirements = doc.CreateElement("requirements");

            //NOTE: The defaults are 3.0.0 - I'm just leaving that here since that's the way it's been //SD
            requirements.AppendChild(CreateNode("major", pack.UmbracoVersion == null ? "3" : pack.UmbracoVersion.Major.ToInvariantString(), doc));
            requirements.AppendChild(CreateNode("minor", pack.UmbracoVersion == null ? "0" : pack.UmbracoVersion.Minor.ToInvariantString(), doc));
            requirements.AppendChild(CreateNode("patch", pack.UmbracoVersion == null ? "0" : pack.UmbracoVersion.Build.ToInvariantString(), doc));
            if (pack.UmbracoVersion != null)
            {
                requirements.Attributes.Append(CreateAttribute("type", "strict", doc));
            }

            package.AppendChild(requirements);
            info.AppendChild(package);

            //Author
            XmlNode author = CreateNode("author", "", doc);

            author.AppendChild(CreateNode("name", pack.Author, doc));
            author.AppendChild(CreateNode("website", pack.AuthorUrl, doc));
            info.AppendChild(author);

            info.AppendChild(CreateNode("readme", "<![CDATA[" + pack.Readme + "]]>", doc));

            return(info);
        }
Example #3
0
        public static void Save(PackageInstance.PackageInstance package, string dataSource)
        {
            Reload(dataSource);
            var xmlDef = GetFromId(package.Id, dataSource, false);

            XmlHelper.SetAttribute(Source, xmlDef, "name", package.Name);
            XmlHelper.SetAttribute(Source, xmlDef, "version", package.Version);
            XmlHelper.SetAttribute(Source, xmlDef, "url", package.Url);
            XmlHelper.SetAttribute(Source, xmlDef, "packagepath", package.PackagePath);
            XmlHelper.SetAttribute(Source, xmlDef, "repositoryGuid", package.RepositoryGuid);
            XmlHelper.SetAttribute(Source, xmlDef, "packageGuid", package.PackageGuid);
            XmlHelper.SetAttribute(Source, xmlDef, "hasUpdate", package.HasUpdate.ToString());
            XmlHelper.SetAttribute(Source, xmlDef, "iconUrl", package.IconUrl);
            if (package.UmbracoVersion != null)
            {
                XmlHelper.SetAttribute(Source, xmlDef, "umbVersion", package.UmbracoVersion.ToString(3));
            }

            var licenseNode = xmlDef.SelectSingleNode("license");

            if (licenseNode == null)
            {
                licenseNode = Source.CreateElement("license");
                xmlDef.AppendChild(licenseNode);
            }
            licenseNode.InnerText = package.License;
            XmlHelper.SetAttribute(Source, licenseNode, "url", package.LicenseUrl);

            var authorNode = xmlDef.SelectSingleNode("author");

            if (authorNode == null)
            {
                authorNode = Source.CreateElement("author");
                xmlDef.AppendChild(authorNode);
            }
            authorNode.InnerText = package.Author;
            XmlHelper.SetAttribute(Source, authorNode, "url", package.AuthorUrl);

            XmlHelper.SetCDataNode(Source, xmlDef, "readme", package.Readme);
            XmlHelper.SetInnerXmlNode(Source, xmlDef, "actions", package.Actions);

            var contentNode = xmlDef.SelectSingleNode("content");

            if (contentNode == null)
            {
                contentNode = Source.CreateElement("content");
                xmlDef.AppendChild(contentNode);
            }
            XmlHelper.SetAttribute(Source, contentNode, "nodeId", package.ContentNodeId);
            XmlHelper.SetAttribute(Source, contentNode, "loadChildNodes", package.ContentLoadChildNodes.ToString());

            XmlHelper.SetTextNode(Source, xmlDef, "macros", JoinList(package.Macros, ','));
            XmlHelper.SetTextNode(Source, xmlDef, "templates", JoinList(package.Templates, ','));
            XmlHelper.SetTextNode(Source, xmlDef, "stylesheets", JoinList(package.Stylesheets, ','));
            XmlHelper.SetTextNode(Source, xmlDef, "documenttypes", JoinList(package.Documenttypes, ','));
            XmlHelper.SetTextNode(Source, xmlDef, "languages", JoinList(package.Languages, ','));
            XmlHelper.SetTextNode(Source, xmlDef, "dictionaryitems", JoinList(package.DictionaryItems, ','));
            XmlHelper.SetTextNode(Source, xmlDef, "datatypes", JoinList(package.DataTypes, ','));

            var filesNode = xmlDef.SelectSingleNode("files");

            if (filesNode == null)
            {
                filesNode = Source.CreateElement("files");
                xmlDef.AppendChild(filesNode);
            }
            filesNode.InnerXml = "";

            foreach (var fileStr in package.Files)
            {
                if (string.IsNullOrWhiteSpace(fileStr) == false)
                {
                    filesNode.AppendChild(XmlHelper.AddTextNode(Source, "file", fileStr));
                }
            }

            XmlHelper.SetTextNode(Source, xmlDef, "loadcontrol", package.LoadControl);

            Source.Save(dataSource);
        }