private void EndWriteNode(esProjectNode node, XmlWriter writer) { if (node.IsFolder) { writer.WriteEndElement(); } }
private void Save(esProjectNode node, XmlTextWriter writer) { BeginWriteNode(node, writer); foreach (esProjectNode childNode in node.Children) { Save(childNode, writer); } EndWriteNode(node, writer); }
private void ExecuteRecordedTemplate(esProjectNode node) { try { if (node != null && !node.IsFolder) { Root esMeta = Create(node.Settings as esSettings); esMeta.Input = node.Input; Template template = new Template(); template.Execute(esMeta, node.Template.Header.FullFileName); } } catch (Exception ex) { errors.Add(ex); } }
private void ExecuteRecordedTemplates(esProjectNode node) { try { ExecuteRecordedTemplate(node); foreach (esProjectNode childNode in node.Children) { ExecuteRecordedTemplates(childNode); } } catch (Exception ex) { errors.Add(ex); } }
public void Load(string fileNameAndFilePath, esSettings mainSettings) { userSettings = mainSettings; string version = GetFileVersion(fileNameAndFilePath); if (version != null && version.Substring(0, 4) != "2011" && version.Substring(0, 4) != "2012") { // Convert the old project file in place ConvertProject(fileNameAndFilePath, mainSettings); } RootNode = null; Dictionary <int, esProjectNode> parents = new Dictionary <int, esProjectNode>(); using (XmlTextReader reader = new XmlTextReader(fileNameAndFilePath)) { projectFilePath = fileNameAndFilePath; reader.WhitespaceHandling = WhitespaceHandling.None; esProjectNode currentNode = null; reader.Read(); reader.Read(); if (reader.Name != "EntitySpacesProject") { throw new Exception("Invalid Project File: '" + fileNameAndFilePath + "'"); } reader.Read(); currentNode = new esProjectNode(); currentNode.Name = reader.GetAttribute("Name"); RootNode = currentNode; parents[reader.Depth] = currentNode; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case "Folder": currentNode = new esProjectNode(); currentNode.Name = reader.GetAttribute("Name"); parents[reader.Depth - 1].Children.Add(currentNode); parents[reader.Depth] = currentNode; break; case "RecordedTemplate": currentNode = new esProjectNode(); currentNode.Name = reader.GetAttribute("Name"); currentNode.IsFolder = false; int depth = reader.Depth; // <Template> reader.Read(); currentNode.Template = new Template(); // Path fixup to the template string path = reader.GetAttribute("Path"); path = path.Replace("{fixup}", userSettings.TemplatePath); path = path.Replace("\\\\", "\\"); currentNode.Template.Parse(path); // <Input> reader.Read(); XmlReader input = reader.ReadSubtree(); input.Read(); currentNode.Input = new Hashtable(); while (input.Read()) { string type = input.GetAttribute("Type"); string key = input.GetAttribute("Key"); string value = input.GetAttribute("Value"); if (key == "OutputPath") { value = FixupTheFixup(this.projectFilePath, value); } switch (type) { case "(null)": currentNode.Input[key] = null; break; case "System.String": currentNode.Input[key] = value; break; case "System.Char": currentNode.Input[key] = Convert.ToChar(value); break; case "System.DateTime": currentNode.Input[key] = Convert.ToDateTime(value); break; case "System.Decimal": currentNode.Input[key] = Convert.ToDecimal(value); break; case "System.Double": currentNode.Input[key] = Convert.ToDouble(value); break; case "System.Boolean": currentNode.Input[key] = Convert.ToBoolean(value); break; case "System.Int16": currentNode.Input[key] = Convert.ToInt16(value); break; case "System.Int32": currentNode.Input[key] = Convert.ToInt32(value); break; case "System.Int64": currentNode.Input[key] = Convert.ToInt64(value); break; case "System.Collections.ArrayList": ArrayList list = new ArrayList(); string[] items = value.Split(','); foreach (string item in items) { list.Add(item); } currentNode.Input[key] = list; break; } } // <Settings> reader.Read(); XmlReader settings = reader.ReadSubtree(); currentNode.Settings = new esSettings(); currentNode.Settings = esSettings.Load(settings); // Fixup Settings ... currentNode.Settings.TemplatePath = userSettings.TemplatePath; currentNode.Settings.OutputPath = userSettings.OutputPath; currentNode.Settings.UIAssemblyPath = userSettings.UIAssemblyPath; currentNode.Settings.CompilerAssemblyPath = userSettings.CompilerAssemblyPath; currentNode.Settings.LanguageMappingFile = userSettings.LanguageMappingFile; currentNode.Settings.UserMetadataFile = userSettings.UserMetadataFile; parents[depth - 1].Children.Add(currentNode); break; } } } } }
private void BeginWriteNode(esProjectNode node, XmlTextWriter writer) { if (node.IsFolder) { writer.WriteStartElement("Folder"); writer.WriteAttributeString("Name", node.Name); } else { writer.WriteStartElement("RecordedTemplate"); writer.WriteAttributeString("Name", node.Name); writer.WriteStartElement("Template"); writer.WriteAttributeString("Name", node.Template.Header.Title); writer.WriteAttributeString("Path", node.Template.Header.FullFileName.Replace(userSettings.TemplatePath, "{fixup}")); writer.WriteAttributeString("Version", node.Template.Header.Version); writer.WriteEndElement(); writer.WriteStartElement("Input"); if (node.Input.Count > 0) { foreach (string key in node.Input.Keys) { object value = node.Input[key]; if (key == "OutputPath") { value = this.CreateFixup(this.projectFilePath, (string)value); } if (value == null) { writer.WriteStartElement("Item"); writer.WriteAttributeString("Type", "(null)"); writer.WriteAttributeString("Key", key); writer.WriteEndElement(); continue; } string typeName = value.GetType().FullName; writer.WriteStartElement("Item"); writer.WriteAttributeString("Type", typeName); writer.WriteAttributeString("Key", key); switch (typeName) { case "System.Collections.ArrayList": ArrayList list = value as ArrayList; string values = ""; string comma = ""; foreach (string s in list) { values += comma; values += s; comma = ","; } writer.WriteAttributeString("Value", values); break; default: writer.WriteAttributeString("Value", value.ToString()); break; } writer.WriteEndElement(); } } writer.WriteEndElement(); // Save these off so we can restore them string bakTemplatePath = node.Settings.TemplatePath; string bakOutputPath = node.Settings.OutputPath; string bakUIAssemblyPath = node.Settings.UIAssemblyPath; string bakCompilerAssemblyPath = node.Settings.CompilerAssemblyPath; string bakLanguageMappingFile = node.Settings.LanguageMappingFile; string bakUserMetadataFile = node.Settings.UserMetadataFile; // Remove Hard coded Paths node.Settings.TemplatePath = "{fixup}"; node.Settings.OutputPath = "{fixup}"; node.Settings.UIAssemblyPath = "{fixup}"; node.Settings.CompilerAssemblyPath = "{fixup}"; node.Settings.LanguageMappingFile = "{fixup}"; node.Settings.UserMetadataFile = "{fixup}"; // Now write it node.Settings.Save(writer); writer.WriteEndElement(); // Restore the original values node.Settings.TemplatePath = bakTemplatePath; node.Settings.OutputPath = bakOutputPath; node.Settings.UIAssemblyPath = bakUIAssemblyPath; node.Settings.CompilerAssemblyPath = bakCompilerAssemblyPath; node.Settings.LanguageMappingFile = bakLanguageMappingFile; node.Settings.UserMetadataFile = bakUserMetadataFile; } }
public void Load(string fileNameAndFilePath, esSettings mainSettings) { userSettings = mainSettings; string version = GetFileVersion(fileNameAndFilePath); if (version != null && version.Substring(0, 4) != "2011" && version.Substring(0, 4) != "2012") { // Convert the old project file in place ConvertProject(fileNameAndFilePath, mainSettings); } RootNode = null; Dictionary<int, esProjectNode> parents = new Dictionary<int, esProjectNode>(); using (XmlTextReader reader = new XmlTextReader(fileNameAndFilePath)) { projectFilePath = fileNameAndFilePath; reader.WhitespaceHandling = WhitespaceHandling.None; esProjectNode currentNode = null; reader.Read(); reader.Read(); if (reader.Name != "EntitySpacesProject") { throw new Exception("Invalid Project File: '" + fileNameAndFilePath + "'"); } reader.Read(); currentNode = new esProjectNode(); currentNode.Name = reader.GetAttribute("Name"); RootNode = currentNode; parents[reader.Depth] = currentNode; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case "Folder": currentNode = new esProjectNode(); currentNode.Name = reader.GetAttribute("Name"); parents[reader.Depth - 1].Children.Add(currentNode); parents[reader.Depth] = currentNode; break; case "RecordedTemplate": currentNode = new esProjectNode(); currentNode.Name = reader.GetAttribute("Name"); currentNode.IsFolder = false; int depth = reader.Depth; // <Template> reader.Read(); currentNode.Template = new Template(); // Path fixup to the template string path = reader.GetAttribute("Path"); path = path.Replace("{fixup}", userSettings.TemplatePath); path = path.Replace("\\\\", "\\"); currentNode.Template.Parse(path); // <Input> reader.Read(); XmlReader input = reader.ReadSubtree(); input.Read(); currentNode.Input = new Hashtable(); while (input.Read()) { string type = input.GetAttribute("Type"); string key = input.GetAttribute("Key"); string value = input.GetAttribute("Value"); if (key == "OutputPath") { value = FixupTheFixup(this.projectFilePath, value); } switch (type) { case "(null)": currentNode.Input[key] = null; break; case "System.String": currentNode.Input[key] = value; break; case "System.Char": currentNode.Input[key] = Convert.ToChar(value); break; case "System.DateTime": currentNode.Input[key] = Convert.ToDateTime(value); break; case "System.Decimal": currentNode.Input[key] = Convert.ToDecimal(value); break; case "System.Double": currentNode.Input[key] = Convert.ToDouble(value); break; case "System.Boolean": currentNode.Input[key] = Convert.ToBoolean(value); break; case "System.Int16": currentNode.Input[key] = Convert.ToInt16(value); break; case "System.Int32": currentNode.Input[key] = Convert.ToInt32(value); break; case "System.Int64": currentNode.Input[key] = Convert.ToInt64(value); break; case "System.Collections.ArrayList": ArrayList list = new ArrayList(); string[] items = value.Split(','); foreach (string item in items) { list.Add(item); } currentNode.Input[key] = list; break; } } // <Settings> reader.Read(); XmlReader settings = reader.ReadSubtree(); currentNode.Settings = new esSettings(); currentNode.Settings = esSettings.Load(settings); // Fixup Settings ... currentNode.Settings.TemplatePath = userSettings.TemplatePath; currentNode.Settings.OutputPath = userSettings.OutputPath; currentNode.Settings.UIAssemblyPath = userSettings.UIAssemblyPath; currentNode.Settings.CompilerAssemblyPath = userSettings.CompilerAssemblyPath; currentNode.Settings.LanguageMappingFile = userSettings.LanguageMappingFile; currentNode.Settings.UserMetadataFile = userSettings.UserMetadataFile; parents[depth - 1].Children.Add(currentNode); break; } } } } }
private void ConvertTreeToProject(esProjectNode esParentNode, TreeNode node) { esProjectNode esNode = new esProjectNode(); esNode.Name = node.Text; if (esParentNode == null) { project.RootNode = esNode; } else { esParentNode.Children.Add(esNode); } if (node.Tag != null) { ProjectNodeData tag = node.Tag as ProjectNodeData; esNode.Template = tag.Template; esNode.Settings = tag.Settings; esNode.Input = tag.Input; esNode.IsFolder = false; } foreach (TreeNode childNode in node.Nodes) { ConvertTreeToProject(esNode, childNode); } }
private void ConvertProjectToTree(TreeNode parentNode, esProjectNode esNode) { TreeNode node = null; if (parentNode == null) { node = this.projectTree.Nodes.Add(esNode.Name); } else { node = parentNode.Nodes.Add(esNode.Name); } if(!esNode.IsFolder) { ProjectNodeData tag = new ProjectNodeData(); tag.Template = esNode.Template; tag.Settings = esNode.Settings; tag.Input = esNode.Input; node.Tag = tag; node.ImageIndex = 2; node.SelectedImageIndex = 2; node.ContextMenuStrip = menuTemplate; node.ToolTipText = esNode.Template.Header.Description + " (" + node.FullPath + ")"; } foreach (esProjectNode childNode in esNode.Children) { ConvertProjectToTree(node, childNode); } }