public virtual IThing DescribedThing(IThing item) { IThing result = item; if (item == null) { return(null); } ILink linkResult = null; ICollection <IThing> itemDone = new Set <IThing>(); var stack = new Stack <IThing>(); stack.Push(item); while (stack.Count > 0) { result = stack.Pop(); if (itemDone.Contains(result)) { break; } itemDone.Add(result); foreach (var link in Source.Edges(result)) { var resultId = result.Id; var idLink = (ILink <Id>)link; if (idLink.Marker == 0) { continue; } if (idLink.Leaf == resultId) { if (descriptions.Contains(idLink.Marker) && SchemaFacade.DescriptionableThing(link.Root)) { result = link.Root; stack.Clear(); break; } } else if (idLink.Root == resultId) { if (describedMarkers.ContainsKey(idLink.Marker) && SchemaFacade.DescriptionableThing(link.Root)) { stack.Push(link); linkResult = link; } } } } while (result is ILink) { result = ((ILink)result).Leaf; } if (result == linkResult) { return(item); } return(result); }
public virtual bool SchemaItemFilter(IThing thing) { if (thing == null) { return(false); } bool result = true; foreach (ILink link in Source.Edges(thing)) { var idLink = (ILink <Id>)link; if (idLink.Marker != 0) { if (idLink.Leaf == thing.Id && descriptions.Contains(idLink.Marker)) { return(!SchemaFacade.DescriptionableThing(link.Root)); } } } return(result); }
public virtual IEnumerable <ILink> ThingToDisplayPath(IThing item) { // REMARK: this is duplicate code with ThingToDisplay!! var path = new Stack <ILink> (); IThing result = item; if (item == null) { return(null); } ILink linkResult = null; ICollection <IThing> itemDone = new Set <IThing>(); var stack = new Stack <IThing>(); if (SchemaFacade.DescriptionableThing(item)) { stack.Push(item); } while (stack.Count > 0) { result = stack.Pop(); if (itemDone.Contains(result)) { continue; } itemDone.Add(result); foreach (ILink link in Source.Edges(result)) { var resultId = result.Id; var idLink = (ILink <Id>)link; if (idLink.Marker == 0) { continue; } if (idLink.Root == resultId) { if (descriptions.Contains(idLink.Marker)) { result = link.Leaf; path.Push(link); stack.Clear(); break; } } else if (idLink.Leaf == resultId) { if (describedMarkers.ContainsKey(idLink.Marker)) { path.Push(link); stack.Push(link); linkResult = link; } } } if (SchemaFacade.DescriptionableThing(result)) { stack.Push(result); } } if (result == linkResult) { return(new EmptyCollection <ILink>()); } return(path); }