internal TemplateLineParser(string line, int LineNumber, TemplateData Data, Generator Parent)
 {
     _line = line;
     _lineNumber = LineNumber;
     _data = Data;
     _parent = Parent;
 }
 /// <summary>
 /// Create a new line parser
 /// </summary>
 /// <param name="line">A line of text from a template file</param>
 /// <param name="Data">The data source</param>
 /// <param name="TemplateFolder">The folder contianing the template (used for includes)</param>
 internal TemplateLineParser(string line, int LineNumber, TemplateData Data, string TemplateFolder)
 {
     _line = line;
     _lineNumber = LineNumber;
     _data = Data;
     _templateFolder = TemplateFolder;
 }
示例#3
0
 /// <summary>
 /// Create a new instance of a template parser
 /// </summary>
 /// <param name="Template">The template to be parsed</param>
 /// <param name="Data">The Data to use in the template</param>
 /// <param name="Parent">The parent generator object</param>
 public TemplateParser(Template Template, TemplateData Data, Generator Parent)
 {
     _data = Data;
     _parent = Parent;
     _template = Template;
     _templateLines = _template.Content.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
 }
示例#4
0
        /// <summary>
        /// Generates code files for the data object using each template 
        /// </summary>
        /// <param name="Data"></param>
        /// <returns></returns>
        public CodeFiles GenerateCode(TemplateData Data)
        {
            CodeFiles result = new CodeFiles();
            GenerationEventArgs e = new GenerationEventArgs() { DataObjectName = Data.DataContainerName };

            string type = Data.DataContainer.IsView ? "view" : "table";

            // generate code files for each template
            foreach (Template template in _templates.Where(t => t.IsInclude == false))
            {
                // only run templates for the right type of data object (ie. view or table)
                if (template.For.Contains(type))
                {
                    TemplateParser parser = new TemplateParser(template, Data, this);
                    CodeFile[] files = parser.ParseTemplate();
                    foreach (CodeFile file in files)
                        result.AddCodeFile(file);

                    e.TemplatesApplied.Add(template.FileName);
                    e.ParsingErrors.AddRange(parser.Exceptions);
                }

                // trigger the generated event
                OnCodeGenerated(e);
            }

            // merge in data common and safe reader
            result.Merge(GetDALCommonFiles(Data.RootNamespace));

            return result;
        }
示例#5
0
        /// <summary>
        /// Generates code files for each data object in the array using each template
        /// </summary>
        /// <param name="Data"></param>
        /// <returns></returns>
        public CodeFiles GenerateCode(TemplateData[] Data)
        {
            CodeFiles master = new CodeFiles();

            foreach (TemplateData data in Data)
            {
                CodeFiles files = GenerateCode(data);
                master.Merge(files);
            }

            return master;
        }
示例#6
0
        void Test2()
        {
            Database db = server.GetDatabase("Simplicity");

            List<TemplateData> data = new List<TemplateData>();

            foreach (Table table in db.GetTables("dbo"))
            {
                TemplateData item = new TemplateData(table, "Nathan Townsend", "Simplicity", "Simplicity");
                data.Add(item);
                Console.WriteLine("Added Item: " + table.Name);
            }

            Generator gen = new Generator();
            gen.GenerateCodeFiles(data.ToArray(), @"C:\Temp");
        }
示例#7
0
 /// <summary>
 /// Generates code files from each data object and writes them to the folder
 /// </summary>
 /// <param name="Data"></param>
 /// <param name="Folder"></param>
 public CodeFiles GenerateCodeFiles(TemplateData[] Data, string Folder)
 {
     CodeFiles files = GenerateCode(Data);
     WriteFiles(files, Folder);
     return files;
 }
示例#8
0
 /// <summary>
 /// Generates code files from the data object and writes them to disk
 /// </summary>
 /// <param name="Data">The data needed by the templates</param>
 /// <param name="Folder">The folder where the code files will be written</param>
 public void GenerateCodeFiles(TemplateData Data, string Folder)
 {
     CodeFiles files = GenerateCode(Data);
     WriteFiles(files, Folder);
 }