public override void correct()
        {
            EAOutputLogger.log(this.model, this.outputName
                               , string.Format("{0} Starting create links between attributes and elements'"
                                               , DateTime.Now.ToLongTimeString())
                               , 0
                               , LogTypeEnum.log);



            //get al the classes with stereotype BusinessEntity
            var classes = this.model.getElementWrappersByQuery(@"select distinct o.[Object_ID]
																from t_object o
																left join t_xref x on (o.[ea_guid] = x.[Client])
																where o.[Stereotype] like 'BusinessEntity' or o.[StereoType] like 'bEntity'
																or (x.[Name] = 'StereoTypes' and x.[Description] = 'BusinessEntity' or x.[Description] = 'bEntity')"                                                                );

            //loop the attribues in the classes, filter the enums out
            foreach (var businessEntity in classes)
            {
                foreach (var attribute in businessEntity.attributes.Where(x => x.classifier is UML.Classes.Kernel.Enumeration))
                {
                    if (!attribute.relationships.Any())
                    {
                        EAOutputLogger.log(this.model, this.outputName
                                           , string.Format("{0} Create <<usage>> link from '{1}.{2}' to '{3}'"
                                                           , DateTime.Now.ToLongTimeString()
                                                           , businessEntity.name
                                                           , attribute.name
                                                           , attribute.classifier)
                                           , businessEntity.id
                                           , LogTypeEnum.log);

                        // create a 'usage' link from the enum attributes to the enum entities
                        TSF_EA.Usage usage = this.model.factory.createNewElement <TSF_EA.Usage>(attribute.owner, string.Empty);
                        usage.source = attribute;
                        usage.target = (TSF_EA.Element)attribute.classifier;
                        usage.targetEnd.isNavigable = true;
                        usage.save();
                    }
                }
            }



            EAOutputLogger.log(this.model, this.outputName
                               , string.Format("{0} Finished create links between attributes and elements'"
                                               , DateTime.Now.ToLongTimeString())
                               , 0
                               , LogTypeEnum.log);
        }
Exemple #2
0
        void correctElementRelations()
        {
            EAOutputLogger.log(this.model, this.outputName
                               , string.Format("{0} Starting corrections for the dependencies, usages and realisations"
                                               , DateTime.Now.ToLongTimeString())
                               , 0
                               , LogTypeEnum.log);

            //First get al the dependencies, usages and realisations
            foreach (var mdRelation in magicDrawReader.allMDElementRelations)
            {
                //check if the relation already exists
                if (!exists(mdRelation.Key, mdRelation.Value.sourceMDGUID, mdRelation.Value.targetMDGUID, mdRelation.Value.relationType, mdRelation.Value.stereotype))
                {
                    var sourceElement = this.getElementByMDid(mdRelation.Value.sourceMDGUID);
                    var targetElement = this.getElementByMDid(mdRelation.Value.targetMDGUID);

                    if (mdRelation.Value.relationType == "Usage" && sourceElement == null && targetElement != null)
                    {
                        //get the attribute with mdGuid = sourceMdGuid of the relation
                        foreach (var mdAttribute in magicDrawReader.allAttributes.Where(x => x.mdGuid == mdRelation.Value.sourceMDGUID))
                        {
                            //mdAttribute = source attribute
                            var attributeParent = this.getElementByMDid(mdAttribute.mdParentGuid);
                            if (attributeParent != null)
                            {
                                // create a 'usage' link from the enum attributes to the enum entities
                                TSF_EA.Usage usage = this.model.factory.createNewElement <TSF_EA.Usage>(attributeParent, string.Empty);

                                //check all atributes in the parent for an attribute with the same name as the mdAttribute
                                foreach (var attribute in attributeParent.attributes.Where(x => x.name == mdAttribute.name))
                                {
                                    usage.source = attribute;
                                    usage.target = targetElement;
                                    usage.targetEnd.isNavigable = true;
                                    usage.save();


                                    EAOutputLogger.log(this.model, this.outputName
                                                       , string.Format("{0} Created <<usage>> link from '{1}.{2}' to '{3}'"
                                                                       , DateTime.Now.ToLongTimeString()
                                                                       , attributeParent.name
                                                                       , attribute.name
                                                                       , targetElement.name)
                                                       , attributeParent.id
                                                       , LogTypeEnum.log);
                                }
                            }
                        }
                    }

                    if (sourceElement != null && targetElement != null)
                    {
                        //create the actual relation
                        var newRelation = this.model.factory.createNewElement(sourceElement, mdRelation.Value.name, mdRelation.Value.relationType) as TSF_EA.ConnectorWrapper;

                        //set target
                        newRelation.target = targetElement;

                        //set the target end navigable by default
                        newRelation.targetEnd.isNavigable = true;

                        //set the stereotype
                        newRelation.addStereotype(this.model.factory.createStereotype(newRelation, mdRelation.Value.stereotype));

                        //save the new relation
                        newRelation.save();

                        //set the md_guid tagged value
                        newRelation.addTaggedValue("md_guid", mdRelation.Key);

                        //tell the user
                        EAOutputLogger.log(this.model, this.outputName
                                           , string.Format("{0} Created relation of type {1} between '{2}' and '{3}'"
                                                           , DateTime.Now.ToLongTimeString()
                                                           , mdRelation.Value.relationType
                                                           , sourceElement.name
                                                           , targetElement.name)
                                           , sourceElement.id
                                           , LogTypeEnum.log);
                    }
                }
            }

            EAOutputLogger.log(this.model, this.outputName
                               , string.Format("{0} Finished corrections for the dependencies, usages and realisations"
                                               , DateTime.Now.ToLongTimeString())
                               , 0
                               , LogTypeEnum.log);
        }