Exemplo n.º 1
0
        void test1()
        {
            Builder builder = new Builder(@"C:\Temp\test.dll");
            CompilerResults result = builder.Compile(@"C:\Temp\CSharp");

            // write output messages if they exist
            for (int i = 0; i < result.Output.Count; i++)
            {
                Console.WriteLine("Output Message " + i.ToString() + ": " + result.Output[i]);
            }

            // show the full path to the generated dll file
            Console.WriteLine("DLL Path: " +  result.PathToAssembly);

            // show any errors
            Console.WriteLine("Compiler errors: " + result.Errors.Count.ToString());
            foreach (CompilerError error in result.Errors)
            {
                Console.WriteLine(error.FileName);
                Console.WriteLine(error.Line);
                Console.WriteLine(error.ErrorText);
                Console.WriteLine("- - - - - - - - - - - - - - - - - - - - - ");
                Console.WriteLine();
                Console.WriteLine();
            }
        }
Exemplo n.º 2
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");
            }
        }