/// <summary> /// Parses the template for tables and views and returns the result code file /// </summary> /// <returns></returns> CodeFile[] ParseTablesAndViews() { StringBuilder sb = new StringBuilder(); int lineNum = 1; foreach (string line in _templateLines) { try { TemplateLineParser lineParser = new TemplateLineParser(line, lineNum, _data, _parent); sb.AppendLine(lineParser.ParseLine()); } catch (Exception ex) { _templateExceptions.Add(ex); } lineNum += 1; } // create teh code file to return CodeFile file = new CodeFile(); // stored procedure files need the template name included, but DAL and DO classes do not if(_type == CodeFileType.SP) file.FileName = string.Format("{0}_{1}.{2}", _data.DataContainerName, Path.GetFileNameWithoutExtension(_template.FileName), GetFileExtension()); else file.FileName = string.Format("{0}.{1}", _data.DataContainerName, GetFileExtension()); file.FileContents = sb.ToString().Trim(); file.FileType = _type; return new CodeFile[] { file }; }
/// <summary> /// Adds a code file to the collection /// </summary> /// <param name="file"></param> public void AddCodeFile(CodeFile file) { switch (file.FileType) { case CodeFileType.DAL: DALFiles.Add(file); break; case CodeFileType.DO: DOFiles.Add(file); break; case CodeFileType.SP: SPFiles.Add(file); break; } }
/// <summary> /// Parses the template for each index and returns the result code files /// </summary> /// <returns></returns> CodeFile[] ParseIndexes() { List<CodeFile> codeFiles = new List<CodeFile>(); foreach (Index index in _data.DataContainer.GetIndexes()) { // load the index _data.LoadIndex(index); StringBuilder sb = new StringBuilder(); // parse the template int lineNum = 1; foreach (string line in _templateLines) { try { TemplateLineParser lineParser = new TemplateLineParser(line, lineNum, _data, _parent); sb.AppendLine(lineParser.ParseLine()); } catch (Exception ex) { _templateExceptions.Add(ex); } lineNum += 1; } // create code file definition CodeFile file = new CodeFile() { FileName = string.Format("{0}_GetBy{1}.{2}", _data.DataContainerName, _data.IndexName, GetFileExtension()), FileContents = sb.ToString().Trim(), FileType = _type }; // add the code file to the list codeFiles.Add(file); } return codeFiles.ToArray(); }
/// <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; }