public override void correct() { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting corrections for «mapsTo» dependencies" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); //Get all the dependencies foreach (var mdDependency in magicDrawReader.allMapsToDependencies) { //check if the dependency already exists //first try to find it using the MD guid string sqlGetExistingRelations = @"select c.Connector_ID from (t_connector c inner join t_connectortag tv on( c.Connector_ID = tv.ElementID and tv.Property = 'md_guid')) where tv.VALUE = '" + mdDependency.md_guid + "'"; //Ook testen of er nog geen relatie met dat stereotype bestaat. var correspondingDependencies = this.model.getRelationsByQuery(sqlGetExistingRelations).OfType <TSF_EA.Dependency>().ToList(); //if not found by mdGUID then to find all dependencies between source and target if (!correspondingDependencies.Any()) { //find the corresponding dependency based on the source and target md_guid's sqlGetExistingRelations = @"select c.Connector_ID from ((((t_connector c inner join t_object obs on c.Start_Object_ID = obs.Object_ID) inner join t_objectproperties obstv on (obstv.Object_ID = obs.Object_ID and obstv.Property = 'md_guid')) inner join t_object obe on c.End_Object_ID = obe.Object_ID) inner join t_objectproperties obetv on (obetv.Object_ID = obe.Object_ID and obetv.Property = 'md_guid')) where c.Connector_Type = 'Dependency' and obstv.Value = '" + mdDependency.sourceMDGUID + @"' and obetv.Value = '" + mdDependency.targetMDGUID + "'"; correspondingDependencies = this.model.getRelationsByQuery(sqlGetExistingRelations).OfType <TSF_EA.Dependency>().ToList(); } if (!correspondingDependencies.Any()) { //doesn't exists, we have to create it var sourceElement = this.getElementByMDid(mdDependency.sourceMDGUID); var targetElement = this.getElementByMDid(mdDependency.targetMDGUID); if (sourceElement != null && targetElement != null) { TSF_EA.Dependency newDependency = this.model.factory.createNewElement <TSF_EA.Dependency>(sourceElement, string.Empty); newDependency.target = targetElement; newDependency.targetEnd.isNavigable = true; correspondingDependencies.Add(newDependency); } } //add the stereotype and save foreach (var dependency in correspondingDependencies) { dependency.addStereotype(this.model.factory.createStereotype(dependency, "mapsTo")); dependency.save(); //tell the user EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Corrected «mapsTo» dependency between '{1}' and '{2}'" , DateTime.Now.ToLongTimeString() , dependency.source.name , dependency.target.name) , ((TSF_EA.ElementWrapper)dependency.source).id , LogTypeEnum.error); } } //Log Finished EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished corrections for «mapsTo» dependencies" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }
public void synchronizeStereotypes() { string profile; var stereotypes = new ArrayList(); //UPCC3 - Model Management Abstract Syntax profile = "UPCC3 - Model Management Abstract Syntax"; stereotypes.Add("UPCCLibrary"); stereotypes.Add("DOCLibrary"); stereotypes.Add("bLibrary"); stereotypes.Add("BIELibrary"); stereotypes.Add("BDTLibrary"); stereotypes.Add("CCLibrary"); stereotypes.Add("CDTLibrary"); stereotypes.Add("ENUMLibrary"); stereotypes.Add("PRIMLibrary"); stereotypes.Add("UsageRule"); stereotypes.Add("basedOn"); stereotypes.Add("equivalentTo"); foreach (var stereotype in stereotypes) { model.wrappedModel.CustomCommand("Repository", "SynchProfile", "Profile=" + profile + ";Stereotype=" + stereotype + ";"); } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished profile '{1}'" , DateTime.Now.ToLongTimeString() , profile) , 0 , LogTypeEnum.log); //UPCC3 - DOCLibrary Abstract Syntax profile = "UPCC3 - DOCLibrary Abstract Syntax"; stereotypes.Clear(); stereotypes.Add("MA"); stereotypes.Add("ASMA"); foreach (var stereotype in stereotypes) { model.wrappedModel.CustomCommand("Repository", "SynchProfile", "Profile=" + profile + ";Stereotype=" + stereotype + ";"); } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished profile '{1}'" , DateTime.Now.ToLongTimeString() , profile) , 0 , LogTypeEnum.log); //UPCC3 - BIELibrary Abstract Syntax profile = "UPCC3 - BIELibrary Abstract Syntax"; stereotypes.Clear(); stereotypes.Add("ABIE"); stereotypes.Add("BBIE"); stereotypes.Add("ASBIE"); foreach (var stereotype in stereotypes) { model.wrappedModel.CustomCommand("Repository", "SynchProfile", "Profile=" + profile + ";Stereotype=" + stereotype + ";"); } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished profile '{1}'" , DateTime.Now.ToLongTimeString() , profile) , 0 , LogTypeEnum.log); //UPCC3 - BDTLibrary Abstract Syntax profile = "UPCC3 - BDTLibrary Abstract Syntax"; stereotypes.Clear(); stereotypes.Add("BDT"); stereotypes.Add("CON"); stereotypes.Add("SCBVD"); stereotypes.Add("SUP"); foreach (var stereotype in stereotypes) { model.wrappedModel.CustomCommand("Repository", "SynchProfile", "Profile=" + profile + ";Stereotype=" + stereotype + ";"); } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished profile '{1}'" , DateTime.Now.ToLongTimeString() , profile) , 0 , LogTypeEnum.log); //UPCC3 - CCLibrary Abstract Syntax profile = "UPCC3 - CCLibrary Abstract Syntax"; stereotypes.Clear(); stereotypes.Add("ACC"); stereotypes.Add("BCC"); stereotypes.Add("ASCC"); foreach (var stereotype in stereotypes) { model.wrappedModel.CustomCommand("Repository", "SynchProfile", "Profile=" + profile + ";Stereotype=" + stereotype + ";"); } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished profile '{1}'" , DateTime.Now.ToLongTimeString() , profile) , 0 , LogTypeEnum.log); //UPCC3 - CDTLibrary Abstract Syntax profile = "UPCC3 - CDTLibrary Abstract Syntax"; stereotypes.Clear(); stereotypes.Add("CDT"); stereotypes.Add("CON"); stereotypes.Add("SUP"); stereotypes.Add("CDTProperty"); foreach (var stereotype in stereotypes) { model.wrappedModel.CustomCommand("Repository", "SynchProfile", "Profile=" + profile + ";Stereotype=" + stereotype + ";"); } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished profile '{1}'" , DateTime.Now.ToLongTimeString() , profile) , 0 , LogTypeEnum.log); //UPCC3 - ENUMLibrary Abstract Syntax profile = "UPCC3 - ENUMLibrary Abstract Syntax"; stereotypes.Clear(); stereotypes.Add("IDSCHEME"); stereotypes.Add("ValueDomain"); stereotypes.Add("ENUM"); stereotypes.Add("CodelistEntry"); foreach (var stereotype in stereotypes) { model.wrappedModel.CustomCommand("Repository", "SynchProfile", "Profile=" + profile + ";Stereotype=" + stereotype + ";"); } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished profile '{1}'" , DateTime.Now.ToLongTimeString() , profile) , 0 , LogTypeEnum.log); //UPCC3 - PRIMLibrary Abstract Syntax profile = "UPCC3 - PRIMLibrary Abstract Syntax"; stereotypes.Clear(); stereotypes.Add("PRIM"); stereotypes.Add("ValueDomain"); foreach (var stereotype in stereotypes) { model.wrappedModel.CustomCommand("Repository", "SynchProfile", "Profile=" + profile + ";Stereotype=" + stereotype + ";"); } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished profile '{1}'" , DateTime.Now.ToLongTimeString() , profile) , 0 , LogTypeEnum.log); //UPCC3 - BusinessContext Abstract Syntax profile = "UPCC3 - BusinessContext Abstract Syntax"; stereotypes.Clear(); stereotypes.Add("BusinessContext"); stereotypes.Add("BusinessProcessContextValue"); stereotypes.Add("BusinessProcessRoleContextValue"); stereotypes.Add("ClassificationScheme"); stereotypes.Add("GeopoliticalContextValue"); stereotypes.Add("IndustryClassificationContextValue"); stereotypes.Add("OfficialConstraintsContextValue"); stereotypes.Add("ProductClassificationContextValue"); stereotypes.Add("SupportingRoleContextValue"); stereotypes.Add("SystemCapabilitiesContextValue"); stereotypes.Add("ContextValue"); foreach (var stereotype in stereotypes) { model.wrappedModel.CustomCommand("Repository", "SynchProfile", "Profile=" + profile + ";Stereotype=" + stereotype + ";"); } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished profile '{1}'" , DateTime.Now.ToLongTimeString() , profile) , 0 , LogTypeEnum.log); }
public override void correct() { //Log start EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting changing type from CentralBufferNode to Object'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); //Look for all the CentralBufferNodes under an Activity and change the type to Object this.model.executeSQL(@"update t_object set [Object_Type] = 'Object' where Object_ID in (select o1.[Object_ID] from t_object o1 inner join t_object o2 on o1.[ParentID] = o2.[Object_ID] where o2.[Object_Type] = 'Activity' and o1.[Object_Type] = 'CentralBufferNode')" ); EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished changing type from CentralBufferNode to Object'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting changing the status of the Objects'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); //Loop each object and set the state to the corresponding state in the source file foreach (var mdObject in magicDrawReader.allObjects) { this.model.executeSQL(@"update t_object set [StateFlags] = '" + mdObject.Value + @"' where Object_ID in (select o.[Object_ID] from t_object o inner join [t_objectproperties] op on o.[Object_ID] = op.[Object_ID] where op.[Property] = 'md_guid' and op.[value] = '" + mdObject.Key + "')"); EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Set state for object '{1}' to '{2}'" , DateTime.Now.ToLongTimeString() , mdObject.Key , mdObject.Value) , 0 , LogTypeEnum.log); } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished set states on objects'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }
public override void correct() { int diagramCounter = 0; EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting corrections for diagrams'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); //Loop each diagram foreach (var mdDiagramKeyValue in magicDrawReader.allDiagrams) { //find the corresponding diagram in EA var ownerID = magicDrawReader.getDiagramOnwerID(mdDiagramKeyValue.Key); var mdDiagram = mdDiagramKeyValue.Value; string getCorrespondingdiagramSQL = @"select d.Diagram_ID from ((t_diagram d inner join t_object o on o.Object_ID = d.ParentID) inner join t_objectproperties tv on (tv.Object_ID = o.Object_ID and tv.Property = 'md_guid')) where tv.Value = '" + ownerID + "'" + " and d.Name = '" + mdDiagram.name.Replace("'", "''") + "'" + " and d.Package_ID in (" + packageTreeIDString + ")" + @" union select d.Diagram_ID from (((t_diagram d inner join t_package p on d.Package_ID = p.Package_ID) inner join t_object o on o.ea_guid = p.ea_guid) inner join t_objectproperties tv on (tv.Object_ID = o.Object_ID and tv.Property = 'md_guid')) where d.ParentID = 0 and tv.Value = '" + ownerID + "'" + " and d.Name = '" + mdDiagram.name.Replace("'", "''") + "'" + " and d.Package_ID in (" + packageTreeIDString + ")"; var eaDiagrams = this.model.getDiagramsByQuery(getCorrespondingdiagramSQL); //loop the found diagrams foreach (var eaDiagram in eaDiagrams) { diagramCounter++; if (eaDiagram != null && eaDiagram.owner is TSF_EA.ElementWrapper) { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Processing diagram number {1}: '{2}.{3}'" , DateTime.Now.ToLongTimeString() , diagramCounter , eaDiagram.owner.name , eaDiagram.name) , ((TSF_EA.ElementWrapper)eaDiagram.owner).id , LogTypeEnum.log); } else if (eaDiagram != null) { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Processing diagram number {1}: '{2}'" , DateTime.Now.ToLongTimeString() , diagramCounter , eaDiagram.name) , 0 , LogTypeEnum.log); } else { break; } //loop all diagramObjects in the mdDiagram that are not activity partitions foreach (var mdDiagramObject in mdDiagram.diagramObjects.Where(x => !x.umlType.StartsWith("Swimlane"))) { addElementToDiagram(mdDiagramObject, eaDiagram); } //save diagram in between? //eaDiagram.save(); //then do all Activity Partitions foreach (var mdDiagramObject in mdDiagram.diagramObjects.Where(x => x.umlType.StartsWith("Swimlane"))) { addElementToDiagram(mdDiagramObject, eaDiagram); } //then do all the messages int i = 1; //default previous y = -100 int previousY = -100; foreach (var mdMessageLink in mdDiagram.diagramObjects.Where(x => x.umlType == "SeqMessage").OrderBy(y => y.y)) { //get the corresponding message string sqlGetMessage = @"select * from (t_connector c inner join t_connectortag tv on (c.Connector_ID = tv.ElementID and tv.Property = 'md_guid')) where tv.VALUE = '" + mdMessageLink.mdID + "'"; var messages = this.model.getRelationsByQuery(sqlGetMessage); foreach (TSF_EA.Message message in messages) { message.sequence = i; int y = mdMessageLink.y * -1; message.y = y; message.WrappedConnector.DiagramID = eaDiagram.DiagramID; message.save(); //update pdata5 SY field. This needs to be filled with the 35 + the difference between the current Y and the previous Y int SYValue = 35 - (previousY - y); //set the previousY previousY = y; //get pdata5 string pdata5 = "SX=0;SY=0;EX=0;EY=0;$LLB=;LLT=;LMT=CX=250:CY=13:OX=0:OY=0:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=1:DIR=0:ROT=0;LMB=;LRT=;LRB=;IRHS=;ILHS=;"; //set SY value pdata5 = KeyValuePairsHelper.setValueForKey("SY", SYValue.ToString(), pdata5); //update pdata5 string sqlUpdatePdata5 = "update t_connector set PDATA5 = '" + pdata5 + "' where ea_guid = '" + message.uniqueID + "'"; this.model.executeSQL(sqlUpdatePdata5); } i++; } //save the diagram eaDiagram.save(); //set the line styles correctLines(eaDiagram); } //if no diagram found in EA then report it as error if (!eaDiagrams.Any()) { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Could not find EA diagram for diagram with ID '{1}'" , DateTime.Now.ToLongTimeString() , mdDiagramKeyValue.Key) , 0 , LogTypeEnum.error); } } // after all diagram are done we fix the activity partition using a query fixActivityPartitions(); EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished corrections for diagrams'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }
public MappingSet getMappingSet(TSF_EA.ElementWrapper sourceRoot) { if (sourceRoot == null) { return(null); } //find the actual source root and target roots var tagComments = sourceRoot.taggedValues.Where(x => (x.name == this.settings.linkedElementTagName || x.name == this.settings.linkedAssociationTagName || x.name == this.settings.linkedAttributeTagName) && x.comment.Contains("<mappingSet>")) .Select(x => x.comment); var mappingSets = new List <MappingSet>(); foreach (var tagComment in tagComments) { var xdoc = XDocument.Load(new StringReader(tagComment)); //get source root var actualSourceRootID = xdoc.Descendants(EA_MP.MappingFactory.mappingSetName).FirstOrDefault()? .Descendants(EA_MP.MappingFactory.mappingSetSourceName).FirstOrDefault()?.Value ?? string.Empty; var actualSourceRoot = this.model.getElementByGUID(actualSourceRootID) as TSF_EA.ElementWrapper; //get target root var actualTargetRootID = xdoc.Descendants(EA_MP.MappingFactory.mappingSetName).FirstOrDefault()? .Descendants(EA_MP.MappingFactory.mappingSetTargetName).FirstOrDefault()?.Value ?? string.Empty; var actualtargetRoot = this.model.getElementByGUID(actualTargetRootID) as TSF_EA.ElementWrapper; if (actualSourceRoot != null && actualtargetRoot != null) { //create the mappingSet var foundMappingSet = EA_MP.MappingFactory.createMappingSet(actualSourceRoot, actualtargetRoot, this.settings); //add to list mappingSets.Add(foundMappingSet); } } MappingSet mappingSet = null; if (mappingSets.Any()) { if (mappingSets.Count == 1) { mappingSet = mappingSets.First(); } else { //let the user select the trace element var selectTargetForm = new SelectTargetForm(); //set items var targets = mappingSets.Select(x => x.target.source); selectTargetForm.setItems(targets); //show form var dialogResult = selectTargetForm.ShowDialog(this.model.mainEAWindow); if (dialogResult == DialogResult.Cancel) { return(null); } var targetRootElement = selectTargetForm.selectedItem as TSF_EA.ElementWrapper; //get corresponding mapping set mappingSet = mappingSets.First(x => x.target.source == targetRootElement); } } else { //go up in the hierarchy to find an element that is a source root for a mapping var parentSourceRoot = this.getParentRootSource(sourceRoot); //TODO load only part of the mapping if (parentSourceRoot != null) { return(this.getMappingSet(parentSourceRoot)); } } //log progress this.clearOutput(); //log progress var startTime = DateTime.Now; EAOutputLogger.log($"Start loading mapping for {sourceRoot.name}", sourceRoot.id); //create the mapping set mappingSet.loadAllMappings(); //log progress var endTime = DateTime.Now; var processingTime = (endTime - startTime).TotalSeconds; EAOutputLogger.log($"Finished loading mapping for {sourceRoot.name} in {processingTime.ToString("N0")} seconds", sourceRoot.id); return(mappingSet); }
void correctAssociations() { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting corrections for the associations" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); //First get all the associations foreach (var mdAssociation in magicDrawReader.allAssociations) { //Check if the association already exists if (!exists(mdAssociation.Key, mdAssociation.Value.source.endClassID, mdAssociation.Value.target.endClassID, "Association", mdAssociation.Value.stereotype)) { //It it does not exist -> create var sourceElement = this.getElementByMDid(mdAssociation.Value.source.endClassID); var targetElement = this.getElementByMDid(mdAssociation.Value.target.endClassID); if (sourceElement != null && targetElement != null) { //create the actual association TSF_EA.Association newAssociation = this.model.factory.createNewElement <TSF_EA.Association>(sourceElement, string.Empty); //set source end properties setEndProperties(newAssociation.sourceEnd, mdAssociation.Value.source); //set target end properties setEndProperties(newAssociation.targetEnd, mdAssociation.Value.target); //set the target end navigable by default newAssociation.targetEnd.isNavigable = true; if (mdAssociation.Value.stereotype == "participates") { newAssociation.targetEnd.isNavigable = false; } //set target class newAssociation.target = targetElement; //set the stereotype newAssociation.addStereotype(this.model.factory.createStereotype(newAssociation, mdAssociation.Value.stereotype)); //save the new association newAssociation.save(); //set the md_guid tagged value newAssociation.addTaggedValue("md_guid", mdAssociation.Key); //tell the user EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Created «" + mdAssociation.Value.stereotype + "» association between '{1}' and '{2}'" , DateTime.Now.ToLongTimeString() , newAssociation.source.name , newAssociation.target.name) , ((TSF_EA.ElementWrapper)newAssociation.source).id , LogTypeEnum.log); } } } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished corrections for the associations" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }
public void clearEAOutput() { EAOutputLogger.clearLog(this.model, this.outputName); }
/// <summary> /// Checks if the attribute type is present as the source element of one of the schema elements /// If it finds a match the type is set to the subset elemnt of this schema element /// </summary> public void createSubsetProperty() { //no need to do anything if the subset element does not exist if (this.owner.subsetElement != null) { HashSet <SBF.SchemaElement> schemaElements = this.owner.owner.elements; if (this.subSetProperty == null) { this.subSetProperty = this.model.factory.createNewElement <UML.Classes.Kernel.Property>(this.owner.subsetElement, this.sourceProperty.name); } else { //report rename if (this.subSetProperty.name != this.sourceProperty.name) { EAOutputLogger.log(this.model, this.owner.owner.settings.outputName , string.Format("Attribute '{0}' has been renamed from '{1}' since the last schema generation" , this.sourceProperty.owner.name + "." + this.sourceProperty.name , this.subSetProperty.name) , ((UTF_EA.ElementWrapper)sourceProperty.owner).id , LogTypeEnum.warning); } //report different type string newTypeName = (this.redefinedElement != null) ? this.redefinedElement.name : this.sourceProperty.type.name; if (this.subSetProperty.type.name != newTypeName) { EAOutputLogger.log(this.model, this.owner.owner.settings.outputName , string.Format("Attribute '{0}' has changed type from '{1}' to '{2}' since the last schema generation" , this.sourceProperty.owner.name + "." + this.sourceProperty.name , this.subSetProperty.type.name , newTypeName) , ((UTF_EA.ElementWrapper)sourceProperty.owner).id , LogTypeEnum.warning); } //report report different multiplicity if (((UTF_EA.Attribute) this.subSetProperty).EAMultiplicity != this.multiplicity) { EAOutputLogger.log(this.model, this.owner.owner.settings.outputName , string.Format("Attribute '{0}' has changed multiplicity from '{1}' to '{2}' since the last schema generation" , this.sourceProperty.owner.name + "." + this.sourceProperty.name , this.subSetProperty.multiplicity , this.sourceProperty.multiplicity) , ((UTF_EA.ElementWrapper)sourceProperty.owner).id , LogTypeEnum.warning); } } this.subSetProperty.name = this.sourceProperty.name; this.subSetProperty.type = this.sourceProperty.type; this.subSetProperty.stereotypes = this.sourceProperty.stereotypes; this.subSetProperty.multiplicity = this.multiplicity; this.subSetProperty.position = this.sourceProperty.position; //alias ((UTF_EA.Attribute) this.subSetProperty).alias = ((UTF_EA.Attribute)sourceProperty).alias; //notes only update them if they are empty if (this.subSetProperty.ownedComments.Count == 0 || !this.subSetProperty.ownedComments.Any(x => x.body.Length > 0)) { this.subSetProperty.ownedComments = this.sourceProperty.ownedComments; if (this.owner.owner.settings.prefixNotes && this.owner.owner.settings.prefixNotesText.Length > 0 && this.subSetProperty.ownedComments.Any(x => x.body.Length > 0)) { foreach (var comment in subSetProperty.ownedComments) { comment.body = this.owner.owner.settings.prefixNotesText + Environment.NewLine + comment.body; } } } //resolve the type foreach (EASchemaElement element in schemaElements) { if (this.redefinedElement != null && this.redefinedElement.subsetElement != null && this.subSetProperty != null) { //replace the type by the subset element of the redefined type this.subSetProperty.type = this.redefinedElement.subsetElement; } //check for restriction of type choice because that can contain the type that is used to redefine this attribute else if (this.choiceElements != null && this.choiceElements.Count > 0 && this.subSetProperty != null) { var redefinedTypeElement = this.choiceElements[0]; if (redefinedTypeElement.subsetElement != null) { this.subSetProperty.type = redefinedTypeElement.subsetElement; } else { this.subSetProperty.type = redefinedTypeElement.sourceElement; } } else if (element.sourceElement != null && element.subsetElement != null && this.subSetProperty != null && element.sourceElement.Equals(this.subSetProperty.type) && element.name == this.subSetProperty.type.name) { //replace the type if it matches the source element this.subSetProperty.type = element.subsetElement; } } ((UTF_EA.Element) this.subSetProperty).save(); //copy tagged values ((EASchema)this.owner.owner).copyTaggedValues((UTF_EA.Element) this.sourceProperty, (UTF_EA.Element) this.subSetProperty); //add tagged value with reference to source attribute ((UTF_EA.Element) this.subSetProperty).addTaggedValue(this.owner.owner.settings.sourceAttributeTagName, ((UTF_EA.Element) this.sourceProperty).guid); } }
/// <summary> /// Checks if the attribute type is present as the source element of one of the schema elements /// If it finds a match the type is set to the subset elemnt of this schema element /// </summary> public void createSubsetLiteral() { HashSet <SBF.SchemaElement> schemaElements = this.owner.owner.elements; if (this.subSetLiteral == null) { this.isNew = true; this.subSetLiteral = this.model.factory.createNewElement <UML.Classes.Kernel.EnumerationLiteral>(this.owner.subsetElement, this.sourceLiteral.name); } else { if (this.subSetLiteral.name != this.sourceLiteral.name) { EAOutputLogger.log(this.model, this.owner.owner.settings.outputName , string.Format("Literal value '{0}' has been renamed from '{1}' since the last schema generation" , this.sourceLiteral.owner.name + "." + this.sourceLiteral.name , this.subSetLiteral.name) , ((UTF_EA.ElementWrapper)sourceLiteral.owner).id , LogTypeEnum.warning); } } this.subSetLiteral.name = this.sourceLiteral.name; this.subSetLiteral.stereotypes = this.sourceLiteral.stereotypes; //Set position for new items if (this.isNew) { this.subSetLiteral.position = this.sourceLiteral.position; } //alias (only if subset alias is empty) if (string.IsNullOrEmpty(((UTF_EA.EnumerationLiteral)subSetLiteral).alias)) { ((UTF_EA.EnumerationLiteral)subSetLiteral).alias = ((UTF_EA.EnumerationLiteral)sourceLiteral).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.EnumerationLiteral)subSetLiteral).alias, ((UTF_EA.EnumerationLiteral)sourceLiteral).alias)) { EAOutputLogger.log(this.model, this.owner.owner.settings.outputName , string.Format("Literal value '{0}' has alias '{1}' in the model and a different alias '{2}' in the subset" , this.sourceLiteral.owner.name + "." + this.sourceLiteral.name , ((UTF_EA.EnumerationLiteral)subSetLiteral).alias , ((UTF_EA.EnumerationLiteral)sourceLiteral).alias) , ((UTF_EA.ElementWrapper)sourceLiteral.owner).id , LogTypeEnum.warning); } //notes only update them if they are empty if (this.subSetLiteral.ownedComments.Count == 0 || !this.subSetLiteral.ownedComments.Any(x => x.body.Length > 0)) { this.subSetLiteral.ownedComments = this.sourceLiteral.ownedComments; if (this.owner.owner.settings.prefixNotes && this.owner.owner.settings.prefixNotesText.Length > 0 && this.subSetLiteral.ownedComments.Any(x => x.body.Length > 0)) { foreach (var comment in subSetLiteral.ownedComments) { comment.body = this.owner.owner.settings.prefixNotesText + Environment.NewLine + comment.body; } } } ((UTF_EA.Element) this.subSetLiteral).save(); //copy tagged values ((UTF_EA.Element) this.subSetLiteral).copyTaggedValues((UTF_EA.Element) this.sourceLiteral); //add tagged value with reference to source literal value ((UTF_EA.Element) this.subSetLiteral).addTaggedValue(this.owner.owner.settings.sourceAttributeTagName, ((UTF_EA.Element) this.sourceLiteral).guid); }
public override void correct() { //Log start EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting converting embedded properties to attributes'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); //Start converting List <TSF_EA.ElementWrapper> properties = this.model.getElementWrappersByQuery(@"select o1.[Object_ID] from [t_object] o1 where o1.[Object_Type] = 'Part'"); foreach (TSF_EA.Property property in properties) { //Tell the user which property we are dealing with EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Correcting property '{1}' with GUID '{2}'" , DateTime.Now.ToLongTimeString() , property.name , property.guid) , 0 , LogTypeEnum.log); if (!string.IsNullOrEmpty(property.name)) { //Create attribute with the name of the property TSF_EA.Attribute newAttribute = this.model.factory.createNewElement <TSF_EA.Attribute>(property.owner, property.name); if (property.classifier != null) { newAttribute.type = property.classifier; } newAttribute.multiplicity = property.multiplicity; newAttribute.save(); //Tell the user which attribute we created EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Create attribute '{1}' with type '{2}'" , DateTime.Now.ToLongTimeString() , newAttribute.name , newAttribute.type) , 0 , LogTypeEnum.log); } else if (property.classifier != null) { //Create attribute with the name of the classifier TSF_EA.Attribute newAttribute = this.model.factory.createNewElement <TSF_EA.Attribute>(property.owner, property.classifier.name); newAttribute.type = property.classifier; newAttribute.multiplicity = property.multiplicity; newAttribute.save(); //Tell the user which attribute we created EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Create attribute '{1}' with type '{2}'" , DateTime.Now.ToLongTimeString() , newAttribute.name , newAttribute.type) , 0 , LogTypeEnum.log); } else { //Alert the user that we couldn't create the attribute EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Could not create attribute for property with id '{1}'" , DateTime.Now.ToLongTimeString() , property.guid ) , property.id , LogTypeEnum.error); //stop processing break; } //Delete property property.delete(); } //Log Finished EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished converting embedded properties to attributes'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }
public void addLineToEAOutput(string outputline, string parameter) { EAOutputLogger.log(this._model, this.outputName, string.Format("{0} {1} {2}", DateTime.Now.ToLongTimeString(), outputline, parameter), 0, LogTypeEnum.log); }
/// <summary> /// create a mappingSet based on the data in the CSV file /// </summary> /// <param name="model">the model that contains the elements</param> /// <param name="filePath">the path to the CSV file</param> /// <returns>a mapping set representing the mapping in the file</returns> public static MappingSet createMappingSet(Model model, string filePath, MappingSettings settings, Element sourceRootElement = null, Element targetRootElement = null) { MappingSet newMappingSet = null; var engine = new FileHelperEngine <CSVMappingRecord>(); var parsedFile = engine.ReadFile(filePath); int i = 1; Package rootPackage = null; foreach (CSVMappingRecord mappingRecord in parsedFile) { //find source var source = findElement(model, mappingRecord.sourcePath, sourceRootElement); //find target var target = findElement(model, mappingRecord.targetPath, targetRootElement); if (source == null) { EAOutputLogger.log(model, settings.outputName , string.Format("Could not find element that matches: '{0}'", mappingRecord.sourcePath) , 0, LogTypeEnum.error); } else if (target == null) { EAOutputLogger.log(model, settings.outputName , string.Format("Could not find element that matches: '{0}'", mappingRecord.targetPath) , 0, LogTypeEnum.error); } else { //first check if the mappingSet is already created if (newMappingSet == null) { //determine if this should be a PackageMappingSet or an ElementMappingSet if (sourceRootElement is Package) { rootPackage = sourceRootElement as Package; newMappingSet = new PackageMappingSet(sourceRootElement as Package); } else if (sourceRootElement is ElementWrapper) { rootPackage = sourceRootElement.owningPackage as Package; newMappingSet = new ElementMappingSet(sourceRootElement as ElementWrapper); } else { rootPackage = source.owningPackage as Package; newMappingSet = new PackageMappingSet((Package)source.owningPackage); } } MappingLogic newMappingLogic = null; //check if there is any mapping logic if (!string.IsNullOrEmpty(mappingRecord.mappingLogic)) { if (settings.useInlineMappingLogic) { newMappingLogic = new MappingLogic(mappingRecord.mappingLogic); } else { //Check fo an existing mapping logic newMappingLogic = getExistingMappingLogic(model, settings, mappingRecord.mappingLogic, rootPackage); if (newMappingLogic == null) { var mappingElement = model.factory.createNewElement(rootPackage, "mapping logic " + i, settings.mappingLogicType) as ElementWrapper; if (mappingElement != null) { //increase counter for new mapping element name i++; mappingElement.notes = mappingRecord.mappingLogic; mappingElement.save(); //create the mappingLogic newMappingLogic = new MappingLogic(mappingElement); } else { //else we create an inline mapping logic anyway newMappingLogic = new MappingLogic(mappingRecord.mappingLogic); } } } } Mapping newMapping = null; var sourceAssociationEnd = source as AssociationEnd; var targetAssociationEnd = target as AssociationEnd; //create the new mapping //we can't create connector mappings for mappings to or from associations so we have to use tagged value mappings for those. if (settings.useTaggedValues || sourceAssociationEnd != null || targetAssociationEnd != null) { //if the source or target are associationEnds then we replace them by their association if (sourceAssociationEnd != null) { source = sourceAssociationEnd.association as Element; } if (targetAssociationEnd != null) { target = targetAssociationEnd.association as Element; } newMapping = new TaggedValueMapping(source, target, mappingRecord.sourcePath, mappingRecord.targetPath, settings); } else { newMapping = new ConnectorMapping(source, target, mappingRecord.sourcePath, mappingRecord.targetPath, settings); } if (newMappingLogic != null) { newMapping.mappingLogic = newMappingLogic; } newMapping.save(); newMappingSet.addMapping(newMapping); } } return(newMappingSet); }
public override void correct() { //Log start EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting Corrections the Package Structure'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); // Data package aanmaken dat zal gebruikt worden om alles onder te plaatsen TSF_EA.Package newData = this.model.factory.createNewElement <TSF_EA.Package>(mdPackage, "Data"); newData.save(); //reload the new package to make sure we have a complete object newData = (TSF_EA.Package) this.model.getElementWrapperByPackageID(newData.packageID); //loop all subPackages foreach (TSF_EA.Package dataPackage in mdPackage.nestedPackages.Where(x => !x.Equals(newData))) // Doorloopt de Magicdraw Import { //tell the user which package we are dealing with EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Correcting package '{1}' with GUID '{2}'" , DateTime.Now.ToLongTimeString() , dataPackage.name , dataPackage.guid) , 0 , LogTypeEnum.log); foreach (TSF_EA.Package workPackage in dataPackage.nestedPackages) { if (workPackage.isEmpty) { //workPackage.delete(); //lege packages deleten } else { if (hasPackage(workPackage, newData)) { // inhoud moven naar desbetreffende package moveContent(workPackage, getPackage(workPackage, newData)); } else { if (workPackage.name == "AT" || workPackage.name == "BE" || workPackage.name == "CH" || workPackage.name == "DE" || workPackage.name == "DK" || workPackage.name == "NL" || workPackage.name == "NO" || workPackage.name == "SE" || workPackage.name == "SI") { string getEbixNationalPackageSQL = @"select o.[Object_ID] from (t_object o inner join [t_objectproperties] tv on o.[Object_ID] = tv.[Object_ID] ) where tv.[Property] = 'md_guid' and tv.value = '_11_5_5300164_1160397913975_435853_333'" ; var ebixNationalPackage = (TSF_EA.Package)model.getElementWrappersByQuery(getEbixNationalPackageSQL).FirstOrDefault(); workPackage.owningPackage = ebixNationalPackage; workPackage.save(); } else { workPackage.owningPackage = newData; workPackage.save(); if (hasPackage(workPackage, newData)) { // inhoud moven naar desbetreffende package moveContent(workPackage, getPackage(workPackage, newData)); } else { if (workPackage.name == "AT" || workPackage.name == "BE" || workPackage.name == "CH" || workPackage.name == "DE" || workPackage.name == "DK" || workPackage.name == "NL" || workPackage.name == "NO" || workPackage.name == "SE" || workPackage.name == "SI") { var pack = (TSF_EA.Package)model.getElementWrapperByGUID("{AE324957-30D4-41a6-A507-B31E05EE5EA5}"); workPackage.owningPackage = pack; workPackage.save(); } else { workPackage.owningPackage = newData; workPackage.save(); } } } } } foreach (TSF_EA.Diagram diagram in dataPackage.ownedDiagrams) { diagram.owningPackage = newData; diagram.save(); } } //Delete the unneeded packages if (dataPackage.guid != newData.guid) { dataPackage.delete(); } } //refresh the package to show the new structure mdPackage.refresh(); //Log Finished EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished Corrections the Package Structure'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }
/// <summary> /// import the mapings specified in the file into the given mappingSet /// </summary> /// <param name="mappingSet">the mappingset to import the mappings into</param> /// <param name="filePath">the path to the file containing the mappings</param> public static void importMappings(MappingSet mappingSet, string filePath, Model model) { IEnumerable <CSVMappingRecord> mappingRecords; //remove all existing mappings foreach (var mapping in mappingSet.mappings) { mapping.delete(); } //map source and target to be sure mappingSet.source.mapTo(mappingSet.target); //make sure the target node tree has been build ((MappingNode)mappingSet.target).buildNodeTree(); //read the csv file using (var textReader = new StreamReader(filePath)) { var csv = new CSV.CsvReader(textReader, false); csv.Configuration.RegisterClassMap <CSVMappingRecordMap>(); csv.Configuration.Delimiter = ";"; mappingRecords = csv.GetRecords <CSVMappingRecord>(); var sourceNodes = new Dictionary <string, MP.MappingNode>(); var targetNodes = new Dictionary <string, MP.MappingNode>(); //now loop the records foreach (var csvRecord in mappingRecords) { if (string.IsNullOrEmpty(csvRecord.sourcePath) || (string.IsNullOrEmpty(csvRecord.targetPath) && string.IsNullOrEmpty(csvRecord.mappingLogic))) { //don't even bother if not both fields are filled in continue; } //convert any newLines (\n") coming from excel (Alt-Enter) to "real" newlines csvRecord.mappingLogic = csvRecord.mappingLogic.Replace("\n", Environment.NewLine); //find the source //first check if we already known the node MP.MappingNode sourceNode = null; if (!string.IsNullOrEmpty(csvRecord.sourcePath) && !sourceNodes.TryGetValue(csvRecord.sourcePath, out sourceNode)) { //find out if we know a parent node of this node var parentNode = findParentNode(sourceNodes, csvRecord.sourcePath); if (parentNode == null) { //no parent found, start at the top parentNode = mappingSet.source; } //find the node from the parent sourceNode = parentNode.findNode(csvRecord.sourcePath.Split('.').ToList()); } if (sourceNode == null) { EAOutputLogger.log($"Could not find source element corresponding to '{csvRecord.sourcePath}'", 0, LogTypeEnum.warning); //don't bother going any further continue; } //find the target MP.MappingNode targetNode = null; //first check if we already known the node if (!string.IsNullOrEmpty(csvRecord.targetPath) && !targetNodes.TryGetValue(csvRecord.targetPath, out targetNode)) { //find out if we know a parent node of this node var parentNode = findParentNode(targetNodes, csvRecord.targetPath); if (parentNode == null) { //no parent found, start at the top parentNode = mappingSet.target; } //find the node from the parent targetNode = parentNode.findNode(csvRecord.targetPath.Split('.').ToList()); if (targetNode == null) { EAOutputLogger.log($"Could not find target element corresponding to '{csvRecord.targetPath}'", 0, LogTypeEnum.warning); } } //if we found both then we map them if (sourceNode != null) { if (targetNode != null) { var newMapping = sourceNode.mapTo(targetNode); newMapping.mappingLogics = createMappingLogicsFromCSVString(csvRecord.mappingLogic, mappingSet.EAContexts, model); newMapping.save(); EAOutputLogger.log($"Mapping created from '{csvRecord.sourcePath}' to '{csvRecord.targetPath}'", 0); } else { var newMapping = sourceNode.createEmptyMapping(false); newMapping.mappingLogics = createMappingLogicsFromCSVString(csvRecord.mappingLogic, mappingSet.EAContexts, model); newMapping.save(); EAOutputLogger.log($"Empty mapping created for '{csvRecord.sourcePath}' ", 0); } } } } }
public override void correct() { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting to correct Associations" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); //fix the <<participates>> stereotypes this.fixParticipation(); // get all the associations foreach (MDAssociation mdAssociation in magicDrawReader.allAssociations.Values) { //first find the corresponding association in the EA model var eaAssociation = findCorrespondingAssociation(mdAssociation); if (eaAssociation != null) { //fix navigability this.fixNavigability(eaAssociation); //correct the "(Unspecified)..(Unspecified)" multiplicities in the database string sqlCorrectUnspecified = "update t_connector set DestCard = null where DestCard like '%unspecified%'"; this.model.executeSQL(sqlCorrectUnspecified); sqlCorrectUnspecified = "update t_connector set SourceCard = null where SourceCard like '%unspecified%'"; this.model.executeSQL(sqlCorrectUnspecified); //check first if the multiplicity is to be corrected if (!mdAssociation.source.lowerBound.Equals(eaAssociation.sourceEnd.lower.ToString()) || !mdAssociation.source.upperBound.Equals(eaAssociation.sourceEnd.upper.ToString()) || !mdAssociation.target.lowerBound.Equals(eaAssociation.targetEnd.lower.ToString()) || !mdAssociation.target.upperBound.Equals(eaAssociation.targetEnd.upper.ToString())) { //actually fix the multiplicities try { bool updatedMultiplicity = false; //set source (only if not both empty) if (!string.IsNullOrEmpty(mdAssociation.source.lowerBound) && !string.IsNullOrEmpty(mdAssociation.source.upperBound)) { var sourceMultiplicity = new TSF_EA.Multiplicity(mdAssociation.source.lowerBound, mdAssociation.source.upperBound); eaAssociation.sourceEnd.multiplicity = sourceMultiplicity; updatedMultiplicity = true; } //set target (only if not both empty) if (!string.IsNullOrEmpty(mdAssociation.target.lowerBound) && !string.IsNullOrEmpty(mdAssociation.target.upperBound)) { var targetMultiplicity = new TSF_EA.Multiplicity(mdAssociation.target.lowerBound, mdAssociation.target.upperBound); eaAssociation.targetEnd.multiplicity = targetMultiplicity; updatedMultiplicity = true; } //tell the user we have updated the multiplicities if (updatedMultiplicity) { //save the association eaAssociation.save(); //let the user know EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Corrected multiplicity of association between '{1}' and '{2}'" , DateTime.Now.ToLongTimeString() , eaAssociation.source.name , eaAssociation.target.name) , ((TSF_EA.ElementWrapper)eaAssociation.source).id , LogTypeEnum.log); } } catch (Exception e) { //tell the user we could not fix the multiplicity EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Could not update multiplicities between '{1}' and '{2}' because of error '{3}'" , DateTime.Now.ToLongTimeString() , eaAssociation.source.name , eaAssociation.target.name , e.GetType().Name) , ((TSF_EA.ElementWrapper)eaAssociation.source).id , LogTypeEnum.error); //also log the complete error Logger.logError(string.Format("Exception '{0}' with message '{1}' occurred at stacktrace: {2}" , e.GetType().Name , e.Message , e.StackTrace)); } } } } //Log finished EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting to correct Associationss" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }
public override void correct() { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting fix notes'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); // get al the diagrams foreach (var mdDiagramKeyValue in magicDrawReader.allDiagrams) { var mdDiagram = mdDiagramKeyValue.Value; var ownerID = magicDrawReader.getDiagramOnwerID(mdDiagramKeyValue.Key); var parentElement = getElementByMDid(ownerID); foreach (var mdDiagramNote in mdDiagram.diagramNotes) { if (parentElement != null) { TSF_EA.NoteComment newNote = this.model.factory.createNewElement <TSF_EA.NoteComment>(parentElement, string.Empty); newNote.ownedComments.FirstOrDefault().body = mdDiagramNote.text; newNote.save(); var linkedElement = getElementByMDid(mdDiagramNote.linkedElement); if (linkedElement != null) { TSF_EA.ConnectorWrapper noteLink = newNote.addOwnedElement <TSF_EA.ConnectorWrapper>(string.Empty, "NoteLink"); noteLink.target = linkedElement; noteLink.save(); EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Create note '{1}' for '{2}'" , DateTime.Now.ToLongTimeString() , newNote.ownedComments.FirstOrDefault().body , getElementByMDid(mdDiagramNote.linkedElement).name) , newNote.id , LogTypeEnum.log); } else { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Create note '{1}'" , DateTime.Now.ToLongTimeString() , newNote.ownedComments.FirstOrDefault().body) , newNote.id , LogTypeEnum.log); } } else { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} No parent for note '{1}'" , DateTime.Now.ToLongTimeString() , mdDiagramNote.text) , 0 , LogTypeEnum.log); } } } //Log finished EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished fix notes" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }
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); }
/// <summary> /// creates a subset of the source model with only the properties and associations used in this schema /// </summary> /// <param name="destinationPackage">the package to create the subset in</param> /// <param name="copyDatatype"></param> public void createSubsetModel(UML.Classes.Kernel.Package destinationPackage, HashSet <SBF.SchemaElement> elements) { //loop the elements to create the subSetElements foreach (EASchemaElement schemaElement in elements) { //tell the user what we are doing EAOutputLogger.log(this.model, this.settings.outputName, "Creating subset element for : '" + schemaElement.name + "'" , 0, LogTypeEnum.log); //do not copy elements that are shared if (!schemaElement.isShared) { //only create subset elements for classes, not for datatypes if (schemaElement.sourceElement is UML.Classes.Kernel.Class || schemaElement.sourceElement is UML.Classes.Kernel.Enumeration) { schemaElement.createSubsetElement(destinationPackage); //Logger.log("after EASchema::creating single subset element"); } else if (schemaElement.sourceElement is UML.Classes.Kernel.DataType && this.settings.copyDataTypes) { //if the datatypes are limited then only the ones in the list should be copied if (!this.settings.limitDataTypes || this.settings.dataTypesToCopy.Contains(schemaElement.sourceElement.name)) { schemaElement.createSubsetElement(destinationPackage); } } } } //Logger.log("after EASchema::creating subsetelements"); // then loop them again to create the associations foreach (EASchemaElement schemaElement in elements) { if (!schemaElement.isShared) { //only create subset elements for classes and enumerations and datatypes if (schemaElement.sourceElement is UML.Classes.Kernel.Class || schemaElement.sourceElement is UML.Classes.Kernel.Enumeration || schemaElement.sourceElement is UML.Classes.Kernel.DataType) { //tell the user what we are doing EAOutputLogger.log(this.model, this.settings.outputName, "Creating subset associations for: '" + schemaElement.name + "'" , 0, LogTypeEnum.log); schemaElement.createSubsetAssociations(); //Logger.log("after EASchema::creating single subset association"); //tell the user what we are doing EAOutputLogger.log(this.model, this.settings.outputName, "Creating subset attributes for: '" + schemaElement.name + "'" , 0, LogTypeEnum.log); // and to resolve the attributes types to subset types if required schemaElement.createSubsetAttributes(); //tell the user what we are doing EAOutputLogger.log(this.model, this.settings.outputName, "Creating subset literals for: '" + schemaElement.name + "'" , 0, LogTypeEnum.log); //Logger.log("after EASchema::createSubsetAttributes "); schemaElement.createSubsetLiterals(); //clean up attribute type dependencies we don't need anymore schemaElement.cleanupAttributeDependencies(); if (!this.settings.dontCreateAttributeDependencies) { //tell the user what we are doing EAOutputLogger.log(this.model, this.settings.outputName, "Creating attribute depencendies for: '" + schemaElement.name + "'" , 0, LogTypeEnum.log); //and add a dependency from the schemaElement to the type of the attributes schemaElement.addAttributeTypeDependencies(); } //order the attributes if (!this.settings.keepOriginalAttributeOrder && !this.settings.setAttributeOrderZero && !(this.settings.orderAssociationsAlphabetically && this.settings.orderAssociationsAmongstAttributes)) { schemaElement.orderAttributes(); } //order the associations if (this.settings.orderAssociationsAlphabetically) { //tell the user what we are doing EAOutputLogger.log(this.model, this.settings.outputName, "Ordering associations for: '" + schemaElement.name + "'" , 0, LogTypeEnum.log); //and add a dependency from the schemaElement to the type of the attributes schemaElement.orderAssociationsAlphabetically(); } //Logger.log("after EASchema::addAttributeTypeDependencies"); //tell the user what we are doing EAOutputLogger.log(this.model, this.settings.outputName, "Creating generalizations for: '" + schemaElement.name + "'" , 0, LogTypeEnum.log); //add generalizations if both elements are in the subset schemaElement.addGeneralizations(); } } } //then loop them againe to remove those subset elements that don't have any attributes or associations // or generalizations, or are used as type if (this.settings.deleteUnusedSchemaElements) { foreach (EASchemaElement schemaElement in elements) { if (schemaElement.subsetElement != null) { //remove those subset elements that don't have any attributes or associations //reload the element because otherwise the API does not return any attributes or associations var reloadedElement = model.getElementByGUID(schemaElement.subsetElement.uniqueID) as Classifier; if (reloadedElement != null && !reloadedElement.attributes.Any() && !reloadedElement.getRelationships <UML.Classes.Kernel.Association>().Any() && !reloadedElement.getRelationships <UML.Classes.Kernel.Generalization>().Any() && !reloadedElement.getDependentTypedElements <UML.Classes.Kernel.TypedElement>().Any() && (reloadedElement is TSF_EA.ElementWrapper && !((TSF_EA.ElementWrapper)reloadedElement).primitiveParentNames.Any())) { //tell the user what we are doing EAOutputLogger.log(this.model, this.settings.outputName, "Deleting subset element for: '" + schemaElement.name + "'" , 0, LogTypeEnum.log); schemaElement.subsetElement.delete(); } } } } //then synchronize the tagged values where needed synchronizeTaggedValues(); //save the new schema contents to the destination package this.saveSchemaContent(destinationPackage); }
public override void correct() { /* Check how the Depencency matrix information can be transferred to EA. * Since this seems to be linking attributes with other attributes or associations we * will probably need to use tagged values to create the links and specific SQL Searches * to get the information out of EA as well. * (to be check with Thibault if the information is present or not)*/ EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting corrections for relationship matrixes'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); foreach (var mdDependency in magicDrawReader.allAttDependencies) { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Get dependency '{1}' --> '{2}'" , DateTime.Now.ToLongTimeString() , mdDependency.sourceName , mdDependency.targetName) , 0 , LogTypeEnum.log); //get the corresponding attributes in EA //source element var sourceElement = (TSF_EA.Class)getElementByMDid(mdDependency.sourceParentGuid); //target element var targetElement = (TSF_EA.Class)getElementByMDid(mdDependency.targetParentGuid); if (sourceElement != null & targetElement != null) { var sourceAttribute = (TSF_EA.Attribute)sourceElement.attributes.FirstOrDefault(x => x.name == mdDependency.sourceName); mdDependency.sourceGuid = sourceAttribute != null? sourceAttribute.guid: string.Empty; var targetAttribute = (TSF_EA.Attribute)targetElement.attributes.FirstOrDefault(x => x.name == mdDependency.targetName); mdDependency.targetGuid = targetAttribute != null? targetAttribute.guid: string.Empty; if (sourceAttribute != null && targetAttribute != null) { sourceAttribute.addTaggedValue("sourceAttribute", mdDependency.targetGuid); EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Set sourceAttribute '{1}' for '{2}'" , DateTime.Now.ToLongTimeString() , mdDependency.targetName , mdDependency.sourceName) , 0 , LogTypeEnum.log); } } } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished Corrections for Dependency Matrix'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }
public override void correct() { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting corrections for cross MDzip relations" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); //loop all simple element to element cross mdzip relations foreach (var crossRelation in magicDrawReader.allCrossMDzipRelations) { //check if the relation doesn't exist yet string sqlGetExistingRelations = @"select c.Connector_ID from (t_connector c inner join t_connectortag tv on( c.Connector_ID = tv.ElementID and tv.Property = 'md_guid')) where tv.VALUE = '" + crossRelation.Key + "'"; var newRelation = this.model.getRelationsByQuery(sqlGetExistingRelations).FirstOrDefault(); if (newRelation == null) { MDElementRelation relation = crossRelation.Value; //find source var source = this.getElementByMDid(relation.sourceMDGUID); //find target var target = this.getElementByMDid(relation.targetMDGUID); //create relation if (source != null && target != null) { //create the actual relation newRelation = this.model.factory.createNewElement(source, relation.name, relation.relationType) as TSF_EA.ConnectorWrapper; if (newRelation != null) { newRelation.target = target; newRelation.save(); //save md_guid tag newRelation.addTaggedValue("md_guid", crossRelation.Key); //tell the user what is happening EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Created relation of type {1} between '{2}' and '{3}'" , DateTime.Now.ToLongTimeString() , relation.relationType , source.name , target.name) , source.id , LogTypeEnum.log); } else { //report the fact that we could not create the relation EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Could not create relation of type {1} between '{2}' and '{3}'" , DateTime.Now.ToLongTimeString() , relation.relationType , source.name , target.name) , source.id , LogTypeEnum.error); } } } //save md_guid tag if (newRelation != null) { newRelation.addTaggedValue("md_guid", crossRelation.Key); } } //loop all cross MDzip Associations foreach (var mdCrossAssocation in magicDrawReader.allCrossMDzipAssociations) { //check if the relation doesn't exist yet string sqlGetExistingRelations = @"select c.Connector_ID from (t_connector c inner join t_connectortag tv on( c.Connector_ID = tv.ElementID and tv.Property = 'md_guid')) where tv.VALUE = '" + mdCrossAssocation.Key + "'"; TSF_EA.Association newCrossAssociation = this.model.getRelationsByQuery(sqlGetExistingRelations).FirstOrDefault() as TSF_EA.Association; if (newCrossAssociation == null) { var mdAssociation = mdCrossAssocation.Value; //get the source element var source = this.getElementByMDid(mdAssociation.source.endClassID); //get the target element var target = this.getElementByMDid(mdAssociation.target.endClassID); if (source != null && target != null) { //create the actual association newCrossAssociation = this.model.factory.createNewElement <TSF_EA.Association>(source, string.Empty); //set source end properties setEndProperties(newCrossAssociation.sourceEnd, mdAssociation.source); //set target end properties setEndProperties(newCrossAssociation.targetEnd, mdAssociation.target); //set target class newCrossAssociation.target = target; //set navigability newCrossAssociation.targetEnd.isNavigable = true; //save the association newCrossAssociation.save(); //tell the user what is happening EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Created association between '{1}' and '{2}'" , DateTime.Now.ToLongTimeString() , source.name , target.name) , source.id , LogTypeEnum.log); } else { //report the fact that we could not create the relation EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Could not create association between '{1}' and '{2}'" , DateTime.Now.ToLongTimeString() , source.name , target.name) , source.id , LogTypeEnum.error); } } //set the md_guid tagged value, also on existing associations if (newCrossAssociation != null) { newCrossAssociation.addTaggedValue("md_guid", mdCrossAssocation.Key); } } EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished corrections for cross MDzip relations" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }
public UML.Classes.Kernel.Classifier createSubsetElement(UML.Classes.Kernel.Package destinationPackage) { //first create the element in the destination Package if (this.subsetElement == null) { if (this.sourceElement is UML.Classes.Kernel.Enumeration) { this.subsetElement = this.model.factory.createNewElement <UML.Classes.Kernel.Enumeration>(destinationPackage, this.wrappedSchemaType.TypeName); } else if (this.sourceElement is UML.Classes.AssociationClasses.AssociationClass) { this.subsetElement = this.model.factory.createNewElement <UML.Classes.AssociationClasses.AssociationClass>(destinationPackage, this.wrappedSchemaType.TypeName); } else if (this.sourceElement is UML.Classes.Kernel.Class) { this.subsetElement = this.model.factory.createNewElement <UML.Classes.Kernel.Class>(destinationPackage, this.wrappedSchemaType.TypeName); } else if (this.sourceElement is UML.Classes.Kernel.DataType) { this.subsetElement = this.model.factory.createNewElement <UML.Classes.Kernel.DataType>(destinationPackage, this.wrappedSchemaType.TypeName); } } else { //report change of name of the element if (this.sourceElement.name != this.subsetElement.name) { EAOutputLogger.log(this.model, this.owner.settings.outputName , string.Format("Element '{0}' has changed name from '{1}' since the last schema generation" , this.sourceElement.name , this.subsetElement.name) , ((UTF_EA.ElementWrapper)sourceElement).id , LogTypeEnum.warning); } } //stereotypes this.subsetElement.stereotypes = this.sourceElement.stereotypes; //alias //only copy alias is the alias in the subset is empty if (string.IsNullOrEmpty(((UTF_EA.ElementWrapper)subsetElement).alias)) { ((UTF_EA.ElementWrapper)subsetElement).alias = ((UTF_EA.ElementWrapper)sourceElement).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.ElementWrapper)subsetElement).alias, ((UTF_EA.ElementWrapper)sourceElement).alias)) { EAOutputLogger.log(this.model, this.owner.settings.outputName , string.Format("Property '{0}' has alias '{1}' in the model and a different alias '{2}' in the subset" , this.sourceElement.name , ((UTF_EA.ElementWrapper)subsetElement).alias , ((UTF_EA.ElementWrapper)sourceElement).alias) , ((UTF_EA.ElementWrapper)sourceElement).id , LogTypeEnum.warning); } //genlinks ((UTF_EA.ElementWrapper)subsetElement).genLinks = ((UTF_EA.ElementWrapper)sourceElement).genLinks; //notes only update them if they are empty if (this.subsetElement.ownedComments.Count == 0 || !this.subsetElement.ownedComments.Any(x => x.body.Length > 0)) { this.subsetElement.ownedComments = this.sourceElement.ownedComments; if (this.owner.settings.prefixNotes && this.owner.settings.prefixNotesText.Length > 0 && this.subsetElement.ownedComments.Any(x => x.body.Length > 0)) { foreach (var comment in subsetElement.ownedComments) { comment.body = this.owner.settings.prefixNotesText + Environment.NewLine + comment.body; } } } //save the new subset element ((UTF_EA.Element) this.subsetElement).save(); //copy tagged values ((EASchema)this.owner).copyTaggedValues((UTF_EA.Element) this.sourceElement, (UTF_EA.Element) this.subsetElement); //set reference to source element if (this.owner.settings.tvInsteadOfTrace) { //add a tagged value from the subset element to the source element ((UTF_EA.ElementWrapper) this.subsetElement).addTaggedValue(this.owner.settings.elementTagName, this.sourceElement.uniqueID); } else { //add a trace relation from the subset element to the source element // check if trace already exists? var trace = this.subsetElement.getRelationships <UML.Classes.Dependencies.Abstraction>() .FirstOrDefault(x => this.sourceElement.Equals(x.supplier)) as UML.Classes.Dependencies.Abstraction; if (trace == null) { trace = this.model.factory.createNewElement <UML.Classes.Dependencies.Abstraction>(this.subsetElement, string.Empty); trace.addStereotype(this.model.factory.createStereotype(trace, "trace")); trace.target = this.sourceElement; trace.save(); } } //return the new element return(this.subsetElement); }
/// <summary> /// If a user selects any of the outputs listed by the Add-in, this function will be invoked. /// The function receives the Schema Composer automation interface, which can be used to traverse the schema. /// </summary> /// <param name="Repository"></param> /// <param name="composer"></param> public override void EA_GenerateFromSchema(EA.Repository Repository, EA.SchemaComposer composer, string exports) { try { Schema schema = this.schemaFactory.createSchema(composer, this.settings); UML.Classes.Kernel.Package targetPackage = null; if (this.settings.generateToArtifactPackage) { targetPackage = schema.containerElement?.owningPackage; } else { var targetPackageTag = schema.containerElement?.taggedValues.FirstOrDefault(x => x.name == targetPackageTagName); if (targetPackageTag != null) { targetPackage = targetPackageTag?.tagValue as UML.Classes.Kernel.Package; } } if (targetPackage == null) { targetPackage = this.model.getUserSelectedPackage() as UML.Classes.Kernel.Package; } if (targetPackage != null) { //save target package as tagged value on schema artifact if (!this.settings.generateToArtifactPackage) { this.saveTargetPackageTag(schema, targetPackage); } Cursor.Current = Cursors.WaitCursor; bool writable = true; //check if package is writable if (this.settings.checkSecurity) { writable = targetPackage.isCompletelyWritable; if (!writable) { var lockPackageResponse = MessageBox.Show("Package is read-only" + Environment.NewLine + "Would you like to lock the package?" , "Lock target Package?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); //lock the elements immediately if (lockPackageResponse == DialogResult.Yes) { writable = this.makeCompletelyWritable(targetPackage); if (!writable) { //if not writable then inform user and stop further processing; MessageBox.Show("Target package could not be locked", "Target Read-Only", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } //only proceed if target package is writable if (writable) { //check if the already contains classes var response = DialogResult.No; response = MessageBox.Show($"Are you sure you want to generate the subset to package '{targetPackage.name}'?" , "Generate Subset?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (response == DialogResult.Yes) { if (this.EAModel.EAVersion >= 1308) { //disable ui updates to speed up process. Only for v13 or higher this.EAModel.wrappedModel.EnableUIUpdates = false; } //update the subset this.updateMessageSubset(schema, targetPackage); //refresh package to make changes visible Only for v13 or higher if (this.EAModel.EAVersion >= 1308) { targetPackage.refresh(); } //check for any errors or warnings var errorCount = EAOutputLogger.getErrors(this.EAModel, this.settings.outputName).Count(); var warningCount = EAOutputLogger.getWarnings(this.EAModel, this.settings.outputName).Count(); if (errorCount > 0 || warningCount > 0) { MessageBox.Show(this.EAModel.mainEAWindow, $"Generation resulted in {errorCount} errors and {warningCount} warnings.\nPlease check the output log" , "Errors or Warnings!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } Cursor.Current = Cursors.Default; } } catch (Exception e) { processException(e); } finally { if (this.EAModel.EAVersion >= 1308) { //re-enable gui updates. Only for V13 or higher this.EAModel.wrappedModel.EnableUIUpdates = true; } } }
private void clearOutput() { EAOutputLogger.clearLog(this.model, this.settings.outputName); }
/// <summary> /// create a mappingSet based on the data in the CSV file /// </summary> /// <param name="model">the model that contains the elements</param> /// <param name="filePath">the path to the CSV file</param> /// <returns>a mapping set representing the mapping in the file</returns> public static MappingSet createMappingSet(Model model, string filePath, MappingSettings settings, ElementWrapper sourceRootElement, ElementWrapper targetRootElement) { MappingSet newMappingSet = null; IEnumerable <CSVMappingRecord> mappingRecords; //read the csv file using (var textReader = new StreamReader(filePath)) { var csv = new CSV.CsvReader(textReader, false); csv.Configuration.RegisterClassMap <CSVMappingRecordMap>(); csv.Configuration.Delimiter = ";"; mappingRecords = csv.GetRecords <CSVMappingRecord>(); } //create the new mapping set newMappingSet = createMappingSet(sourceRootElement, targetRootElement, settings); //remove all existing mappings //TODO: warn if mappings exist? foreach (var mapping in newMappingSet.mappings) { mapping.delete(); } //make sure the target node tree has been build ((MappingNode)newMappingSet.target).buildNodeTree(); //now loop the records foreach (var csvRecord in mappingRecords) { EAOutputLogger.log(model, settings.outputName , $"Parsed source: '{csvRecord.sourcePath}' target: '{csvRecord.targetPath}' logic: '{csvRecord.mappingLogic}'" , 0, LogTypeEnum.log); } return(newMappingSet); // int i = 1; //Package rootPackage = null; //foreach (CSVMappingRecord mappingRecord in parsedFile) //{ // //find source // var source = findElement(model, mappingRecord.sourcePath, sourceRootElement); // //find target // var target = findElement(model, mappingRecord.targetPath,targetRootElement); // if (source == null ) // { // EAOutputLogger.log(model,settings.outputName // ,string.Format("Could not find element that matches: '{0}'",mappingRecord.sourcePath) // ,0,LogTypeEnum.error); // } // else if( target == null) // { // EAOutputLogger.log(model,settings.outputName // ,string.Format("Could not find element that matches: '{0}'",mappingRecord.targetPath) // ,0,LogTypeEnum.error); // } // else // { // //first check if the mappingSet is already created // if (newMappingSet == null) // { // //determine if this should be a PackageMappingSet or an ElementMappingSet // if (sourceRootElement is Package) // { // rootPackage = sourceRootElement as Package; // //newMappingSet = new PackageMappingSet(sourceRootElement as Package); // } // else if (sourceRootElement is ElementWrapper) // { // rootPackage = sourceRootElement.owningPackage as Package; // //newMappingSet = new ElementMappingSet(sourceRootElement as ElementWrapper); // } // else // { // rootPackage = source.owningPackage as Package; // //newMappingSet = new PackageMappingSet((Package)source.owningPackage); // } // } // MappingLogic newMappingLogic = null; // //check if there is any mapping logic // if (! string.IsNullOrEmpty(mappingRecord.mappingLogic)) // { // if (settings.useInlineMappingLogic) // { // newMappingLogic = new MappingLogic(mappingRecord.mappingLogic); // } // else // { // //Check fo an existing mapping logic // newMappingLogic = getExistingMappingLogic(model, settings, mappingRecord.mappingLogic, rootPackage); // if (newMappingLogic == null) // { // var mappingElement = model.factory.createNewElement(rootPackage, "mapping logic " + i,settings.mappingLogicType) as ElementWrapper; // if (mappingElement != null) // { // //increase counter for new mapping element name // i++; // mappingElement.notes = mappingRecord.mappingLogic; // mappingElement.save(); // //create the mappingLogic // newMappingLogic = new MappingLogic(mappingElement); // } // else // { // //else we create an inline mapping logic anyway // newMappingLogic = new MappingLogic(mappingRecord.mappingLogic); // } // } // } // } // Mapping newMapping = null; // var sourceAssociationEnd = source as AssociationEnd; // var targetAssociationEnd = target as AssociationEnd; // //create the new mapping // //we can't create connector mappings for mappings to or from associations so we have to use tagged value mappings for those. // if (settings.useTaggedValues // || sourceAssociationEnd != null || targetAssociationEnd != null) // { // //if the source or target are associationEnds then we replace them by their association // if (sourceAssociationEnd != null) source = sourceAssociationEnd.association as Element; // if (targetAssociationEnd != null) target = targetAssociationEnd.association as Element; // //newMapping = new TaggedValueMapping(source,target,mappingRecord.sourcePath,mappingRecord.targetPath,settings); // } // else // { // //newMapping = new ConnectorMapping(source,target,mappingRecord.sourcePath,mappingRecord.targetPath,settings); // } // if (newMappingLogic != null) newMapping.mappingLogic = newMappingLogic; // newMapping.save(); // newMappingSet.addMapping(newMapping); // } //} }
private void log(string msg) { EAOutputLogger.log(this.model, this.settings.outputName, msg); }
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 or if settings if (subSetAssociation.ownedComments.Count == 0 || !subSetAssociation.ownedComments.Any(x => x.body.Length > 0) || this.owner.owner.settings.keepNotesInSync) { subSetAssociation.ownedComments = this.sourceAssociation.ownedComments; if (!this.owner.owner.settings.keepNotesInSync && 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; //derived subSetAssociation.isDerived = this.sourceAssociation.isDerived; //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); }
public override void correct() { //Log start EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting correct stereotypes and tagged values'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); // uniqueIdentifier -> uniqueID this.model.executeSQL(@"update t_objectproperties set [Property] = 'uniqueID' where [Property] = 'uniqueIdentifier'" ); this.model.executeSQL(@"update t_attributetag set [Property] = 'uniqueID' where [Property] = 'uniqueIdentifier'" ); this.model.executeSQL(@"update t_connectortag set [Property] = 'uniqueID' where [Property] = 'uniqueIdentifier'" ); // versionIdentifier -> versionID this.model.executeSQL(@"update t_objectproperties set [Property] = 'versionID' where [Property] = 'versionIdentifier'" ); this.model.executeSQL(@"update t_attributetag set [Property] = 'versionID' where [Property] = 'versionIdentifier'" ); this.model.executeSQL(@"update t_connectortag set [Property] = 'versionID' where [Property] = 'versionIdentifier'" ); // businessTerm -> businessTermName this.model.executeSQL(@"update t_objectproperties set [Property] = 'businessTermName' where [Property] = 'businessTerm'" ); this.model.executeSQL(@"update t_attributetag set [Property] = 'businessTermName' where [Property] = 'businessTerm'" ); this.model.executeSQL(@"update t_connectortag set [Property] = 'businessTermName' where [Property] = 'businessTerm'" ); // codeListAgencyIdentifier -> codeListAgencyID this.model.executeSQL(@"update t_objectproperties set [Property] = 'codeListAgencyID' where [Property] = 'codeListAgencyIdentifier'" ); this.model.executeSQL(@"update t_attributetag set [Property] = 'codeListAgencyID' where [Property] = 'codeListAgencyIdentifier'" ); this.model.executeSQL(@"update t_connectortag set [Property] = 'codeListAgencyID' where [Property] = 'codeListAgencyIdentifier'" ); // codeListIdentifier -> codeListID this.model.executeSQL(@"update t_objectproperties set [Property] = 'codeListID' where [Property] = 'codeListIdentifier'" ); this.model.executeSQL(@"update t_attributetag set [Property] = 'codeListID' where [Property] = 'codeListIdentifier'" ); this.model.executeSQL(@"update t_connectortag set [Property] = 'codeListID' where [Property] = 'codeListIdentifier'" ); // synchronize stereotypes synchronizeStereotypes(); EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished correct stereotypes and tagged values'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }
public override void correct() { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Starting add guard conditions'" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); //Add the guard conditions // PDATA2 For ControlFlow: Constraints/Guard property foreach (var mdGuardObject in magicDrawReader.allGuards) { var sourceObject = getElementByMDid(mdGuardObject.sourceMdGuid); var targetObject = getElementByMDid(mdGuardObject.targetMdGuid); if (sourceObject != null && targetObject != null) { EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Add guard '{1}' between'{2}' and '{3}' " , DateTime.Now.ToLongTimeString() , mdGuardObject.guardCondition , sourceObject.name , targetObject.name) , sourceObject.id , LogTypeEnum.log); int startObjectId = sourceObject.id; int endObjectId = targetObject.id; string guardCondition = mdGuardObject.guardCondition; guardCondition = guardCondition.Replace("[", string.Empty); guardCondition = guardCondition.Replace("]", string.Empty); guardCondition = guardCondition.Trim(); string sqlGetRelations = @"select con.[Connector_ID] from t_connector con where con.start_object_id = " + startObjectId + @" and con.end_object_id = " + endObjectId + @" and con.connector_type = 'ControlFlow'" ; var controlFlows = this.model.getRelationsByQuery(sqlGetRelations); var controlFlow = controlFlows.FirstOrDefault(x => string.IsNullOrEmpty(x.guardCondition)); if (controlFlow != null) { controlFlow.guardCondition = guardCondition; } } } //Log finished EAOutputLogger.log(this.model, this.outputName , string.Format("{0} Finished add guard conditions" , DateTime.Now.ToLongTimeString()) , 0 , LogTypeEnum.log); }