Exemplo n.º 1
0
        private void GenerateSequences(DBInfo.Core.Model.Database db)
        {
            if (!Directory.Exists(OutputDir + "\\" + SequencesDir))
            {
                Directory.CreateDirectory(OutputDir + "\\" + SequencesDir);
            }

            foreach (DBInfo.Core.Model.Sequence s in db.Sequences)
            {
                CreateSequence xmlSequence = new CreateSequence();
                xmlSequence.Name         = s.SequenceName;
                xmlSequence.Initial      = s.Initial.ToString();
                xmlSequence.MinValue     = s.MinValue.ToString();
                xmlSequence.MaxValue     = s.MaxValue.ToString();
                xmlSequence.Increment    = s.Increment.ToString();
                xmlSequence.CycleOnLimit = s.CycleOnLimit ? YesNo.Yes : YesNo.No;

                StatementCollection stCol = new StatementCollection();
                stCol.Statement    = new Statement[1];
                stCol.Statement[0] = xmlSequence;
                generateXMLOutput(stCol, OutputDir + "\\" + SequencesDir + "\\" + s.SequenceName + ".sequence.xml", false);
            }
        }
Exemplo n.º 2
0
        private void generateXMLOutput(StatementCollection col, string FileName, bool generateCDATAForSourceCode)
        {
            MemoryStream ms = new MemoryStream();

            if (generateCDATAForSourceCode)
            {
                //Change the contents of all nodes named "SourceCode" to CDATA. There's no option to do this automatticaly in XMLSerializer
                XmlSerializer ser = new XmlSerializer(typeof(StatementCollection), "http://dbinfo.sourceforge.net/Schemas/DBInfo.xsd");
                ser.Serialize(ms, col);

                FileStream fs = new FileStream(FileName, FileMode.Create, FileAccess.ReadWrite);
                fixSourceCodeNode(ms, fs);

                ms.Close();
                fs.Close();
            }
            else
            {
                FileStream    fs  = new FileStream(FileName, FileMode.Create, FileAccess.ReadWrite);
                XmlSerializer ser = new XmlSerializer(typeof(StatementCollection), "http://dbinfo.sourceforge.net/Schemas/DBInfo.xsd");
                ser.Serialize(fs, col);
                fs.Close();
            }
        }
Exemplo n.º 3
0
        private void GenerateConstraints(List <DBInfo.Core.Statement.CreateCheckConstraint> createCheckList,
                                         List <DBInfo.Core.Statement.CreatePrimaryKey> createPKList)
        {
            if (!Directory.Exists(OutputDir + "\\" + ConstraintsDir))
            {
                Directory.CreateDirectory(OutputDir + "\\" + ConstraintsDir);
            }

            List <string> tableNames =
                (from DBInfo.Core.Statement.CreateCheckConstraint ccc in createCheckList
                 select ccc.CheckConstraint.TableName).Union <string>(
                    from DBInfo.Core.Statement.CreatePrimaryKey cpk in createPKList
                    select cpk.Table.TableName).Distinct <string>().ToList <string>();

            foreach (string tableName in tableNames)
            {
                DBInfo.Core.Statement.CreatePrimaryKey createPK =
                    (from DBInfo.Core.Statement.CreatePrimaryKey cpk in createPKList
                     where cpk.Table.TableName == tableName
                     select cpk).FirstOrDefault <DBInfo.Core.Statement.CreatePrimaryKey>();

                List <DBInfo.Core.Statement.CreateCheckConstraint> createCheckStatements =
                    (from DBInfo.Core.Statement.CreateCheckConstraint ccc in createCheckList
                     where ccc.CheckConstraint.TableName == tableName
                     select ccc).ToList <DBInfo.Core.Statement.CreateCheckConstraint>();

                int StatementCount = 0;
                if (createPK != null)
                {
                    StatementCount++;
                }
                StatementCount += createCheckStatements.Count;
                StatementCollection stCol = new StatementCollection();
                stCol.Statement = new Statement[StatementCount];
                int count = 0;

                if (createPK != null)
                {
                    DBInfo.XMLDatabase.CreatePrimaryKey xmlPK = new DBInfo.XMLDatabase.CreatePrimaryKey();
                    xmlPK.TableName      = createPK.Table.TableName;
                    xmlPK.PrimaryKeyName = createPK.Table.PrimaryKeyName;
                    xmlPK.Columns        = new string[createPK.Table.PrimaryKeyColumns.Count];

                    foreach (string c in createPK.Table.PrimaryKeyColumns)
                    {
                        xmlPK.Columns[createPK.Table.PrimaryKeyColumns.IndexOf(c)] = c;
                    }
                    stCol.Statement[0] = xmlPK;
                    count++;
                }

                foreach (DBInfo.Core.Statement.CreateCheckConstraint ccc in createCheckStatements)
                {
                    CreateCheckConstraint xmlCK = new CreateCheckConstraint();
                    xmlCK.TableName           = ccc.CheckConstraint.TableName;
                    xmlCK.CheckConstraintName = ccc.CheckConstraint.CheckConstraintName;
                    xmlCK.SourceCode          = ccc.CheckConstraint.Expression;
                    stCol.Statement[count]    = xmlCK;
                    count++;
                }

                generateXMLOutput(stCol, OutputDir + "\\" + ConstraintsDir + "\\" + tableName + ".constraints.xml", true);
            }
        }