internal AssociationClipboardFormat(
            Association association, EntityTypeClipboardFormat clipboardEntity1, EntityTypeClipboardFormat clipboardEntity2)
            : base(association)
        {
            _associationName = association.LocalName.Value;
            _clipboardEntity1 = clipboardEntity1;
            _clipboardEntity2 = clipboardEntity2;

            var associationEnds = association.AssociationEnds();
            Debug.Assert(
                associationEnds.Count == 2,
                String.Format(CultureInfo.CurrentCulture, "Invalid AssocationEnd counts for Assocation {0}", association.DisplayName));

            if (associationEnds.Count == 2)
            {
                _multiplicity1 = associationEnds[0].Multiplicity.Value;
                _multiplicity2 = associationEnds[1].Multiplicity.Value;
                _associationEndRole1 = associationEnds[0].Role.Value;
                _associationEndRole2 = associationEnds[1].Role.Value;
                if (association.ReferentialConstraint != null)
                {
                    _referentialConstraint = new ReferentialConstraintClipboardFormat(association.ReferentialConstraint);
                }
            }
            else
            {
                _multiplicity1 = String.Empty;
                _multiplicity2 = String.Empty;
                _associationEndRole1 = String.Empty;
                _associationEndRole2 = String.Empty;
            }
        }
        internal AssociationClipboardFormat(
            Association association, EntityTypeClipboardFormat clipboardEntity1, EntityTypeClipboardFormat clipboardEntity2)
            : base(association)
        {
            _associationName  = association.LocalName.Value;
            _clipboardEntity1 = clipboardEntity1;
            _clipboardEntity2 = clipboardEntity2;

            var associationEnds = association.AssociationEnds();

            Debug.Assert(
                associationEnds.Count == 2,
                String.Format(CultureInfo.CurrentCulture, "Invalid AssociationEnd counts for Association {0}", association.DisplayName));

            if (associationEnds.Count == 2)
            {
                _multiplicity1       = associationEnds[0].Multiplicity.Value;
                _multiplicity2       = associationEnds[1].Multiplicity.Value;
                _associationEndRole1 = associationEnds[0].Role.Value;
                _associationEndRole2 = associationEnds[1].Role.Value;
                if (association.ReferentialConstraint != null)
                {
                    _referentialConstraint = new ReferentialConstraintClipboardFormat(association.ReferentialConstraint);
                }
            }
            else
            {
                _multiplicity1       = String.Empty;
                _multiplicity2       = String.Empty;
                _associationEndRole1 = String.Empty;
                _associationEndRole2 = String.Empty;
            }
        }
Example #3
0
        // Given the list of EntityTypeShapes, create the following in objects:
        // - List of the EntityClipboardFormat that represents the shape's entities and shape's property (for example: FillColor).
        // - List of the AssociationClipboardFormat that represent the associations among the shape's entities.
        // - List of the ClipboardFormat object that represent the inheritance among the shape's entities.
        internal EntitiesClipboardFormat(ICollection <EntityTypeShape> entityTypeShapes)
        {
            // Get a list of distinct entity-types from the entity-type-shape collection.
            var entitiesMap = new Dictionary <EntityType, EntityTypeClipboardFormat>(entityTypeShapes.Count);

            foreach (var ets in entityTypeShapes)
            {
                var et = ets.EntityType.Target;
                if (et == null ||
                    entitiesMap.ContainsKey(et))
                {
                    continue;
                }

                var clipboardEntity = new EntityTypeClipboardFormat(ets);
                _entities.Add(clipboardEntity);
                entitiesMap.Add(et, clipboardEntity);
            }

            // Figure out the association and the inheritance between the selected entities.
            IList <EntityType> selectedEntityTypes = entitiesMap.Keys.ToList();
            var associations = new HashSet <Association>();
            var inheritances = new Dictionary <EntityType, EntityType>();

            foreach (var et in selectedEntityTypes)
            {
                // Add inheritance if both base and derived type is in the list.
                var cet = et as ConceptualEntityType;
                if (cet != null &&
                    selectedEntityTypes.Contains(cet.BaseType.Target) &&
                    inheritances.ContainsKey(cet) == false)
                {
                    inheritances.Add(cet, cet.BaseType.Target);
                }

                var participatingAssociations = Association.GetAssociationsForEntityType(et);
                foreach (var assoc in participatingAssociations)
                {
                    if (associations.Contains(assoc))
                    {
                        break;
                    }

                    var entityTypesInAssociation = assoc.AssociationEnds().Select(ae => ae.Type.Target).ToList();
                    // if both participating entity-types are in the list, add the association.
                    if (entityTypesInAssociation.Except(selectedEntityTypes).Count() == 0)
                    {
                        associations.Add(assoc);
                    }
                }
            }
            InitializeAssociationAndInheritanceClipboardObjects(entitiesMap, associations, inheritances);
        }
        // Given the list of EntityTypeShapes, create the following in objects:
        // - List of the EntityClipboardFormat that represents the shape's entities and shape's property (for example: FillColor).
        // - List of the AssociationClipboardFormat that represent the associations among the shape's entities.
        // - List of the ClipboardFormat object that represent the inheritance among the shape's entities.
        internal EntitiesClipboardFormat(ICollection<EntityTypeShape> entityTypeShapes)
        {
            // Get a list of distinct entity-types from the entity-type-shape collection.
            var entitiesMap = new Dictionary<EntityType, EntityTypeClipboardFormat>(entityTypeShapes.Count);
            foreach (var ets in entityTypeShapes)
            {
                var et = ets.EntityType.Target;
                if (et == null
                    || entitiesMap.ContainsKey(et))
                {
                    continue;
                }

                var clipboardEntity = new EntityTypeClipboardFormat(ets);
                _entities.Add(clipboardEntity);
                entitiesMap.Add(et, clipboardEntity);
            }

            // Figure out the association and the inheritance between the selected entities.
            IList<EntityType> selectedEntityTypes = entitiesMap.Keys.ToList();
            var associations = new HashSet<Association>();
            var inheritances = new Dictionary<EntityType, EntityType>();

            foreach (var et in selectedEntityTypes)
            {
                // Add inheritance if both base and derived type is in the list.
                var cet = et as ConceptualEntityType;
                if (cet != null
                    && selectedEntityTypes.Contains(cet.BaseType.Target)
                    && inheritances.ContainsKey(cet) == false)
                {
                    inheritances.Add(cet, cet.BaseType.Target);
                }

                var participatingAssociations = Association.GetAssociationsForEntityType(et);
                foreach (var assoc in participatingAssociations)
                {
                    if (associations.Contains(assoc))
                    {
                        break;
                    }

                    var entityTypesInAssociation = assoc.AssociationEnds().Select(ae => ae.Type.Target).ToList();
                    // if both participating entity-types are in the list, add the association.
                    if (entityTypesInAssociation.Except(selectedEntityTypes).Count() == 0)
                    {
                        associations.Add(assoc);
                    }
                }
            }
            InitializeAssociationAndInheritanceClipboardObjects(entitiesMap, associations, inheritances);
        }
 internal EntitiesClipboardFormat(
     ICollection<EntityType> entities, ICollection<Association> associations, IDictionary<EntityType, EntityType> inheritances)
 {
     var entitiesMap = new Dictionary<EntityType, EntityTypeClipboardFormat>(entities.Count);
     foreach (var entity in entities)
     {
         // Check if the entity has been added. Copying a self association could cause the same entities to be added twice in the list.
         if (entitiesMap.ContainsKey(entity) == false)
         {
             var clipboardEntity = new EntityTypeClipboardFormat(entity);
             _entities.Add(clipboardEntity);
             entitiesMap.Add(entity, clipboardEntity);
         }
     }
     InitializeAssociationAndInheritanceClipboardObjects(entitiesMap, associations, inheritances);
 }
Example #6
0
        internal EntitiesClipboardFormat(
            ICollection <EntityType> entities, ICollection <Association> associations, IDictionary <EntityType, EntityType> inheritances)
        {
            var entitiesMap = new Dictionary <EntityType, EntityTypeClipboardFormat>(entities.Count);

            foreach (var entity in entities)
            {
                // Check if the entity has been added. Copying a self association could cause the same entities to be added twice in the list.
                if (entitiesMap.ContainsKey(entity) == false)
                {
                    var clipboardEntity = new EntityTypeClipboardFormat(entity);
                    _entities.Add(clipboardEntity);
                    entitiesMap.Add(entity, clipboardEntity);
                }
            }
            InitializeAssociationAndInheritanceClipboardObjects(entitiesMap, associations, inheritances);
        }
 /// <summary>
 ///     The behavior is as follow:
 ///     Creates a copy of an EntityType from clipboard format in Entity Model if:
 ///     - The entity-type does not exist in the model.
 ///     - The passed in diagram parameter is null.
 ///     OR
 ///     Create the shape for the entity-type in the Diagram Model if:
 ///     - The diagram is not null AND the entity-type exists in the model AND the corresponding entity-type-shape does not exist in the diagram.
 /// </summary>
 /// <param name="diagram"></param>
 /// <param name="clipboardEntity"></param>
 /// <param name="modelSpace"></param>
 internal CopyEntityCommand(Diagram diagram, EntityTypeClipboardFormat clipboardEntity, ModelSpace modelSpace)
 {
     _clipboardEntity = clipboardEntity;
     _modelSpace = modelSpace;
     _diagram = diagram;
 }
 /// <summary>
 ///     Creates a copy of EntityType from clipboard format
 /// </summary>
 /// <param name="clipboardEntity"></param>
 /// <param name="modelSpace"></param>
 /// <returns></returns>
 internal CopyEntityCommand(EntityTypeClipboardFormat clipboardEntity, ModelSpace modelSpace)
     : this(null, clipboardEntity, modelSpace)
 {
 }
        private void AddNewConceptualEntityTypesFromArtifact(
            CommandProcessorContext cpc, HashSet<EntityType> entityTypesFromTempArtifactToBeAdded,
            out Dictionary<EntityType, EntityType> tempArtifactCEntityTypeToNewCEntityTypeInExistingArtifact)
        {
            tempArtifactCEntityTypeToNewCEntityTypeInExistingArtifact = new Dictionary<EntityType, EntityType>();

            // add in all new C-side Entity Types (creating clones because the
            // EntityType objects in entityTypesToBeAdded are from the temporary DB artifact)
            foreach (var etFromTempArtifact in entityTypesFromTempArtifactToBeAdded)
            {
                var etcf = new EntityTypeClipboardFormat(etFromTempArtifact);
                var cmd = new CopyEntityCommand(etcf, ModelSpace.Conceptual);
                CommandProcessor.InvokeSingleCommand(cpc, cmd);
                var newEntityTypeInExistingArtifact = cmd.EntityType;

                // add an EntitySetMapping for the new EntityType
                if (null != newEntityTypeInExistingArtifact)
                {
                    // add mapping from EntityType in the temp artifact to the newly-created
                    // EntityType in the existing artifact
                    tempArtifactCEntityTypeToNewCEntityTypeInExistingArtifact.Add(
                        etFromTempArtifact, newEntityTypeInExistingArtifact);

                    var esmInTempArtifact = ModelHelper.FindEntitySetMappingForEntityType(etFromTempArtifact);
                    var newEntitySet = newEntityTypeInExistingArtifact.EntitySet as ConceptualEntitySet;
                    if (null == esmInTempArtifact)
                    {
                        Debug.Fail("null esmInTempArtifact");
                    }
                    else if (null == newEntitySet)
                    {
                        Debug.Fail("null newEntitySet");
                    }
                    else
                    {
                        CloneEntitySetMapping(
                            cpc, esmInTempArtifact,
                            _preExistingModel.Artifact.MappingModel().FirstEntityContainerMapping, newEntitySet,
                            tempArtifactCEntityTypeToNewCEntityTypeInExistingArtifact);
                    }
                }
                else
                {
                    throw new UpdateModelFromDatabaseException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resources.UpdateFromDatabaseCannotCreateEntityType,
                            etFromTempArtifact.ToPrettyString()));
                }
            }
        }