Пример #1
0
        private static TemplateProject DeserialiseTemplateProject(XmlNode templateProjectNode)
        {
            TemplateProject project = new TemplateProject();

            var delimiterAtt = templateProjectNode.Attributes["delimiter-style"];

            if (delimiterAtt != null)
            {
                project.Delimiter = (TemplateProject.DelimiterTypes)Enum.Parse(typeof(TemplateProject.DelimiterTypes), delimiterAtt.Value, true);
            }

            foreach (XmlNode folderNode in templateProjectNode.SelectNodes("folder"))
            {
                Folder subFolder = DeserialiseFolder(folderNode);
                subFolder.ParentFolder = project.OutputFolder;
                project.OutputFolder.Folders.Add(subFolder);
            }
            foreach (XmlNode fileNode in templateProjectNode.SelectNodes("file"))
            {
                File file = DeserialiseFile(fileNode);
                file.ParentFolder = project.OutputFolder;
                project.OutputFolder.Files.Add(file);
            }
            foreach (XmlNode fileNode in templateProjectNode.SelectNodes("static-file"))
            {
                StaticFile file = DeserialiseStaticFile(fileNode);
                file.ParentFolder = project.OutputFolder;
                project.OutputFolder.StaticFiles.Add(file);
            }
            return(project);
        }
Пример #2
0
        public static TemplateProject DeserialiseTemplateProject(string xml)
        {
            FolderIdCounter = 2;             // OutputFolder = 1
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            TemplateProject proj = DeserialiseTemplateProject(doc.DocumentElement);

            proj.IsDirty = false;
            return(proj);
        }
        private static void SerialiseTemplateProject(TemplateProject project, XmlWriter writer)
        {
            writer.WriteStartElement("visual-nhibernate-template");
            writer.WriteAttributeString("version", 1.ToString());
            writer.WriteAttributeString("delimiter-style", project.Delimiter.ToString());

            foreach (var subFolder in project.OutputFolder.Folders)
            {
                SerialiseFolder(subFolder, writer);
            }

            foreach (var file in project.OutputFolder.Files)
            {
                SerialiseFile(file, writer);
            }

            foreach (var file in project.OutputFolder.StaticFiles)
            {
                SerialiseStaticFile(file, writer);
            }

            writer.WriteEndElement();
        }
 public static string Serialise(TemplateProject project)
 {
     return(Serialise(writer => SerialiseTemplateProject(project, writer)));
 }