public override bool Equals(object obj) { Multiplicity other = obj as Multiplicity; if (other == null) { return(false); } return(this.EACardinality == other.EACardinality); }
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); }