예제 #1
0
        public void AddRelatedItemsTest()
        {
            var shapeColor = Color.Cyan;

            ChangeEntityTypesFillColorTest(
                "AddRelatedItems",
                shapeColor,
                (artifact, commandProcessorContext) =>
            {
                var diagram = CreateDiagramCommand.CreateDiagramWithDefaultName(commandProcessorContext);
                var docData = GetDocData(commandProcessorContext.EditingContext);
                docData.OpenDiagram(diagram.Id.Value);

                CreateEntityTypeShapeCommand.CreateEntityTypeShapeAndConnectorsInDiagram(
                    commandProcessorContext,
                    diagram,
                    (ConceptualEntityType)artifact.ConceptualModel.EntityTypes().Single(et => et.LocalName.Value == "author"),
                    shapeColor, false);

                var entityDesignerDiagram = docData.GetEntityDesignerDiagram(diagram.Id.Value);
                var author = entityDesignerDiagram.GetShape("author");
                Assert.IsNotNull(author, "Could not get DSL entity type shape instance of 'author'.");

                entityDesignerDiagram.SelectDiagramItems(new[] { author });
                Dte.ExecuteCommand("OtherContextMenus.MicrosoftDataEntityDesignContext.IncludeRelated");

                var titleauthor = entityDesignerDiagram.GetShape("titleauthor");
                Assert.IsNotNull(titleauthor, "Could not get DSL entity type shape instance of 'titleauthor'.");

                Assert.AreEqual(shapeColor, author.FillColor);
                Assert.AreEqual(shapeColor, titleauthor.FillColor);
            });
        }
예제 #2
0
        internal static void StaticInvoke(CommandProcessorContext cpc, EntityTypeShape entityTypeShape)
        {
            var viewModel = entityTypeShape.GetRootViewModel();

            Debug.Assert(viewModel != null, "Unable to find root view model from entity-type-shape:" + entityTypeShape.AccessibleName);
            if (viewModel != null)
            {
                var entityType = viewModel.ModelXRef.GetExisting(entityTypeShape.ModelElement) as EntityType;
                var diagram    = viewModel.ModelXRef.GetExisting(entityTypeShape.Diagram) as Diagram;
                Debug.Assert(entityType != null && diagram != null);
                if (entityType != null &&
                    diagram != null)
                {
                    var cmd = new CreateEntityTypeShapeCommand(diagram, entityType);
                    CommandProcessor.InvokeSingleCommand(cpc, cmd);
                    var modelEntityShape = cmd.EntityTypeShape;
                    Debug.Assert(modelEntityShape != null);
                    viewModel.ModelXRef.Add(modelEntityShape, entityTypeShape, viewModel.EditingContext);
                }
            }
        }
예제 #3
0
        private static void InjectEntityTypeShapeCommand(
            CommandProcessorContext commandProcessorContext, HashSet <ShapeChangeInformation> shapeChangeInfoSet, Diagram diagram,
            ConceptualEntityType entityType, XObjectChange changeAction)
        {
            // First check to see if there is already a change in the original transaction
            // for the EntityTypeShape that matches the one that we're getting
            var shapeChangeInfoToQuery = new ShapeChangeInformation
            {
                ChangeType    = changeAction,
                ModelEFObject = entityType,
                DiagramId     = diagram.Id.Value
            };

            var shapeChangeInfoExists = shapeChangeInfoSet.Contains(shapeChangeInfoToQuery);

            // We only want to create model diagram if the transaction is originated from this diagram.
            if (changeAction == XObjectChange.Add)
            {
                // We only want to inject the entity-type-shape if the transaction is originated from the passed in diagram.
                if (commandProcessorContext != null &&
                    commandProcessorContext.EfiTransaction != null)
                {
                    var contextItem =
                        commandProcessorContext.EfiTransaction.GetContextValue <DiagramContextItem>(
                            EfiTransactionOriginator.TransactionOriginatorDiagramId);

                    if (contextItem != null &&
                        contextItem.DiagramId == diagram.Id.Value)
                    {
                        // look in the dictionary for an 'add' to an EntityTypeShape that points to this modelobject.
                        if (shapeChangeInfoExists == false)
                        {
                            var cmd = new CreateEntityTypeShapeCommand(diagram, entityType);
                            CommandProcessor.InvokeSingleCommand(commandProcessorContext, cmd);
                        }

                        // We have the ability to create an EntityType and an Inheritance in one transaction, so we need
                        // to check for it here.
                        if (entityType.BaseType.Target != null)
                        {
                            InjectInheritanceConnectorCommand(
                                commandProcessorContext, shapeChangeInfoSet, diagram, entityType.BaseType, changeAction);
                        }
                    }
                }
            }
            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
                foreach (
                    var entityTypeShape in
                    entityType.GetAntiDependenciesOfType <EntityTypeShape>()
                    .Where(ets => ets.Diagram != null && ets.Diagram.Id == diagram.Id.Value))
                {
                    if (entityTypeShape != null)
                    {
                        var deleteEntityTypeShapeCommand = entityTypeShape.GetDeleteCommand();
                        CommandProcessor.InvokeSingleCommand(commandProcessorContext, deleteEntityTypeShapeCommand);
                    }
                }
            }
        }