///--------------------------------------------------------------------------------
 /// <summary>This method loads information from an
 /// xml attribute.</summary>
 ///
 /// <param name="xmlAttribute">The attribute to load.</param>
 ///--------------------------------------------------------------------------------
 public void LoadAttribute(System.Xml.XmlAttribute xmlAttribute)
 {
     try
     {
         XmlAttributeID   = Guid.NewGuid();
         XmlAttributeName = xmlAttribute.Name;
         LocalName        = xmlAttribute.LocalName;
         Value            = xmlAttribute.Value;
         BaseURI          = xmlAttribute.BaseURI;
         Prefix           = xmlAttribute.Prefix;
         NamespaceURI     = xmlAttribute.NamespaceURI;
         NodeType         = xmlAttribute.NodeType.ToString();
         InnerText        = xmlAttribute.InnerText;
         InnerXml         = xmlAttribute.InnerXml;
         OuterXml         = xmlAttribute.OuterXml;
         SchemaInfo       = xmlAttribute.SchemaInfo.ToString();
     }
     catch (Exception ex)
     {
         bool reThrow = BusinessConfiguration.HandleException(ex);
         if (reThrow)
         {
             throw;
         }
     }
 }
        ///--------------------------------------------------------------------------------
        /// <summary>This method loads information from an
        /// xml document.</summary>
        ///
        /// <param name="xmlDocument">The document to load.</param>
        ///--------------------------------------------------------------------------------
        public void LoadDocument(System.Xml.XmlDocument xmlDocument)
        {
            try
            {
                XmlDocumentID   = Guid.NewGuid();
                XmlDocumentName = xmlDocument.Name;
                LocalName       = xmlDocument.LocalName;
                Value           = xmlDocument.Value;
                BaseURI         = xmlDocument.BaseURI;
                NamespaceURI    = xmlDocument.NamespaceURI;
                if (xmlDocument.DocumentType != null)
                {
                    DocumentType = xmlDocument.DocumentType.ToString();
                }
                NodeType   = xmlDocument.NodeType.ToString();
                InnerText  = xmlDocument.InnerText;
                InnerXml   = xmlDocument.InnerXml;
                OuterXml   = xmlDocument.OuterXml;
                SchemaInfo = xmlDocument.SchemaInfo.ToString();

                // load nodes
                if (xmlDocument.ChildNodes != null)
                {
                    foreach (System.Xml.XmlNode loopNode in xmlDocument.ChildNodes)
                    {
                        XmlNode node = new XmlNode();
                        node.XmlDocument = this;
                        node.LoadNode(loopNode);
                        XmlNodeList.Add(node);
                    }
                }

                // load attributes
                if (xmlDocument.Attributes != null)
                {
                    foreach (System.Xml.XmlAttribute loopAttribute in xmlDocument.Attributes)
                    {
                        XmlAttribute attribute = new XmlAttribute();
                        attribute.XmlDocument = this;
                        attribute.LoadAttribute(loopAttribute);
                        XmlAttributeList.Add(attribute);
                    }
                }
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                if (reThrow)
                {
                    throw;
                }
            }
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This loads information from a MySQL foreign key.</summary>
        ///
        /// <param name="sqlConnection">The input sql connection</param>
        /// <param name="variables">Database level variables</param>
        /// <param name="keyColumn">The key column row data</param>
        ///--------------------------------------------------------------------------------
        public void LoadMySQLColumn(MySqlConnection sqlConnection, NameObjectCollection variables, DataRow keyColumn)
        {
            try
            {
                // load foreign key  information
                foreach (DataColumn column in keyColumn.Table.Columns)
                {
                    // load important properties into foreign key, the rest as additional sql properties
                    switch (column.ColumnName)
                    {
                    case "COLUMN_NAME":
                        SqlForeignKeyColumnName = keyColumn[column.ColumnName].GetString();
                        break;

                    case "REFERENCED_COLUMN_NAME":
                        ReferencedColumn = keyColumn[column.ColumnName].GetString();
                        break;

                    case "ORDINAL_POSITION":
                        Order = keyColumn[column.ColumnName].GetInt();
                        break;

                    default:
                        SqlProperty property = new SqlProperty();
                        property.SqlPropertyID       = Guid.NewGuid();
                        property.SqlForeignKeyColumn = this;
                        property.LoadMySQLProperty(column.ColumnName, null, keyColumn[column.ColumnName].GetString());
                        SqlPropertyList.Add(property);
                        break;
                    }
                }
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                if (reThrow)
                {
                    throw;
                }
            }
        }
 ///--------------------------------------------------------------------------------
 /// <summary>This method loads an output db with information from a
 /// SQL database.</summary>
 ///--------------------------------------------------------------------------------
 public void LoadOutputDB()
 {
     try
     {
         if (!String.IsNullOrEmpty(DbServerName) && !String.IsNullOrEmpty(DbName))
         {
             Database sqlDatabase = null;
             Server   sqlServer   = new Server(DbServerName);
             sqlServer.SetDefaultInitFields(true);
             sqlServer.ConnectionContext.LoginSecure = true;
             sqlServer.ConnectionContext.Connect();
             foreach (Database loopDb in sqlServer.Databases)
             {
                 if (loopDb.Name == DbName)
                 {
                     sqlDatabase = loopDb;
                     break;
                 }
             }
             if (sqlDatabase == null)
             {
                 OutputDatabase = null;
                 throw new ApplicationException(String.Format(DisplayValues.Exception_SourceDbNotFound, DbName));
             }
             else
             {
                 // load the database information
                 OutputDatabase = new SqlDatabase();
                 OutputDatabase.SqlDatabaseID = Guid.NewGuid();
                 OutputDatabase.LoadSqlServerDatabase(sqlDatabase);
             }
         }
     }
     catch (ApplicationAbortException)
     {
         throw;
     }
     catch (Exception ex)
     {
         bool reThrow = BusinessConfiguration.HandleException(ex);
         Solution.ShowIssue(ex.Message + "\r\n" + ex.StackTrace);
     }
 }
Exemple #5
0
        ///--------------------------------------------------------------------------------
        /// <summary>This loads information from a SQL indexed column.</summary>
        ///
        /// <param name="sqlIndexedColumn">The input sql indexed column.</param>
        ///--------------------------------------------------------------------------------
        public void LoadColumn(IndexedColumn sqlIndexedColumn)
        {
            try
            {
                // load the basic index column information
                SqlIndexedColumnName = sqlIndexedColumn.Name;
                DbID       = sqlIndexedColumn.ID;
                IsIncluded = sqlIndexedColumn.IsIncluded;
                IsComputed = sqlIndexedColumn.IsComputed;
                Descending = sqlIndexedColumn.Descending;
                Urn        = sqlIndexedColumn.Urn;
                State      = sqlIndexedColumn.State.ToString();

                // load information for each property
                //foreach (Microsoft.SqlServer.Management.Smo.Property loopProperty in sqlIndexedColumn.Properties)
                //{
                //    if (loopProperty.Expensive == false && loopProperty.IsNull == false && !String.IsNullOrEmpty(loopProperty.Value.ToString()))
                //    {
                //        SqlProperty property = new SqlProperty();
                //        property.SqlPropertyID = Guid.NewGuid();
                //        property.SqlIndexedColumn = this;
                //        property.LoadProperty(loopProperty);
                //        SqlPropertyList.Add(property);
                //    }
                //}
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                if (reThrow)
                {
                    throw;
                }
            }
        }
Exemple #6
0
 ///--------------------------------------------------------------------------------
 /// <summary>This loads information for a MySQL property.</summary>
 ///
 /// <param name="propertyName">The input property name.</param>
 /// <param name="propertyType">The input property type.</param>
 /// <param name="propertyValue">The input property value.</param>
 ///--------------------------------------------------------------------------------
 public void LoadMySQLProperty(string propertyName, string propertyType, string propertyValue)
 {
     try
     {
         // load the basic property information
         SqlPropertyName = propertyName;
         SqlType         = propertyType;
         SqlValue        = propertyValue;
     }
     catch (ApplicationAbortException)
     {
         throw;
     }
     catch (Exception ex)
     {
         bool reThrow = BusinessConfiguration.HandleException(ex);
         if (reThrow)
         {
             throw;
         }
     }
 }
Exemple #7
0
 ///--------------------------------------------------------------------------------
 /// <summary>This loads information from a SQL property.</summary>
 ///
 /// <param name="sqlProperty">The input sql property.</param>
 ///--------------------------------------------------------------------------------
 public void LoadProperty(Property sqlProperty)
 {
     try
     {
         // load the basic property information
         SqlPropertyName = sqlProperty.Name;
         SqlType         = sqlProperty.Type.ToString();
         SqlValue        = sqlProperty.Value.ToString();
     }
     catch (ApplicationAbortException)
     {
         throw;
     }
     catch (Exception ex)
     {
         bool reThrow = BusinessConfiguration.HandleException(ex);
         if (reThrow)
         {
             throw;
         }
     }
 }
 ///--------------------------------------------------------------------------------
 /// <summary>This loads information from a SQL extended property.</summary>
 ///
 /// <param name="sqlExtendedProperty">The input sql extended property.</param>
 ///--------------------------------------------------------------------------------
 public void LoadExtendedProperty(ExtendedProperty sqlExtendedProperty)
 {
     try
     {
         // load the basic extended property information
         SqlExtendedPropertyName = sqlExtendedProperty.Name;
         SqlValue = sqlExtendedProperty.Value.ToString();
         Urn      = sqlExtendedProperty.Urn;
         State    = sqlExtendedProperty.State.ToString();
     }
     catch (ApplicationAbortException)
     {
         throw;
     }
     catch (Exception ex)
     {
         bool reThrow = BusinessConfiguration.HandleException(ex);
         if (reThrow)
         {
             throw;
         }
     }
 }
 ///--------------------------------------------------------------------------------
 /// <summary>This method loads a specification source with information from an
 /// xml document.</summary>
 ///--------------------------------------------------------------------------------
 public void LoadSpecificationSource()
 {
     try
     {
         System.Xml.XmlDocument document = new System.Xml.XmlDocument();
         document.LoadXml(FileHelper.GetText(SourceFilePath));
         if (document.OuterXml == String.Empty)
         {
             SpecDocument = null;
             throw new ApplicationException(String.Format(DisplayValues.Exception_SourceXmlMissing, SourceFilePath));
         }
         else
         {
             // load the document information
             SpecDocument = new XmlDocument();
             SpecDocument.LoadDocument(document);
         }
     }
     catch (Exception ex)
     {
         bool reThrow = BusinessConfiguration.HandleException(ex);
         Solution.ShowIssue(ex.Message + "\r\n" + ex.StackTrace);
     }
 }
Exemple #10
0
        ///--------------------------------------------------------------------------------
        /// <summary>This loads information from a SQL foreign key.</summary>
        ///
        /// <param name="sqlForeignKey">The input sql foreign key.</param>
        ///--------------------------------------------------------------------------------
        public void LoadForeignKey(ForeignKey sqlForeignKey)
        {
            try
            {
                // load the basic foreign key information
                SqlForeignKeyName = sqlForeignKey.Name;
                DbID                  = sqlForeignKey.ID;
                ReferencedKey         = sqlForeignKey.ReferencedKey;
                ReferencedTable       = sqlForeignKey.ReferencedTable;
                ReferencedTableSchema = sqlForeignKey.ReferencedTableSchema;
                IsChecked             = sqlForeignKey.IsChecked;
                IsSystemNamed         = sqlForeignKey.IsSystemNamed;
                CreateDate            = sqlForeignKey.CreateDate;
                DateLastModified      = sqlForeignKey.DateLastModified;
                Urn   = sqlForeignKey.Urn;
                State = sqlForeignKey.State.ToString();

                // load information for each property
                foreach (Microsoft.SqlServer.Management.Smo.Property loopProperty in sqlForeignKey.Properties)
                {
                    if (DebugHelper.DebugAction == DebugAction.Stop)
                    {
                        return;
                    }
                    if (loopProperty.Expensive == false && loopProperty.IsNull == false && !String.IsNullOrEmpty(loopProperty.Value.ToString()))
                    {
                        if (loopProperty.Name == "ID" || loopProperty.Name == "IsEnabled")
                        {
                            SqlProperty property = new SqlProperty();
                            property.SqlPropertyID = Guid.NewGuid();
                            property.SqlForeignKey = this;
                            property.LoadProperty(loopProperty);
                            SqlPropertyList.Add(property);
                        }
                    }
                }

                // load information for each extended property
                //foreach (ExtendedProperty loopProperty in sqlForeignKey.ExtendedProperties)
                //{
                //    SqlExtendedProperty property = new SqlExtendedProperty();
                //    property.SqlExtendedPropertyID = Guid.NewGuid();
                //    property.SqlForeignKey = this;
                //    property.LoadExtendedProperty(loopProperty);
                //    SqlExtendedPropertyList.Add(property);
                //}

                // load information for each column
                foreach (ForeignKeyColumn loopColumn in sqlForeignKey.Columns)
                {
                    if (DebugHelper.DebugAction == DebugAction.Stop)
                    {
                        return;
                    }
                    SqlForeignKeyColumn column = new SqlForeignKeyColumn();
                    column.SqlForeignKeyColumnID = Guid.NewGuid();
                    column.SqlForeignKey         = this;
                    column.LoadColumn(loopColumn);
                    SqlForeignKeyColumnList.Add(column);
                }
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                if (reThrow)
                {
                    throw;
                }
            }
        }
Exemple #11
0
        ///--------------------------------------------------------------------------------
        /// <summary>This loads information from a MySQL foreign key.</summary>
        ///
        /// <param name="sqlConnection">The input sql connection</param>
        /// <param name="variables">Database level variables</param>
        /// <param name="key">The key row data</param>
        /// <param name="keyColumns">The key columns table data</param>
        ///--------------------------------------------------------------------------------
        public void LoadMySQLForeignKey(MySqlConnection sqlConnection, NameObjectCollection variables, DataRow key, DataTable keyColumns)
        {
            try
            {
                // load foreign key  information
                foreach (DataColumn column in key.Table.Columns)
                {
                    if (DebugHelper.DebugAction == DebugAction.Stop)
                    {
                        return;
                    }
                    // load important properties into foreign key, the rest as additional sql properties
                    switch (column.ColumnName)
                    {
                    case "constraint_name":
                        SqlForeignKeyName = key[column.ColumnName].GetString();
                        break;

                    case "referenced_table_name":
                        ReferencedTable = key[column.ColumnName].GetString();
                        break;

                    case "referenced_table_schema":
                        ReferencedTableSchema = key[column.ColumnName].GetString();
                        break;

                    default:
                        SqlProperty property = new SqlProperty();
                        property.SqlPropertyID = Guid.NewGuid();
                        property.SqlForeignKey = this;
                        property.LoadMySQLProperty(column.ColumnName, null, key[column.ColumnName].GetString());
                        SqlPropertyList.Add(property);
                        break;
                    }
                }

                // load information for each column
                if (keyColumns != null)
                {
                    foreach (DataRow row in keyColumns.Rows)
                    {
                        if (DebugHelper.DebugAction == DebugAction.Stop)
                        {
                            return;
                        }
                        if (row["TABLE_NAME"].GetString() == SqlTable.SqlTableName && row["CONSTRAINT_NAME"].GetString() == SqlForeignKeyName)
                        {
                            SqlForeignKeyColumn column = new SqlForeignKeyColumn();
                            column.SqlForeignKeyColumnID = Guid.NewGuid();
                            column.SqlForeignKey         = this;
                            column.LoadMySQLColumn(sqlConnection, variables, row);
                            SqlForeignKeyColumnList.Add(column);
                        }
                    }
                }
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                if (reThrow)
                {
                    throw;
                }
            }
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This loads information from a SQL column.</summary>
        ///
        /// <param name="sqlColumn">The input sql column.</param>
        ///--------------------------------------------------------------------------------
        public void LoadColumn(Column sqlColumn)
        {
            try
            {
                // load the basic column information
                SqlColumnName     = sqlColumn.Name;
                DbID              = sqlColumn.ID;
                DataType          = sqlColumn.DataType.ToString();
                MaximumLength     = sqlColumn.DataType.MaximumLength;
                NumericPrecision  = sqlColumn.DataType.NumericPrecision;
                NumericScale      = sqlColumn.DataType.NumericScale;
                Default           = sqlColumn.Default;
                DefaultSchema     = sqlColumn.DefaultSchema;
                IsFullTextIndexed = sqlColumn.IsFullTextIndexed;
                IsForeignKey      = sqlColumn.IsForeignKey;
                InPrimaryKey      = sqlColumn.InPrimaryKey;
                Nullable          = sqlColumn.Nullable;
                Identity          = sqlColumn.Identity;
                IdentitySeed      = sqlColumn.IdentitySeed;
                IdentityIncrement = sqlColumn.IdentityIncrement;
                Urn   = sqlColumn.Urn;
                State = sqlColumn.State.ToString();

                // load information for each property
                foreach (Microsoft.SqlServer.Management.Smo.Property loopProperty in sqlColumn.Properties)
                {
                    if (loopProperty.Expensive == false && loopProperty.IsNull == false && !String.IsNullOrEmpty(loopProperty.Value.ToString()))
                    {
                        if (loopProperty.Name == "ID" || loopProperty.Name == "Length")
                        {
                            SqlProperty property = new SqlProperty();
                            property.SqlPropertyID = Guid.NewGuid();
                            property.SqlColumn     = this;
                            property.LoadProperty(loopProperty);
                            SqlPropertyList.Add(property);
                        }
                    }
                }

                // load information for each extended property
                //foreach (ExtendedProperty loopProperty in sqlColumn.ExtendedProperties)
                //{
                //    SqlExtendedProperty property = new SqlExtendedProperty();
                //    property.SqlExtendedPropertyID = Guid.NewGuid();
                //    property.SqlColumn = this;
                //    property.LoadExtendedProperty(loopProperty);
                //    SqlExtendedPropertyList.Add(property);
                //}
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                if (reThrow)
                {
                    throw;
                }
            }
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This loads information from a MySQL column.</summary>
        ///
        /// <param name="sqlConnection">The input sql connection</param>
        /// <param name="variables">Database level variables</param>
        /// <param name="column">The column row data</param>
        ///--------------------------------------------------------------------------------
        public void LoadMySQLColumn(MySqlConnection sqlConnection, NameObjectCollection variables, DataRow column)
        {
            try
            {
                // doesn't seem to be a column property for these...
                IdentitySeed      = variables["auto_increment_offset"].GetInt();
                IdentityIncrement = variables["auto_increment_increment"].GetInt();
                //IsForeignKey = sqlColumn.IsForeignKey;

                // load column information
                foreach (DataColumn item in column.Table.Columns)
                {
                    // load important properties into column, the rest as additional sql properties
                    switch (item.ColumnName)
                    {
                    case "COLUMN_NAME":
                        SqlColumnName = column[item.ColumnName].GetString();
                        break;

                    case "DATA_TYPE":
                        DataType = column[item.ColumnName].GetString();
                        break;

                    case "CHARACTER_MAXIMUM_LENGTH":
                        MaximumLength = column[item.ColumnName].GetInt();
                        break;

                    case "NUMERIC_PRECISION":
                        NumericPrecision = column[item.ColumnName].GetInt();
                        break;

                    case "NUMERIC_SCALE":
                        NumericScale = column[item.ColumnName].GetInt();
                        break;

                    case "COLUMN_DEFAULT":
                        Default = column[item.ColumnName].GetString();
                        break;

                    case "COLUMN_KEY":
                        InPrimaryKey = column[item.ColumnName].GetString() == "PRI";
                        break;

                    case "IS_NULLABLE":
                        Nullable = column[item.ColumnName].GetBool();
                        break;

                    case "ORDINAL_POSITION":
                        Order = column[item.ColumnName].GetInt();
                        break;

                    case "EXTRA":
                        Identity = column[item.ColumnName].GetString().Contains("auto_increment");
                        break;

                    default:
                        SqlProperty property = new SqlProperty();
                        property.SqlPropertyID = Guid.NewGuid();
                        property.SqlColumn     = this;
                        property.LoadMySQLProperty(item.ColumnName, null, column[item.ColumnName].GetString());
                        SqlPropertyList.Add(property);
                        break;
                    }
                }
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                if (reThrow)
                {
                    throw;
                }
            }
        }
Exemple #14
0
        ///--------------------------------------------------------------------------------
        /// <summary>This loads information from a SQL index.</summary>
        ///
        /// <param name="sqlIndex">The input sql index.</param>
        ///--------------------------------------------------------------------------------
        public void LoadIndex(Index sqlIndex)
        {
            try
            {
                // load the basic index information
                SqlIndexName  = sqlIndex.Name;
                DbID          = sqlIndex.ID;
                IsClustered   = sqlIndex.IsClustered;
                IsUnique      = sqlIndex.IsUnique;
                IsXmlIndex    = sqlIndex.IsXmlIndex;
                IsFullTextKey = sqlIndex.IsFullTextKey;
                FileGroup     = sqlIndex.FileGroup;
                Urn           = sqlIndex.Urn;
                State         = sqlIndex.State.ToString();

                // load information for each property
                foreach (Microsoft.SqlServer.Management.Smo.Property loopProperty in sqlIndex.Properties)
                {
                    if (DebugHelper.DebugAction == DebugAction.Stop)
                    {
                        return;
                    }
                    if (loopProperty.Expensive == false && loopProperty.IsNull == false && !String.IsNullOrEmpty(loopProperty.Value.ToString()))
                    {
                        if (loopProperty.Name == "ID" || loopProperty.Name == "IgnoreDuplicateKeys" || loopProperty.Name == "IndexKeyType")
                        {
                            SqlProperty property = new SqlProperty();
                            property.SqlPropertyID = Guid.NewGuid();
                            property.SqlIndex      = this;
                            property.LoadProperty(loopProperty);
                            SqlPropertyList.Add(property);
                        }
                    }
                }

                // load information for each extended property
                //foreach (ExtendedProperty loopProperty in sqlIndex.ExtendedProperties)
                //{
                //    SqlExtendedProperty property = new SqlExtendedProperty();
                //    property.SqlExtendedPropertyID = Guid.NewGuid();
                //    property.SqlIndex = this;
                //    property.LoadExtendedProperty(loopProperty);
                //    SqlExtendedPropertyList.Add(property);
                //}

                // load information for each column
                foreach (IndexedColumn loopColumn in sqlIndex.IndexedColumns)
                {
                    if (DebugHelper.DebugAction == DebugAction.Stop)
                    {
                        return;
                    }
                    SqlIndexedColumn column = new SqlIndexedColumn();
                    column.SqlIndexedColumnID = Guid.NewGuid();
                    column.SqlIndex           = this;
                    column.LoadColumn(loopColumn);
                    SqlIndexedColumnList.Add(column);
                }
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                if (reThrow)
                {
                    throw;
                }
            }
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method loads a specification source with information from a
        /// SQL database.</summary>
        ///--------------------------------------------------------------------------------
        public void LoadSpecificationSource()
        {
            try
            {
                switch (DatabaseTypeCode)
                {
                case (int)BLL.Config.DatabaseTypeCode.SqlServer:
                    Database sqlDatabase = null;

                    Server sqlServer;
                    if (SourceDbServerName.StartsWith("(localdb)", StringComparison.OrdinalIgnoreCase))
                    {
                        var conn = new ServerConnection(new SqlConnection(String.Format("server={0};integrated security=true", SourceDbServerName)));
                        sqlServer = new Server(conn);
                        sqlServer.SetDefaultInitFields(true);
                    }
                    else
                    {
                        sqlServer = new Server(SourceDbServerName);
                        sqlServer.SetDefaultInitFields(true);
                        if (!String.IsNullOrEmpty(PasswordClearText) && !String.IsNullOrEmpty(UserName))
                        {
                            // sql server authentication
                            sqlServer.ConnectionContext.LoginSecure = false;
                            sqlServer.ConnectionContext.Login       = UserName;
                            sqlServer.ConnectionContext.Password    = PasswordClearText;
                        }
                        else
                        {
                            // windows authentication
                            sqlServer.ConnectionContext.LoginSecure = true;
                        }
                    }
                    sqlServer.ConnectionContext.Connect();
                    if (sqlServer.ConnectionContext.IsOpen == false)
                    {
                        SpecDatabase = null;
                        ApplicationException ex = new ApplicationException(String.Format(DisplayValues.Exception_SourceDbServerConnection, SourceDbServerName));
                        Solution.ShowIssue(ex.Message + "\r\n" + ex.StackTrace);
                        throw ex;
                    }

                    if (SourceDbName.Contains("\\"))
                    {
                        var dbName = Path.GetFileNameWithoutExtension(SourceDbName);
                        sqlDatabase = sqlServer.Databases[dbName];

                        if (sqlDatabase == null)
                        {
                            // attach the database instead of opening the database by name
                            var stringColl = new StringCollection();
                            stringColl.Add(SourceDbName);
                            stringColl.Add(Path.Combine(Path.GetDirectoryName(SourceDbName), Path.GetFileNameWithoutExtension(SourceDbName) + "_log.ldf"));

                            sqlServer.AttachDatabase(dbName, stringColl);

                            sqlDatabase = sqlServer.Databases[SourceDbName];
                        }
                    }
                    else
                    {
                        sqlDatabase = sqlServer.Databases[SourceDbName];
                    }

                    if (sqlDatabase == null)
                    {
                        SpecDatabase = null;
                        ApplicationException ex = new ApplicationException(String.Format(DisplayValues.Exception_SourceDbNotFound, SourceDbName, SourceDbServerName));
                        Solution.ShowIssue(ex.Message + "\r\n" + ex.StackTrace);
                        throw ex;
                    }
                    else
                    {
                        // load the database information
                        SpecDatabase = new SqlDatabase();
                        SpecDatabase.SqlDatabaseID = Guid.NewGuid();
                        SpecDatabase.Solution      = Solution;
                        SpecDatabase.LoadSqlServerDatabase(sqlDatabase);
                    }
                    break;

                case (int)BLL.Config.DatabaseTypeCode.MySQL:
                    string myConnectionString = "SERVER=" + SourceDbServerName + ";" +
                                                "DATABASE=" + SourceDbName + ";" +
                                                "UID=" + UserName + ";" +
                                                "PASSWORD="******";";
                    MySqlConnection connection = new MySqlConnection(myConnectionString);
                    using (connection)
                    {
                        try
                        {
                            connection.Open();
                        }
                        catch
                        {
                            SpecDatabase = null;
                            ApplicationException ex = new ApplicationException(String.Format(DisplayValues.Exception_MySQLConnection, SourceDbName, SourceDbServerName));
                            Solution.ShowIssue(ex.Message + "\r\n" + ex.StackTrace);
                            throw;
                        }
                        // load the database information
                        SpecDatabase = new SqlDatabase();
                        SpecDatabase.SqlDatabaseID = Guid.NewGuid();
                        SpecDatabase.Solution      = Solution;
                        SpecDatabase.LoadMySQLDatabase(connection);
                        connection.Close();
                    }
                    break;

                default:
                    throw new NotImplementedException("DatabaseTypeCode value " + DatabaseTypeCode + " not implemented!");
                }
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                Solution.ShowIssue(ex.ToString());
            }
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This loads information from a MySQL database.</summary>
        ///
        /// <param name="sqlConnection">The input sql connection</param>
        ///--------------------------------------------------------------------------------
        public void LoadMySQLDatabase(MySqlConnection sqlConnection)
        {
            try
            {
                // load the basic database information
                SqlDatabaseName = sqlConnection.Database;
                //Owner = sqlDatabase.Owner;
                //PrimaryFilePath = sqlDatabase.PrimaryFilePath;
                //DefaultSchema = sqlDatabase.DefaultSchema;
                //DefaultFileGroup = sqlDatabase.DefaultFileGroup;
                //CreateDate = sqlDatabase.CreateDate;

                // load variables
                NameObjectCollection variables = new NameObjectCollection();
                MySqlCommand         command   = sqlConnection.CreateCommand();
                command.CommandText = "SHOW VARIABLES;";
                MySqlDataReader Reader;
                Reader = command.ExecuteReader();
                while (Reader.Read())
                {
                    variables[Reader.GetValue(0).ToString()] = Reader.GetValue(1).ToString();
                }
                Reader.Close();

                // add variables to database properties
                foreach (string variable in variables.AllKeys)
                {
                    if (DebugHelper.DebugAction == DebugAction.Stop)
                    {
                        return;
                    }
                    SqlProperty property = new SqlProperty();
                    property.SqlPropertyID = Guid.NewGuid();
                    property.SqlDatabase   = this;
                    property.LoadMySQLProperty(variable, null, variables[variable].ToString());
                    SqlPropertyList.Add(property);
                }

                // load tables of schema info
                DataTable tables            = null;
                DataTable columns           = null;
                DataTable indexes           = null;
                DataTable indexColumns      = null;
                DataTable foreignKeys       = null;
                DataTable foreignKeyColumns = null;
                try
                {
                    tables = sqlConnection.GetSchema("Tables");
                }
                catch
                {
                    Solution.ShowIssue(String.Format(DisplayValues.Exception_MySQLSchemaLoad, "Tables", SqlDatabaseName), null, Solution.IsSampleMode);
                }
                try
                {
                    columns = sqlConnection.GetSchema("Columns");
                }
                catch
                {
                    Solution.ShowIssue(String.Format(DisplayValues.Exception_MySQLSchemaLoad, "Columns", SqlDatabaseName), null, Solution.IsSampleMode);
                }
                try
                {
                    indexes = sqlConnection.GetSchema("Indexes");
                }
                catch
                {
                    Solution.ShowIssue(String.Format(DisplayValues.Exception_MySQLSchemaLoad, "Indexes", SqlDatabaseName), null, Solution.IsSampleMode);
                }
                try
                {
                    indexColumns = sqlConnection.GetSchema("IndexColumns");
                }
                catch
                {
                    Solution.ShowIssue(String.Format(DisplayValues.Exception_MySQLSchemaLoad, "IndexColumns", SqlDatabaseName), null, Solution.IsSampleMode);
                }
                try
                {
                    foreignKeys = sqlConnection.GetSchema("Foreign Keys");
                }
                catch
                {
                    Solution.ShowIssue(String.Format(DisplayValues.Exception_MySQLSchemaLoad, "Foreign Keys", SqlDatabaseName), null, Solution.IsSampleMode);
                }
                try
                {
                    foreignKeyColumns = sqlConnection.GetSchema("Foreign Key Columns");
                }
                catch
                {
                    Solution.ShowIssue(String.Format(DisplayValues.Exception_MySQLSchemaLoad, "Foreign Key Columns", SqlDatabaseName), null, Solution.IsSampleMode);
                }

                // load information for each table
                if (tables != null)
                {
                    foreach (DataRow row in tables.Rows)
                    {
                        if (DebugHelper.DebugAction == DebugAction.Stop)
                        {
                            return;
                        }
                        SqlTable table = new SqlTable();
                        table.SqlTableID  = Guid.NewGuid();
                        table.SqlDatabase = this;
                        table.LoadMySQLTable(sqlConnection, variables, row, columns, indexes, indexColumns, foreignKeys, foreignKeyColumns);
                        SqlTableList.Add(table);
                    }
                }
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                if (reThrow)
                {
                    throw;
                }
            }
        }
Exemple #17
0
        ///--------------------------------------------------------------------------------
        /// <summary>This loads information from a MySQL index.</summary>
        ///
        /// <param name="sqlConnection">The input sql connection</param>
        /// <param name="variables">Database level variables</param>
        /// <param name="index">The table row data</param>
        /// <param name="indexColumns">The index columns table data</param>
        ///--------------------------------------------------------------------------------
        public void LoadMySQLIndex(MySqlConnection sqlConnection, NameObjectCollection variables, DataRow index, DataTable indexColumns)
        {
            try
            {
                // load index information
                foreach (DataColumn column in index.Table.Columns)
                {
                    // load important properties into index, the rest as additional sql properties
                    switch (column.ColumnName)
                    {
                    case "INDEX_NAME":
                        SqlIndexName = index[column.ColumnName].GetString();
                        break;

                    case "PRIMARY":
                        IsClustered = index[column.ColumnName].GetBool();                                 // may not be a good setting
                        break;

                    case "UNIQUE":
                        IsUnique = index[column.ColumnName].GetBool();
                        break;

                    default:
                        SqlProperty property = new SqlProperty();
                        property.SqlPropertyID = Guid.NewGuid();
                        property.SqlIndex      = this;
                        property.LoadMySQLProperty(column.ColumnName, null, index[column.ColumnName].GetString());
                        SqlPropertyList.Add(property);
                        break;
                    }
                }

                // load information for each column
                if (indexColumns != null)
                {
                    foreach (DataRow row in indexColumns.Rows)
                    {
                        if (DebugHelper.DebugAction == DebugAction.Stop)
                        {
                            return;
                        }
                        if (row["TABLE_NAME"].GetString() == SqlTable.SqlTableName && row["INDEX_NAME"].GetString() == SqlIndexName)
                        {
                            SqlIndexedColumn column = new SqlIndexedColumn();
                            column.SqlIndexedColumnID = Guid.NewGuid();
                            column.SqlIndex           = this;
                            column.LoadMySQLColumn(sqlConnection, variables, row);
                            SqlIndexedColumnList.Add(column);
                        }
                    }
                }
            }
            catch (ApplicationAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                bool reThrow = BusinessConfiguration.HandleException(ex);
                if (reThrow)
                {
                    throw;
                }
            }
        }