/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:FdoGenerate"/> class. /// </summary> /// <param name="doc">The XMI document.</param> /// <param name="outputDir">The output dir.</param> /// <param name="outputFile">The output file name.</param> /// ------------------------------------------------------------------------------------ public FdoGenerate(XmlDocument doc, string outputDir, string outputFile) { FdoGenerate.Generator = this; m_Document = doc; m_OutputDir = outputDir; m_OutputFileName = outputFile; XmlElement entireModel = (XmlElement)doc.GetElementsByTagName("EntireModel")[0]; m_Model = new Model(entireModel); m_Engine = new VelocityEngine(); m_Engine.Init(); m_Context = new VelocityContext(); m_Context.Put("fdogenerate", this); m_Context.Put("model", m_Model); RuntimeSingleton.RuntimeServices.SetApplicationAttribute("FdoGenerate.Engine", m_Engine); RuntimeSingleton.RuntimeServices.SetApplicationAttribute("FdoGenerate.Context", m_Context); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Executes the task. /// </summary> /// ------------------------------------------------------------------------------------ protected override void ExecuteTask() { string oldDir = Directory.GetCurrentDirectory(); try { var doc = new XmlDocument(); try { if (Path.GetDirectoryName(m_templateFile).Length > 0) { Directory.SetCurrentDirectory(Path.GetDirectoryName(m_templateFile)); } Log(Level.Verbose, "Loading XML file {0}.", XmlFile); doc.Load(XmlFile); } catch (XmlException e) { throw new BuildException("Error loading XML file", e); } var config = new XmlDocument(); var handGeneratedClasses = new Dictionary <string, List <string> >(); try { Log(Level.Verbose, "Loading hand generated classes from \"HandGenerated.xml\"."); config.Load("HandGenerated.xml"); foreach (XmlElement node in config.GetElementsByTagName("Class")) { var props = new List <string>(); // ReSharper disable PossibleNullReferenceException foreach (XmlNode propertyNode in node.SelectNodes("property")) // ReSharper restore PossibleNullReferenceException { props.Add(propertyNode.Attributes["name"].Value); } if (props.Count > 0) { handGeneratedClasses.Add(node.Attributes["id"].Value, props); } } } catch (XmlException e) { throw new BuildException("Error loading hand generated classes", e); } // Dictionary<ClassName, Property> var intPropTypeOverridesClasses = new Dictionary <string, Dictionary <string, string> >(); try { Log(Level.Verbose, "Loading hand generated classes from \"IntPropTypeOverrides.xml\"."); config.Load("IntPropTypeOverrides.xml"); foreach (XmlElement node in config.GetElementsByTagName("Class")) { // Dictionary<PropertyName, PropertyType> var props = new Dictionary <string, string>(); // ReSharper disable PossibleNullReferenceException foreach (XmlNode propertyNode in node.SelectNodes("property")) // ReSharper restore PossibleNullReferenceException { props.Add(propertyNode.Attributes["name"].Value, propertyNode.Attributes["type"].Value); } if (props.Count > 0) { intPropTypeOverridesClasses.Add(node.Attributes["id"].Value, props); } } } catch (XmlException e) { throw new BuildException("Error loading IntPropTypeOverrides classes", e); } try { // Remember current directory. var originalCurrentDirectory = Directory.GetCurrentDirectory(); Log(Level.Verbose, "Processing template {0}.", m_templateFile); var fdoGenerate = new FdoGenerate(doc, OutputDir) { Overrides = handGeneratedClasses, IntPropTypeOverrides = intPropTypeOverridesClasses }; // Generate the main code. fdoGenerate.SetOutput(OutputFile); fdoGenerate.Process(Path.GetFileName(m_templateFile)); // Generate flat DB SQL for SqlServer. // 'Flat' here means one table per concrete class in the model. //fdoGenerate.SetOutput("BootstrapFlatlandSqlServerDB.sql"); //fdoGenerate.Process("FlatlandSqlServer.vm.sql"); // Generate flat DB SQL for Firebird. // 'Flat' here means one table per concrete class in the model. //fdoGenerate.SetOutput("BootstrapFlatlandFirebirdDB.sql"); //fdoGenerate.Process("FlatlandFirebird.vm.sql"); // Generate the backend provider(s) code. if (!string.IsNullOrEmpty(BackendTemplateFiles)) { foreach (var backendDir in BackendTemplateFiles.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { var beDir = backendDir.Trim(); if (beDir == string.Empty) { continue; } var curDir = Path.Combine(Path.Combine(OutputDir, "FDOGenerate"), beDir); Directory.SetCurrentDirectory(curDir); fdoGenerate.SetOutput(Path.Combine(beDir, beDir + @"Generated.cs")); fdoGenerate.Process("Main" + beDir + ".vm.cs"); } } // Restore original directory. Directory.SetCurrentDirectory(originalCurrentDirectory); } catch (Exception e) { throw new BuildException("Error processing template", e); } } finally { Directory.SetCurrentDirectory(oldDir); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Executes the task. /// </summary> /// ------------------------------------------------------------------------------------ protected override void ExecuteTask() { string oldDir = Directory.GetCurrentDirectory(); try { XmlDocument doc = new XmlDocument(); try { if (Path.GetDirectoryName(m_templateFile).Length > 0) Directory.SetCurrentDirectory(Path.GetDirectoryName(m_templateFile)); Log(Level.Verbose, "Loading XMI file {0}.", XMIFile); doc.Load(XMIFile); } catch (XmlException e) { throw new BuildException("Error loading XMI file", e); } XmlDocument config = new XmlDocument(); Dictionary<string, List<string>> handGeneratedClasses = new Dictionary<string, List<string>>(); try { Log(Level.Verbose, "Loading hand generated classes from \"HandGenerated.xml\"."); config.Load("HandGenerated.xml"); foreach (XmlElement node in config.GetElementsByTagName("Class")) { List<string> props = new List<string>(); foreach (XmlNode propertyNode in node.SelectNodes("property")) { props.Add(propertyNode.Attributes["name"].Value); } if (props.Count > 0) { handGeneratedClasses.Add(node.Attributes["id"].Value, props); } } } catch (XmlException e) { throw new BuildException("Error loading hand generated classes", e); } // Dictionary<ClassName, Property> Dictionary<string, Dictionary<string, string>> intPropTypeOverridesClasses = new Dictionary<string, Dictionary<string, string>>(); try { Log(Level.Verbose, "Loading hand generated classes from \"IntPropTypeOverrides.xml\"."); config.Load("IntPropTypeOverrides.xml"); foreach (XmlElement node in config.GetElementsByTagName("Class")) { // Dictionary<PropertyName, PropertyType> Dictionary<string, string> props = new Dictionary<string, string>(); foreach (XmlNode propertyNode in node.SelectNodes("property")) { props.Add(propertyNode.Attributes["name"].Value, propertyNode.Attributes["type"].Value); } if (props.Count > 0) { intPropTypeOverridesClasses.Add(node.Attributes["id"].Value, props); } } } catch (XmlException e) { throw new BuildException("Error loading IntPropTypeOverrides classes", e); } Dictionary<string, ModuleInfo> moduleLocations = new Dictionary<string, ModuleInfo>(); try { Log(Level.Verbose, "Loading module locations from \"ModuleLocations.xml\"."); config.Load("ModuleLocations.xml"); foreach (XmlElement moduleNode in config.GetElementsByTagName("module")) { ModuleInfo moduleInfo = new ModuleInfo(); moduleInfo.Name = moduleNode.Attributes["name"].Value; moduleInfo.Assembly = moduleNode.Attributes["assembly"].Value; moduleInfo.Path = moduleNode.Attributes["path"].Value; moduleLocations.Add(moduleInfo.Name, moduleInfo); } } catch (XmlException e) { throw new BuildException("Error loading module locations", e); } try { Log(Level.Verbose, "Processing template {0}.", m_templateFile); FdoGenerate fdoGenerate = new FdoGenerate(doc, OutputDir); fdoGenerate.Overrides = handGeneratedClasses; fdoGenerate.IntPropTypeOverrides = intPropTypeOverridesClasses; fdoGenerate.ModuleLocations = moduleLocations; fdoGenerate.Process(Path.GetFileName(m_templateFile)); } catch (Exception e) { throw new BuildException("Error processing template", e); } } finally { Directory.SetCurrentDirectory(oldDir); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Executes the task. /// </summary> /// ------------------------------------------------------------------------------------ protected override void ExecuteTask() { string oldDir = Directory.GetCurrentDirectory(); try { XmlDocument doc = new XmlDocument(); try { if (Path.GetDirectoryName(m_templateFile).Length > 0) { Directory.SetCurrentDirectory(Path.GetDirectoryName(m_templateFile)); } Log(Level.Verbose, "Loading XMI file {0}.", XMIFile); doc.Load(XMIFile); } catch (XmlException e) { throw new BuildException("Error loading XMI file", e); } XmlDocument config = new XmlDocument(); Dictionary <string, List <string> > handGeneratedClasses = new Dictionary <string, List <string> >(); try { Log(Level.Verbose, "Loading hand generated classes from \"HandGenerated.xml\"."); config.Load("HandGenerated.xml"); foreach (XmlElement node in config.GetElementsByTagName("Class")) { List <string> props = new List <string>(); foreach (XmlNode propertyNode in node.SelectNodes("property")) { props.Add(propertyNode.Attributes["name"].Value); } if (props.Count > 0) { handGeneratedClasses.Add(node.Attributes["id"].Value, props); } } } catch (XmlException e) { throw new BuildException("Error loading hand generated classes", e); } // Dictionary<ClassName, Property> Dictionary <string, Dictionary <string, string> > intPropTypeOverridesClasses = new Dictionary <string, Dictionary <string, string> >(); try { Log(Level.Verbose, "Loading hand generated classes from \"IntPropTypeOverrides.xml\"."); config.Load("IntPropTypeOverrides.xml"); foreach (XmlElement node in config.GetElementsByTagName("Class")) { // Dictionary<PropertyName, PropertyType> Dictionary <string, string> props = new Dictionary <string, string>(); foreach (XmlNode propertyNode in node.SelectNodes("property")) { props.Add(propertyNode.Attributes["name"].Value, propertyNode.Attributes["type"].Value); } if (props.Count > 0) { intPropTypeOverridesClasses.Add(node.Attributes["id"].Value, props); } } } catch (XmlException e) { throw new BuildException("Error loading IntPropTypeOverrides classes", e); } Dictionary <string, ModuleInfo> moduleLocations = new Dictionary <string, ModuleInfo>(); try { Log(Level.Verbose, "Loading module locations from \"ModuleLocations.xml\"."); config.Load("ModuleLocations.xml"); foreach (XmlElement moduleNode in config.GetElementsByTagName("module")) { ModuleInfo moduleInfo = new ModuleInfo(); moduleInfo.Name = moduleNode.Attributes["name"].Value; moduleInfo.Assembly = moduleNode.Attributes["assembly"].Value; moduleInfo.Path = moduleNode.Attributes["path"].Value; moduleLocations.Add(moduleInfo.Name, moduleInfo); } } catch (XmlException e) { throw new BuildException("Error loading module locations", e); } try { Log(Level.Verbose, "Processing template {0}.", m_templateFile); FdoGenerate fdoGenerate = new FdoGenerate(doc, OutputDir); fdoGenerate.Overrides = handGeneratedClasses; fdoGenerate.IntPropTypeOverrides = intPropTypeOverridesClasses; fdoGenerate.ModuleLocations = moduleLocations; fdoGenerate.Process(Path.GetFileName(m_templateFile)); } catch (Exception e) { throw new BuildException("Error processing template", e); } } finally { Directory.SetCurrentDirectory(oldDir); } }