Esempio n. 1
0
        //---------------------------------------------------------------------------------------------------------------------------

        protected void DoPopulatePerTable()
        {
            Helper h = new Helper();

            Tuple <string, string> schematable = h.SplitSchemaFromTable(_param.fqtable);

            string aclass = h.GetCsharpClassName(_param.p._prefixObjectsWithSchema, schematable.Item1, schematable.Item2);

            string csharpfile = _param.p._unitTestDirectory + @"\" + _param.theclass + ".Populate." + aclass + ".cs";

            h.MessageVerbose("[{0}]", csharpfile);
            using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsingUnitTest(sw, _param.p._unitTestTableNamespacePrefix, _param.p._unitTestTableNamespace);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, _param.p._unitTestNamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, _param.theclass, _param.baseclass))
                    {
                        h.Write(sw, tab, "protected void Populate!#( bool insert, $.# obj )".Replace("!", h.IdentifierSeparator).Replace("#", aclass).Replace("$", _param.p._unitTestTableNamespacePrefix));

                        h.Write(sw, tab, "{");
                        this.PopulateTable(aclass, sw, tab);
                        h.Write(sw, tab, "}");
                    }     // end class
                }         // end namespace
            }             // eof
        }
Esempio n. 2
0
        // generate CodeGenUnitTestClass.cs - entry point

        protected void EntryPoint(Program p, string theclass, string baseclass)
        {
            Helper h = new Helper();

            string csharpfile = p._unitTestDirectory + @"\" + theclass + ".cs";

            h.MessageVerbose("[{0}]", csharpfile);
            using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsingUnitTest(sw, p._unitTestTableNamespacePrefix, p._unitTestTableNamespace);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, p._unitTestNamespace))
                {
                    h.Write(sw, tab, "[nu.TestFixture]");
                    using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, baseclass))
                    {
                        // create constructor
                        using (UnitTestConstructorBlock conb = new UnitTestConstructorBlock(sw, tab, theclass))
                        {}

                        // unit test entry point
                        h.Write(sw, tab, "[nu.Test]");
                        h.Write(sw, tab, "public void CodegenUnitTest_InsertUpdateDelete()");
                        h.Write(sw, tab, "{");
                        h.Write(sw, tab + 1, "this.AssertObjectsNew() ;");
                        h.Write(sw, tab + 1, " ");
                        h.Write(sw, tab + 1, "this.PopulateObjectsForInsert() ;");
                        h.Write(sw, tab + 1, "this.AssertObjectsAfterInsert() ;");
                        h.Write(sw, tab + 1, " ");
                        h.Write(sw, tab + 1, "this.PopulateObjectsForUpdate() ;");
                        h.Write(sw, tab + 1, "this.AssertObjectsAfterUpdate() ;");
                        h.Write(sw, tab + 1, " ");
                        h.Write(sw, tab + 1, "this.DeleteObjects() ;");
                        h.Write(sw, tab, "}");

                        h.Write(sw, tab, " ");
                        h.Write(sw, tab, "public override void SetUp()");
                        h.Write(sw, tab, "{");
                        h.Write(sw, tab + 1, "base.SetUp();");
                        h.Write(sw, tab + 1, "this.UnitTestSetUp();");
                        h.Write(sw, tab, "}");

                        h.Write(sw, tab + 1, " ");
                        h.Write(sw, tab, "public override void TearDown()");
                        h.Write(sw, tab, "{");
                        h.Write(sw, tab + 1, "this.UnitTestTearDown();");
                        h.Write(sw, tab + 1, "base.TearDown();");
                        h.Write(sw, tab, "}");
                    }     // end class
                }         // end namespace
            }             // eof
        }
Esempio n. 3
0
        public void DoDatabase(Program p)
        {
            Helper h = new Helper();

            h.MessageVerbose("### Generating database classes ###");
            p._databaseSubDirectory = p._codegen.SelectSingleNode("/CodeGen/Database/@SubDirectory").Value;

            // do class XXXXDatabaseSingletonHelper
            string csharpnamespace = p._namespace + "." + p._databaseSubDirectory;
            string theclass        = h.GetCsharpClassName(null, null, p._databaseName) + "DatabaseSingletonHelper";
            string csharpfile      = p._directory + @"\" + p._databaseSubDirectory + @"\" + theclass + ".cs";

            h.MessageVerbose("[{0}]", csharpfile);
            using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsing(sw);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, "acr.DatabaseBaseSingletonHelper"))
                    {}
                }         // end namespace
            }             // eof

            // do class XXXXDatabase
            theclass   = h.GetCsharpClassName(null, null, p._databaseName) + "Database";
            csharpfile = p._directory + @"\" + p._databaseSubDirectory + @"\" + theclass + ".cs";

            h.MessageVerbose("[{0}]", csharpfile);
            using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsing(sw);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, "acr.DatabaseBase<" + theclass + "SingletonHelper>"))
                    {
                        using (DatabaseConstructorBlock conb = new DatabaseConstructorBlock(sw, tab, theclass, p._databaseName))
                        {}
                    }     // end class
                }         // end namespace
            }             // eof

            h.MessageVerbose("### Generating database classes - done ###");
        }         // end do database
Esempio n. 4
0
        // generate CodeGenUnitTestClass.DeleteObjects.cs
        // have to delete objects in reverse referential integrity order

        protected void DeleteObjects(Program p, string theclass, string baseclass)
        {
            Helper h = new Helper();

            string csharpfile = p._unitTestDirectory + @"\" + theclass + ".DeleteObjects.cs";

            if (!h.IgnoreCodegenFile(csharpfile))             // dont do this if we find /do not codegen/ in the file
            {
                h.MessageVerbose("[{0}]", csharpfile);
                using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
                {
                    int tab = 0;

                    // header
                    h.WriteCodeGenHeader(sw);
                    h.WriteUsingUnitTest(sw, p._unitTestTableNamespacePrefix, p._unitTestTableNamespace);

                    // namespace
                    using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, p._unitTestNamespace))
                    {
                        using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, baseclass))
                        {
                            h.Write(sw, tab, "protected void DeleteObjects()");
                            h.Write(sw, tab, "{");

                            int i = 0;
                            foreach (string fqtable in _unitTestTablesReverse)
                            {
                                i++;

                                Tuple <string, string> schematable = h.SplitSchemaFromTable(fqtable);

                                string aclass = h.GetCsharpClassName(p._prefixObjectsWithSchema, schematable.Item1, schematable.Item2);

                                h.Write(sw, tab + 1, "// #".Replace("#", aclass));
                                h.Write(sw, tab + 1, string.Format("acr.CodeGenEtc.ConsoleMessage( ! this.QuietMode, \"[{0}/{1}] # - delete\" ) ;".Replace("#", aclass), i, _unitTestTables.Count));

                                // do the delete code here
                                h.Write(sw, tab + 1, "obj2!#.MarkForDeletionˡ = true ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                                h.Write(sw, tab + 1, "base.AssertFlagsBeforeDelete( obj2!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                                h.Write(sw, tab + 1, "obj3!# = factory!#Factory.Saveˡ( _connection, obj2!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                                h.Write(sw, tab + 1, "nu.Assert.IsNull( obj3!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                                h.Write(sw, tab + 1, "base.AssertFlagsAfterDelete( obj2!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                                h.Write(sw, tab + 1, "rowcount3!# = factory!#Factory.GetRowCountˡ( _connection ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                                h.Write(sw, tab + 1, "nu.Assert.AreEqual( rowcount3!#, rowcount0!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                                h.Write(sw, tab + 1, " ");
                            }
                            h.Write(sw, tab, "}");
                        }         // end class
                    }             // end namespace
                }                 // eof
            }
        }
Esempio n. 5
0
        // generate CodeGenUnitTestClass.PopulateObjectsForInsert.cs

        protected void PopulateObjectsForInsert(Program p, string theclass, string baseclass)
        {
            Helper h = new Helper();

            string csharpfile = p._unitTestDirectory + @"\" + theclass + ".PopulateObjectsForInsert.cs";

            h.MessageVerbose("[{0}]", csharpfile);
            using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsingUnitTest(sw, p._unitTestTableNamespacePrefix, p._unitTestTableNamespace);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, p._unitTestNamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, baseclass))
                    {
                        h.Write(sw, tab, "protected void PopulateObjectsForInsert()");
                        h.Write(sw, tab, "{");

                        int i = 0;
                        foreach (string fqtable in _unitTestTables)
                        {
                            i++;

                            Tuple <string, string> schematable = h.SplitSchemaFromTable(fqtable);

                            string aclass = h.GetCsharpClassName(p._prefixObjectsWithSchema, schematable.Item1, schematable.Item2);

                            h.Write(sw, tab + 1, "// #".Replace("#", aclass));
                            h.Write(sw, tab + 1, string.Format("acr.CodeGenEtc.ConsoleMessage( ! this.QuietMode, \"[{0}/{1}] # - insert\" ) ;".Replace("#", aclass), i, _unitTestTables.Count));
                            h.Write(sw, tab + 1, "this.Populate!#( true, obj0!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab + 1, "this.PopulateOverride!#( true, obj0!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));

                            // do the insert code here
                            h.Write(sw, tab + 1, "base.AssertFlagsBeforeInsert( obj0!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab + 1, "rowcount0!# = factory!#Factory.GetRowCountˡ( _connection ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab + 1, "obj1!# = factory!#Factory.Saveˡ( _connection, obj0!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab + 1, "nu.Assert.IsNotNull( obj1!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab + 1, "base.AssertFlagsObjectLoaded( obj1!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab + 1, "base.AssertFlagsAfterInsert( obj0!# ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab + 1, "rowcount1!# = factory!#Factory.GetRowCountˡ( _connection ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab + 1, "nu.Assert.AreEqual( rowcount1!#, rowcount0!# + 1 ) ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab + 1, " ");
                        }
                        h.Write(sw, tab, "}");
                    }     // end class
                }         // end namespace
            }             // eof
        }
Esempio n. 6
0
        // generate CodeGenUnitTestClass.State.cs

        protected void State(Program p, string theclass, string baseclass)
        {
            Helper h = new Helper();

            string csharpfile = p._unitTestDirectory + @"\" + theclass + ".State.cs";

            h.MessageVerbose("[{0}]", csharpfile);
            using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsingUnitTest(sw, p._unitTestTableNamespacePrefix, p._unitTestTableNamespace);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, p._unitTestNamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, baseclass))
                    {
                        // factory for every table
                        List <string> allTables = p._di.Tables.Get();
                        foreach (string fqtable in allTables)
                        {
                            Tuple <string, string> schematable = h.SplitSchemaFromTable(fqtable);

                            string aclass = h.GetCsharpClassName(p._prefixObjectsWithSchema, schematable.Item1, schematable.Item2);

                            h.Write(sw, tab, "// #".Replace("#", aclass));
                            h.Write(sw, tab, "protected $.#Factory factory!#Factory = new $.#Factory() ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass).Replace("$", p._unitTestTableNamespacePrefix));
                            h.Write(sw, tab, " ");
                            h.Write(sw, tab, "protected $.# obj0!# = new $.#() ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass).Replace("$", p._unitTestTableNamespacePrefix));
                            h.Write(sw, tab, "protected $.# obj1!# = null ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass).Replace("$", p._unitTestTableNamespacePrefix));
                            h.Write(sw, tab, "protected $.# obj2!# = null ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass).Replace("$", p._unitTestTableNamespacePrefix));
                            h.Write(sw, tab, "protected $.# obj3!# = null ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass).Replace("$", p._unitTestTableNamespacePrefix));
                            h.Write(sw, tab, " ");
                            h.Write(sw, tab, "protected int rowcount0!# = 0 ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab, "protected int rowcount1!# = 0 ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab, "protected int rowcount2!# = 0 ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab, "protected int rowcount3!# = 0 ;".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab, " ");
                        }
                    } // end class
                }     // end namespace
            }         // eof
        }
Esempio n. 7
0
        // generate CodeGenUnitTestClass.AssertObjectsAfterInsert.cs

        protected void AssertObjectsAfterInsert(Program p, string theclass, string baseclass)
        {
            Helper h = new Helper();

            string csharpfile = p._unitTestDirectory + @"\" + theclass + ".AssertObjectsAfterInsert.cs";

            h.MessageVerbose("[{0}]", csharpfile);
            using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsingUnitTest(sw, p._unitTestTableNamespacePrefix, p._unitTestTableNamespace);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, p._unitTestNamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, baseclass))
                    {
                        h.Write(sw, tab, "protected void AssertObjectsAfterInsert()");
                        h.Write(sw, tab, "{");

                        foreach (string fqtable in _unitTestTables)
                        {
                            Tuple <string, string> schematable = h.SplitSchemaFromTable(fqtable);

                            string aclass = h.GetCsharpClassName(p._prefixObjectsWithSchema, schematable.Item1, schematable.Item2);

                            h.Write(sw, tab + 1, "// #".Replace("#", aclass));
                            h.Write(sw, tab + 1, "this.Assert!#( true, obj1!#, obj0!# ) ; ".Replace("!", h.IdentifierSeparator).Replace("#", aclass));
                            h.Write(sw, tab + 1, " ");
                        }
                        h.Write(sw, tab, "}");
                    }     // end class
                }         // end namespace
            }             // eof
        }
Esempio n. 8
0
        //--------------------------------------------------------------------------------------------------------------------

        protected void DoTable(Program p, string fqtable)
        {
            Helper     h  = new Helper();
            ColumnInfo ci = new ColumnInfo();

            List <string> parameters = new List <string>();
            Dictionary <string, string> parameterdictionary = new Dictionary <string, string>();

            Tuple <string, string> schematable = h.SplitSchemaFromTable(fqtable);

            string thedatabase = h.GetCsharpClassName(null, null, p._databaseName);

            string csharpnamespace   = p._namespace + "." + p._tableSubDirectory;
            string resourcenamespace = p._resourceNamespace + "." + p._tableSubDirectory;

            string theclass           = h.GetCsharpClassName(p._prefixObjectsWithSchema, schematable.Item1, schematable.Item2);
            string csharpfile         = p._directory + @"\" + p._tableSubDirectory + @"\" + theclass + ".cs";
            string csharpchildrenfile = p._directory + @"\" + p._tableSubDirectory + @"\" + theclass + "Children.cs";

            string csharpfactoryfile = csharpfile.Replace(".cs", "Factory.cs");
            string thefactoryclass   = theclass + "Factory";

            // config for this table, if any
            string  xpath    = "/CodeGen/Tables/Table[@Class='" + theclass + "']";
            XmlNode xmltable = p._codegen.SelectSingleNode(xpath);

            // select sql
            string selectsql = "select * from {0} t ";

            // get field list
            List <Tuple <string, string> > columns = ci.GetTableColumns(fqtable);

            // get computed columns
            List <string> computedcolumns = p._di.ComputedColumns.Get(fqtable);

            // get identity columns
            List <string> identitycolumns = p._di.IdentityColumns.Get(fqtable);

            // get timestamp columns
            List <string> timestampcolumns = p._di.TimestampColumns.Get(fqtable);

            // get primary keys
            List <string> pkcolumns = p._di.PrimaryKeyColumns.Get(fqtable, "PK");

            // do class
            h.MessageVerbose("[{0}]", csharpfile);
            using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsing(sw);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, "acr.RowBase"))
                    {
                        // properties and constructor
                        using (RowConstructorBlock conb = new RowConstructorBlock(sw, tab, theclass, columns, pkcolumns, p._concurrencyColumn))
                        {}
                    }     // end class
                }         // end namespace
            }             // eof

            // do children objects in class
            h.MessageVerbose("[{0}]", csharpchildrenfile);
            using (StreamWriter sw = new StreamWriter(csharpchildrenfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsing(sw);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, "acr.RowBase"))
                    {
                        // get parent objects for this object
                        List <Tuple <string, string> > parenttables = p._di.ParentTables.Get(fqtable, "PK");
                        foreach (Tuple <string, string> parenttable in parenttables)
                        {
                            string fqparenttable = parenttable.Item1;
                            string fkconstraint  = parenttable.Item2;

                            List <string> fkcolumns = p._di.ConstraintColumns_ChildSide.Get(fqtable, fkconstraint, "PK");
                            if (fkcolumns.Count > 0)
                            {
                                h.MessageVerbose("[{0}].[{1}].parent [{2}]", csharpnamespace, theclass, fqparenttable);

                                using (ParentObjectBlock pob = new ParentObjectBlock(sw, tab, p, fqparenttable, fkcolumns, theclass))
                                {}
                            }
                        }

                        // get children objects for this object
                        List <Tuple <string, string> > childtables = p._di.ChildTables.Get(fqtable);
                        foreach (Tuple <string, string> childtable in childtables)
                        {
                            string fqchildtable = childtable.Item1;
                            string fkconstraint = childtable.Item2;

                            List <string> fkcolumns = p._di.ConstraintColumns_ChildSide.Get(fqchildtable, fkconstraint, "PK");
                            if (fkcolumns.Count > 0)
                            {
                                List <string> parentcolumns = p._di.ConstraintColumns_ParentSide.Get(fqtable, fkconstraint, "PK");

                                h.MessageVerbose("[{0}].[{1}].child [{2}]", csharpnamespace, theclass, fqchildtable);
                                using (ChildObjectBlock cob = new ChildObjectBlock(sw, tab, p, fqtable, fqchildtable, fkcolumns, parentcolumns, theclass))
                                {}
                            }
                        }
                    }     // end class
                }         // end namespace
            }             // eof

            // do class factory
            h.MessageVerbose("[{0}]", csharpfactoryfile);
            using (StreamWriter sw = new StreamWriter(csharpfactoryfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsing(sw, p._namespace);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, thefactoryclass,
                                                          "acr.FactoryBase< " +
                                                          theclass + ", " +
                                                          "ns." + p._databaseSubDirectory + "." + thedatabase + "DatabaseSingletonHelper, " +
                                                          "ns." + p._databaseSubDirectory + "." + thedatabase + "Database >"
                                                          ))
                    {
                        // primary key parameter dictionary
                        Dictionary <string, string> parameterdictionarypk = new Dictionary <string, string>();
                        foreach (string pkcolumn in pkcolumns)
                        {
                            foreach (var column in columns)
                            {
                                if (pkcolumn == column.Item1)
                                {
                                    string name = h.GetCsharpColumnName(pkcolumn, theclass);
                                    string type = h.GetCsharpColumnType(column.Item2);

                                    parameterdictionarypk.Add(name, type);
                                }
                            }
                        }

                        string whereloadpk = this.GetWhereClausePK(pkcolumns, parameterdictionarypk, "", columns, theclass);
                        string wheresavepk = this.GetWhereClausePK(pkcolumns, parameterdictionarypk, p._concurrencyColumn, columns, theclass);

                        string deletesql = "delete {0} ";

                        string insertsql         = "insert {0}" + this.GetInsertClause(columns, computedcolumns, identitycolumns, timestampcolumns, theclass);
                        string insertidentitysql = "insert {0}" + this.GetInsertClause(columns, computedcolumns, new List <string>(), timestampcolumns, theclass);

                        string updatesql = this.GetUpdateClause(columns, computedcolumns, identitycolumns, timestampcolumns, theclass);
                        if (updatesql.Length > 0)
                        {
                            updatesql = "update {0}" + updatesql;
                        }

                        // constructor
                        using (TableFactoryConstructorBlock conb = new TableFactoryConstructorBlock(sw, tab, fqtable, selectsql, insertsql, insertidentitysql, updatesql, deletesql, whereloadpk, wheresavepk, thefactoryclass))
                        {}

                        // save method - only if table has pk
                        if (pkcolumns.Count > 0)
                        {
                            parameterdictionary = new Dictionary <string, string>();
                            parameterdictionary.Add("connˡ", "sds.SqlConnection");

                            foreach (string key in parameterdictionarypk.Keys)
                            {
                                parameterdictionary.Add(key, parameterdictionarypk[key]);
                            }

                            h.MessageVerbose("[{0}].[{1}].[{2}]", csharpnamespace, theclass, "Save");

                            // save the object
                            using (TableFactorySaveMethodBlock mb = new TableFactorySaveMethodBlock(sw, tab, parameterdictionary, columns, identitycolumns, p._concurrencyColumn, theclass))
                            {}

                            // save a list of objects
                            using (TableFactorySaveListMethodBlock mb1 = new TableFactorySaveListMethodBlock(sw, tab, theclass))
                            {}
                        }

                        // load by primary key method - only if table has pk
                        if (pkcolumns.Count > 0)
                        {
                            parameters = new List <string>();
                            parameters.Add("connˡ");

                            foreach (string key in parameterdictionarypk.Keys)
                            {
                                parameters.Add(key);
                            }

                            parameters.Add("tranˡ");

                            parameterdictionary = new Dictionary <string, string>();
                            parameterdictionary.Add("connˡ", "sds.SqlConnection");

                            foreach (string key in parameterdictionarypk.Keys)
                            {
                                parameterdictionary.Add(key, parameterdictionarypk[key]);
                            }

                            parameterdictionary.Add("tranˡ", "sds.SqlTransaction");

                            h.MessageVerbose("[{0}].[{1}].[{2}]", csharpnamespace, theclass, "LoadByPrimaryKeyˡ");
                            using (TableFactoryPrimaryKeyMethodBlock mb = new TableFactoryPrimaryKeyMethodBlock(sw, tab, "LoadByPrimaryKeyˡ", parameters, parameterdictionary, theclass, resourcenamespace))
                            {}
                        }

                        // load by foreign key methods
                        List <Tuple <string, string> > foreignkeys = p._di.ForeignKeys.Get(fqtable);
                        foreach (Tuple <string, string> foreignkey in foreignkeys)
                        {
                            string fqfktable    = foreignkey.Item1;
                            string fkconstraint = foreignkey.Item2;

                            Tuple <string, string> fkschematable = h.SplitSchemaFromTable(fqfktable);

                            string        fktable   = h.GetSchemaAndTableName(p._prefixObjectsWithSchema, fkschematable.Item1, fkschematable.Item2);
                            List <string> fkcolumns = p._di.ForeignKeyConstraintColumns.Get(fqtable, fkconstraint);

                            // foreign key parameter dictionary
                            parameters = new List <string>();
                            parameters.Add("connˡ");

                            foreach (string fkcolumn in fkcolumns)
                            {
                                foreach (var column in columns)
                                {
                                    if (fkcolumn == column.Item1)
                                    {
                                        string name = h.GetCsharpColumnName(fkcolumn, theclass);
                                        parameters.Add(name);
                                    }
                                }
                            }

                            parameters.Add("topNˡ");
                            parameters.Add("orderByˡ");
                            parameters.Add("tranˡ");

                            Dictionary <string, string> parameterdictionaryfk = new Dictionary <string, string>();
                            parameterdictionaryfk.Add("connˡ", "sds.SqlConnection");

                            foreach (string fkcolumn in fkcolumns)
                            {
                                foreach (var column in columns)
                                {
                                    if (fkcolumn == column.Item1)
                                    {
                                        string name = h.GetCsharpColumnName(fkcolumn, theclass);
                                        string type = h.GetCsharpColumnType(column.Item2);

                                        parameterdictionaryfk.Add(name, type);
                                    }
                                }
                            }

                            parameterdictionaryfk.Add("topNˡ", "int?");
                            parameterdictionaryfk.Add("orderByˡ", "scg.List<acr.CodeGenOrderBy>");
                            parameterdictionaryfk.Add("tranˡ", "sds.SqlTransaction");

                            string wherefk = this.GetWhereClauseFK(fkcolumns, theclass);

                            string byparameters = "";
                            foreach (string fkcolumn in fkcolumns)
                            {
                                byparameters += h.GetCsharpColumnName(fkcolumn, theclass);
                            }

                            string method = "LoadByForeignKey" + h.IdentifierSeparator + "From" + h.IdentifierSeparator + fktable + h.IdentifierSeparator + "By" + h.IdentifierSeparator + byparameters;

                            h.MessageVerbose("[{0}].[{1}].fk [{2}]", csharpnamespace, theclass, method);
                            using (TableFactoryForeignKeyMethodBlock mb = new TableFactoryForeignKeyMethodBlock(sw, tab, method, parameters, parameterdictionaryfk, wherefk, theclass, resourcenamespace))
                            {}
                        }

                        // load all method
                        parameters = new List <string>();
                        parameters.Add("connˡ");
                        parameters.Add("topNˡ");
                        parameters.Add("orderByˡ");
                        parameters.Add("tranˡ");

                        parameterdictionary = new Dictionary <string, string>();
                        parameterdictionary.Add("connˡ", "sds.SqlConnection");
                        parameterdictionary.Add("topNˡ", "int?");
                        parameterdictionary.Add("orderByˡ", "scg.List<acr.CodeGenOrderBy>");
                        parameterdictionary.Add("tranˡ", "sds.SqlTransaction");

                        h.MessageVerbose("[{0}].[{1}].[{2}]", csharpnamespace, theclass, "Loadˡ");
                        using (ViewFactoryMethodBlock mb = new ViewFactoryMethodBlock(sw, tab, "Loadˡ", parameters, parameterdictionary, "", theclass, resourcenamespace))
                        {}

                        // load by where
                        parameters = new List <string>();
                        parameters.Add("connˡ");
                        parameters.Add("whereˡ");
                        parameters.Add("parametersˡ");
                        parameters.Add("topNˡ");
                        parameters.Add("orderByˡ");
                        parameters.Add("tranˡ");

                        parameterdictionary = new Dictionary <string, string>();
                        parameterdictionary.Add("connˡ", "sds.SqlConnection");
                        parameterdictionary.Add("whereˡ", "string");
                        parameterdictionary.Add("parametersˡ", "scg.List<sds.SqlParameter>");
                        parameterdictionary.Add("topNˡ", "int?");
                        parameterdictionary.Add("orderByˡ", "scg.List<acr.CodeGenOrderBy>");
                        parameterdictionary.Add("tranˡ", "sds.SqlTransaction");

                        h.MessageVerbose("[{0}].[{1}].[{2}]", csharpnamespace, theclass, "LoadByWhereˡ");
                        using (ViewFactoryMethodBlock mb = new ViewFactoryMethodBlock(sw, tab, "LoadByWhereˡ", parameters, parameterdictionary, "", theclass, resourcenamespace))
                        {}

                        // other load methods
                        if (xmltable != null)
                        {
                            XmlNodeList xmlmethods = xmltable.SelectNodes("Methods/Method");
                            foreach (XmlNode xmlmethod in xmlmethods)
                            {
                                string method = xmlmethod.SelectSingleNode("@Name").InnerText;

                                // where resource
                                string whereresource = xmlmethod.SelectSingleNode("@Where").InnerText;

                                // parameters
                                parameters = new List <string>();
                                parameters.Add("connˡ");

                                XmlNodeList xmlparameters = xmlmethod.SelectNodes("Parameters/Parameter");
                                foreach (XmlNode xmlparameter in xmlparameters)
                                {
                                    parameters.Add(xmlparameter.SelectSingleNode("@Name").InnerText);
                                }

                                parameters.Add("topNˡ");
                                parameters.Add("orderByˡ");
                                parameters.Add("tranˡ");

                                parameterdictionary = new Dictionary <string, string>();
                                parameterdictionary.Add("connˡ", "sds.SqlConnection");

                                xmlparameters = xmlmethod.SelectNodes("Parameters/Parameter");
                                foreach (XmlNode xmlparameter in xmlparameters)
                                {
                                    parameterdictionary.Add(xmlparameter.SelectSingleNode("@Name").InnerText,
                                                            xmlparameter.SelectSingleNode("@Type").InnerText);
                                }

                                parameterdictionary.Add("topNˡ", "int?");
                                parameterdictionary.Add("orderByˡ", "scg.List<acr.CodeGenOrderBy>");
                                parameterdictionary.Add("tranˡ", "sds.SqlTransaction");

                                // method
                                h.MessageVerbose("[{0}].[{1}].method [{2}]", csharpnamespace, theclass, method);
                                using (ViewFactoryMethodBlock mb = new ViewFactoryMethodBlock(sw, tab, method, parameters, parameterdictionary, whereresource, theclass, resourcenamespace))
                                {}
                            }
                        }
                    } // end class
                }     // end namespace
            }         // eof
        }             // end do table
Esempio n. 9
0
        //--------------------------------------------------------------------------------------------------------------------

        protected void DoStoredProc(Program p, string fqstoredprocedure)
        {
            Helper h = new Helper();
            StoredProcedureParameterInfo sppi  = new StoredProcedureParameterInfo();
            StoredProcedureResultsetInfo sprsi = new StoredProcedureResultsetInfo();

            var schemastoredprocedure = h.SplitSchemaFromTable(fqstoredprocedure);

            string thedatabase     = h.GetCsharpClassName(null, null, p._databaseName);
            string csharpnamespace = p._namespace + "." + p._storedProcsSubDirectory;

            string csharpstoredproc = h.GetCsharpClassName(p._prefixObjectsWithSchema, schemastoredprocedure.Item1, schemastoredprocedure.Item2);
            string csharpfile       = p._directory + @"\" + p._storedProcsSubDirectory + @"\" + csharpstoredproc + ".cs";

            string thefactoryclass   = "StoredProcedureFactory";
            string csharpfactoryfile = p._directory + @"\" + p._storedProcsSubDirectory + @"\" + thefactoryclass + ".cs";

            // do each stored proc in a separate file, but same factory class
            h.MessageVerbose("[{0}]", csharpfile);

            // check for dud parameters - cursor, table - ignore the sp if so
            if (sppi.HasDudParameterStoredProcedure(fqstoredprocedure))
            {
                h.MessageVerbose("[{0}] Ignoring stored procedure because it has dud parameters.", fqstoredprocedure);
                return;
            }

            // get sp parameters
            List <string> parameters = new List <string>();

            parameters.Add("connˡ");

            var spparameters = sppi.GetStoredProcedureParameterInfo(fqstoredprocedure);

            if (spparameters != null)
            {
                foreach (var spparameter in spparameters)
                {
                    parameters.Add(spparameter.Name);
                }
            }

            parameters.Add("tranˡ");

            // the results sets
            var rsi = sprsi.GetResultsetInfo(fqstoredprocedure);

            // write out the stored proc wrapper to its file
            using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsing(sw, p._namespace);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                {
                    using (ClassBlock cb = new ClassBlock(
                               sw,
                               tab++,
                               thefactoryclass,
                               "acr.StoredProcedureFactoryBase< " + "ns." + p._databaseSubDirectory + "." + thedatabase + "DatabaseSingletonHelper, " + "ns." + p._databaseSubDirectory + "." + thedatabase + "Database >"))
                    {
                        // execute block
                        h.MessageVerbose("[{0}].[{1}]", csharpnamespace, csharpstoredproc);

                        using (StoredProcedureFactoryExecuteBlock mb = new StoredProcedureFactoryExecuteBlock(
                                   p,
                                   sw,
                                   tab,
                                   fqstoredprocedure,
                                   csharpstoredproc,
                                   parameters,
                                   sppi,
                                   rsi))
                        {}
                    }     // end class
                }         // end namespace
            }             // eof

            // write out the classes for stored proc result sets, if any
            int i = 0;

            foreach (var rs in rsi.Resultsets)
            {
                i++;
                string therecordsetclass   = csharpstoredproc + h.IdentifierSeparator + "rs" + i;
                string csharprecordsetfile = p._directory + @"\" + p._storedProcsSubDirectory + @"\" + csharpstoredproc + ".rs" + i + ".cs";

                h.MessageVerbose("[{0}]", csharprecordsetfile);
                using (StreamWriter sw = new StreamWriter(csharprecordsetfile, false, UTF8Encoding.UTF8))
                {
                    int tab = 0;

                    // header
                    h.WriteCodeGenHeader(sw);
                    h.WriteUsing(sw, p._namespace);

                    // namespace
                    using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                    {
                        using (ClassBlock cb = new ClassBlock(sw, tab++, therecordsetclass, "acr.RowBase"))
                        {
                            h.MessageVerbose("[{0}].[{1}] row", csharpnamespace, therecordsetclass);

                            using (StoredProcedureRowConstructorBlock mb = new StoredProcedureRowConstructorBlock(sw, tab, therecordsetclass, rs.Columns))
                            {}
                        } // end class
                    }     // end namespace
                }         // eof
            }
        }                 // end do sp
Esempio n. 10
0
        // generate CodeGenUnitTestClass.CodegenRunTimeSettings.cs
        // this file in NOT overwritten if it exists

        protected void CodegenRunTimeSettings(Program p, string theclass, string baseclass)
        {
            Helper h = new Helper();

            string csharpfile = p._unitTestDirectory + @"\" + theclass + ".CodegenRunTimeSettings.cs";

            if (!File.Exists(csharpfile))
            {
                h.MessageVerbose("[{0}]", csharpfile);
                using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
                {
                    int tab = 0;

                    // header
                    h.WriteCodeGenHeader2(sw);
                    h.WriteUsingUnitTest(sw, p._unitTestTableNamespacePrefix, p._unitTestTableNamespace);

                    // namespace
                    using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, p._unitTestNamespace))
                    {
                        using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, baseclass))
                        {
                            h.Write(sw, tab, "public override string ConnectionString");
                            h.Write(sw, tab, "{");
                            h.Write(sw, tab + 1, "get");
                            h.Write(sw, tab + 1, "{");
                            h.Write(sw, tab + 2, "return @\"" + p._connectionString + "\" ;");
                            h.Write(sw, tab + 1, "}");
                            h.Write(sw, tab, "}");

                            h.Write(sw, tab, " ");
                            h.Write(sw, tab, "public override bool QuietMode");
                            h.Write(sw, tab, "{");
                            h.Write(sw, tab + 1, "get");
                            h.Write(sw, tab + 1, "{");
                            h.Write(sw, tab + 2, "return false ;");
                            h.Write(sw, tab + 1, "}");
                            h.Write(sw, tab, "}");

                            h.Write(sw, tab, " ");
                            h.Write(sw, tab, "public override bool DisableCheckConstraints");
                            h.Write(sw, tab, "{");
                            h.Write(sw, tab + 1, "get");
                            h.Write(sw, tab + 1, "{");
                            h.Write(sw, tab + 2, "return true ;");
                            h.Write(sw, tab + 1, "}");
                            h.Write(sw, tab, "}");

                            h.Write(sw, tab, " ");
                            h.Write(sw, tab, "public override bool DisableTriggers");
                            h.Write(sw, tab, "{");
                            h.Write(sw, tab + 1, "get");
                            h.Write(sw, tab + 1, "{");
                            h.Write(sw, tab + 2, "return true ;");
                            h.Write(sw, tab + 1, "}");
                            h.Write(sw, tab, "}");

                            h.Write(sw, tab, " ");
                            h.Write(sw, tab, "public override System.Transactions.IsolationLevel TransactionIsolationLevel");
                            h.Write(sw, tab, "{");
                            h.Write(sw, tab + 1, "get");
                            h.Write(sw, tab + 1, "{");
                            h.Write(sw, tab + 2, "return System.Transactions.IsolationLevel.Serializable ;");
                            h.Write(sw, tab + 1, "}");
                            h.Write(sw, tab, "}");

                            h.Write(sw, tab, " ");
                            h.Write(sw, tab, "public void UnitTestSetUp()");
                            h.Write(sw, tab, "{");
                            h.Write(sw, tab, "}");

                            h.Write(sw, tab, " ");
                            h.Write(sw, tab, "public void UnitTestTearDown()");
                            h.Write(sw, tab, "{");
                            h.Write(sw, tab, "}");
                        }         // end class
                    }             // end namespace
                }                 // eof
            }
        }
Esempio n. 11
0
        protected void DoQuery(Program p, XmlNode query)
        {
            Helper     h  = new Helper();
            ColumnInfo ci = new ColumnInfo();

            string thedatabase = h.GetCsharpClassName(null, null, p._databaseName);

            string csharpnamespace   = p._namespace + "." + p._querySubDirectory;
            string resourcenamespace = p._resourceNamespace + "." + p._querySubDirectory;

            string csharpfile = p._directory + @"\" + p._querySubDirectory + @"\" + query.SelectSingleNode("@CodeFile").Value;
            string theclass   = query.SelectSingleNode("@Class").Value;

            string csharpfactoryfile = csharpfile.Replace(".cs", "Factory.cs");
            string thefactoryclass   = theclass + "Factory";

            // query resource
            string queryfile     = query.SelectSingleNode("@Select").Value;
            string queryresource = resourcenamespace + "." + query.SelectSingleNode("@Select").Value;

            // do class
            h.MessageVerbose("[{0}]", csharpfile);
            using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsing(sw);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, "acr.RowBase"))
                    {
                        // get columns
                        var columns = ci.GetQueryColumns(queryfile);

                        // properties and constructor
                        using (RowConstructorBlock conb = new RowConstructorBlock(sw, tab, theclass, columns, null, ""))
                        {}
                    }     // end class
                }         // end namespace
            }             // end of file

            // do class factory
            h.MessageVerbose("[{0}]", csharpfactoryfile);
            using (StreamWriter sw = new StreamWriter(csharpfactoryfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsing(sw, p._namespace);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, thefactoryclass,
                                                          "acr.FactoryBase< " +
                                                          theclass + ", " +
                                                          "ns." + p._databaseSubDirectory + "." + thedatabase + "DatabaseSingletonHelper, " +
                                                          "ns." + p._databaseSubDirectory + "." + thedatabase + "Database >"
                                                          ))
                    {
                        // constructor
                        using (QueryFactoryConstructorBlock conb = new QueryFactoryConstructorBlock(sw, tab, queryresource, thefactoryclass))
                        {}

                        // method
                        XmlNodeList xmlmethods = query.SelectNodes("Methods/Method");
                        foreach (XmlNode xmlmethod in xmlmethods)
                        {
                            string themethod = xmlmethod.SelectSingleNode("@Name").InnerText;

                            // where resource
                            string whereresource = xmlmethod.SelectSingleNode("@Where").InnerText;

                            // parameters
                            List <string> parameters = new List <string>();
                            Dictionary <string, string> parameterdictionary = new Dictionary <string, string>();

                            parameters = new List <string>();
                            parameters.Add("connˡ");

                            XmlNodeList xmlparameters = xmlmethod.SelectNodes("Parameters/Parameter");
                            foreach (XmlNode xmlparameter in xmlparameters)
                            {
                                parameters.Add(xmlparameter.SelectSingleNode("@Name").InnerText);
                            }

                            parameters.Add("topNˡ");
                            parameters.Add("orderByˡ");
                            parameters.Add("tranˡ");

                            parameterdictionary.Add("connˡ", "sds.SqlConnection");

                            xmlparameters = xmlmethod.SelectNodes("Parameters/Parameter");
                            foreach (XmlNode xmlparameter in xmlparameters)
                            {
                                parameterdictionary.Add(xmlparameter.SelectSingleNode("@Name").InnerText,
                                                        xmlparameter.SelectSingleNode("@Type").InnerText);
                            }

                            parameterdictionary.Add("topNˡ", "int?");
                            parameterdictionary.Add("orderByˡ", "scg.List<acr.CodeGenOrderBy>");
                            parameterdictionary.Add("tranˡ", "sds.SqlTransaction");

                            // method
                            h.MessageVerbose("[{0}].[{1}].method [{2}]", csharpnamespace, theclass, themethod);

                            using (QueryFactoryMethodBlock mb = new QueryFactoryMethodBlock(sw, tab, themethod, parameters, parameterdictionary, whereresource, theclass, resourcenamespace))
                            {}
                        } // end method
                    }     // end class
                }         // end namespace
            }             // end of file
        }
Esempio n. 12
0
        protected void DoStoredProcs(Program p)
        {
            Helper h = new Helper();

            List <StoredProcGeneratorParameters> threadParamList = new List <StoredProcGeneratorParameters>();

            h.MessageVerbose("### Generating code gen stored procs ###");
            _storedProcsSubDirectory = _codegen.SelectSingleNode("/CodeGen/StoredProcs/@SubDirectory").Value;

            List <string> storedprocedures = p._di.StoredProcedures.Get();

            if (storedprocedures.Count >= 1)               // anything to do ?
            {
                // create a tt class and ttlist class for each table type

                foreach (var fqtabletype in p._di.TableTypes.Get())
                {
                    Tuple <string, string> schematabletype = h.SplitSchemaFromTable(fqtabletype);

                    string csharpnamespace     = p._namespace + "." + p._storedProcsSubDirectory;
                    string csharptabletype     = h.GetCsharpClassName(p._prefixObjectsWithSchema, schematabletype.Item1, schematabletype.Item2);
                    string thetabletypeclass   = csharptabletype + h.IdentifierSeparator + "tt";
                    string csharptabletypefile = p._directory + @"\" + p._storedProcsSubDirectory + @"\" + csharptabletype + ".tt.cs";

                    string thetabletypelistclass   = csharptabletype + h.IdentifierSeparator + "ttlist";
                    string csharptabletypelistfile = p._directory + @"\" + p._storedProcsSubDirectory + @"\" + csharptabletype + ".ttlist.cs";
                    string ttlistbaseclass         = "scg.List< " + thetabletypeclass + " >, scg.IEnumerable< mss.SqlDataRecord >";

                    List <Tuple <string, string, Int16, Byte, Byte> > columns = p._di.TableTypeColumns.Get(fqtabletype);

                    // tt file
                    h.MessageVerbose("[{0}]", csharptabletypefile);
                    using (StreamWriter sw = new StreamWriter(csharptabletypefile, false, UTF8Encoding.UTF8))
                    {
                        int tab = 0;

                        // header
                        h.WriteCodeGenHeader(sw);
                        h.WriteUsing(sw, p._namespace);

                        // namespace
                        using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                            using (ClassBlock cb = new ClassBlock(sw, tab++, thetabletypeclass, "acr.RowBase"))
                                using (StoredProcedureRowConstructorBlock mb = new StoredProcedureRowConstructorBlock(sw, tab, thetabletypeclass, columns, true))
                                {}
                    }

                    // tt list file
                    h.MessageVerbose("[{0}]", csharptabletypelistfile);
                    using (StreamWriter sw = new StreamWriter(csharptabletypelistfile, false, UTF8Encoding.UTF8))
                    {
                        int tab = 0;

                        // header
                        h.WriteCodeGenHeader(sw);
                        h.WriteUsing(sw, p._namespace);

                        // namespace
                        using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                            using (ClassBlock cb = new ClassBlock(sw, tab++, thetabletypelistclass, ttlistbaseclass))
                                using (StoredProcedureTableTypeEnumeratorBlock mb = new StoredProcedureTableTypeEnumeratorBlock(sw, tab, thetabletypeclass, columns))
                                {}
                    }
                }

                // write each stored procedure in a file

                using (MyThreadPoolManager tpm = new MyThreadPoolManager(p._threads, storedprocedures.Count))                     // max threads: _threads, queue length: no of sp's
                {
                    foreach (string storedprocedure in storedprocedures)
                    {
                        StoredProcGeneratorParameters tgp = new StoredProcGeneratorParameters();
                        threadParamList.Add(tgp);

                        tgp.p = p;
                        tgp.fqstoredprocedure = storedprocedure;

                        tpm.Queue(new StoredProcGeneratorThreadPoolItem(tgp));
                    }
                    tpm.WaitUntilAllStarted();
                    tpm.WaitUntilAllFinished();
                }
            }
            h.MessageVerbose("### Generating code gen stored procs - done ###");

            // handle any thread exceptions
            foreach (StoredProcGeneratorParameters tgp in threadParamList)
            {
                if (tgp.exception != null)
                {
                    throw new ApplicationException("DoStoredProcs() worker thread exception", tgp.exception);
                }
            }
        }
Esempio n. 13
0
        protected void DoAssetPerTable()
        {
            Helper h = new Helper();

            Tuple <string, string> schematable = h.SplitSchemaFromTable(_param.fqtable);

            string aclass = h.GetCsharpClassName(_param.p._prefixObjectsWithSchema, schematable.Item1, schematable.Item2);

            string csharpfile = _param.p._unitTestDirectory + @"\" + _param.theclass + ".Assert." + aclass + ".cs";

            if (!h.IgnoreCodegenFile(csharpfile))                // dont do this if we find /do not codegen/ in the file
            {
                h.MessageVerbose("[{0}]", csharpfile);
                using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
                {
                    int tab = 0;

                    // header
                    h.WriteCodeGenHeader(sw);
                    h.WriteUsingUnitTest(sw, _param.p._unitTestTableNamespacePrefix, _param.p._unitTestTableNamespace);

                    // namespace
                    using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, _param.p._unitTestNamespace))
                    {
                        using (ClassBlock cb = new ClassBlock(sw, tab++, _param.theclass, _param.baseclass))
                        {
                            h.Write(sw, tab, "protected void Assert!#( bool insert, $.# newobj, $.# oldobj )"
                                    .Replace("!", h.IdentifierSeparator)
                                    .Replace("#", aclass)
                                    .Replace("$", _param.p._unitTestTableNamespacePrefix));
                            h.Write(sw, tab, "{");

                            h.Write(sw, tab + 1, string.Format("acr.CodeGenEtc.ConsoleMessage( ! this.QuietMode, \"[{0}/{1}] # - assert\" ) ;".Replace("#", aclass), _param.i, _param.tablecount));
                            h.Write(sw, tab, " ");

                            // always: assert newobj fields not null
                            // Assert.IsNotNull( newobj.field ) ;

                            foreach (var column in _param.columns)
                            {
                                string columnname = h.GetCsharpColumnName(column.Item1, aclass);
                                h.Write(sw, tab + 1, "nu.Assert.IsNotNull( newobj.#, \"@.#\" ) ;".Replace("#", columnname).Replace("@", aclass));
                            }

                            h.Write(sw, tab, " ");

                            // always: assert newojj fields = obldobjfields
                            // AssertAreEqual( type, type )
                            // dont do timestamp or computed columns or identity

                            foreach (var column in _param.columns)
                            {
                                if (_param.identitycolumns.Contains(column.Item1))
                                {
                                    continue;
                                }
                                if (_param.computedcolumns.Contains(column.Item1))
                                {
                                    continue;
                                }
                                if (_param.timestampcolumns.Contains(column.Item1))
                                {
                                    continue;
                                }

                                string columnname = h.GetCsharpColumnName(column.Item1, aclass);
                                h.Write(sw, tab + 1, "base.AssertAreEqual( newobj.#, oldobj.#, \"@.#\" ) ;".Replace("#", columnname).Replace("@", aclass));
                            }
                            h.Write(sw, tab, " ");
                            h.Write(sw, tab, "}");
                        } // end class
                    }     // end namespace
                }         // eof
            }
        }                 // end DoAssetPerTable()
Esempio n. 14
0
        protected void DoView(Program p, string fqview)
        {
            Helper     h  = new Helper();
            ColumnInfo ci = new ColumnInfo();

            Tuple <string, string> schemaview = h.SplitSchemaFromTable(fqview);

            string thedatabase = h.GetCsharpClassName(null, null, p._databaseName);

            string csharpnamespace   = p._namespace + "." + p._viewSubDirectory;
            string resourcenamespace = p._resourceNamespace + "." + p._viewSubDirectory;

            string theclass   = h.GetCsharpClassName(p._prefixObjectsWithSchema, schemaview.Item1, schemaview.Item2);
            string csharpfile = p._directory + @"\" + p._viewSubDirectory + @"\" + theclass + ".cs";

            string csharpfactoryfile = csharpfile.Replace(".cs", "Factory.cs");
            string thefactoryclass   = theclass + "Factory";

            // config for this view, if any
            string  xpath = "/CodeGen/Views/View[@Class='" + theclass + "']";
            XmlNode view  = p._codegen.SelectSingleNode(xpath);

            // select sql
            string selectsql = "select * from {0} t ";

            // do class
            h.MessageVerbose("[{0}]", csharpfile);
            using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsing(sw);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, theclass, "acr.RowBase"))
                    {
                        List <Tuple <string, string> > columns = ci.GetViewColumns(fqview);

                        // properties and constructor
                        using (RowConstructorBlock conb = new RowConstructorBlock(sw, tab, theclass, columns, null, ""))
                        {}
                    }     // end class
                }         // end namespace
            }             // eof

            // do class factory
            h.MessageVerbose("[{0}]", csharpfactoryfile);
            using (StreamWriter sw = new StreamWriter(csharpfactoryfile, false, UTF8Encoding.UTF8))
            {
                int tab = 0;

                // header
                h.WriteCodeGenHeader(sw);
                h.WriteUsing(sw, p._namespace);

                // namespace
                using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace))
                {
                    using (ClassBlock cb = new ClassBlock(sw, tab++, thefactoryclass,
                                                          "acr.FactoryBase< " +
                                                          theclass + ", " +
                                                          "ns." + p._databaseSubDirectory + "." + thedatabase + "DatabaseSingletonHelper, " +
                                                          "ns." + p._databaseSubDirectory + "." + thedatabase + "Database >"
                                                          ))
                    {
                        // constructor
                        using (ViewFactoryConstructorBlock conb = new ViewFactoryConstructorBlock(sw, tab, fqview, selectsql, thefactoryclass))
                        {}

                        // default load all method
                        List <string> parameters = new List <string>();
                        Dictionary <string, string> parameterdictionary = new Dictionary <string, string>();

                        parameters = new List <string>();
                        parameters.Add("connˡ");
                        parameters.Add("topNˡ");
                        parameters.Add("orderByˡ");
                        parameters.Add("tranˡ");

                        parameterdictionary.Add("connˡ", "sds.SqlConnection");
                        parameterdictionary.Add("topNˡ", "int?");
                        parameterdictionary.Add("orderByˡ", "scg.List<acr.CodeGenOrderBy>");
                        parameterdictionary.Add("tranˡ", "sds.SqlTransaction");

                        // method
                        h.MessageVerbose("[{0}].[{1}].[{2}]", csharpnamespace, theclass, "Loadˡ");
                        using (ViewFactoryMethodBlock mb = new ViewFactoryMethodBlock(sw, tab, "Loadˡ", parameters, parameterdictionary, "", theclass, resourcenamespace))
                        {}

                        // load by where
                        parameters = new List <string>();
                        parameters.Add("connˡ");
                        parameters.Add("whereˡ");
                        parameters.Add("parametersˡ");
                        parameters.Add("topNˡ");
                        parameters.Add("orderByˡ");
                        parameters.Add("tranˡ");

                        parameterdictionary = new Dictionary <string, string>();
                        parameterdictionary.Add("connˡ", "sds.SqlConnection");
                        parameterdictionary.Add("whereˡ", "string");
                        parameterdictionary.Add("parametersˡ", "scg.List<sds.SqlParameter>");
                        parameterdictionary.Add("topNˡ", "int?");
                        parameterdictionary.Add("orderByˡ", "scg.List<acr.CodeGenOrderBy>");
                        parameterdictionary.Add("tranˡ", "sds.SqlTransaction");

                        h.MessageVerbose("[{0}].[{1}].[{2}]", csharpnamespace, theclass, "LoadByWhereˡ");
                        using (ViewFactoryMethodBlock mb = new ViewFactoryMethodBlock(sw, tab, "LoadByWhereˡ", parameters, parameterdictionary, "", theclass, resourcenamespace))
                        {}

                        // other methods
                        if (view != null)
                        {
                            XmlNodeList xmlmethods = view.SelectNodes("Methods/Method");
                            foreach (XmlNode xmlmethod in xmlmethods)
                            {
                                string themethod = xmlmethod.SelectSingleNode("@Name").InnerText;

                                // where resource
                                string whereresource = xmlmethod.SelectSingleNode("@Where").InnerText;

                                // parameters
                                parameters = new List <string>();
                                parameters.Add("connˡ");

                                XmlNodeList xmlparameters = xmlmethod.SelectNodes("Parameters/Parameter");
                                foreach (XmlNode xmlparameter in xmlparameters)
                                {
                                    parameters.Add(xmlparameter.SelectSingleNode("@Name").InnerText);
                                }

                                parameters.Add("topNˡ");
                                parameters.Add("orderByˡ");
                                parameters.Add("tranˡ");

                                parameterdictionary = new Dictionary <string, string>();
                                parameterdictionary.Add("connˡ", "sds.SqlConnection");

                                xmlparameters = xmlmethod.SelectNodes("Parameters/Parameter");
                                foreach (XmlNode xmlparameter in xmlparameters)
                                {
                                    parameterdictionary.Add(xmlparameter.SelectSingleNode("@Name").InnerText,
                                                            xmlparameter.SelectSingleNode("@Type").InnerText);
                                }

                                parameterdictionary.Add("topNˡ", "int?");
                                parameterdictionary.Add("orderByˡ", "scg.List<acr.CodeGenOrderBy>");
                                parameterdictionary.Add("tranˡ", "sds.SqlTransaction");

                                // method
                                h.MessageVerbose("[{0}].[{1}].method [{2}]", csharpnamespace, theclass, themethod);

                                using (ViewFactoryMethodBlock mb = new ViewFactoryMethodBlock(sw, tab, themethod, parameters, parameterdictionary, whereresource, theclass, resourcenamespace))
                                {}
                            }
                        }
                    } // end class
                }     // end namespace
            }         // eof
        }             // end do view