public void Load(string fileNameAndFilePath, esSettings mainSettings) { userSettings = mainSettings; RootNode = null; Dictionary <int, IProjectNode> parents = new Dictionary <int, IProjectNode>(); using (XmlTextReader reader = new XmlTextReader(fileNameAndFilePath)) { projectFilePath = fileNameAndFilePath; reader.WhitespaceHandling = WhitespaceHandling.None; IProjectNode currentNode = null; reader.Read(); reader.Read(); if (reader.Name != "EntitySpacesProject") { throw new Exception("Invalid Project File: '" + fileNameAndFilePath + "'"); } reader.Read(); currentNode = new esProjectNode2010(); 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(); esSettings2010 theSettings = new esSettings2010(); theSettings.Load(settings); currentNode.Settings = theSettings; // 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; } } } } }
public void Load(string fileNameAndFilePath, esSettings mainSettings) { userSettings = mainSettings; RootNode = null; Dictionary<int, IProjectNode> parents = new Dictionary<int, IProjectNode>(); using (XmlTextReader reader = new XmlTextReader(fileNameAndFilePath)) { projectFilePath = fileNameAndFilePath; reader.WhitespaceHandling = WhitespaceHandling.None; IProjectNode currentNode = null; reader.Read(); reader.Read(); if (reader.Name != "EntitySpacesProject") { throw new Exception("Invalid Project File: '" + fileNameAndFilePath + "'"); } reader.Read(); currentNode = new esProjectNode2010(); 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(); esSettings2010 theSettings = new esSettings2010(); theSettings.Load(settings); currentNode.Settings = theSettings; // 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; } } } } }