コード例 #1
0
        public void UpdateComparisonProgress(double progress, TableComparison newTable)
        {
            // System.Diagnostics.Debug.WriteLine("Reporting Async Progress: " + progress);
            OperationProgress = progress;

            if (newTable != null)
            {
                bool isInLeftDb  = (newTable.LeftTable != null);
                bool isInRightDb = (newTable.RightTable != null);

                DbTableComparisonViewModel tableVm = new DbTableComparisonViewModel(newTable, isInLeftDb, isInRightDb);
                ComparisonTables.Add(tableVm);
            }
        }
コード例 #2
0
        public DbTableComparisonViewModel(TableComparison tableComp, bool isInLeftDb, bool isInRightDb)
        {
            _tableComp  = tableComp;
            IsInLeftDb  = isInLeftDb;
            IsInRightDb = isInRightDb;

            if (_tableComp.LeftTable != null)
            {
                _tableName = _tableComp.LeftTable.Name;
            }
            else if (_tableComp.RightTable != null)
            {
                _tableName = _tableComp.RightTable.Name;
            }
            else
            {
                _tableName = "< Undefined >";
            }

            PopulateProperties();
        }
コード例 #3
0
 public DbTableComparisonViewModel(TableComparison tableComp)
     : this(tableComp, true, true)
 {
 }
コード例 #4
0
        /// <summary>
        /// Compares the schema (currently, by using field names only) of the left and right profiles,
        /// and
        /// </summary>
        /// <param name="leftProfile"></param>
        /// <param name="rightProfile"></param>
        /// <param name="tableFoundDelegate">A delegate that is invoked whenever a table comparison has completed. Useful for tracking progress.</param>
        /// <returns>TableComparison objects that explain the differences found between both profiles.</returns>
        public static List <TableComparison> CompareSchema(Profile leftProfile, Profile rightProfile, Action <double, TableComparison> tableFoundDelegate)
        {
            List <TableComparison> tables = new List <TableComparison>();

            DbConnection leftConnection  = new DbConnection(leftProfile.Host, leftProfile.Port, leftProfile.UserName, leftProfile.Password, leftProfile.Schema);
            DbConnection rightConnection = new DbConnection(rightProfile.Host, rightProfile.Port, rightProfile.UserName, rightProfile.Password, rightProfile.Schema);

            if (leftConnection.Open())
            {
                if (rightConnection.Open())
                {
                    List <string> leftTables  = DbTableDescriptions.GetTables(leftConnection);
                    List <string> rightTables = DbTableDescriptions.GetTables(rightConnection);

                    int leftTableCount    = leftTables.Count;
                    int currentTableCount = 0;

                    foreach (string leftTable in leftTables)
                    {
                        currentTableCount++;

                        double progress = ((double)currentTableCount / (double)leftTableCount) * 100;

                        // Look for this table in the collection of right tables
                        if (!rightTables.Contains(leftTable))
                        {
                            Table missingTable = new Table(leftTable);

                            // Get the properties of this table
                            List <TableProperty> missingProperties = DbTableDescriptions.GetFieldsForTable(leftTable, leftConnection);
                            missingTable.Properties = missingProperties;

                            missingTable.CreateStatement = DbTableDescriptions.GetCreateTableStatement(leftTable, leftConnection);

                            TableComparison tableComp = new TableComparison(missingTable, null);

                            // Use the supplied delegate to inform the consumer that we've found another table
                            tableFoundDelegate(progress, tableComp);

                            tables.Add(tableComp);
                        }
                        else
                        {
                            // Compare the properties of this table with those of the right table
                            List <TableProperty> leftProperties         = DbTableDescriptions.GetFieldsForTable(leftTable, leftConnection);
                            List <TableProperty> rightProperties        = DbTableDescriptions.GetFieldsForTable(leftTable, rightConnection); // Note: Not a typo. Using "leftTable" as a convenience, since they should be identical.
                            List <TableProperty> leftMissingProperties  = new List <TableProperty>();
                            List <TableProperty> rightMissingProperties = new List <TableProperty>();

                            // Search for properties in the left table that are missing from the right
                            foreach (TableProperty prop in leftProperties)
                            {
                                bool propFound = false;

                                foreach (TableProperty rightProp in rightProperties)
                                {
                                    if (rightProp.Name == prop.Name)
                                    {
                                        propFound = true;
                                    }
                                }

                                if (!propFound)
                                {
                                    leftMissingProperties.Add(prop);
                                }
                            }

                            // Search for properties in the right table that are missing from the left
                            foreach (TableProperty prop in rightProperties)
                            {
                                bool propFound = false;

                                foreach (TableProperty leftProp in leftProperties)
                                {
                                    if (leftProp.Name == prop.Name)
                                    {
                                        propFound = true;
                                    }
                                }

                                if (!propFound)
                                {
                                    rightMissingProperties.Add(prop);
                                }
                            }

                            if (leftMissingProperties.Count > 0 || rightMissingProperties.Count > 0)
                            {
                                TableComparison tableComp = new TableComparison();

                                if (leftMissingProperties.Count > 0)
                                {
                                    Table tableWithMissingProps = new Table(leftTable);
                                    tableWithMissingProps.Properties = leftMissingProperties;

                                    tableComp.LeftTable = tableWithMissingProps;
                                }

                                if (rightMissingProperties.Count > 0)
                                {
                                    Table tableWithMissingProps = new Table(leftTable);
                                    tableWithMissingProps.Properties = rightMissingProperties;

                                    tableComp.RightTable = tableWithMissingProps;
                                }

                                tables.Add(tableComp);

                                tableFoundDelegate(progress, tableComp);
                            }
                            else
                            {
                                tableFoundDelegate(progress, null);
                            }
                        }
                    }

                    rightConnection.Close();
                }
                else
                {
                    throw new Exception("Right connection error.");
                }

                leftConnection.Close();
            }
            else
            {
                throw new Exception("Left connection error.");
            }

            return(tables);
        }
コード例 #5
0
        private void Compare(Table table, TableComparison comparisonMode = TableComparison.TheTableAndSetMatchWithoutRegardForOrder, bool expectedMatch = true)
        {
            var collection = ScenarioContext.Current["Collection"] as IEnumerable <Item>;

            table.CompareToSet(collection, comparisonMode, expectedMatch);
        }
コード例 #6
0
 private void Compare(Table table, TableComparison comparisonMode = TableComparison.TheTableAndSetMatchWithoutRegardForOrder, bool expectedMatch = true)
 {
     var collection = ScenarioContext.Current["Collection"] as IEnumerable<Item>;
     table.CompareToSet(collection, comparisonMode, expectedMatch);
 }