Пример #1
0
        /// <summary>
        /// Finds or adds a conversation node for the specified resource.
        /// </summary>
        /// <param name="res">The resource to find the node for.</param>
        /// <returns>The conversation node instance.</returns>
        private ConversationNode GetConversationNode(IResource res)
        {
            lock ( _conversationNodeMap )
            {
                ConversationNode node = (ConversationNode)_conversationNodeMap [res.Id];
                if (node != null)
                {
                    return(node);
                }

                node = new ConversationNode(res);

                IResource parent = _threadingHandler.GetThreadParent(res);
                if (parent != null)
                {
                    ConversationNode parentNode = GetConversationNode(parent);
                    parentNode.AddChild(node);
                }
                else
                {
                    _conversationRoots.Add(node);
                }

                _conversationNodeMap [res.Id] = node;
                return(node);
            }
        }
Пример #2
0
        /// <summary>
        /// Return <c>true</c> if <c>head</c> of the conversation is reachable from the
        /// <c>intern</c> resource.
        /// </summary>
        public static bool AreLinked(IResource head, IResource intern)
        {
            IResourceThreadingHandler handler = Core.PluginLoader.GetResourceThreadingHandler(head.Type);

            if (handler == null)
            {
                return(false);
            }
            IResource rootRes = intern;

            while (true)
            {
                IResource parent = handler.GetThreadParent(rootRes);
                if (parent == null)
                {
                    break;
                }

                if (parent.Id == head.Id)
                {
                    return(true);
                }

                rootRes = parent;
            }
            return(false);
        }
Пример #3
0
        public IResource GetThreadParent(IResource res)
        {
            IResourceThreadingHandler handler = GetResourceThreadingHandler(res);

            if (handler != null)
            {
                return(handler.GetThreadParent(res));
            }
            return(null);
        }
Пример #4
0
        /// <summary>
        /// Checks the presence of the property upwards the thread parents.
        /// </summary>
        /// <param name="res">The resource in a conversation.</param>
        /// <param name="propId">Property to be checked.</param>
        /// <param name="propId">Resource which has such property, null if none of the parents has it.</param>
        /// <returns>true if any of the parent of the resource contains the specified property.</returns>
        public static bool CheckPropOnParents(IResource res, int propId, out IResource propRes)
        {
            bool result = res.HasProp(propId);

            IResourceThreadingHandler handler = Core.PluginLoader.GetResourceThreadingHandler(res.Type);

            if (handler != null)
            {
                while (!result && res != null)
                {
                    res = handler.GetThreadParent(res);
                    if (res != null)
                    {
                        result = res.HasProp(propId);
                    }
                }
            }
            propRes = result ? res : null;

            return(result);
        }
Пример #5
0
        /// <summary>
        /// Returns the root resource of the specified conversation.
        /// </summary>
        /// <param name="res">The resource in a conversation.</param>
        /// <returns>The root resource of the conversation, or <paramref name="res"/> if no
        /// threading handler has been registered for the resource type.</returns>
        public static IResource GetConversationRoot(IResource res)
        {
            IResourceThreadingHandler handler = Core.PluginLoader.GetResourceThreadingHandler(res.Type);

            if (handler == null)
            {
                return(res);
            }
            IResource rootRes = res;

            while (true)
            {
                IResource parent = handler.GetThreadParent(rootRes);
                if (parent == null)
                {
                    break;
                }

                rootRes = parent;
            }
            return(rootRes);
        }