void BuildPathMap(Locatable locatable) { foreach (object value in locatable.GetAllAttributeValues()) { ILocatableList locatableList = value as ILocatableList; if (locatableList != null) { foreach (Locatable locatableValue in locatableList) { if (locatableValue.IsArchetypeRoot) { string archetypedPath = rootLocatable.PathOfItem(locatableValue); // %HYYKA% // CM: 16/04/09 in normal case, pathMap should not contain duplicated keys. // otherwise, the data instance is invalid. Since this is not for validation purpose, // when there are duplicated path in pathMap, not throw exception. //pathMap.Add(archetypedPath, locatableValue); if (!pathMap.ContainsKey(archetypedPath)) { pathMap.Add(archetypedPath, locatableValue); } } BuildPathMap(locatableValue); } } else { Locatable locatableValue = value as Locatable; if (locatableValue != null) { if (locatableValue.IsArchetypeRoot) { string archetypedPath = rootLocatable.PathOfItem(locatableValue); pathMap.Add(archetypedPath, locatableValue); } BuildPathMap(locatableValue); } } } }
/// <summary> /// In this method, it is assumed that the locatable must be the child of this class. /// </summary> /// <param name="locatable"></param> /// <returns></returns> private string PathOfItemSimple(Pathable item) { Check.Require(item != null); string path = null; string pathSeperator = "/"; System.Collections.Generic.ICollection <System.Collections.Generic.KeyValuePair <string, object> > keyValueList = this.attributesDictionary as System.Collections.Generic.ICollection <System.Collections.Generic.KeyValuePair <string, object> >; foreach (System.Collections.Generic.KeyValuePair <string, object> listItem in keyValueList) { ILocatableList locatableList = listItem.Value as ILocatableList; Pathable locatableItem = listItem.Value as Pathable; if (locatableList != null) { Locatable itemLocatable = item as Locatable; if (locatableList.Contains(itemLocatable)) { DesignByContract.Check.Assert(itemLocatable.Name != null); return(path = pathSeperator + listItem.Key + "[" + itemLocatable.ArchetypeNodeId + " and name/value='" + itemLocatable.Name.Value + "']"); } } else if (listItem.Value == item) { // must be locatable if (item is Locatable) { return(path = pathSeperator + listItem.Key + "[" + ((Locatable)item).ArchetypeNodeId + "]"); } else { return(path = pathSeperator + listItem.Key); } } } // raise exception? throw new InvalidOperationException("item not found in parent's items"); }