コード例 #1
0
ファイル: Generator.cs プロジェクト: nathantownsend/DALAPI
        /// <summary>
        /// Perform the generation command
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GenerateTables_Click(object sender, EventArgs e)
        {
            // create parameters
            GenerationParameters parms = new GenerationParameters()
            {
                AuthorName = _solution.Author,
                DLLDestinationPath = _solution.DLLPath,
                OutputFolder = _solution.OutputFolder,
                RootNamespace = _solution.RootNamespace,
                SchemaName = SchemaNames.Text,
                CompileCode = CompileCode.Checked,
                RunSQLScripts = RunSQLScripts.Checked
            };

            // get selected tables and views to generate
            string[] tableNames = (from object o in Tables.CheckedItems select o.ToString()).ToArray();
            string[] viewNames = (from object o in Views.CheckedItems select o.ToString()).ToArray();

            // load the manager
            _manager.LoadTables(tableNames, SchemaNames.Text);
            _manager.LoadViews(viewNames, SchemaNames.Text);

            // setup the progress bar
            //ProgressIndicator prog = new ProgressIndicator(tableNames.Length + viewNames.Length);
            //prog.Show();
            BasicProgress prog = new BasicProgress();
            prog.Show();

            // run the generator
            _manager.Execute(parms);

            prog.Close();
            prog.Dispose();

            Messages box = new Messages();

            if (_manager.CompilerMessages.Length > 0)
                box.SetMessagesText(_manager.CompilerMessages);
            else
                box.SetMessagesText("The generator has successfully generated you code!");

            box.Show();
        }
コード例 #2
0
        public void Test1()
        {
            // create a parameters object
            GenerationParameters gps = new GenerationParameters()
            {
                AuthorName = "Nathan Townsend",
                DLLDestinationPath = @"C:\Temp\Simplicity\MySimplicity.dll",
                OutputFolder = @"C:\Temp\Simplicity\",
                RootNamespace = "MySimplicity",
                SchemaName = "dbo"
            };

            // create a manager
            Manager manager = new Manager("Nathan-HP\\SQLEXPRESS", "Simplicity");

            // load all the tables
            manager.LoadAllTables(gps.SchemaName);

            // create the code files, the dll file, and execute stored procs on database
            manager.Execute(gps);
        }
コード例 #3
0
ファイル: Manager.cs プロジェクト: nathantownsend/DALAPI
        /// <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");
            }
        }