コード例 #1
0
        /// <summary>
        /// Creates a new migration engine instance.
        /// </summary>
        /// <param name="scriptBuilder">The script builder instance.</param>
        /// <param name="dbComparer">The DB comparer instance.</param>
        public MigrationEngine(IScriptBuilder scriptBuilder, IDatabaseComparer dbComparer)
        {
            Throw.If(scriptBuilder, "scriptBuilder").IsNull();
            Throw.If(dbComparer, "dbComparer").IsNull();

            this.scriptBuilder = scriptBuilder;
            this.dbComparer    = dbComparer;
        }
コード例 #2
0
ファイル: PrincipalForm.cs プロジェクト: posttk421/OpenDBDiff
        private void StartComparision()
        {
            ProgressForm progress      = null;
            string       errorLocation = null;

            try
            {
                if ((!String.IsNullOrEmpty(ProjectSelectorHandler.GetSourceDatabaseName()) &&
                     (!String.IsNullOrEmpty(ProjectSelectorHandler.GetDestinationDatabaseName()))))
                {
                    Options = Options ?? this.ProjectSelectorHandler.GetDefaultProjectOptions();
                    IGenerator        sourceGenerator      = this.ProjectSelectorHandler.SetSourceGenerator(SourceSelector.ConnectionString, Options);
                    IGenerator        destinationGenerator = this.ProjectSelectorHandler.SetDestinationGenerator(DestinationSelector.ConnectionString, Options);
                    IDatabaseComparer databaseComparer     = this.ProjectSelectorHandler.GetDatabaseComparer();

                    progress = new ProgressForm("Source Database", "Destination Database", destinationGenerator, sourceGenerator, databaseComparer);
                    progress.ShowDialog(this);
                    if (progress.Error != null)
                    {
                        throw new SchemaException(progress.Error.Message, progress.Error);
                    }

                    selectedOrigin      = progress.Source;
                    selectedDestination = progress.Destination;

                    txtSyncScript.ConfigurationManager.Language = this.ProjectSelectorHandler.GetScriptLanguage();
                    txtSyncScript.IsReadOnly = false;
                    txtSyncScript.Styles.LineNumber.BackColor = Color.White;
                    txtSyncScript.Styles.LineNumber.IsVisible = false;
                    errorLocation                       = "Generating Synchronized Script";
                    txtSyncScript.Text                  = selectedDestination.ToSqlDiff(this._selectedSchemas).ToSQL();
                    txtSyncScript.IsReadOnly            = true;
                    schemaTreeView1.DatabaseSource      = selectedDestination;
                    schemaTreeView1.DatabaseDestination = selectedOrigin;
                    schemaTreeView1.OnSelectItem       += new SchemaTreeView.SchemaHandler(schemaTreeView1_OnSelectItem);
                    schemaTreeView1_OnSelectItem(schemaTreeView1.SelectedNode);
                    textBox1.Text = selectedOrigin.ActionMessage.Message;

                    btnCopy.Enabled      = true;
                    btnSaveAs.Enabled    = true;
                    btnUpdateAll.Enabled = true;
                }
                else
                {
                    MessageBox.Show(Owner, "Please select a valid connection string", "ERROR", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                if (errorLocation == null && progress != null)
                {
                    errorLocation = String.Format("{0} (while {1})", progress.ErrorLocation, progress.ErrorMostRecentProgress ?? "initializing");
                }

                throw new SchemaException("Error " + (errorLocation ?? " Comparing Databases"), ex);
            }
        }
コード例 #3
0
        // TODO: thread-safe error reporting

        public ProgressForm(string sourceDatabaseName, string destinationDatabaseName, IGenerator destinationGenerator, IGenerator sourceGenerator, IDatabaseComparer comparer)
        {
            Destination = null;
            Source      = null;
            InitializeComponent();
            sourceProgressControl.Maximum      = sourceGenerator.GetMaxValue();
            sourceProgressControl.DatabaseName = sourceDatabaseName;
            this.SourceGenerator = sourceGenerator;

            destinationProgressControl.Maximum      = destinationGenerator.GetMaxValue();
            destinationProgressControl.DatabaseName = destinationDatabaseName;
            this.DestinationGenerator = destinationGenerator;

            this.Comparer = comparer;
        }
コード例 #4
0
        public void SetUp()
        {
            mocks         = new MockRepository();
            scriptBuilder = mocks.CreateMock <IScriptBuilder>();
            msgManager    = mocks.DynamicMock <IScriptMessageManager>();
            connSettings  = mocks.Stub <IConnectionSettings>();

            dbComparer = new DatabaseComparer();

            engine = new MigrationEngine(scriptBuilder, dbComparer);
            engine.MessageManager = msgManager;

            srcDB    = new DatabaseStub("SRC_DB");
            targetDB = new DatabaseStub("TARGET_DB");
        }
コード例 #5
0
ファイル: ProgressForm.cs プロジェクト: wushian/OpenDBDiff
        // TODO: thread-safe error reporting

        public ProgressForm(KeyValuePair <string, IGenerator> originDatabase, KeyValuePair <string, IGenerator> destinationDatabase, IDatabaseComparer comparer)
        {
            InitializeComponent();

            Origin      = null;
            Destination = null;
            originProgressControl.Maximum      = originDatabase.Value.GetMaxValue();
            originProgressControl.DatabaseName = originDatabase.Key;
            this.OriginGenerator = originDatabase.Value;

            destinationProgressControl.Maximum      = destinationDatabase.Value.GetMaxValue();
            destinationProgressControl.DatabaseName = destinationDatabase.Key;
            this.DestinationGenerator = destinationDatabase.Value;

            this.Comparer = comparer;
        }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: qxguoxing/OpenDBDiff
        private void StartComparison()
        {
            ProgressForm progress      = null;
            string       errorLocation = null;

            try
            {
                if ((!String.IsNullOrEmpty(ProjectSelectorHandler.GetSourceDatabaseName()) &&
                     (!String.IsNullOrEmpty(ProjectSelectorHandler.GetDestinationDatabaseName()))))
                {
                    Options = Options ?? this.ProjectSelectorHandler.GetDefaultProjectOptions();
                    var leftGenerator  = this.ProjectSelectorHandler.SetSourceGenerator(LeftDatabaseSelector.ConnectionString, Options);
                    var rightGenerator = this.ProjectSelectorHandler.SetDestinationGenerator(RightDatabaseSelector.ConnectionString, Options);
                    IDatabaseComparer databaseComparer = this.ProjectSelectorHandler.GetDatabaseComparer();

                    var leftPair  = new KeyValuePair <String, IGenerator>(LeftDatabaseSelector.ToString(), leftGenerator);
                    var rightPair = new KeyValuePair <String, IGenerator>(RightDatabaseSelector.ToString(), rightGenerator);

                    // The progress form will execute the comparer to generate action scripts to migrate the right to the left
                    // Hence, inside the ProgressForm and deeper, right is the origin and left is the destination
                    progress = new ProgressForm(rightPair, leftPair, databaseComparer);
                    progress.ShowDialog(this);
                    if (progress.Error != null)
                    {
                        throw new SchemaException(progress.Error.Message, progress.Error);
                    }

                    txtSyncScript.LexerLanguage = this.ProjectSelectorHandler.GetScriptLanguage();
                    txtSyncScript.ReadOnly      = false;
                    errorLocation          = "Generating Synchronized Script";
                    txtSyncScript.Text     = progress.Destination.ToSqlDiff(this._selectedSchemas).ToSQL();
                    txtSyncScript.ReadOnly = true;
                    txtSyncScript.SetMarginWidth();

                    // Notice again that left is destination, because we generated scripts to migrate the right database to the left.
                    schemaTreeView1.LeftDatabase  = progress.Destination;
                    schemaTreeView1.RightDatabase = progress.Origin;

                    schemaTreeView1.OnSelectItem += new SchemaTreeView.SchemaHandler(schemaTreeView1_OnSelectItem);
                    schemaTreeView1_OnSelectItem(schemaTreeView1.SelectedNode);
                    textBox1.Text = progress.Origin.ActionMessage.Message;

                    btnCopy.Enabled      = true;
                    btnSaveAs.Enabled    = true;
                    btnUpdateAll.Enabled = true;
                }
                else
                {
                    MessageBox.Show(Owner, "Please select a valid connection string", "ERROR", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                if (errorLocation == null && progress != null)
                {
                    errorLocation = String.Format("{0} (while {1})", progress.ErrorLocation, progress.ErrorMostRecentProgress ?? "initializing");
                }

                throw new SchemaException("Error " + (errorLocation ?? " Comparing Databases"), ex);
            }
        }