Exemplo 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;
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Merges files from another CodeFiles object into this instance
 /// </summary>
 /// <param name="files"></param>
 public void Merge(CodeFiles files)
 {
     foreach (CodeFile file in files.AllFiles)
         AddCodeFile(file);
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Writes the code files to the folder
 /// </summary>
 /// <param name="files"></param>
 /// <param name="Folder"></param>
 public void WriteFiles(CodeFiles files, string Folder)
 {
     WriteFiles(files.DALFiles, Path.Combine(Folder, "CSharp\\DAL"));
     WriteFiles(files.DOFiles, Path.Combine(Folder, "CSharp\\DO"));
     WriteFiles(files.SPFiles, Path.Combine(Folder, "SQL"));
 }