Пример #1
0
        /// <summary>
        /// Builds a tree of <seealso cref="BaseAssemblyNode" /> from join strategy information.
        /// </summary>
        /// <param name="rootStream">the root stream supplying the event to evaluate</param>
        /// <param name="streamsJoinedPerStream">a map in which the key is the stream number to supply an event,and the value is an array of streams to find events in for the given event
        /// </param>
        /// <param name="isRequiredPerStream">indicates which streams are required join streams versus optional streams</param>
        /// <returns>root assembly node</returns>
        public static BaseAssemblyNodeFactory Build(
            int rootStream,
            IDictionary<int, int[]> streamsJoinedPerStream,
            bool[] isRequiredPerStream)
        {
            if (streamsJoinedPerStream.Count < 3) {
                throw new ArgumentException("Not a 3-way join");
            }

            if ((rootStream < 0) || (rootStream >= streamsJoinedPerStream.Count)) {
                throw new ArgumentException("Invalid root stream");
            }

            if (isRequiredPerStream.Length != streamsJoinedPerStream.Count) {
                throw new ArgumentException("Arrays not matching up");
            }

            NStreamOuterQueryPlanBuilder.VerifyJoinedPerStream(rootStream, streamsJoinedPerStream);

            if (Log.IsDebugEnabled) {
                Log.Debug(
                    ".build Building node for root stream " +
                    rootStream +
                    " streamsJoinedPerStream=" +
                    NStreamOuterQueryPlanBuilder.Print(streamsJoinedPerStream) +
                    " isRequiredPerStream=" +
                    CompatExtensions.Render(isRequiredPerStream));
            }

            BaseAssemblyNodeFactory topNode = CreateNode(
                true,
                rootStream,
                streamsJoinedPerStream.Count,
                streamsJoinedPerStream.Get(rootStream),
                isRequiredPerStream);

            RecursiveBuild(rootStream, topNode, streamsJoinedPerStream, isRequiredPerStream);

            if (Log.IsDebugEnabled) {
                StringWriter buf = new StringWriter();
                IndentWriter indentWriter = new IndentWriter(buf, 0, 2);
                topNode.PrintDescendends(indentWriter);

                Log.Debug(".build Dumping root node for stream " + rootStream + ": \n" + buf.ToString());
            }

            return topNode;
        }
Пример #2
0
        private static void RecursiveBuild(
            int parentStreamNum,
            BaseAssemblyNodeFactory parentNode,
            IDictionary<int, int[]> streamsJoinedPerStream,
            bool[] isRequiredPerStream)
        {
            int numStreams = streamsJoinedPerStream.Count;

            for (int i = 0; i < streamsJoinedPerStream.Get(parentStreamNum).Length; i++) {
                int streamJoined = streamsJoinedPerStream.Get(parentStreamNum)[i];
                BaseAssemblyNodeFactory childNode = CreateNode(
                    false,
                    streamJoined,
                    numStreams,
                    streamsJoinedPerStream.Get(streamJoined),
                    isRequiredPerStream);
                parentNode.AddChild(childNode);

                if (streamsJoinedPerStream.Get(streamJoined).Length > 0) {
                    RecursiveBuild(streamJoined, childNode, streamsJoinedPerStream, isRequiredPerStream);
                }
            }
        }
 public override void AddChild(BaseAssemblyNodeFactory childNode)
 {
     childStreamIndex[childNode.StreamNum] = childNodes.Count;
     base.AddChild(childNode);
 }