public void CompareObjects(SchemaMemberSelection SourceSelection, SchemaMemberSelection TargetSelection)
        {
            /*T Display.DialogMessage("Comparing...", "Source=[" + (SourceSelection == null ? "<UNMATCHED>" : SourceSelection.MemberNameCaption) +
             *                                 "], Target=[" + (TargetSelection == null ? "<UNMATCHED>" : TargetSelection.MemberNameCaption) + "]"); */

            this.PropertiesGrid.RowDefinitions.Clear();
            this.PropertiesGrid.Children.Clear();

            if (SourceSelection != null && SourceSelection.RefMember != null &&
                TargetSelection != null && TargetSelection.RefMember != null &&
                SourceSelection.RefMember.GetType() != TargetSelection.RefMember.GetType())
            {
                return; // Instances must have same type!
            }
            if ((SourceSelection != null && SourceSelection.RefMember is SchemaMemberGroup) ||
                (TargetSelection != null && TargetSelection.RefMember is SchemaMemberGroup))
            {
                return;
            }

            var Properties = SourceSelection.Get(sel => sel.RefMember as IModelEntity)
                             .Get(ins => ins.ClassDefinition)
                             .Get(cld => cld.Properties)
                             .NullDefault(Enumerable.Empty <MModelPropertyDefinitor>())
                             .Concat(TargetSelection.Get(sel => sel.RefMember as IModelEntity)
                                     .Get(ins => ins.ClassDefinition)
                                     .Get(cld => cld.Properties)
                                     .NullDefault(Enumerable.Empty <MModelPropertyDefinitor>()))
                             .Distinct().OrderBy(prop => prop.Name);

            var SourceInstance = SourceSelection.Get(sel => sel.RefMember as IModelEntity);
            var TargetInstance = TargetSelection.Get(sel => sel.RefMember as IModelEntity);

            foreach (var PropDef in Properties)
            {
                var SourceValue = (SourceInstance == null ? null : PropDef.Read(SourceInstance));
                var TargetValue = (TargetInstance == null ? null : PropDef.Read(TargetInstance));
                if (SourceValue == null && TargetValue == null)
                {
                    continue;
                }

                var ActionCode = MergingManager.MERGE_ACTION_UPDATE;

                /* Cancelled: No property level merge will be provided yet
                 * var ActionCode = (MergingManager.PreferredComparer(SourceValue, TargetValue)
                 *                ? MergingManager.MERGE_ACTION_NONE
                 *                : MergingManager.MERGE_ACTION_UPDATE); */

                AddComparisonRow(PropDef, ActionCode, SourceValue, TargetValue,
                                 SourceSelection != null && TargetSelection != null);
            }
        }
Example #2
0
        public void CompareProperties(SchemaMemberSelection SourceSelection, SchemaMemberSelection TargetSelection)
        {
            General.ContractRequires(SourceSelection != null || TargetSelection != null);

            if (SourceSelection == null)
            {
                SourceSelection = TargetSelection.FindEquivalentCounterpartAtSameLevel(this.SourceSelectionRoot, MergingManager.PreferredComparer);
                if (SourceSelection != null)
                {
                    this.MergerCompoBrowserSource.TvSelection.PostCall(tv =>
                    {
                        if (this.MergerCompoBrowserSource.LastPointedItem != null)
                        {
                            this.MergerCompoBrowserSource.LastPointedItem.IsPointed = false;
                        }
                        this.MergerCompoBrowserSource.LastPointedItem = SourceSelection;
                        SourceSelection.IsPointed = true;

                        var Container = tv.FindContainerByItemInAllChildren(SourceSelection);
                        if (Container != null)
                        {
                            Container.BringIntoView();
                        }
                    });
                }
            }

            if (TargetSelection == null)
            {
                TargetSelection = SourceSelection.FindEquivalentCounterpartAtSameLevel(this.TargetSelectionRoot, MergingManager.PreferredComparer);
                if (TargetSelection != null)
                {
                    this.MergerCompoBrowserTarget.TvSelection.PostCall(tv =>
                    {
                        if (this.MergerCompoBrowserTarget.LastPointedItem != null)
                        {
                            this.MergerCompoBrowserTarget.LastPointedItem.IsPointed = false;
                        }
                        this.MergerCompoBrowserTarget.LastPointedItem = TargetSelection;
                        TargetSelection.IsPointed = true;

                        var Container = tv.FindContainerByItemInAllChildren(TargetSelection);
                        if (Container != null)
                        {
                            Container.BringIntoView();
                        }
                    });
                }
            }

            this.MergerPropertiesComparer.CompareObjects(SourceSelection, TargetSelection);
        }
Example #3
0
        public MergePreparer(Composition SourceComposition, Composition TargetComposition,
                             SchemaMemberSelection SourceSelectionRoot, SchemaMemberSelection TargetSelectionRoot)
            : this()
        {
            General.ContractRequiresNotNull(SourceComposition, TargetComposition, SourceSelectionRoot, TargetSelectionRoot);

            this.SourceComposition   = SourceComposition;
            this.SourceSelectionRoot = SourceSelectionRoot;

            this.TargetComposition   = TargetComposition;
            this.TargetSelectionRoot = TargetSelectionRoot;

            this.MergerCompoBrowserTarget.IsForSelection = false;

            //- this.DataContext = this.TargetConfiguration;
        }
        private void TvSelection_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            var Selection = e.NewValue as SchemaMemberSelection;

            if (Selection == null)
            {
                return;
            }

            if (this.LastPointedItem != null)
            {
                this.LastPointedItem.IsPointed = false;
            }

            Selection.IsPointed  = true;
            this.LastPointedItem = Selection;

            if (this.SelectedMemberOperation == null)
            {
                return;
            }

            SelectedMemberOperation(Selection);
        }
        private static CompositionMerger CreateMerger(Composition SourceComposition, Composition TargetComposition,
                                                      SchemaMemberSelection Selection)
        {
            var Merger = new CompositionMerger(SourceComposition, TargetComposition);

            var SelectedPairs = Selection.GetSelection(true);

            Merger.SourceEntities.AddRange(SelectedPairs.Select(sel => sel.Key.RefMember)
                                           .CastAs <IModelEntity, object>());

            foreach (var SelectedPair in SelectedPairs)
            {
                if (SelectedPair.Value.RefMember == GroupConceptDefs && SelectedPair.Key.RefMember is ConceptDefinition)
                {
                    Merger.SelectedConceptDefs.Add((ConceptDefinition)SelectedPair.Key.RefMember);
                }
                else
                if (SelectedPair.Value.RefMember == GroupRelationshipDefs && SelectedPair.Key.RefMember is RelationshipDefinition)
                {
                    Merger.SelectedRelationshipDefs.Add((RelationshipDefinition)SelectedPair.Key.RefMember);
                }
                else
                if (SelectedPair.Value.RefMember == GroupLinkRoleVariantDefs && SelectedPair.Key.RefMember is SimplePresentationElement)
                {
                    Merger.SelectedLinkRoleVariantDefs.Add((SimplePresentationElement)SelectedPair.Key.RefMember);
                }
                else
                if (SelectedPair.Value.RefMember == GroupBaseTables && SelectedPair.Key.RefMember is Table)
                {
                    Merger.SelectedBaseTables.Add((Table)SelectedPair.Key.RefMember);
                }
                else
                if (SelectedPair.Value.RefMember == GroupExternalLanguages && SelectedPair.Key.RefMember is ExternalLanguageDeclaration)
                {
                    Merger.SelectedExternalLanguages.Add((ExternalLanguageDeclaration)SelectedPair.Key.RefMember);
                }
                else
                if (SelectedPair.Value.RefMember == GroupIdeaDefClusters && SelectedPair.Key.RefMember is FormalPresentationElement)
                {
                    var IdeaDefCluster = (FormalPresentationElement)SelectedPair.Key.RefMember;
                    if (SourceComposition.CompositeContentDomain.ConceptDefClusters.Contains(IdeaDefCluster))
                    {
                        Merger.SelectedConceptDefClusters.Add(IdeaDefCluster);
                    }
                    else
                    {
                        Merger.SelectedRelationshipDefClusters.Add(IdeaDefCluster);
                    }
                }
                else
                if (SelectedPair.Value.RefMember == GroupMarkerDefs && SelectedPair.Key.RefMember is MarkerDefinition)
                {
                    Merger.SelectedMarkerDefs.Add((MarkerDefinition)SelectedPair.Key.RefMember);
                }
                else
                if (SelectedPair.Key.RefMember is IModelEntity)
                {
                    Merger.SelectedOtherEntities.Add((IModelEntity)SelectedPair.Key.RefMember);
                }
            }

            return(Merger);
        }
        public static bool PrepareAndMergeCompositions(Composition SourceComposition, Composition TargetComposition)
        {
            var InstanceController = EntityInstanceController.AssignInstanceController(TargetComposition);

            InstanceController.StartEdit();

            var Randomizer      = new Random();
            var SourceSelection = SchemaMemberSelection.CreateSelectionTree(SourceComposition, null, null,
                                                                            obj =>
            {
                var MrgActIdx = Randomizer.Next(0, 3);
                return(Tuple.Create(MrgActIdx != 0 || !SchemaMemberSelection.GetAccesor(obj)
                                    .ChildrenGetter(obj).IsEmpty(),                                                         // Is-Selectable
                                    MrgActIdx != 0 && MrgActIdx != 3,                                                       // Is-Selected
                                    !(obj is SchemaMemberGroup),                                                            // Can-show-is-selected
                                    (IRecognizableElement)MergingManager.MergeActions[MrgActIdx]));                         // Merge-Action
            });

            var TargetSelection = SchemaMemberSelection.CreateSelectionTree(TargetComposition);

            var PreparePanel = new MergePreparer(SourceComposition, TargetComposition, SourceSelection, TargetSelection);

            /*
             * InstanceController.PostValidate = ((curr, prev) =>
             * {
             *  if (curr.TargetDirectory.IsAbsent() || !Directory.Exists(curr.TargetDirectory))
             *      return "Target directory not set or not found".IntoList();
             *
             *  return null;
             * });
             * InstanceController.PreApply = ((curr, prev, args) =>
             * {
             *  curr.ExcludedIdeasGlobalIds.Clear();
             *  curr.ExcludedIdeasGlobalIds.AddRange(ConfigPanel.TargetConfiguration.CurrentSelection.GetSelection(false)   // Gets the not-selected Ideas
             *                                              .Select(sel => sel.TargetIdea.GlobalId.ToString()));
             *  return true;
             * }); */

            var EditPanel = Display.CreateEditPanel(TargetComposition, PreparePanel);

            var Title   = "Merge '" + TargetComposition.Name + "' with '" + SourceComposition.Name + "'";
            var DoMerge = InstanceController.Edit(EditPanel, "Merge Compositions/Domains content", true, null, 950, 650).IsTrue();

            if (DoMerge)
            {
                var Merger = CreateMerger(SourceComposition, TargetComposition, SourceSelection);

                var Started = ProgressiveThreadedExecutor <int> .Execute <int>(Title, Merger.Merge,
                                                                               (opresult) =>
                {
                    if (!opresult.WasSuccessful)
                    {
                        Display.DialogMessage("Merge not completed!", opresult.Message, EMessageType.Warning);
                        return;
                    }

                    if (opresult.Message != null)
                    {
                        Console.WriteLine(opresult.Message);
                    }

                    Display.DialogMessage("Merge completed", opresult.Message.AbsentDefault("Compositions Merge successfully executed."));
                });
            }

            return(DoMerge);
        }
        static MergingManager()
        {
            MergeActions.Add(new SimplePresentationElement("<NONE>", MERGE_ACTION_NONE, "Do nothing. No differences were detected."));
            MergeActions.Add(new SimplePresentationElement("Create", MERGE_ACTION_CREATE, "Create this object in the target, because not exist there.", Display.GetAppImage("add.png")));
            MergeActions.Add(new SimplePresentationElement("Update", MERGE_ACTION_UPDATE, "Update this object in the target, because differences were detected.", Display.GetAppImage("page_white_edit.png")));
            MergeActions.Add(new SimplePresentationElement("Delete", MERGE_ACTION_DELETE, "Delete this object (NOT RECOMMENDED), because not exist is the source.", Display.GetAppImage("delete.png")));

            SchemaMemberSelection.ClearRegisteredMemberTypeOperationsSets();

            // From the most specific to the most general...
            SchemaMemberSelection.RegisterMemberTypeOperationsSet <SchemaMemberGroup>(grp => grp.ChildrenGetter(),
                                                                                      grp => grp.Name,
                                                                                      grp => grp.Summary,
                                                                                      grp => grp.Pictogram);

            SchemaMemberSelection.RegisterMemberTypeOperationsSet <Idea>(//idea => idea.CompositeIdeas.OrderBy(ci => (ci is Concept ? "0" : "1") + ci.Name),
                idea => General.CreateArrayWithoutNulls <IRecognizableElement>
                    ((idea.CompositeConcepts.Any()
                                                         ? new SchemaMemberGroup("[CONCEPTS]", Display.GetAppImage("ref_concept.png"),
                                                                                 () => idea.CompositeConcepts.OrderBy(it => it.Name))
                                                         : null),
                    (idea.CompositeRelationships.Any()
                                                         ? new SchemaMemberGroup("[RELATIONSHIPS]", Display.GetAppImage("ref_relationship.png"),
                                                                                 () => idea.CompositeRelationships.OrderBy(it => it.Name))
                                                         : null),
                    (idea.CompositeActiveView != null
                                                         ? new SchemaMemberGroup("[COMPLEMENTS]", Display.GetAppImage("shapes.png"),
                                                                                 () => idea.CompositeActiveView.GetFreeComplements())
                                                         : null),
                    //- (idea is Composition ? idea.CompositeContentDomain : null),
                    (idea is Composition
                                                         ? new SchemaMemberGroup("[DOMAIN]", Display.GetAppImage("page_definition.png"),
                                                                                 () => idea.CompositeContentDomain.IntoEnumerable())
                                                         : null)),
                idea => idea.NameCaption,
                idea => idea.Summary,
                idea => idea.Pictogram,
                idea => idea.DescriptiveCaption,
                idea => idea.Definitor.Pictogram);

            SchemaMemberSelection.RegisterMemberTypeOperationsSet <Domain>(
                dom => General.CreateArrayWithoutNulls(GroupConceptDefs = new SchemaMemberGroup("Concept Definitions", ConceptDefinition.PredefinedDefaultPictogram,
                                                                                                () => dom.ConceptDefinitions.OrderBy(it => it.Name)),
                                                       GroupRelationshipDefs = new SchemaMemberGroup("Relationship Definitions", RelationshipDefinition.PredefinedDefaultPictogram,
                                                                                                     () => dom.RelationshipDefinitions.OrderBy(it => it.Name)),
                                                       GroupLinkRoleVariantDefs = new SchemaMemberGroup("Link-Role Variant Definitions", Display.GetAppImage("link_role_variants.png"),
                                                                                                        () => dom.LinkRoleVariants.OrderBy(it => it.Name)),
                                                       GroupTableStructureDefs = new SchemaMemberGroup("Table-Structure Definitions", Display.GetAppImage("table_alter.png"),
                                                                                                       () => dom.TableDefinitions.OrderBy(it => it.Name)),
                                                       GroupBaseTables = new SchemaMemberGroup("Base Tables", Display.GetAppImage("table_multiple.png"),
                                                                                               () => dom.BaseTables.OrderBy(it => it.Name)),
                                                       GroupExternalLanguages = new SchemaMemberGroup("External Languages", Display.GetAppImage("page_white_code_red.png"),
                                                                                                      () => dom.ExternalLanguages.OrderBy(it => it.Name)),
                                                       GroupIdeaDefClusters = new SchemaMemberGroup("Idea-Definition Clusters", Display.GetAppImage("def_clusters.png"),
                                                                                                    () => dom.ConceptDefClusters.OrderBy(it => it.Name)
                                                                                                    .Concat(dom.RelationshipDefClusters.OrderBy(it => it.Name))),
                                                       GroupMarkerDefs = new SchemaMemberGroup("Marker Definitions", Display.GetAppImage("tag_red.png"),
                                                                                               () => dom.MarkerDefinitions.OrderBy(it => it.Name))),
                dom => dom.NameCaption,
                dom => dom.Summary,
                dom => dom.Pictogram);

            SchemaMemberSelection.RegisterMemberTypeOperationsSet <IdeaDefinition>(idef => null,
                                                                                   idef => idef.NameCaption,
                                                                                   idef => idef.Summary,
                                                                                   idef => idef.Pictogram);

            /*- SchemaMemberSelection.RegisterMemberTypeOperationsSet<MarkerDefinition>(mdef => null,
             *                                                                      mdef => mdef.NameCaption,
             *                                                                      mdef => mdef.Summary,
             *                                                                      mdef => mdef.Pictogram); */

            SchemaMemberSelection.RegisterMemberTypeOperationsSet <IRecognizableElement>(elem => null,
                                                                                         elem => elem.Name,
                                                                                         elem => elem.Summary,
                                                                                         elem => elem.Pictogram);

            SchemaMemberSelection.RegisterMemberTypeOperationsSet <VisualComplement>(vcom => null,
                                                                                     vcom => vcom.ContentAsText.GetTruncatedWithEllipsis(32).RemoveNewLines() +
                                                                                     " [" + vcom.Kind.Name + "]" +
                                                                                     " {" + vcom.GlobalId.ToString() + "}".Trim());

            SchemaMemberSelection.RegisterMemberTypeOperationsSet <IUniqueElement>(elem => null,
                                                                                   elem => "{" + elem.GlobalId.ToString() + "}: " + elem.ToString());

            SchemaMemberSelection.RegisterMemberTypeOperationsSet <object>(obj => null,
                                                                           obj => obj.ToString());
        }