internal static void StaticInvoke(CommandProcessorContext cpc, InheritanceConnector inheritanceConnector)
        {
            // if there was a circular inheritance, this connector will be deleted, if so, we just return
            if (inheritanceConnector.IsDeleted)
            {
                return;
            }

            var viewModel = inheritanceConnector.GetRootViewModel();
            Debug.Assert(
                viewModel != null, "Unable to find root view model from inheritance connector: " + inheritanceConnector.AccessibleName);

            if (viewModel != null)
            {
                var modelEntityTypeBase = viewModel.ModelXRef.GetExisting(inheritanceConnector.ModelElement) as EntityTypeBaseType;
                if (modelEntityTypeBase != null)
                {
                    var modelEntity = modelEntityTypeBase.Parent as EntityType;
                    var modelDiagram = viewModel.ModelXRef.GetExisting(inheritanceConnector.Diagram) as Diagram;
                    Debug.Assert(modelEntity != null && modelDiagram != null);
                    if (modelEntity != null
                        && modelDiagram != null)
                    {
                        var cmd = new CreateInheritanceConnectorCommand(modelDiagram, modelEntity);
                        CommandProcessor.InvokeSingleCommand(cpc, cmd);
                        var modelInheritanceConnector = cmd.InheritanceConnector;
                        viewModel.ModelXRef.Add(modelInheritanceConnector, inheritanceConnector, viewModel.EditingContext);
                    }
                }
            }
        }
예제 #2
0
        private static void InjectInheritanceConnectorCommand(
            CommandProcessorContext commandProcessorContext, HashSet<ShapeChangeInformation> shapeChangeInfoSet,
            Diagram diagram, EntityTypeBaseType baseType, XObjectChange changeAction)
        {
            // First check to see if there is already a change in the original transaction 
            // for the InheritanceConnector that matches the one that we're getting
            var shapeChangeInfoToQuery = new ShapeChangeInformation
                {
                    ChangeType = changeAction,
                    ModelEFObject = baseType.OwnerEntityType,
                    DiagramId = diagram.Id.Value
                };

            var shapeChangeInfoExists = shapeChangeInfoSet.Contains(shapeChangeInfoToQuery);

            if (changeAction == XObjectChange.Add
                && shapeChangeInfoExists == false)
            {
                var participatingEntityTypes = new List<EntityType>();

                var derivedEntityType = baseType.Parent as EntityType;
                Debug.Assert(derivedEntityType != null, "Where is the parent EntityType of this BaseType attribute?");

                if (derivedEntityType != null)
                {
                    // The inheritance connector is added if
                    // - the participating entities exists in the diagram.
                    // or
                    // - the participating entities will be added in the current transaction.
                    participatingEntityTypes.Add(derivedEntityType);
                    participatingEntityTypes.Add(((ConceptualEntityType)derivedEntityType).BaseType.Target);

                    foreach (var entityType in participatingEntityTypes)
                    {
                        if (diagram.EntityTypeShapes.Where(ets => ets.EntityType.Target == entityType).Any()
                            || shapeChangeInfoSet.Where(
                                sc =>
                                sc.DiagramId == diagram.Id.Value && sc.ModelEFObject == entityType && sc.ChangeType == XObjectChange.Add)
                                   .Any())
                        {
                            continue;
                        }
                        // If it reach this point, that means that we should not add inheritance connector in the diagram.
                        return;
                    }
                    var cmd = new CreateInheritanceConnectorCommand(diagram, derivedEntityType);
                    CommandProcessor.InvokeSingleCommand(commandProcessorContext, cmd);
                }
            }
            else if (changeAction == XObjectChange.Remove
                     && shapeChangeInfoExists == false)
            {
                // this is happening before the transaction is taking place so we are free to look up anti-dependencies
                // on this delete
                var owningEntityType = baseType.Parent as EntityType;
                if (owningEntityType != null)
                {
                    foreach (
                        var inheritanceConnector in
                            owningEntityType.GetAntiDependenciesOfType<InheritanceConnector>()
                                .Where(ic => ic.Diagram != null && ic.Diagram.Id == diagram.Id.Value))
                    {
                        if (inheritanceConnector != null)
                        {
                            var deleteInheritanceConnectorCommand = inheritanceConnector.GetDeleteCommand();
                            CommandProcessor.InvokeSingleCommand(commandProcessorContext, deleteInheritanceConnectorCommand);
                        }
                    }
                }
            }
        }