/// <summary> /// Ensures that two Procedure have matching GUID, and recursively. /// obj is the leader for Guid. If other doesn't match obj guid, /// 1. other does not have a guid, in that case, other should have the same guid as obj /// 2. other already has a guid. In that case, there is a mismatch between objects, and the process stops here /// </summary> /// <param name="obj"></param> /// <param name="other"></param> public static void ensureGuidProcedure(Generated.Procedure obj, Generated.Procedure other) { if ( obj == null ) { if ( other != null ) { // Side effect, setup a GUID if needed for the other part (other) string guid = other.Guid; } return; } if ( other == null ) { if ( obj != null ) { // Side effect, setup a GUID if needed for the other part (obj) string guid = obj.Guid; } return; } if ( obj.Guid != other.getGuid() ) { if ( string.IsNullOrEmpty(other.getGuid()) || GuidByName && (obj.Name == other.Name) ) { // These are matching elements, copy the guid from obj other.setGuid ( obj.Guid ); } else { // Elements do not match. Stop the recursive process return; } } ensureGuidReqRelated (obj, other); ensureGuidStateMachine ( obj.getStateMachine(), other.getStateMachine() ); if ( obj.allRules() != null ) { if ( other.allRules() != null ) { foreach ( Generated.Rule subElement in obj.allRules() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Rule otherElement in other.allRules() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidRule ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Rule otherElement in other.allRules() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidRule ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidRule ( subElement, null ); } } foreach ( Generated.Rule otherElement in other.allRules() ) { bool found = false; foreach ( Generated.Rule subElement in obj.allRules() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidRule ( null, otherElement ); } } } else { foreach ( Generated.Rule subElement in obj.allRules() ) { ensureGuidRule ( subElement, null ); } } } else { if ( other.allRules() != null ) { foreach ( Generated.Rule otherElement in other.allRules() ) { ensureGuidRule ( null, otherElement ); } } } if ( obj.allParameters() != null ) { if ( other.allParameters() != null ) { foreach ( Generated.Parameter subElement in obj.allParameters() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Parameter otherElement in other.allParameters() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidParameter ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Parameter otherElement in other.allParameters() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidParameter ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidParameter ( subElement, null ); } } foreach ( Generated.Parameter otherElement in other.allParameters() ) { bool found = false; foreach ( Generated.Parameter subElement in obj.allParameters() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidParameter ( null, otherElement ); } } } else { foreach ( Generated.Parameter subElement in obj.allParameters() ) { ensureGuidParameter ( subElement, null ); } } } else { if ( other.allParameters() != null ) { foreach ( Generated.Parameter otherElement in other.allParameters() ) { ensureGuidParameter ( null, otherElement ); } } } }
/// <summary> /// Compares two Procedure and annotates the differences on the first one /// </summary> /// <param name="obj"></param> /// <param name="other"></param> public static void compareProcedure(Generated.Procedure obj, Generated.Procedure other, VersionDiff diff) { if ( other == null ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "", "", obj.Name ) ); return; } compareReqRelated (obj, other, diff); if ( obj.getStateMachine() == null ) { if ( other.getStateMachine() != null ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aChange, "StateMachine", "" ) ); } } else { compareStateMachine ( obj.getStateMachine(), other.getStateMachine(), diff ); } if ( obj.allRules() != null ) { if ( other.allRules() != null ) { foreach ( Generated.Rule subElement in obj.allRules() ) { bool compared = false; foreach ( Generated.Rule otherElement in other.allRules() ) { if ( subElement.Guid == otherElement.Guid ) { compareRule ( subElement, otherElement, diff ); compared = true; break; } } if ( !compared ) { diff.appendChanges ( new Diff(subElement, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Rules", "", subElement.Name ) ); } } foreach ( Generated.Rule otherElement in other.allRules() ) { bool found = false; foreach ( Generated.Rule subElement in obj.allRules() ) { if ( subElement.Guid == otherElement.Guid ) { found = true; break; } } if ( !found ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove , "Rules", otherElement.Name) ); } } } else { foreach ( Generated.Rule subElement in obj.allRules() ) { diff.appendChanges ( new Diff(subElement, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Rules", "", subElement.Name ) ); } } } else { if ( other.allRules() != null ) { foreach ( Generated.Rule otherElement in other.allRules() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove , "Rules", otherElement.Name) ); } } } if ( obj.allParameters() != null ) { if ( other.allParameters() != null ) { foreach ( Generated.Parameter subElement in obj.allParameters() ) { bool compared = false; foreach ( Generated.Parameter otherElement in other.allParameters() ) { if ( subElement.Guid == otherElement.Guid ) { compareParameter ( subElement, otherElement, diff ); compared = true; break; } } if ( !compared ) { diff.appendChanges ( new Diff(subElement, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Parameters", "", subElement.Name ) ); } } foreach ( Generated.Parameter otherElement in other.allParameters() ) { bool found = false; foreach ( Generated.Parameter subElement in obj.allParameters() ) { if ( subElement.Guid == otherElement.Guid ) { found = true; break; } } if ( !found ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove , "Parameters", otherElement.Name) ); } } } else { foreach ( Generated.Parameter subElement in obj.allParameters() ) { diff.appendChanges ( new Diff(subElement, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Parameters", "", subElement.Name ) ); } } } else { if ( other.allParameters() != null ) { foreach ( Generated.Parameter otherElement in other.allParameters() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove , "Parameters", otherElement.Name) ); } } } if ( obj.getWidth() != other.getWidth() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aChange, "Width", other.getWidth().ToString(), obj.getWidth().ToString()) ); } if ( obj.getHeight() != other.getHeight() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aChange, "Height", other.getHeight().ToString(), obj.getHeight().ToString()) ); } if ( obj.getX() != other.getX() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aChange, "X", other.getX().ToString(), obj.getX().ToString()) ); } if ( obj.getY() != other.getY() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aChange, "Y", other.getY().ToString(), obj.getY().ToString()) ); } if ( obj.getHidden() != other.getHidden() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aChange, "Hidden", other.getHidden().ToString(), obj.getHidden().ToString()) ); } if ( obj.getPinned() != other.getPinned() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aChange, "Pinned", other.getPinned().ToString(), obj.getPinned().ToString()) ); } }
/// <summary> /// Searches a specific string in Function and updates the list /// of model element with all the elements in which that string is found /// </summary> /// <param name="obj"></param> /// <param name="obj">The string to search for</param> /// <param name="occurences">The list of model elements which hold the searched string</param> public static void searchFunction(Generated.Function obj, string searchString, List<ModelElement> occurences) { searchType (obj, searchString, occurences); if ( obj.allParameters() != null ) { foreach ( Generated.Parameter subElement in obj.allParameters() ) { searchParameter ( subElement, searchString, occurences ); } } if ( obj.allCases() != null ) { foreach ( Generated.Case subElement in obj.allCases() ) { searchCase ( subElement, searchString, occurences ); } } if ( obj.getTypeName() != null && obj.getTypeName().Contains (searchString) ) { occurences.Add ( obj ); } }
/// <summary> /// Searches a specific string in Procedure and updates the list /// of model element with all the elements in which that string is found /// </summary> /// <param name="obj"></param> /// <param name="obj">The string to search for</param> /// <param name="occurences">The list of model elements which hold the searched string</param> public static void searchProcedure(Generated.Procedure obj, string searchString, List<ModelElement> occurences) { searchReqRelated (obj, searchString, occurences); if ( obj.getStateMachine() != null ) { searchStateMachine ( obj.getStateMachine(), searchString, occurences ); } if ( obj.allRules() != null ) { foreach ( Generated.Rule subElement in obj.allRules() ) { searchRule ( subElement, searchString, occurences ); } } if ( obj.allParameters() != null ) { foreach ( Generated.Parameter subElement in obj.allParameters() ) { searchParameter ( subElement, searchString, occurences ); } } }
/// <summary> /// Compares two Function and annotates the differences on the first one /// </summary> /// <param name="obj"></param> /// <param name="other"></param> public static void compareFunction(Generated.Function obj, Generated.Function other, VersionDiff diff) { if ( other == null ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "", "", obj.Name ) ); return; } compareType (obj, other, diff); if ( obj.allParameters() != null ) { if ( other.allParameters() != null ) { foreach ( Generated.Parameter subElement in obj.allParameters() ) { bool compared = false; foreach ( Generated.Parameter otherElement in other.allParameters() ) { if ( subElement.Guid == otherElement.Guid ) { compareParameter ( subElement, otherElement, diff ); compared = true; break; } } if ( !compared ) { diff.appendChanges ( new Diff(subElement, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Parameters", "", subElement.Name ) ); } } foreach ( Generated.Parameter otherElement in other.allParameters() ) { bool found = false; foreach ( Generated.Parameter subElement in obj.allParameters() ) { if ( subElement.Guid == otherElement.Guid ) { found = true; break; } } if ( !found ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove , "Parameters", otherElement.Name) ); } } } else { foreach ( Generated.Parameter subElement in obj.allParameters() ) { diff.appendChanges ( new Diff(subElement, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Parameters", "", subElement.Name ) ); } } } else { if ( other.allParameters() != null ) { foreach ( Generated.Parameter otherElement in other.allParameters() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove , "Parameters", otherElement.Name) ); } } } if ( obj.allCases() != null ) { if ( other.allCases() != null ) { int i = 0; while ( i < obj.countCases() && i < other.countCases() ) { Generated.Case element = obj.getCases( i ); Generated.Case otherElement = other.getCases( i ); compareCase ( element, otherElement, diff ); i += 1; } while ( i < obj.countCases() ) { diff.appendChanges ( new Diff(obj.getCases(i), HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Cases", "", obj.getCases( i ).Name ) ); i += 1; } while ( i < other.countCases() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove, "Cases", other.getCases( i ).Name) ); i += 1; } } else { foreach ( Generated.Case subElement in obj.allCases() ) { diff.appendChanges ( new Diff(subElement, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Cases", "", subElement.Name ) ); } } } else { if ( other.allCases() != null ) { foreach ( Generated.Case otherElement in other.allCases() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove , "Cases", otherElement.Name) ); } } } if ( !CompareUtil.canonicalStringEquality(obj.getTypeName(), other.getTypeName()) ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aChange, "TypeName", other.getTypeName(), obj.getTypeName()) ); } if ( obj.getCacheable() != other.getCacheable() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aChange, "Cacheable", other.getCacheable().ToString(), obj.getCacheable().ToString()) ); } }