Пример #1
0
        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);
        }
Пример #2
0
        public void Initialize()
        {
            SchemaFacade.InitSchemata();
            descriptions.Clear();
            hiddens.Clear();
            describedMarkers.Clear();

            descriptions.Add(CommonSchema.DescriptionMarker.Id);
            hiddens.Add(CommonSchema.DescriptionMarker.Id);

            IThingGraph markerGraph = new ThingGraph();
            var         markers     = Markers();

            GraphExtensions.MergeInto(Schema.IdentityGraph, markerGraph);
            ThingGraph.DeepCopy(markers, markerGraph);
            markerGraph.DeepCopy(markers, ThingGraph);

            foreach (var marker in markerGraph)
            {
                var markerId = marker.Id;
                foreach (var link in markerGraph.Edges(marker))
                {
                    if (link.Marker == null)
                    {
                        continue;
                    }

                    var idLink = (ILink <Id>)link;

                    if (ViewMetaSchemaHideEnabled &&
                        idLink.Marker == ViewMetaSchema.Hide.Id &&
                        idLink.Leaf == markerId)
                    {
                        hiddens.Add(markerId);
                    }

                    if (idLink.Marker == MetaSchema.DescriptionMarker.Id)
                    {
                        if (idLink.Leaf == markerId)
                        {
                            hiddens.Add(markerId);
                            descriptions.Add(markerId);
                        }
                        else
                        {
                            describedMarkers[markerId] = idLink.Leaf;
                        }
                    }
                }
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }