Exemplo n.º 1
0
        /// <summary>
        /// This method Remote Compare Databases
        /// </summary>
        public void RemoteCompareDatabases()
        {
            try
            {
                // clear the text
                Clear();

                // locals
                string           message          = "";
                string           title            = "Validation Failed";
                Database         sourceDatabase   = new Database();
                Database         targetDatabase   = new Database();
                SchemaComparison schemaComparison = new SchemaComparison();

                // Set Focus to this button
                this.HiddenButton.Focus();

                // Disable the button
                this.CompareDatabasesButton.Enabled = false;

                // Change the Cursor
                this.Cursor = Cursors.WaitCursor;

                // Refresh the UI
                this.Refresh();

                // Capture the CompareInfo
                CaptureCompareInfo();

                // Save the current settings
                SaveSettings();

                // Is this valid
                bool validConnections = this.CompareInfo.IsValid();

                // if the validConnections
                if (validConnections)
                {
                    // Load the Schema for both databases
                    LoadDatabaseSchema(this.CompareInfo.SourceXmlFilePath, ref sourceDatabase);
                    LoadDatabaseSchema(this.CompareInfo.TargetDatabaseConnector, ref targetDatabase);

                    // Compare the database structure
                    CompareDatabaseStructure(sourceDatabase, targetDatabase);

                    // Increment the CompareCount
                    this.Settings.CompareCount++;

                    // Save the Settings
                    this.Settings.Save();
                }
                else
                {
                    // Show a failed reason
                    message = this.CompareInfo.InvalidReason;

                    // Show the user a message
                    MessageBoxHelper.ShowMessage(message, title);
                }
            }
            catch (Exception error)
            {
                // for debugging only
                string err = error.ToString();

                // Show the error
                this.ResultsTextBox.Text = "An error occurred: " + Environment.NewLine + err;
            }
            finally
            {
                // Renable the button
                CompareDatabasesButton.Enabled = true;
                this.Cursor = Cursors.Default;
                this.Refresh();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method does the actual comparison; it is called by the RemoteCompare and the normal comparison
        /// </summary>
        private void CompareDatabaseStructure(Database sourceDatabase, Database targetDatabase)
        {
            // local
            SchemaComparison schemaComparison = new SchemaComparison();

            // verify both objects exist
            if (NullHelper.Exists(sourceDatabase, targetDatabase))
            {
                // test if any data was loaded before showing 'The target database is up to date message incorrectly'
                if (sourceDatabase.Tables.Count > 0)
                {
                    // Get the value for IgnoreDiagramProcedures
                    bool ignoreDiagramProcedures = this.IgnoreDiagramProceduresCheckBox.Checked;

                    // Create a new database comparer
                    DatabaseComparer comparer = new DatabaseComparer(sourceDatabase, targetDatabase, ignoreDiagramProcedures);

                    // Compare the two database schemas
                    schemaComparison = comparer.Compare();
                }
                else
                {
                    // Add this as a message
                    schemaComparison.SchemaDifferences.Add("The source database does not contain any tables; the comparison cannot continue.");
                }

                // compare the two schemas
                if (schemaComparison != null)
                {
                    // if the two database are equal
                    if (schemaComparison.IsEqual)
                    {
                        // Show the two databases are equal
                        this.ResultsTextBox.Text = "The target database is up to date.";
                    }
                    else
                    {
                        // Display the count
                        this.CountLabel.Text = "Count: " + schemaComparison.SchemaDifferences.Count;

                        // Create a string builder
                        StringBuilder sb = new StringBuilder("The target database is not valid.");

                        // Append a new line
                        sb.Append(Environment.NewLine);

                        // iterate the errors
                        foreach (string schemaDifference in schemaComparison.SchemaDifferences)
                        {
                            // Append an indention
                            sb.Append("    ");
                            sb.Append(schemaDifference);
                            sb.Append(Environment.NewLine);
                        }

                        // Show the schema differences
                        this.ResultsTextBox.Text = sb.ToString();

                        // This is a stub for an update for Version 3.0 that isn't ready to be released
                        //// create a message for how to
                        //message = "Would you like to attempt to fix any errors if possible?";

                        //// Get the users response
                        //DialogResult result = MessageBoxHelper.GetUserResponse(message, "Fix Schema Differences?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                        //// if the user choose yes
                        //if (result == DialogResult.Yes)
                        //{
                        //    // attempt to fix any schema differences
                        //    int fixedCount = SqlUpdater.FixSchemaDifferences(schemaComparison.SchemaDifferences, targetDatabaseConnector, sourceDatabase);
                        //}
                    }
                }
            }
            else if (NullHelper.IsNull(sourceDatabase))
            {
                // Show the user a message
                this.ResultsTextBox.Text = "The source database could not be loaded.";
            }
            else if (NullHelper.IsNull(targetDatabase))
            {
                // Show the user a message
                this.ResultsTextBox.Text = "The target database could not be loaded.";
            }
        }