/// <summary> /// This helper function will create a Diagram using default name. /// NOTE: If the cpc already has an active transaction, these changes will be in that transaction /// and the caller of this helper method must commit it to see these changes commited /// otherwise the diagram will never be created. /// </summary> /// <param name="cpc"></param> /// <returns>The new ComplexType</returns> internal static Diagram CreateDiagramWithDefaultName(CommandProcessorContext cpc) { Debug.Assert(cpc != null, "The passed in CommandProcessorContext is null."); if (cpc != null) { var service = cpc.EditingContext.GetEFArtifactService(); var entityDesignArtifact = service.Artifact as EntityDesignArtifact; if (entityDesignArtifact == null || entityDesignArtifact.DesignerInfo == null || entityDesignArtifact.DesignerInfo.Diagrams == null) { throw new CannotLocateParentItemException(); } var diagramName = ModelHelper.GetUniqueNameWithNumber( typeof(Diagram), entityDesignArtifact.DesignerInfo.Diagrams, Resources.Model_DefaultDiagramName); // go create it var cp = new CommandProcessor(cpc); var cmd = new CreateDiagramCommand(diagramName, entityDesignArtifact.DesignerInfo.Diagrams); cp.EnqueueCommand(cmd); cp.Invoke(); return(cmd.Diagram); } return(null); }
/// <summary> /// This helper function will create a Diagram using default name. /// NOTE: If the cpc already has an active transaction, these changes will be in that transaction /// and the caller of this helper method must commit it to see these changes commited /// otherwise the diagram will never be created. /// </summary> /// <param name="cpc"></param> /// <returns>The new ComplexType</returns> internal static Diagram CreateDiagramWithDefaultName(CommandProcessorContext cpc) { Debug.Assert(cpc != null, "The passed in CommandProcessorContext is null."); if (cpc != null) { var service = cpc.EditingContext.GetEFArtifactService(); var entityDesignArtifact = service.Artifact as EntityDesignArtifact; if (entityDesignArtifact == null || entityDesignArtifact.DesignerInfo == null || entityDesignArtifact.DesignerInfo.Diagrams == null) { throw new CannotLocateParentItemException(); } var diagramName = ModelHelper.GetUniqueNameWithNumber( typeof(Diagram), entityDesignArtifact.DesignerInfo.Diagrams, Resources.Model_DefaultDiagramName); // go create it var cp = new CommandProcessor(cpc); var cmd = new CreateDiagramCommand(diagramName, entityDesignArtifact.DesignerInfo.Diagrams); cp.EnqueueCommand(cmd); cp.Invoke(); return cmd.Diagram; } return null; }