Ejemplo n.º 1
0
        // create an Assert.#.cs file for each table
        // containing the function Assert.#( bool insert, # lhs, # rhs )

        protected void Assert(Program p, string theclass, string baseclass)
        {
            Helper h = new Helper();
            List <UnitTestGeneratorAssetPerTableParameters> threadParamList = new List <UnitTestGeneratorAssetPerTableParameters>();

            if (_unitTestTables.Count >= 1)
            {
                using (MyThreadPoolManager tpm = new MyThreadPoolManager(p._threads, _unitTestTables.Count))                     // max threads: _threads, queue length: no of tables
                {
                    int i = 0;
                    foreach (string fqtable in _unitTestTables)
                    {
                        i++;
                        UnitTestGeneratorAssetPerTableParameters utgaptp = new UnitTestGeneratorAssetPerTableParameters();
                        threadParamList.Add(utgaptp);

                        utgaptp.p                = p;
                        utgaptp.theclass         = theclass;
                        utgaptp.baseclass        = baseclass;
                        utgaptp.fqtable          = fqtable;
                        utgaptp.i                = i;
                        utgaptp.tablecount       = _unitTestTables.Count;
                        utgaptp.identitycolumns  = _identityColumnsMap [fqtable];
                        utgaptp.computedcolumns  = _computedColumnsMap [fqtable];
                        utgaptp.timestampcolumns = _timestampColumnsMap[fqtable];
                        utgaptp.columns          = _columnsMap             [fqtable];

                        tpm.Queue(new UnitTestGeneratorAssetPerTableThreadPoolItem(utgaptp));
                    }
                    tpm.WaitUntilAllStarted();
                    tpm.WaitUntilAllFinished();
                }
            }

            // handle any thread exceptions
            foreach (UnitTestGeneratorAssetPerTableParameters utgaptp in threadParamList)
            {
                if (utgaptp.exception != null)
                {
                    throw new ApplicationException("Unit test Assert() worker thread exception", utgaptp.exception);
                }
            }
        } // end Assert
Ejemplo n.º 2
0
        public void DoTables(Program p)
        {
            Helper h = new Helper();

            List <TableGeneratorParameters> list = new List <TableGeneratorParameters>();

            h.MessageVerbose("### Generating code gen tables ###");

            List <string> tables = p._di.Tables.Get();

            if (tables.Count >= 1)                                                                  // anything to do ?
            {
                using (MyThreadPoolManager tpm = new MyThreadPoolManager(p._threads, tables.Count)) // max threads: _threads, queue length: no of tables
                {
                    foreach (string table in tables)
                    {
                        TableGeneratorParameters tgp = new TableGeneratorParameters();
                        list.Add(tgp);

                        tgp.p       = p;
                        tgp.fqtable = table;

                        tpm.Queue(new TableGeneratorThreadPoolItem(tgp));
                    }
                    tpm.WaitUntilAllStarted();
                    tpm.WaitUntilAllFinished();
                }
            }

            h.MessageVerbose("### Generating code gen tables - done ###");

            // handle any thread exceptions
            foreach (TableGeneratorParameters tgp in list)
            {
                if (tgp.exception != null)
                {
                    throw new ApplicationException("DoTables() worker thread exception", tgp.exception);
                }
            }
        } // end do tables
Ejemplo n.º 3
0
        public void DoViews(Program p)
        {
            Helper h = new Helper();

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

            h.MessageVerbose("### Generating code gen views ###");

            List <string> views = p._di.Views.Get();

            if (views.Count >= 1)                                                                  // anything to do ?
            {
                using (MyThreadPoolManager tpm = new MyThreadPoolManager(p._threads, views.Count)) // max threads: _threads, queue length: no of tables
                {
                    foreach (string fqview in views)
                    {
                        ViewGeneratorParameters vgp = new ViewGeneratorParameters();
                        threadParamList.Add(vgp);

                        vgp.p      = p;
                        vgp.fqview = fqview;

                        tpm.Queue(new ViewGeneratorThreadPoolItem(vgp));
                    }
                    tpm.WaitUntilAllStarted();
                    tpm.WaitUntilAllFinished();
                }
            }

            h.MessageVerbose("### Generating code gen views - done ###");

            // handle any thread exceptions
            foreach (ViewGeneratorParameters vgp in threadParamList)
            {
                if (vgp.exception != null)
                {
                    throw new ApplicationException("DoViews() worker thread exception", vgp.exception);
                }
            }
        }
Ejemplo n.º 4
0
        public void DoQueries(Program p)
        {
            Helper h = new Helper();
            List <QueryGeneratorParameters> threadParamList = new List <QueryGeneratorParameters>();

            h.MessageVerbose("### Generating code gen queries ###");

            if (p._queries.Count >= 1)                                                                  // anything to do ?
            {
                using (MyThreadPoolManager tpm = new MyThreadPoolManager(p._threads, p._queries.Count)) // max threads: _threads, queue length: no of tables
                {
                    foreach (XmlNode query in p._queries)
                    {
                        QueryGeneratorParameters qgp = new QueryGeneratorParameters();
                        threadParamList.Add(qgp);

                        qgp.p     = p;
                        qgp.query = query;

                        tpm.Queue(new QueryGeneratorThreadPoolItem(qgp));
                    }
                    tpm.WaitUntilAllStarted();
                    tpm.WaitUntilAllFinished();
                }
            }

            h.MessageVerbose("### Generating code gen queries - done ###");

            // handle any thread exceptions
            foreach (QueryGeneratorParameters qgp in threadParamList)
            {
                if (qgp.exception != null)
                {
                    throw new ApplicationException("DoQueries() worker thread exception", qgp.exception);
                }
            }
        }
Ejemplo n.º 5
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);
                }
            }
        }