Exemple #1
0
		/// ------------------------------------------------------------------------------------
		/// <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);
			}
		}
Exemple #2
0
        /// ------------------------------------------------------------------------------------
        /// <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);
            }
        }
Exemple #3
0
        /// ------------------------------------------------------------------------------------
        /// <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);
            }
        }