Exemplo n.º 1
0
 public void CopyFrom(DatabaseMergeResult r)
 {
     foreach (var item in r.ColumnOperations)
     {
         columnOperations.Add(item);
     }
     foreach (var item in r.KeyOperations)
     {
         keyOperations.Add(item);
     }
     foreach (var item in r.IndexOperations)
     {
         indexOperations.Add(item);
     }
     foreach (var item in r.TableOperations)
     {
         tableOperations.Add(item);
     }
     foreach (var item in r.ViewOperations)
     {
         viewOperations.Add(item);
     }
     foreach (var item in r.RelationshipOperations)
     {
         if (!relationshipOperations.Any(o => o.Object == item.Object))
         {
             relationshipOperations.Add(item);
         }
     }
 }
Exemplo n.º 2
0
        public DatabaseMergeResult ProcessTable(ITable key, ITable value)
        {
            var columnResult       = ProcessTableForTableMemberChanges(key, key.Columns, value.Columns, n => n.Name, new ColumnOperationFactory(), new Column.ColumnComparer());
            var keyResult          = ProcessTableForTableMemberChanges(key, key.Keys, value.Keys, n => n.Name, new KeyOperationFactory(), new Key.KeyComparer());
            var indexResult        = ProcessTableForTableMemberChanges(key, key.Indexes.Where(i => i.IndexType != ArchAngel.Providers.EntityModel.Helper.DatabaseIndexType.PrimaryKey && i.IndexType != ArchAngel.Providers.EntityModel.Helper.DatabaseIndexType.ForeignKey), value.Indexes.Where(i => i.IndexType != ArchAngel.Providers.EntityModel.Helper.DatabaseIndexType.PrimaryKey && i.IndexType != ArchAngel.Providers.EntityModel.Helper.DatabaseIndexType.ForeignKey), n => n.Name, new IndexOperationFactory(), new Index.IndexComparer());
            var relationshipResult = ProcessTableForTableMemberChanges(key, key.Relationships, value.Relationships, n => n.Name, new RelationshipOperationFactory(), new RelationshipImpl.RelationshipComparer());

            DatabaseMergeResult result = new DatabaseMergeResult();

            result.AddColumnOperations(columnResult);
            result.AddKeyOperations(keyResult);
            result.AddIndexOperations(indexResult);
            result.AddRelationshipOperations(relationshipResult);

            return(result);
        }
Exemplo n.º 3
0
        public DatabaseMergeResult ProcessTables(IEnumerable <ITable> tables1, IEnumerable <ITable> tables2)
        {
            DatabaseMergeResult result = new DatabaseMergeResult();

            // Get all of the tables with the same name in the existing and refreshed table lists
            IEnumerable <KeyValuePair <ITable, ITable> > union = GetEqualTables(tables1, tables2);

            //Find changed table components.
            foreach (var tablePair in union)
            {
                var r = ProcessTable(tablePair.Key, tablePair.Value);
                result.CopyFrom(r);
            }

            return(result);
        }
        public DatabaseMergeResult MergeDatabases(IDatabase db1, IDatabase db2)
        {
            DatabaseMergeResult mergeResult = new DatabaseMergeResult();

            #region Tables
            IEnumerable <ITable> tables1 = db1.Tables;
            IEnumerable <ITable> tables2 = db2.Tables;

            List <ITable> newTables     = tables1.Compliment(tables2).ToList();
            List <ITable> removedTables = tables2.Compliment(tables1).ToList();

            // Check for changed tables.
            Func <ITable, string> sorter        = n => n.Name;
            Table.TableComparer   comparer      = new Table.TableComparer();
            IEnumerable <ITable>  intersection1 = tables1.Intersect(tables2, comparer).OrderBy(sorter);
            var commonItems = intersection1.Zip(tables2.Intersect(tables1, comparer).OrderBy(sorter));

            foreach (var memberPair in commonItems)
            {
                if (memberPair.Key.HasChanges(memberPair.Value))
                {
                    mergeResult.AddTableOperation(new TableChangeOperation(memberPair.Key, memberPair.Value));
                }
            }

            foreach (var t in newTables)
            {
                mergeResult.AddTableOperation(new TableAdditionOperation(db1, t));
            }

            foreach (var t in removedTables)
            {
                mergeResult.AddTableOperation(new TableRemovalOperation(t));
            }

            TableProcessor processor    = new TableProcessor();
            var            tableResults = processor.ProcessTables(tables1, tables2);
            mergeResult.CopyFrom(tableResults);
            #endregion

            #region Views
            IEnumerable <ITable> views1 = db1.Views;
            IEnumerable <ITable> views2 = db2.Views;

            List <ITable> newViews     = views1.Compliment(views2).ToList();
            List <ITable> removedViews = views2.Compliment(views1).ToList();

            // Check for changed tables.
            IEnumerable <ITable> viewsIntersection1 = views1.Intersect(views2, comparer).OrderBy(sorter);
            var commonViewItems = intersection1.Zip(views2.Intersect(views1, comparer).OrderBy(sorter));

            foreach (var memberPair in commonViewItems)
            {
                if (memberPair.Key.HasChanges(memberPair.Value))
                {
                    mergeResult.AddViewOperation(new TableChangeOperation(memberPair.Key, memberPair.Value));
                }
            }

            foreach (var t in newViews)
            {
                mergeResult.AddViewOperation(new TableAdditionOperation(db1, t));
            }

            foreach (var t in removedViews)
            {
                mergeResult.AddViewOperation(new TableRemovalOperation(t));
            }

            TableProcessor viewProcessor = new TableProcessor();
            var            viewResults   = processor.ProcessTables(views1, views2);
            mergeResult.CopyFrom(viewResults);
            #endregion

            return(mergeResult);
        }