Esempio n. 1
0
        public void Acc_CodeGen2_VBRunClassTemplate()
        {
            DataProvider  provider = DataService.GetInstance("NorthwindAccess");
            TurboTemplate bits     = CodeService.BuildClassTemplate("Products", new VBCodeLanguage(), provider);

            bits.Render();
            Assert.IsTrue(bits.FinalCode.Length > 0);
        }
Esempio n. 2
0
    protected void btnGo_Click(object sender, EventArgs e)
    {
        string sOutPath = txtOut.Text;

        if (!Directory.Exists(sOutPath))
        {
            Directory.CreateDirectory(sOutPath);
        }
        try
        {
            ICodeLanguage language = CodeLanguageFactory.GetByShortName(languageSelect.SelectedValue);

            string providerName = (string)Session[PROVIDER_NAME];
            if (!String.IsNullOrEmpty(providerName))
            {
                DataProvider provider = DataService.GetInstance(providerName);
                if (provider != null)
                {
                    TurboCompiler turboCompiler = new TurboCompiler();
                    StringBuilder sbTableList   = new StringBuilder();
                    foreach (ListItem item in chkTables.Items)
                    {
                        if (item.Selected)
                        {
                            sbTableList.AppendLine(item.Value);
                        }
                    }

                    foreach (ListItem item in chkTables.Items)
                    {
                        if (item.Selected)
                        {
                            TableSchema.Table t = DataService.GetTableSchema(item.Value, provider.Name, TableType.Table);
                            if (t.ForeignKeys.Count > 0)
                            {
                                //provider.GetManyToManyTables(t, evalTables);
                            }
                            string        className     = DataService.GetTableSchema(item.Value, providerName, TableType.Table).ClassName;
                            string        filePath      = Path.Combine(sOutPath, className + language.FileExtension);
                            TurboTemplate classTemplate = CodeService.BuildClassTemplate(item.Value, language, provider);
                            classTemplate.OutputPath = filePath;
                            turboCompiler.AddTemplate(classTemplate);
                            //SubSonic.Sugar.Files.CreateToFile(filePath, usings + CodeService.RunClass(item.Value, providerName, language));

                            if (chkODS.Checked)
                            {
                                filePath = Path.Combine(sOutPath, className + "Controller" + language.FileExtension);
                                TurboTemplate odsTemplate = CodeService.BuildODSTemplate(item.Value, language, provider);
                                odsTemplate.OutputPath = filePath;
                                turboCompiler.AddTemplate(odsTemplate);
                                //SubSonic.Sugar.Files.CreateToFile(filePath, usings + CodeService.RunODS(item.Value, providerName, language));
                            }
                        }
                    }

                    //output the Views
                    foreach (ListItem item in chkViews.Items)
                    {
                        if (item.Selected)
                        {
                            string        className    = DataService.GetTableSchema(item.Value, providerName, TableType.View).ClassName;
                            string        filePath     = Path.Combine(sOutPath, className + language.FileExtension);
                            TurboTemplate viewTemplate = CodeService.BuildViewTemplate(item.Value, language, provider);
                            viewTemplate.OutputPath = filePath;
                            turboCompiler.AddTemplate(viewTemplate);
                            //SubSonic.Sugar.Files.CreateToFile(filePath, usings + CodeService.RunReadOnly(item.Value, providerName, language));
                        }
                    }
                    //output the SPs
                    if (chkSP.Checked)
                    {
                        string        filePath   = Path.Combine(sOutPath, "StoredProcedures" + language.FileExtension);
                        TurboTemplate spTemplate = CodeService.BuildSPTemplate(language, provider);
                        spTemplate.OutputPath = filePath;
                        turboCompiler.AddTemplate(spTemplate);
                        //SubSonic.Sugar.Files.CreateToFile(filePath, usings + CodeService.RunSPs(providerName, language));
                    }

                    //structs
                    string        structPath      = Path.Combine(sOutPath, "AllStructs" + language.FileExtension);
                    TurboTemplate structsTemplate = CodeService.BuildStructsTemplate(language, provider);
                    structsTemplate.OutputPath = structPath;
                    turboCompiler.AddTemplate(structsTemplate);
                    //SubSonic.Sugar.Files.CreateToFile(structPath, usings + CodeService.RunStructs(language));

                    if (turboCompiler.Templates.Count > 0)
                    {
                        turboCompiler.Run();
                        foreach (TurboTemplate template in turboCompiler.Templates)
                        {
                            Utility.WriteTrace("Writing " + template.TemplateName + " as " + template.OutputPath.Substring(template.OutputPath.LastIndexOf("\\") + 1));
                            SubSonic.Sugar.Files.CreateToFile(template.OutputPath, template.FinalCode);
                        }
                    }
                    lblResult.Text = "View your files: <a href='file://" + sOutPath + "'>" + sOutPath + "</a>";
                }
            }
        }
        catch (Exception x)
        {
            lblResult.Text = "Error: " + x.Message;
        }
    }
Esempio n. 3
0
        private static void GenerateTables()
        {
            //if (DataService.Provider == null)
            SetProvider();

            string fileExt = FileExtension.DOT_CS;
            string lang    = _language;


            if (FileExtension.IsVB(lang))
            {
                language = new VBCodeLanguage();
                fileExt  = FileExtension.DOT_VB;
            }
            //string usings = ParseUtility.GetUsings(language);

            if (DataService.Providers.Count == 0)
            {
                Console.WriteLine("There's a problem with the providers - none were loaded and no exceptions where thrown.");
            }
            else
            {
                //loop the providers, and if there's more than one, output to their own folder
                //for tidiness
                foreach (DataProvider provider in DataService.Providers)
                {
                    //get the table list
                    string[] tables  = DataService.GetTableNames(provider.Name);
                    string   message = "Generating classes for " + provider.Name + " (" + tables.Length + " total)";
                    if (tables.Length > 200)
                    {
                        message += " that's a serious amount of tables to generate. But we can handle it. You just will need to be patient and go get some coffee while we do this thang...";
                    }
                    else if (tables.Length > 100)
                    {
                        message += " that's a lot of tables. This could take a few minutes...";
                    }
                    else if (tables.Length > 50)
                    {
                        message += " - moderate amount of tables... this could take 30 seconds or so...";
                    }


                    AddLogEntry(LogState.Information, message);
                    string outDir = GetOutSubDir(provider);

                    /*
                     * ArrayList evalTables = new ArrayList();
                     * foreach (string tbl in tables)
                     * {
                     *  TableSchema.Table t = DataService.GetTableSchema(tbl, provider.Name);
                     *  Console.Write(".");
                     *  if(t.ForeignKeys.Count > 0)
                     *  {
                     *      provider.GetManyToManyTables(t, evalTables);
                     *  }
                     * }
                     */
                    foreach (string tbl in tables)
                    {
                        if (IsInList(tbl) && !IsExcluded(tbl) && CodeService.ShouldGenerate(tbl, provider.Name))
                        {
                            string        className = DataService.GetSchema(tbl, provider.Name, TableType.Table).ClassName;
                            TurboTemplate tt        = CodeService.BuildClassTemplate(tbl, language, provider);
                            tt.OutputPath = Path.Combine(outDir, className + fileExt);
                            turboCompiler.AddTemplate(tt);
                        }
                    }
                }
                AddLogEntry(LogState.Information, "Finished");
            }
        }