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