Exemplo n.º 1
0
 internal TemplateLineParser(string line, int LineNumber, TemplateData Data, Generator Parent)
 {
     _line = line;
     _lineNumber = LineNumber;
     _data = Data;
     _parent = Parent;
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generates code for the loaded tables and views
        /// </summary>
        /// <param name="Params">Values usedin the generated code</param>
        public void Execute(GenerationParameters Params)
        {
            _messages.Clear();

            // create template data objects for the generator
            List<TemplateData> data = new List<TemplateData>();
            foreach (Table table in _tables)
                data.Add(new TemplateData(table, Params.AuthorName, Params.RootNamespace, _database.Name));

            foreach (View view in _views)
                data.Add(new TemplateData(view, Params.AuthorName, Params.RootNamespace, _database.Name));
            Console.WriteLine("Template data created");

            // generate table & view definitions
            DatabaseScriptWriter writer = _database.GetDatabaseScriptWriter(Params.SchemaName);

            // tables
            ScriptObject[] tables = writer.Tables;
            if (tables.Length > 0)
            {
                string tablePath = Path.Combine(Params.OutputFolder, "Tables");
                if (!Directory.Exists(tablePath))
                    Directory.CreateDirectory(tablePath);
                foreach (ScriptObject table in tables)
                    File.WriteAllText(Path.Combine(tablePath, table.Name + ".sql"), table.Content);
            }

            // views
            ScriptObject[] views = writer.Views;
            if (views.Length > 0)
            {
                string viewPath = Path.Combine(Params.OutputFolder, "Views");
                if (!Directory.Exists(viewPath))
                    Directory.CreateDirectory(viewPath);
                foreach (ScriptObject view in views)
                    File.WriteAllText(Path.Combine(viewPath, view.Name + ".sql"), view.Content);
            }

            // generate the code files
            Generator gen = new Generator();
            gen.CodeGenerated += gen_CodeGenerated;
            CodeFiles files = gen.GenerateCodeFiles(data.ToArray(), Params.OutputFolder);
            Console.WriteLine("Code files generated");

            // compile the dll file and write it to the destination
            if (Params.CompileCode)
            {
                string[] CSharpFiles = (from CodeFile f in files.AllFiles where f.FileType != CodeFileType.SP select f.FileContents).ToArray();
                Builder builder = new Builder(Params.DLLDestinationPath);
                string sourcePath = Path.Combine(Params.OutputFolder, "CSharp");
                CompilerResults results = builder.Compile(sourcePath);

                Console.WriteLine("Comppiler Finished with " + results.Errors.Count.ToString() + " errors");

                // show any errors
                Console.WriteLine("Compiler errors: " + results.Errors.Count.ToString());
                foreach (CompilerError error in results.Errors)
                {
                    _messages.AppendLine("COMPILE ERROR");
                    _messages.AppendLine("File Name: " + error.FileName);
                    _messages.AppendLine("Line Number: " + error.Line.ToString());
                    _messages.AppendLine(error.ErrorText);
                    _messages.AppendLine("- - - - - - - - - - - - - - - - - - - - - ");
                    _messages.AppendLine();
                    _messages.AppendLine();
                }
            }

            // execute the stored procedures
            if (Params.RunSQLScripts)
            {
                string[] SPFiles = (from CodeFile f in files.AllFiles where f.FileType == CodeFileType.SP select f.FileContents).ToArray();
                DatabaseScriptRunner sqlRunner = _database.GetDatabaseScriptRunner();
                sqlRunner.RunScripts(SPFiles);
                Console.WriteLine("Stored Procedures have been executed");
            }
        }