private int GetHvoCommonAncestor(int hvoBeforeListChange, int prevListItemsClass, int newListItemsClass)
{
XmlNode prevClassNode = GetTreeNode(prevListItemsClass);
XmlNode newClassNode = GetTreeNode(newListItemsClass);
int hvoCommonAncestor = 0;
// NOTE: the class of hvoBeforeListChange could be different then prevListItemsClass, if the item is a ghost (owner).
int classOfHvoBeforeListChange = Cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(hvoBeforeListChange).ClassID;
// so go up the parent of the previous one until it's an ancestor of the newClass.
XmlNode ancestorOfPrev = prevClassNode.ParentNode;
while (ancestorOfPrev != null)
{
if (newClassNode.SelectSingleNode("ancestor::" + ancestorOfPrev.Name) != null)
{
XmlNode commonAncestor = ancestorOfPrev;
var classCommonAncestor = Cache.MetaDataCacheAccessor.GetClassId(commonAncestor.Name);
if (DomainObjectServices.IsSameOrSubclassOf(Cache.DomainDataByFlid.MetaDataCache, classOfHvoBeforeListChange, classCommonAncestor))
hvoCommonAncestor = hvoBeforeListChange;
else
{
var obj = Cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(hvoBeforeListChange);
hvoCommonAncestor = obj.OwnerOfClass(classCommonAncestor).Hvo;
}
break;
}
ancestorOfPrev = ancestorOfPrev.ParentNode;
}
return hvoCommonAncestor;
}
}