/// <summary>
 ///     The behavior is as follow:
 ///     Creates copy of EntityTypes and relationships between them from clipboard format in the Entity Model if:
 ///     - The entity-types and/or relationships do not exist in the model.
 ///     - The passed in diagram parameter is null.
 ///     OR
 ///     Create the associated diagram items in the Diagram Model if:
 ///     - The diagram is not null AND entity-types and/or relationships exist in the model AND the corresponding diagram items do not exist in the diagram.
 /// </summary>
 /// <param name="diagram"></param>
 /// <param name="clipboardEntities"></param>
 /// <param name="modelSpace"></param>
 internal CopyEntitiesCommand(Diagram diagram, EntitiesClipboardFormat clipboardEntities, ModelSpace modelSpace)
 {
     _diagram = diagram;
     _clipboardEntities = clipboardEntities;
     _modelSpace = modelSpace;
 }
 /// <summary>
 ///     Creates a copy of EntityTypes and relationships between them from clipboard format
 /// </summary>
 /// <param name="property"></param>
 internal CopyEntitiesCommand(EntitiesClipboardFormat clipboardEntities, ModelSpace modelSpace)
     : this(null, clipboardEntities, modelSpace)
 {
     _clipboardEntities = clipboardEntities;
     _modelSpace = modelSpace;
 }
        /// <summary>
        ///     Loop through Clipboard objects and determine whether there are EFObject that should be in the diagram but are not.
        /// </summary>
        /// <param name="clipboardObjects"></param>
        /// <returns></returns>
        private IList<EFElement> GetEFElementNotInDiagramFromClipboardObject(EntitiesClipboardFormat clipboardObjects)
        {
            var modelDiagram = ModelElement.ModelXRef.GetExisting(this) as ModelDiagram;
            var artifactSet = modelDiagram.Artifact.ArtifactSet;

            IList<EFElement> efElements = new List<EFElement>();

            // We are only interested in entity-types all the associations will be automatically created when entity-types are added to diagram.
            foreach (var clipboardObject in clipboardObjects.ClipboardEntities)
            {
                var efElement = artifactSet.LookupSymbol(clipboardObject.NormalizedName);
                if (efElement != null
                    && modelDiagram.IsEFObjectRepresentedInDiagram(efElement) == false)
                {
                    efElements.Add(efElement);
                }
            }

            return efElements;
        }
 /// <summary>
 ///     OnDragLeave ensure that the _clipboardObject is cleared.
 /// </summary>
 /// <param name="e"></param>
 public override void OnDragLeave(DiagramPointEventArgs e)
 {
     _clipboardObjects = null;
     base.OnDragLeave(e);
 }
 /// <summary>
 ///     The even handler when ojbects are dragged over the designer.
 /// </summary>
 /// <param name="e"></param>
 public override void OnDragEnter(DiagramDragEventArgs e)
 {
     // Depending on type of objects are being dragged, display the appropriate icons.
     _clipboardObjects = GetClipboardObjectFromDragEventArgs(e);
     if (_clipboardObjects != null)
     {
         e.Effect = GetDropEffects();
         e.Handled = true;
     }
     else
     {
         base.OnDragEnter(e);
     }
 }
 /// <summary>
 ///     The event handler when objects are dropped to the designer.
 ///     If clipboard object is not null, we will go through the objects in the clipboard object and create appropriate Escher objects.
 /// </summary>
 /// <param name="e"></param>
 public override void OnDragDrop(DiagramDragEventArgs e)
 {
     try
     {
         Arranger.Start(e.IsDropLocationUserSpecified ? e.MousePosition : PointD.Empty);
         if (_clipboardObjects != null)
         {
             var modelDiagram = ModelElement.ModelXRef.GetExisting(this) as ModelDiagram;
             var cpc = new CommandProcessorContext(
                 ModelElement.EditingContext, EfiTransactionOriginator.EntityDesignerOriginatorId, EntityDesignerResources.Tx_DropItems);
             CommandProcessor.InvokeSingleCommand(
                 cpc, 
                 new CreateDiagramItemForEFElementsCommand(
                     GetEFElementNotInDiagramFromClipboardObject(_clipboardObjects),
                     modelDiagram, e.Shift || e.Control));
         }
         else
         {
             base.OnDragDrop(e);
         }
     }
     finally
     {
         _clipboardObjects = null;
         Arranger.End();
         if (e.IsDropLocationUserSpecified == false)
         {
             EnsureSelectionVisible();
         }
     }
 }