Exemplo n.º 1
0
        /// <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(_node("name", pack.Name, doc));
            package.AppendChild(_node("version", pack.Version, doc));
            
            XmlNode license = _node("license", pack.License, doc);
            license.Attributes.Append(_attribute("url", pack.LicenseUrl, doc));
            package.AppendChild(license);
            
            package.AppendChild(_node("url", pack.Url, doc));
            
            XmlNode Requirements = doc.CreateElement("requirements");
            Requirements.AppendChild(_node("major", "3", doc));
            Requirements.AppendChild(_node("minor", "0", doc));
            Requirements.AppendChild(_node("patch", "0", doc));
            package.AppendChild(Requirements);
            info.AppendChild(package);

            //Author
            XmlNode author = _node("author", "", doc);
            author.AppendChild(_node("name", pack.Author, doc));
            author.AppendChild(_node("website", pack.AuthorUrl, doc));
            info.AppendChild(author);

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

            return info;
        }
Exemplo n.º 2
0
        private static PackageInstance ConvertXmlToPackage(XmlNode n)
        {
            PackageInstance retVal = new 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));

                bool _enableSkins = false;
                bool.TryParse(safeAttribute("enableSkins", n), out _enableSkins);
                retVal.EnableSkins = _enableSkins;

                retVal.SkinRepoGuid = string.IsNullOrEmpty(safeAttribute("skinRepoGuid", n)) ? Guid.Empty : new Guid(safeAttribute("skinRepoGuid", n));

                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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <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(_node("name", pack.Name, doc));
            package.AppendChild(_node("version", pack.Version, doc));

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

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

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

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

            Requirements.AppendChild(_node("major", "3", doc));
            Requirements.AppendChild(_node("minor", "0", doc));
            Requirements.AppendChild(_node("patch", "0", doc));
            package.AppendChild(Requirements);
            info.AppendChild(package);

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

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

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

            return(info);
        }
Exemplo n.º 5
0
        public void Publish()
        {
            CreatedPackage  package = this;
            PackageInstance pack    = package.Data;

            try
            {
                PublishEventArgs e = new PublishEventArgs();
                package.FireBeforePublish(e);

                if (!e.Cancel)
                {
                    int outInt = 0;

                    //Path checking...
                    string localPath = IOHelper.MapPath(SystemDirectories.Media + "/" + pack.Folder);

                    if (!System.IO.Directory.Exists(localPath))
                    {
                        System.IO.Directory.CreateDirectory(localPath);
                    }

                    //Init package file...
                    createPackageManifest();
                    //Info section..
                    appendElement(utill.PackageInfo(pack, _packageManifest));

                    //Documents...
                    int _contentNodeID = 0;
                    if (!String.IsNullOrEmpty(pack.ContentNodeId) && int.TryParse(pack.ContentNodeId, out _contentNodeID))
                    {
                        XmlNode documents = _packageManifest.CreateElement("Documents");

                        XmlNode      documentSet = _packageManifest.CreateElement("DocumentSet");
                        XmlAttribute importMode  = _packageManifest.CreateAttribute("importMode", "");
                        importMode.Value = "root";
                        documentSet.Attributes.Append(importMode);
                        documents.AppendChild(documentSet);

                        //load content from umbraco.
                        cms.businesslogic.web.Document umbDocument = new Document(_contentNodeID);
                        documentSet.AppendChild(umbDocument.ToXml(_packageManifest, pack.ContentLoadChildNodes));

                        appendElement(documents);
                    }

                    //Document types..
                    List <DocumentType> dtl      = new List <DocumentType>();
                    XmlNode             docTypes = _packageManifest.CreateElement("DocumentTypes");
                    foreach (string dtId in pack.Documenttypes)
                    {
                        if (int.TryParse(dtId, out outInt))
                        {
                            DocumentType docT = new DocumentType(outInt);

                            AddDocumentType(docT, ref dtl);
                        }
                    }
                    foreach (DocumentType d in dtl)
                    {
                        docTypes.AppendChild(d.ToXml(_packageManifest));
                    }

                    appendElement(docTypes);

                    //Templates
                    XmlNode templates = _packageManifest.CreateElement("Templates");
                    foreach (string templateId in pack.Templates)
                    {
                        if (int.TryParse(templateId, out outInt))
                        {
                            Template t = new Template(outInt);
                            templates.AppendChild(t.ToXml(_packageManifest));
                        }
                    }
                    appendElement(templates);

                    //Stylesheets
                    XmlNode stylesheets = _packageManifest.CreateElement("Stylesheets");
                    foreach (string ssId in pack.Stylesheets)
                    {
                        if (int.TryParse(ssId, out outInt))
                        {
                            StyleSheet s = new StyleSheet(outInt);
                            stylesheets.AppendChild(s.ToXml(_packageManifest));
                        }
                    }
                    appendElement(stylesheets);

                    //Macros
                    XmlNode macros = _packageManifest.CreateElement("Macros");
                    foreach (string macroId in pack.Macros)
                    {
                        if (int.TryParse(macroId, out outInt))
                        {
                            macros.AppendChild(utill.Macro(int.Parse(macroId), true, localPath, _packageManifest));
                        }
                    }
                    appendElement(macros);

                    //Dictionary Items
                    XmlNode dictionaryItems = _packageManifest.CreateElement("DictionaryItems");
                    foreach (string dictionaryId in pack.DictionaryItems)
                    {
                        if (int.TryParse(dictionaryId, out outInt))
                        {
                            Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(outInt);
                            dictionaryItems.AppendChild(di.ToXml(_packageManifest));
                        }
                    }
                    appendElement(dictionaryItems);

                    //Languages
                    XmlNode languages = _packageManifest.CreateElement("Languages");
                    foreach (string langId in pack.Languages)
                    {
                        if (int.TryParse(langId, out outInt))
                        {
                            language.Language lang = new umbraco.cms.businesslogic.language.Language(outInt);

                            languages.AppendChild(lang.ToXml(_packageManifest));
                        }
                    }
                    appendElement(languages);

                    //Datatypes
                    XmlNode dataTypes = _packageManifest.CreateElement("DataTypes");
                    foreach (string dtId in pack.DataTypes)
                    {
                        if (int.TryParse(dtId, out outInt))
                        {
                            cms.businesslogic.datatype.DataTypeDefinition dtd = new umbraco.cms.businesslogic.datatype.DataTypeDefinition(outInt);
                            dataTypes.AppendChild(dtd.ToXml(_packageManifest));
                        }
                    }
                    appendElement(dataTypes);

                    //Files
                    foreach (string fileName in pack.Files)
                    {
                        utill.AppendFileToManifest(fileName, localPath, _packageManifest);
                    }

                    //Load control on install...
                    if (!string.IsNullOrEmpty(pack.LoadControl))
                    {
                        XmlNode control = _packageManifest.CreateElement("control");
                        control.InnerText = pack.LoadControl;
                        utill.AppendFileToManifest(pack.LoadControl, localPath, _packageManifest);
                        appendElement(control);
                    }

                    //Actions
                    if (!string.IsNullOrEmpty(pack.Actions))
                    {
                        try
                        {
                            XmlDocument xd_actions = new XmlDocument();
                            xd_actions.LoadXml("<Actions>" + pack.Actions + "</Actions>");
                            XmlNode actions = xd_actions.DocumentElement.SelectSingleNode(".");


                            if (actions != null)
                            {
                                actions = _packageManifest.ImportNode(actions, true).Clone();
                                appendElement(actions);
                            }
                        }
                        catch { }
                    }

                    string manifestFileName = localPath + "/package.xml";

                    if (System.IO.File.Exists(manifestFileName))
                    {
                        System.IO.File.Delete(manifestFileName);
                    }

                    _packageManifest.Save(manifestFileName);
                    _packageManifest = null;


                    //string packPath = Settings.PackagerRoot.Replace(System.IO.Path.DirectorySeparatorChar.ToString(), "/") + "/" + pack.Name.Replace(' ', '_') + "_" + pack.Version.Replace(' ', '_') + "." + Settings.PackageFileExtension;

                    // check if there's a packages directory below media
                    string packagesDirectory = SystemDirectories.Media + "/created-packages";
                    if (!System.IO.Directory.Exists(IOHelper.MapPath(packagesDirectory)))
                    {
                        System.IO.Directory.CreateDirectory(IOHelper.MapPath(packagesDirectory));
                    }


                    string packPath = packagesDirectory + "/" + (pack.Name + "_" + pack.Version).Replace(' ', '_') + "." + Settings.PackageFileExtension;
                    utill.ZipPackage(localPath, IOHelper.MapPath(packPath));

                    pack.PackagePath = packPath;

                    if (pack.PackageGuid.Trim() == "")
                    {
                        pack.PackageGuid = Guid.NewGuid().ToString();
                    }

                    package.Save();

                    //Clean up..
                    System.IO.File.Delete(localPath + "/package.xml");
                    System.IO.Directory.Delete(localPath, true);

                    package.FireAfterPublish(e);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error <CreatedPackage>("An error occurred", ex);
            }
        }
Exemplo n.º 6
0
        public static PackageInstance MakeNew(string Name, string dataSource)
        {
            PackageInstance retVal = new PackageInstance();

            try
            {
                Reload(dataSource);

                int _maxId = 1;
                // Find max id
                foreach (XmlNode n in Source.SelectNodes("packages/package"))
                {
                    if (int.Parse(n.Attributes.GetNamedItem("id").Value) >= _maxId)
                        _maxId = int.Parse(n.Attributes.GetNamedItem("id").Value) + 1;
                }

                XmlElement instance = Source.CreateElement("package");
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "id", _maxId.ToString()));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "version", ""));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "url", ""));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "name", Name));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "folder", System.Guid.NewGuid().ToString()));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "packagepath", ""));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "repositoryGuid", ""));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "packageGuid", System.Guid.NewGuid().ToString()));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "hasUpdate", "false"));

                instance.Attributes.Append(xmlHelper.addAttribute(Source, "enableSkins", "false"));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "skinRepoGuid", ""));

                XmlElement license = Source.CreateElement("license");
                license.InnerText = "MIT license";
                license.Attributes.Append(xmlHelper.addAttribute(Source, "url", "http://www.opensource.org/licenses/mit-license.php"));
                instance.AppendChild(license);

                XmlElement author = Source.CreateElement("author");
                author.InnerText = "";
                author.Attributes.Append(xmlHelper.addAttribute(Source, "url", ""));
                instance.AppendChild(author);
                
                instance.AppendChild(xmlHelper.addTextNode(Source, "readme", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "actions", ""));

                instance.AppendChild(xmlHelper.addTextNode(Source, "datatypes", ""));

                XmlElement content = Source.CreateElement("content");
                content.InnerText = "";
                content.Attributes.Append(xmlHelper.addAttribute(Source, "nodeId", ""));
                content.Attributes.Append(xmlHelper.addAttribute(Source, "loadChildNodes", "false"));
                instance.AppendChild(content);

                instance.AppendChild(xmlHelper.addTextNode(Source, "templates", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "stylesheets", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "documenttypes", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "macros", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "files", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "languages", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "dictionaryitems", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "loadcontrol", ""));

                Source.SelectSingleNode("packages").AppendChild(instance);
                Source.Save(dataSource);
                retVal = data.Package(_maxId, dataSource);
            }
            catch (Exception ex)
            {
				LogHelper.Error<data>("An error occurred", ex);
            }

            return retVal;
        }
Exemplo n.º 7
0
		public static void Save(PackageInstance package, string dataSource) 
		{
			try
			{
                Reload(dataSource);
                XmlNode _xmlDef = GetFromId(package.Id, dataSource, false);
                _xmlDef.Attributes.GetNamedItem("name").Value = package.Name;
                _xmlDef.Attributes.GetNamedItem("version").Value = package.Version;
                _xmlDef.Attributes.GetNamedItem("url").Value = package.Url;
                _xmlDef.Attributes.GetNamedItem("packagepath").Value = package.PackagePath;
                _xmlDef.Attributes.GetNamedItem("repositoryGuid").Value = package.RepositoryGuid;
                _xmlDef.Attributes.GetNamedItem("packageGuid").Value = package.PackageGuid;

                _xmlDef.Attributes.GetNamedItem("hasUpdate").Value = package.HasUpdate.ToString();
                _xmlDef.Attributes.GetNamedItem("enableSkins").Value = package.EnableSkins.ToString();
                _xmlDef.Attributes.GetNamedItem("skinRepoGuid").Value = package.SkinRepoGuid.ToString();

                    

                _xmlDef.SelectSingleNode("license").FirstChild.Value = package.License;
                _xmlDef.SelectSingleNode("license").Attributes.GetNamedItem("url").Value = package.LicenseUrl;

                _xmlDef.SelectSingleNode("author").InnerText = package.Author;
                _xmlDef.SelectSingleNode("author").Attributes.GetNamedItem("url").Value = package.AuthorUrl;

                _xmlDef.SelectSingleNode("readme").InnerXml = "<![CDATA[" + package.Readme + "]]>";

                if(_xmlDef.SelectSingleNode("actions") == null)
                    _xmlDef.AppendChild(xmlHelper.addTextNode(Source, "actions", ""));

                _xmlDef.SelectSingleNode("actions").InnerXml = package.Actions;

                _xmlDef.SelectSingleNode("content").Attributes.GetNamedItem("nodeId").Value =  package.ContentNodeId.ToString();
                _xmlDef.SelectSingleNode("content").Attributes.GetNamedItem("loadChildNodes").Value = package.ContentLoadChildNodes.ToString();
                
                _xmlDef.SelectSingleNode("macros").InnerText = joinList(package.Macros, ',');
                _xmlDef.SelectSingleNode("templates").InnerText = joinList(package.Templates, ',');
                _xmlDef.SelectSingleNode("stylesheets").InnerText = joinList(package.Stylesheets, ',');
                _xmlDef.SelectSingleNode("documenttypes").InnerText = joinList(package.Documenttypes, ',');

                _xmlDef.SelectSingleNode("languages").InnerText = joinList(package.Languages, ',');
                _xmlDef.SelectSingleNode("dictionaryitems").InnerText = joinList(package.DictionaryItems, ',');
                _xmlDef.SelectSingleNode("datatypes").InnerText = joinList(package.DataTypes, ',');
                
                _xmlDef.SelectSingleNode("files").InnerXml = "";

                foreach (string fileStr in package.Files) {
                    if(!string.IsNullOrEmpty(fileStr.Trim()))
                        _xmlDef.SelectSingleNode("files").AppendChild(xmlHelper.addTextNode(data.Source, "file", fileStr));
                }

                _xmlDef.SelectSingleNode("loadcontrol").InnerText = package.LoadControl;

                Source.Save(dataSource);

               
            }
			catch(Exception F)
			{
				LogHelper.Error<data>("An error occurred", F);
			}   
			
		}
Exemplo n.º 8
0
        private static PackageInstance ConvertXmlToPackage(XmlNode n) {
            PackageInstance retVal = new 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));

                    bool _enableSkins = false;
                    bool.TryParse(safeAttribute("enableSkins", n), out _enableSkins);
                    retVal.EnableSkins = _enableSkins;

                    retVal.SkinRepoGuid = string.IsNullOrEmpty(safeAttribute("skinRepoGuid", n)) ? Guid.Empty : new Guid(safeAttribute("skinRepoGuid", n));

                    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;
        }
Exemplo n.º 9
0
        public static void Save(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, "enableSkins", package.EnableSkins.ToString());
            XmlHelper.SetAttribute(Source, xmlDef, "skinRepoGuid", package.SkinRepoGuid.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);
        }
Exemplo n.º 10
0
        public static PackageInstance MakeNew(string Name, string dataSource)
        {
            PackageInstance retVal = new PackageInstance();

            try
            {
                Reload(dataSource);

                int _maxId = 1;
                // Find max id
                foreach (XmlNode n in Source.SelectNodes("packages/package"))
                {
                    if (int.Parse(n.Attributes.GetNamedItem("id").Value) >= _maxId)
                    {
                        _maxId = int.Parse(n.Attributes.GetNamedItem("id").Value) + 1;
                    }
                }

                XmlElement instance = Source.CreateElement("package");
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "id", _maxId.ToString()));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "version", ""));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "url", ""));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "name", Name));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "folder", System.Guid.NewGuid().ToString()));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "packagepath", ""));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "repositoryGuid", ""));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "packageGuid", System.Guid.NewGuid().ToString()));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "hasUpdate", "false"));

                instance.Attributes.Append(xmlHelper.addAttribute(Source, "enableSkins", "false"));
                instance.Attributes.Append(xmlHelper.addAttribute(Source, "skinRepoGuid", ""));

                XmlElement license = Source.CreateElement("license");
                license.InnerText = "MIT license";
                license.Attributes.Append(xmlHelper.addAttribute(Source, "url", "http://www.opensource.org/licenses/mit-license.php"));
                instance.AppendChild(license);

                XmlElement author = Source.CreateElement("author");
                author.InnerText = "";
                author.Attributes.Append(xmlHelper.addAttribute(Source, "url", ""));
                instance.AppendChild(author);

                instance.AppendChild(xmlHelper.addTextNode(Source, "readme", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "actions", ""));

                instance.AppendChild(xmlHelper.addTextNode(Source, "datatypes", ""));

                XmlElement content = Source.CreateElement("content");
                content.InnerText = "";
                content.Attributes.Append(xmlHelper.addAttribute(Source, "nodeId", ""));
                content.Attributes.Append(xmlHelper.addAttribute(Source, "loadChildNodes", "false"));
                instance.AppendChild(content);

                instance.AppendChild(xmlHelper.addTextNode(Source, "templates", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "stylesheets", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "documenttypes", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "macros", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "files", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "languages", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "dictionaryitems", ""));
                instance.AppendChild(xmlHelper.addTextNode(Source, "loadcontrol", ""));

                Source.SelectSingleNode("packages").AppendChild(instance);
                Source.Save(dataSource);
                retVal = data.Package(_maxId, dataSource);
            }
            catch (Exception ex)
            {
                LogHelper.Error <data>("An error occurred", ex);
            }

            return(retVal);
        }
Exemplo n.º 11
0
        public static void Save(PackageInstance package, string dataSource)
        {
            try
            {
                Reload(dataSource);
                XmlNode _xmlDef = GetFromId(package.Id, dataSource, false);
                _xmlDef.Attributes.GetNamedItem("name").Value           = package.Name;
                _xmlDef.Attributes.GetNamedItem("version").Value        = package.Version;
                _xmlDef.Attributes.GetNamedItem("url").Value            = package.Url;
                _xmlDef.Attributes.GetNamedItem("packagepath").Value    = package.PackagePath;
                _xmlDef.Attributes.GetNamedItem("repositoryGuid").Value = package.RepositoryGuid;
                _xmlDef.Attributes.GetNamedItem("packageGuid").Value    = package.PackageGuid;

                _xmlDef.Attributes.GetNamedItem("hasUpdate").Value    = package.HasUpdate.ToString();
                _xmlDef.Attributes.GetNamedItem("enableSkins").Value  = package.EnableSkins.ToString();
                _xmlDef.Attributes.GetNamedItem("skinRepoGuid").Value = package.SkinRepoGuid.ToString();



                _xmlDef.SelectSingleNode("license").FirstChild.Value = package.License;
                _xmlDef.SelectSingleNode("license").Attributes.GetNamedItem("url").Value = package.LicenseUrl;

                _xmlDef.SelectSingleNode("author").InnerText = package.Author;
                _xmlDef.SelectSingleNode("author").Attributes.GetNamedItem("url").Value = package.AuthorUrl;

                _xmlDef.SelectSingleNode("readme").InnerXml = "<![CDATA[" + package.Readme + "]]>";

                if (_xmlDef.SelectSingleNode("actions") == null)
                {
                    _xmlDef.AppendChild(xmlHelper.addTextNode(Source, "actions", ""));
                }

                _xmlDef.SelectSingleNode("actions").InnerXml = package.Actions;

                _xmlDef.SelectSingleNode("content").Attributes.GetNamedItem("nodeId").Value         = package.ContentNodeId.ToString();
                _xmlDef.SelectSingleNode("content").Attributes.GetNamedItem("loadChildNodes").Value = package.ContentLoadChildNodes.ToString();

                _xmlDef.SelectSingleNode("macros").InnerText        = joinList(package.Macros, ',');
                _xmlDef.SelectSingleNode("templates").InnerText     = joinList(package.Templates, ',');
                _xmlDef.SelectSingleNode("stylesheets").InnerText   = joinList(package.Stylesheets, ',');
                _xmlDef.SelectSingleNode("documenttypes").InnerText = joinList(package.Documenttypes, ',');

                _xmlDef.SelectSingleNode("languages").InnerText       = joinList(package.Languages, ',');
                _xmlDef.SelectSingleNode("dictionaryitems").InnerText = joinList(package.DictionaryItems, ',');
                _xmlDef.SelectSingleNode("datatypes").InnerText       = joinList(package.DataTypes, ',');

                _xmlDef.SelectSingleNode("files").InnerXml = "";

                foreach (string fileStr in package.Files)
                {
                    if (!string.IsNullOrEmpty(fileStr.Trim()))
                    {
                        _xmlDef.SelectSingleNode("files").AppendChild(xmlHelper.addTextNode(data.Source, "file", fileStr));
                    }
                }

                _xmlDef.SelectSingleNode("loadcontrol").InnerText = package.LoadControl;

                Source.Save(dataSource);
            }
            catch (Exception F)
            {
                LogHelper.Error <data>("An error occurred", F);
            }
        }