/// <summary> /// Ensures that two Folder 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 ensureGuidFolder(Generated.Folder obj, Generated.Folder 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.allFolders() != null ) { if ( other.allFolders() != null ) { foreach ( Generated.Folder subElement in obj.allFolders() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Folder otherElement in other.allFolders() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidFolder ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Folder otherElement in other.allFolders() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidFolder ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidFolder ( subElement, null ); } } foreach ( Generated.Folder otherElement in other.allFolders() ) { bool found = false; foreach ( Generated.Folder subElement in obj.allFolders() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidFolder ( null, otherElement ); } } } else { foreach ( Generated.Folder subElement in obj.allFolders() ) { ensureGuidFolder ( subElement, null ); } } } else { if ( other.allFolders() != null ) { foreach ( Generated.Folder otherElement in other.allFolders() ) { ensureGuidFolder ( null, otherElement ); } } } if ( obj.allTranslations() != null ) { if ( other.allTranslations() != null ) { foreach ( Generated.Translation subElement in obj.allTranslations() ) { bool found = false; // Try first to assign Guid to elements which do not have a guid // This helps handling duplicated in lists foreach ( Generated.Translation otherElement in other.allTranslations() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) && otherElement.getGuid() == null ) { ensureGuidTranslation ( subElement, otherElement ); found = true; break; } } if ( !found ) { foreach ( Generated.Translation otherElement in other.allTranslations() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { ensureGuidTranslation ( subElement, otherElement ); found = true; break; } } } if ( !found ) { ensureGuidTranslation ( subElement, null ); } } foreach ( Generated.Translation otherElement in other.allTranslations() ) { bool found = false; foreach ( Generated.Translation subElement in obj.allTranslations() ) { if ( CompareUtil.canonicalStringEquality(subElement.Name, otherElement.Name) ) { found = true; break; } } if ( !found ) { ensureGuidTranslation ( null, otherElement ); } } } else { foreach ( Generated.Translation subElement in obj.allTranslations() ) { ensureGuidTranslation ( subElement, null ); } } } else { if ( other.allTranslations() != null ) { foreach ( Generated.Translation otherElement in other.allTranslations() ) { ensureGuidTranslation ( null, otherElement ); } } } }
/// <summary> /// Searches a specific string in TranslationDictionary 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 searchTranslationDictionary(Generated.TranslationDictionary obj, string searchString, List<ModelElement> occurences) { searchNamable (obj, searchString, occurences); if ( obj.allFolders() != null ) { foreach ( Generated.Folder subElement in obj.allFolders() ) { searchFolder ( subElement, searchString, occurences ); } } if ( obj.allTranslations() != null ) { foreach ( Generated.Translation subElement in obj.allTranslations() ) { searchTranslation ( subElement, searchString, occurences ); } } }
/// <summary> /// Compares two TranslationDictionary and annotates the differences on the first one /// </summary> /// <param name="obj"></param> /// <param name="other"></param> public static void compareTranslationDictionary(Generated.TranslationDictionary obj, Generated.TranslationDictionary other, VersionDiff diff) { if ( other == null ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "", "", obj.Name ) ); return; } compareNamable (obj, other, diff); if ( obj.allFolders() != null ) { if ( other.allFolders() != null ) { foreach ( Generated.Folder subElement in obj.allFolders() ) { bool compared = false; foreach ( Generated.Folder otherElement in other.allFolders() ) { if ( subElement.Guid == otherElement.Guid ) { compareFolder ( subElement, otherElement, diff ); compared = true; break; } } if ( !compared ) { diff.appendChanges ( new Diff(subElement, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Folders", "", subElement.Name ) ); } } foreach ( Generated.Folder otherElement in other.allFolders() ) { bool found = false; foreach ( Generated.Folder subElement in obj.allFolders() ) { if ( subElement.Guid == otherElement.Guid ) { found = true; break; } } if ( !found ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove , "Folders", otherElement.Name) ); } } } else { foreach ( Generated.Folder subElement in obj.allFolders() ) { diff.appendChanges ( new Diff(subElement, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Folders", "", subElement.Name ) ); } } } else { if ( other.allFolders() != null ) { foreach ( Generated.Folder otherElement in other.allFolders() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove , "Folders", otherElement.Name) ); } } } if ( obj.allTranslations() != null ) { if ( other.allTranslations() != null ) { foreach ( Generated.Translation subElement in obj.allTranslations() ) { bool compared = false; foreach ( Generated.Translation otherElement in other.allTranslations() ) { if ( subElement.Guid == otherElement.Guid ) { compareTranslation ( subElement, otherElement, diff ); compared = true; break; } } if ( !compared ) { diff.appendChanges ( new Diff(subElement, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Translations", "", subElement.Name ) ); } } foreach ( Generated.Translation otherElement in other.allTranslations() ) { bool found = false; foreach ( Generated.Translation subElement in obj.allTranslations() ) { if ( subElement.Guid == otherElement.Guid ) { found = true; break; } } if ( !found ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove , "Translations", otherElement.Name) ); } } } else { foreach ( Generated.Translation subElement in obj.allTranslations() ) { diff.appendChanges ( new Diff(subElement, HistoricalData.Generated.acceptor.ChangeOperationEnum.aAdd, "Translations", "", subElement.Name ) ); } } } else { if ( other.allTranslations() != null ) { foreach ( Generated.Translation otherElement in other.allTranslations() ) { diff.appendChanges ( new Diff(obj, HistoricalData.Generated.acceptor.ChangeOperationEnum.aRemove , "Translations", otherElement.Name) ); } } } }
/// <summary> /// Searches a specific string in ShortcutFolder 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 searchShortcutFolder(Generated.ShortcutFolder obj, string searchString, List<ModelElement> occurences) { searchNamable (obj, searchString, occurences); if ( obj.allFolders() != null ) { foreach ( Generated.ShortcutFolder subElement in obj.allFolders() ) { searchShortcutFolder ( subElement, searchString, occurences ); } } if ( obj.allShortcuts() != null ) { foreach ( Generated.Shortcut subElement in obj.allShortcuts() ) { searchShortcut ( subElement, searchString, occurences ); } } }