/// <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> /// Ensures that two NameSpace 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 ensureGuidNameSpace(Generated.NameSpace obj, Generated.NameSpace 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; } } ensureGuidNamable (obj, other); if ( obj.allNameSpaces() != null ) { if ( other.allNameSpaces() != null ) { foreach ( Generated.NameSpace subElement in obj.allNameSpaces() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.NameSpace otherElement in other.allNameSpaces() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidNameSpace ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.NameSpace otherElement in other.allNameSpaces() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidNameSpace ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidNameSpace ( subElement, null ); } } foreach ( Generated.NameSpace otherElement in other.allNameSpaces() ) { bool found = false; foreach ( Generated.NameSpace subElement in obj.allNameSpaces() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidNameSpace ( null, otherElement ); } } } else { foreach ( Generated.NameSpace subElement in obj.allNameSpaces() ) { ensureGuidNameSpace ( subElement, null ); } } } else { if ( other.allNameSpaces() != null ) { foreach ( Generated.NameSpace otherElement in other.allNameSpaces() ) { ensureGuidNameSpace ( null, otherElement ); } } } if ( obj.allNameSpaceRefs() != null ) { if ( other.allNameSpaceRefs() != null ) { foreach ( Generated.NameSpaceRef subElement in obj.allNameSpaceRefs() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.NameSpaceRef otherElement in other.allNameSpaceRefs() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidNameSpaceRef ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.NameSpaceRef otherElement in other.allNameSpaceRefs() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidNameSpaceRef ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidNameSpaceRef ( subElement, null ); } } foreach ( Generated.NameSpaceRef otherElement in other.allNameSpaceRefs() ) { bool found = false; foreach ( Generated.NameSpaceRef subElement in obj.allNameSpaceRefs() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidNameSpaceRef ( null, otherElement ); } } } else { foreach ( Generated.NameSpaceRef subElement in obj.allNameSpaceRefs() ) { ensureGuidNameSpaceRef ( subElement, null ); } } } else { if ( other.allNameSpaceRefs() != null ) { foreach ( Generated.NameSpaceRef otherElement in other.allNameSpaceRefs() ) { ensureGuidNameSpaceRef ( null, otherElement ); } } } if ( obj.allRanges() != null ) { if ( other.allRanges() != null ) { foreach ( Generated.Range subElement in obj.allRanges() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Range otherElement in other.allRanges() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidRange ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Range otherElement in other.allRanges() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidRange ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidRange ( subElement, null ); } } foreach ( Generated.Range otherElement in other.allRanges() ) { bool found = false; foreach ( Generated.Range subElement in obj.allRanges() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidRange ( null, otherElement ); } } } else { foreach ( Generated.Range subElement in obj.allRanges() ) { ensureGuidRange ( subElement, null ); } } } else { if ( other.allRanges() != null ) { foreach ( Generated.Range otherElement in other.allRanges() ) { ensureGuidRange ( null, otherElement ); } } } if ( obj.allEnumerations() != null ) { if ( other.allEnumerations() != null ) { foreach ( Generated.Enum subElement in obj.allEnumerations() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Enum otherElement in other.allEnumerations() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidEnum ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Enum otherElement in other.allEnumerations() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidEnum ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidEnum ( subElement, null ); } } foreach ( Generated.Enum otherElement in other.allEnumerations() ) { bool found = false; foreach ( Generated.Enum subElement in obj.allEnumerations() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidEnum ( null, otherElement ); } } } else { foreach ( Generated.Enum subElement in obj.allEnumerations() ) { ensureGuidEnum ( subElement, null ); } } } else { if ( other.allEnumerations() != null ) { foreach ( Generated.Enum otherElement in other.allEnumerations() ) { ensureGuidEnum ( null, otherElement ); } } } if ( obj.allStructures() != null ) { if ( other.allStructures() != null ) { foreach ( Generated.Structure subElement in obj.allStructures() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Structure otherElement in other.allStructures() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidStructure ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Structure otherElement in other.allStructures() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidStructure ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidStructure ( subElement, null ); } } foreach ( Generated.Structure otherElement in other.allStructures() ) { bool found = false; foreach ( Generated.Structure subElement in obj.allStructures() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidStructure ( null, otherElement ); } } } else { foreach ( Generated.Structure subElement in obj.allStructures() ) { ensureGuidStructure ( subElement, null ); } } } else { if ( other.allStructures() != null ) { foreach ( Generated.Structure otherElement in other.allStructures() ) { ensureGuidStructure ( null, otherElement ); } } } if ( obj.allCollections() != null ) { if ( other.allCollections() != null ) { foreach ( Generated.Collection subElement in obj.allCollections() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Collection otherElement in other.allCollections() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidCollection ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Collection otherElement in other.allCollections() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidCollection ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidCollection ( subElement, null ); } } foreach ( Generated.Collection otherElement in other.allCollections() ) { bool found = false; foreach ( Generated.Collection subElement in obj.allCollections() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidCollection ( null, otherElement ); } } } else { foreach ( Generated.Collection subElement in obj.allCollections() ) { ensureGuidCollection ( subElement, null ); } } } else { if ( other.allCollections() != null ) { foreach ( Generated.Collection otherElement in other.allCollections() ) { ensureGuidCollection ( null, otherElement ); } } } if ( obj.allStateMachines() != null ) { if ( other.allStateMachines() != null ) { foreach ( Generated.StateMachine subElement in obj.allStateMachines() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.StateMachine otherElement in other.allStateMachines() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidStateMachine ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.StateMachine otherElement in other.allStateMachines() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidStateMachine ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidStateMachine ( subElement, null ); } } foreach ( Generated.StateMachine otherElement in other.allStateMachines() ) { bool found = false; foreach ( Generated.StateMachine subElement in obj.allStateMachines() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidStateMachine ( null, otherElement ); } } } else { foreach ( Generated.StateMachine subElement in obj.allStateMachines() ) { ensureGuidStateMachine ( subElement, null ); } } } else { if ( other.allStateMachines() != null ) { foreach ( Generated.StateMachine otherElement in other.allStateMachines() ) { ensureGuidStateMachine ( null, otherElement ); } } } if ( obj.allFunctions() != null ) { if ( other.allFunctions() != null ) { foreach ( Generated.Function subElement in obj.allFunctions() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Function otherElement in other.allFunctions() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidFunction ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Function otherElement in other.allFunctions() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidFunction ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidFunction ( subElement, null ); } } foreach ( Generated.Function otherElement in other.allFunctions() ) { bool found = false; foreach ( Generated.Function subElement in obj.allFunctions() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidFunction ( null, otherElement ); } } } else { foreach ( Generated.Function subElement in obj.allFunctions() ) { ensureGuidFunction ( subElement, null ); } } } else { if ( other.allFunctions() != null ) { foreach ( Generated.Function otherElement in other.allFunctions() ) { ensureGuidFunction ( null, otherElement ); } } } if ( obj.allProcedures() != null ) { if ( other.allProcedures() != null ) { foreach ( Generated.Procedure subElement in obj.allProcedures() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Procedure otherElement in other.allProcedures() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidProcedure ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Procedure otherElement in other.allProcedures() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidProcedure ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidProcedure ( subElement, null ); } } foreach ( Generated.Procedure otherElement in other.allProcedures() ) { bool found = false; foreach ( Generated.Procedure subElement in obj.allProcedures() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidProcedure ( null, otherElement ); } } } else { foreach ( Generated.Procedure subElement in obj.allProcedures() ) { ensureGuidProcedure ( subElement, null ); } } } else { if ( other.allProcedures() != null ) { foreach ( Generated.Procedure otherElement in other.allProcedures() ) { ensureGuidProcedure ( null, otherElement ); } } } if ( obj.allVariables() != null ) { if ( other.allVariables() != null ) { foreach ( Generated.Variable subElement in obj.allVariables() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Variable otherElement in other.allVariables() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidVariable ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Variable otherElement in other.allVariables() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidVariable ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidVariable ( subElement, null ); } } foreach ( Generated.Variable otherElement in other.allVariables() ) { bool found = false; foreach ( Generated.Variable subElement in obj.allVariables() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidVariable ( null, otherElement ); } } } else { foreach ( Generated.Variable subElement in obj.allVariables() ) { ensureGuidVariable ( subElement, null ); } } } else { if ( other.allVariables() != null ) { foreach ( Generated.Variable otherElement in other.allVariables() ) { ensureGuidVariable ( null, otherElement ); } } } 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 ); } } } }
/// <summary> /// Ensures that two PreCondition 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 ensureGuidPreCondition(Generated.PreCondition obj, Generated.PreCondition 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; } } }
/// <summary> /// Ensures that two Enum 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 ensureGuidEnum(Generated.Enum obj, Generated.Enum 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; } } ensureGuidType (obj, other); if ( obj.allValues() != null ) { if ( other.allValues() != null ) { int i = 0; while ( i < obj.countValues() && i < other.countValues() ) { Generated.EnumValue element = obj.getValues( i ); Generated.EnumValue otherElement = other.getValues( i ); ensureGuidEnumValue ( element, otherElement ); i += 1; } while ( i < obj.countValues() ) { Generated.EnumValue element = obj.getValues( i ); ensureGuidEnumValue ( element, null ); i += 1; } while ( i < other.countValues() ) { Generated.EnumValue otherElement = other.getValues( i ); ensureGuidEnumValue ( null, otherElement ); i += 1; } } else { foreach ( Generated.EnumValue subElement in obj.allValues() ) { ensureGuidEnumValue ( subElement, null ); } } } else { if ( other.allValues() != null ) { foreach ( Generated.EnumValue otherElement in other.allValues() ) { ensureGuidEnumValue ( null, otherElement ); } } } if ( obj.allSubEnums() != null ) { if ( other.allSubEnums() != null ) { foreach ( Generated.Enum subElement in obj.allSubEnums() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Enum otherElement in other.allSubEnums() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidEnum ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Enum otherElement in other.allSubEnums() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidEnum ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidEnum ( subElement, null ); } } foreach ( Generated.Enum otherElement in other.allSubEnums() ) { bool found = false; foreach ( Generated.Enum subElement in obj.allSubEnums() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidEnum ( null, otherElement ); } } } else { foreach ( Generated.Enum subElement in obj.allSubEnums() ) { ensureGuidEnum ( subElement, null ); } } } else { if ( other.allSubEnums() != null ) { foreach ( Generated.Enum otherElement in other.allSubEnums() ) { ensureGuidEnum ( null, otherElement ); } } } }
/// <summary> /// Ensures that two Dictionary 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 ensureGuidDictionary(Generated.Dictionary obj, Generated.Dictionary 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; } } if ( obj.allSpecifications() != null ) { if ( other.allSpecifications() != null ) { foreach ( Generated.Specification subElement in obj.allSpecifications() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Specification otherElement in other.allSpecifications() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidSpecification ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Specification otherElement in other.allSpecifications() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidSpecification ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidSpecification ( subElement, null ); } } foreach ( Generated.Specification otherElement in other.allSpecifications() ) { bool found = false; foreach ( Generated.Specification subElement in obj.allSpecifications() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidSpecification ( null, otherElement ); } } } else { foreach ( Generated.Specification subElement in obj.allSpecifications() ) { ensureGuidSpecification ( subElement, null ); } } } else { if ( other.allSpecifications() != null ) { foreach ( Generated.Specification otherElement in other.allSpecifications() ) { ensureGuidSpecification ( null, otherElement ); } } } if ( obj.allRequirementSets() != null ) { if ( other.allRequirementSets() != null ) { foreach ( Generated.RequirementSet subElement in obj.allRequirementSets() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.RequirementSet otherElement in other.allRequirementSets() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidRequirementSet ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.RequirementSet otherElement in other.allRequirementSets() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidRequirementSet ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidRequirementSet ( subElement, null ); } } foreach ( Generated.RequirementSet otherElement in other.allRequirementSets() ) { bool found = false; foreach ( Generated.RequirementSet subElement in obj.allRequirementSets() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidRequirementSet ( null, otherElement ); } } } else { foreach ( Generated.RequirementSet subElement in obj.allRequirementSets() ) { ensureGuidRequirementSet ( subElement, null ); } } } else { if ( other.allRequirementSets() != null ) { foreach ( Generated.RequirementSet otherElement in other.allRequirementSets() ) { ensureGuidRequirementSet ( null, otherElement ); } } } if ( obj.allRuleDisablings() != null ) { if ( other.allRuleDisablings() != null ) { foreach ( Generated.RuleDisabling subElement in obj.allRuleDisablings() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.RuleDisabling otherElement in other.allRuleDisablings() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidRuleDisabling ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.RuleDisabling otherElement in other.allRuleDisablings() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidRuleDisabling ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidRuleDisabling ( subElement, null ); } } foreach ( Generated.RuleDisabling otherElement in other.allRuleDisablings() ) { bool found = false; foreach ( Generated.RuleDisabling subElement in obj.allRuleDisablings() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidRuleDisabling ( null, otherElement ); } } } else { foreach ( Generated.RuleDisabling subElement in obj.allRuleDisablings() ) { ensureGuidRuleDisabling ( subElement, null ); } } } else { if ( other.allRuleDisablings() != null ) { foreach ( Generated.RuleDisabling otherElement in other.allRuleDisablings() ) { ensureGuidRuleDisabling ( null, otherElement ); } } } if ( obj.allNameSpaces() != null ) { if ( other.allNameSpaces() != null ) { foreach ( Generated.NameSpace subElement in obj.allNameSpaces() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.NameSpace otherElement in other.allNameSpaces() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidNameSpace ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.NameSpace otherElement in other.allNameSpaces() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidNameSpace ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidNameSpace ( subElement, null ); } } foreach ( Generated.NameSpace otherElement in other.allNameSpaces() ) { bool found = false; foreach ( Generated.NameSpace subElement in obj.allNameSpaces() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidNameSpace ( null, otherElement ); } } } else { foreach ( Generated.NameSpace subElement in obj.allNameSpaces() ) { ensureGuidNameSpace ( subElement, null ); } } } else { if ( other.allNameSpaces() != null ) { foreach ( Generated.NameSpace otherElement in other.allNameSpaces() ) { ensureGuidNameSpace ( null, otherElement ); } } } if ( obj.allNameSpaceRefs() != null ) { if ( other.allNameSpaceRefs() != null ) { foreach ( Generated.NameSpaceRef subElement in obj.allNameSpaceRefs() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.NameSpaceRef otherElement in other.allNameSpaceRefs() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidNameSpaceRef ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.NameSpaceRef otherElement in other.allNameSpaceRefs() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidNameSpaceRef ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidNameSpaceRef ( subElement, null ); } } foreach ( Generated.NameSpaceRef otherElement in other.allNameSpaceRefs() ) { bool found = false; foreach ( Generated.NameSpaceRef subElement in obj.allNameSpaceRefs() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidNameSpaceRef ( null, otherElement ); } } } else { foreach ( Generated.NameSpaceRef subElement in obj.allNameSpaceRefs() ) { ensureGuidNameSpaceRef ( subElement, null ); } } } else { if ( other.allNameSpaceRefs() != null ) { foreach ( Generated.NameSpaceRef otherElement in other.allNameSpaceRefs() ) { ensureGuidNameSpaceRef ( null, otherElement ); } } } if ( obj.allTests() != null ) { if ( other.allTests() != null ) { foreach ( Generated.Frame subElement in obj.allTests() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Frame otherElement in other.allTests() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidFrame ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Frame otherElement in other.allTests() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidFrame ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidFrame ( subElement, null ); } } foreach ( Generated.Frame otherElement in other.allTests() ) { bool found = false; foreach ( Generated.Frame subElement in obj.allTests() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidFrame ( null, otherElement ); } } } else { foreach ( Generated.Frame subElement in obj.allTests() ) { ensureGuidFrame ( subElement, null ); } } } else { if ( other.allTests() != null ) { foreach ( Generated.Frame otherElement in other.allTests() ) { ensureGuidFrame ( null, otherElement ); } } } if ( obj.allTestRefs() != null ) { if ( other.allTestRefs() != null ) { foreach ( Generated.FrameRef subElement in obj.allTestRefs() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.FrameRef otherElement in other.allTestRefs() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidFrameRef ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.FrameRef otherElement in other.allTestRefs() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidFrameRef ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidFrameRef ( subElement, null ); } } foreach ( Generated.FrameRef otherElement in other.allTestRefs() ) { bool found = false; foreach ( Generated.FrameRef subElement in obj.allTestRefs() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidFrameRef ( null, otherElement ); } } } else { foreach ( Generated.FrameRef subElement in obj.allTestRefs() ) { ensureGuidFrameRef ( subElement, null ); } } } else { if ( other.allTestRefs() != null ) { foreach ( Generated.FrameRef otherElement in other.allTestRefs() ) { ensureGuidFrameRef ( null, otherElement ); } } } ensureGuidTranslationDictionary ( obj.getTranslationDictionary(), other.getTranslationDictionary() ); ensureGuidShortcutDictionary ( obj.getShortcutDictionary(), other.getShortcutDictionary() ); }
/// <summary> /// Ensures that two Case 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 ensureGuidCase(Generated.Case obj, Generated.Case 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; } } ensureGuidNamable (obj, other); if ( obj.allPreConditions() != null ) { if ( other.allPreConditions() != null ) { int i = 0; while ( i < obj.countPreConditions() && i < other.countPreConditions() ) { Generated.PreCondition element = obj.getPreConditions( i ); Generated.PreCondition otherElement = other.getPreConditions( i ); ensureGuidPreCondition ( element, otherElement ); i += 1; } while ( i < obj.countPreConditions() ) { Generated.PreCondition element = obj.getPreConditions( i ); ensureGuidPreCondition ( element, null ); i += 1; } while ( i < other.countPreConditions() ) { Generated.PreCondition otherElement = other.getPreConditions( i ); ensureGuidPreCondition ( null, otherElement ); i += 1; } } else { foreach ( Generated.PreCondition subElement in obj.allPreConditions() ) { ensureGuidPreCondition ( subElement, null ); } } } else { if ( other.allPreConditions() != null ) { foreach ( Generated.PreCondition otherElement in other.allPreConditions() ) { ensureGuidPreCondition ( null, otherElement ); } } } }
/// <summary> /// Ensures that two Translation 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 ensureGuidTranslation(Generated.Translation obj, Generated.Translation 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; } } ensureGuidReferencesParagraph (obj, other); if ( obj.allSourceTexts() != null ) { if ( other.allSourceTexts() != null ) { foreach ( Generated.SourceText subElement in obj.allSourceTexts() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.SourceText otherElement in other.allSourceTexts() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidSourceText ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.SourceText otherElement in other.allSourceTexts() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidSourceText ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidSourceText ( subElement, null ); } } foreach ( Generated.SourceText otherElement in other.allSourceTexts() ) { bool found = false; foreach ( Generated.SourceText subElement in obj.allSourceTexts() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidSourceText ( null, otherElement ); } } } else { foreach ( Generated.SourceText subElement in obj.allSourceTexts() ) { ensureGuidSourceText ( subElement, null ); } } } else { if ( other.allSourceTexts() != null ) { foreach ( Generated.SourceText otherElement in other.allSourceTexts() ) { ensureGuidSourceText ( null, otherElement ); } } } if ( obj.allSubSteps() != null ) { if ( other.allSubSteps() != null ) { foreach ( Generated.SubStep subElement in obj.allSubSteps() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.SubStep otherElement in other.allSubSteps() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidSubStep ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.SubStep otherElement in other.allSubSteps() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidSubStep ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidSubStep ( subElement, null ); } } foreach ( Generated.SubStep otherElement in other.allSubSteps() ) { bool found = false; foreach ( Generated.SubStep subElement in obj.allSubSteps() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidSubStep ( null, otherElement ); } } } else { foreach ( Generated.SubStep subElement in obj.allSubSteps() ) { ensureGuidSubStep ( subElement, null ); } } } else { if ( other.allSubSteps() != null ) { foreach ( Generated.SubStep otherElement in other.allSubSteps() ) { ensureGuidSubStep ( null, otherElement ); } } } }
/// <summary> /// Ensures that two State 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 ensureGuidState(Generated.State obj, Generated.State 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() ); ensureGuidRule ( obj.getEnterAction(), other.getEnterAction() ); ensureGuidRule ( obj.getLeaveAction(), other.getLeaveAction() ); }