Exemple #1
0
        /// <summary>
        /// updates an existing message subset for a schema
        /// </summary>
        /// <param name="schema">the schema to use as basis</param>
        /// <param name="messageElement">the root element of the subset</param>
        private void updateMessageSubset(Schema schema, UML.Classes.Kernel.Classifier messageElement)
        {
            if (messageElement != null)
            {
                bool          copyDataType    = this.settings.copyDataTypes;
                List <String> datatypesToCopy = null;
                if (copyDataType && this.settings.limitDataTypes)
                {
                    datatypesToCopy = this.settings.dataTypesToCopy;
                }
                schema.updateSubsetModel(messageElement);
            }
            var subsetDiagrams = messageElement.owningPackage.ownedDiagrams;

            if (subsetDiagrams.Count > 0)
            {
                //if there are existing diagram then we update the existing diagrams
                updateExistingDiagrams(schema, subsetDiagrams);
            }
            else
            {
                //if not we create a new diagram
                createNewSubsetDiagram(schema, messageElement.owningPackage);
            }
        }
        /// <summary>
        /// add the subset association to the list if it does not exist
        /// </summary>
        /// <param name="associationTarget">the target for the association</param>
        private void addSubsetAssociation(UML.Classes.Kernel.Classifier associationTarget)
        {
            Association existingAssociation = this.subsetAssociations.FirstOrDefault(x => ((UTF_EA.Association)x).target.Equals(associationTarget));
            Association subsetAssociation   = CreateSubSetAssociation(associationTarget, existingAssociation);

            if (existingAssociation == null &&
                subsetAssociation != null)
            {
                this.subsetAssociations.Add(subsetAssociation);
            }
            //if the association is part of an associationclass then create the link
            this.setAssociationClassProperties();
        }
        private Association CreateSubSetAssociation(UML.Classes.Kernel.Classifier associationTarget, Association existingAssociation)
        {
            Association subSetAssociation;

            if (existingAssociation == null)
            {
                subSetAssociation = this.model.factory.createNewElement <UML.Classes.Kernel.Association>
                                        (this.owner.subsetElement, this.sourceAssociation.name);
                subSetAssociation.addRelatedElement(associationTarget);
            }
            else
            {
                //subset association already exists
                subSetAssociation = existingAssociation;
                //report differences
                //different multiplicity
                if (((UTF_EA.Association)subSetAssociation).targetEnd.EAMultiplicity != this.multiplicity)
                {
                    EAOutputLogger.log(this.model, this.owner.owner.settings.outputName
                                       , string.Format("Multiplicity of association between '{0}' and '{1}' has changed from '{2}' to '{3}'"
                                                       , ((UTF_EA.Association)subSetAssociation).source.name
                                                       , ((UTF_EA.Association)subSetAssociation).target.name
                                                       , ((UTF_EA.Association)subSetAssociation).targetEnd.EAMultiplicity
                                                       , this.multiplicity)
                                       , ((UTF_EA.ElementWrapper)((UTF_EA.Association)subSetAssociation).source).id
                                       , LogTypeEnum.warning);
                }
                //different target rolname
                if (((UTF_EA.Association)subSetAssociation).targetEnd.name != this.otherEnd.name)
                {
                    EAOutputLogger.log(this.model, this.owner.owner.settings.outputName
                                       , string.Format("Target rolename of association between '{0}' and '{1}' has changed from '{2}' to '{3}'"
                                                       , ((UTF_EA.Association)subSetAssociation).source.name
                                                       , ((UTF_EA.Association)subSetAssociation).target.name
                                                       , ((UTF_EA.Association)subSetAssociation).targetEnd.name
                                                       , this.otherEnd.name)
                                       , ((UTF_EA.ElementWrapper)((UTF_EA.Association)subSetAssociation).source).id
                                       , LogTypeEnum.warning);
                }
            }
            //update name
            subSetAssociation.name = this.sourceAssociation.name;
            //alias only if alias in the subset is emtpy
            if (string.IsNullOrEmpty(((UTF_EA.Association)subSetAssociation).alias))
            {
                ((UTF_EA.Association)subSetAssociation).alias = ((UTF_EA.Association)sourceAssociation).alias;
            }
            //Check if the subset alias is different from the source alias and issue warning if that is the case
            if (!string.Equals(((UTF_EA.Association)subSetAssociation).alias, ((UTF_EA.Association)sourceAssociation).alias))
            {
                EAOutputLogger.log(this.model, this.owner.owner.settings.outputName
                                   , string.Format("Association between '{0}' and '{1}' has alias {2} in the model and a different alias '{3}' in the subset"
                                                   , ((UTF_EA.Association)subSetAssociation).source.name
                                                   , ((UTF_EA.Association)subSetAssociation).target.name
                                                   , ((UTF_EA.Association)subSetAssociation).alias
                                                   , ((UTF_EA.Association)sourceAssociation).alias)
                                   , ((UTF_EA.ElementWrapper)((UTF_EA.Association)subSetAssociation).source).id
                                   , LogTypeEnum.warning);
            }
            //notes only update them if they are empty
            if (subSetAssociation.ownedComments.Count == 0 || !subSetAssociation.ownedComments.Any(x => x.body.Length > 0))
            {
                subSetAssociation.ownedComments = this.sourceAssociation.ownedComments;
                if (this.owner.owner.settings.prefixNotes &&
                    this.owner.owner.settings.prefixNotesText.Length > 0 &&
                    subSetAssociation.ownedComments.Any(x => x.body.Length > 0))
                {
                    foreach (var comment in subSetAssociation.ownedComments)
                    {
                        comment.body = this.owner.owner.settings.prefixNotesText + Environment.NewLine + comment.body;
                    }
                }
            }
            //stereotype
            subSetAssociation.stereotypes = this.sourceAssociation.stereotypes;
            //save all changes
            //subSetAssociation.save();
            //copy the association end properties
            //copy source end properties
            this.copyAssociationEndProperties((UTF_EA.AssociationEnd) this.thisEnd,
                                              ((UTF_EA.Association)subSetAssociation).sourceEnd);
            //copy target end properties
            this.copyAssociationEndProperties((UTF_EA.AssociationEnd) this.otherEnd,
                                              ((UTF_EA.Association)subSetAssociation).targetEnd);
            //set the target multiplicity to a possible redefined multiplicity from the schema
            ((UTF_EA.Association)subSetAssociation).targetEnd.EAMultiplicity = this.multiplicity;
            //save all changes
            subSetAssociation.save();
            //copy tagged values
            ((EASchema)this.owner.owner).copyTaggedValues((UTF_EA.Element) this.sourceAssociation, (UTF_EA.Element)subSetAssociation);
            //((UTF_EA.Association)this.subsetAssociation).copyTaggedValues((UTF_EA.Association)this.sourceAssociation);
            //add tagged value with reference to source association
            ((UTF_EA.Association)subSetAssociation).addTaggedValue(
                this.owner.owner.settings.sourceAssociationTagName, ((UTF_EA.Association) this.sourceAssociation).guid);

            //subSetAssociation.save();
            return(subSetAssociation);
        }
 private bool shouldElementBeOnDiagram(UML.Classes.Kernel.Classifier element)
 {
     return(element != null &&
            !this.settings.hiddenElementTypes.Any(x => x.Equals(element.GetType().Name, StringComparison.InvariantCulture)) &&
            !this.settings.hiddenElementTypes.Intersect(element.stereotypes.Select(x => x.name)).Any());
 }