Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets DataCommon and SafeReader classes which are needed in order for the DAL to compile
 /// </summary>
 /// <param name="rootNamespace"></param>
 /// <returns></returns>
 CodeFiles GetDALCommonFiles(string rootNamespace)
 {
     CodeFiles files = new CodeFiles();
     CodeFile dataCommon = new CodeFile(){ FileContents = Resources.DataCommon.Replace("#NameSpace#", rootNamespace), FileName="DataCommon.cs", FileType = CodeFileType.DAL};
     CodeFile safeReader = new CodeFile(){ FileContents = Resources.SafeReader.Replace("#NameSpace#", rootNamespace), FileName="SafeReader.cs", FileType = CodeFileType.DAL};
     files.AddCodeFile(dataCommon);
     files.AddCodeFile(safeReader);
     return files;
 }