Ejemplo n.º 1
0
        /// <summary>
        /// Add merge views for any views in the chain requiring a merge (group view).
        /// Appends to the list of view specifications passed in one ore more
        /// new view specifications that represent merge views.
        /// Merge views have the same parameter list as the (group) view they merge data for.
        /// </summary>
        /// <param name="specifications">is a list of view definitions defining the chain of views.</param>
        /// <exception cref="ViewProcessingException">indicating that the view chain configuration is invalid</exception>
        internal static void AddMergeViews(IList <ViewSpec> specifications)
        {
            if (Log.IsDebugEnabled)
            {
                Log.Debug(".addMergeViews Incoming specifications=" + specifications.Render());
            }

            // A grouping view requires a merge view and cannot be last since it would not group sub-views
            if (specifications.Count > 0)
            {
                var lastView = specifications[specifications.Count - 1];
                var viewEnum = ViewEnumExtensions.ForName(lastView.ObjectNamespace, lastView.ObjectName);
                if ((viewEnum != null) && (viewEnum.Value.GetMergeView() != null))
                {
                    throw new ViewProcessingException(
                              "Invalid use of the '" +
                              lastView.ObjectName +
                              "' view, the view requires one or more child views to group, or consider using the group-by clause");
                }
            }

            var mergeViewSpecs = new LinkedList <ViewSpec>();

            foreach (var spec in specifications)
            {
                var viewEnum = ViewEnumExtensions.ForName(spec.ObjectNamespace, spec.ObjectName);
                if (viewEnum == null)
                {
                    continue;
                }

                var mergeView = viewEnum.Value.GetMergeView();
                if (mergeView == null)
                {
                    continue;
                }

                // The merge view gets the same parameters as the view that requires the merge
                var mergeViewSpec = new ViewSpec(
                    mergeView.Value.GetNamespace(), mergeView.Value.GetName(),
                    spec.ObjectParameters);

                // The merge views are added to the beginning of the list.
                // This enables group views to stagger ie. Marketdata.Group("symbol").Group("feed").xxx.Merge(...).Merge(...)
                mergeViewSpecs.AddFirst(mergeViewSpec);
            }

            specifications.AddAll(mergeViewSpecs);

            if (Log.IsDebugEnabled)
            {
                Log.Debug(".addMergeViews Outgoing specifications=" + specifications.Render());
            }
        }
Ejemplo n.º 2
0
        public void TestForName()
        {
            ViewEnum?enumValue = ViewEnumExtensions.ForName(
                ViewEnum.CORRELATION.GetNamespace(),
                ViewEnum.CORRELATION.GetName());

            Assert.AreEqual(enumValue, ViewEnum.CORRELATION);

            enumValue = ViewEnumExtensions.ForName(ViewEnum.CORRELATION.GetNamespace(), "dummy");
            Assert.IsNull(enumValue);

            enumValue = ViewEnumExtensions.ForName("dummy", ViewEnum.CORRELATION.GetName());
            Assert.IsNull(enumValue);
        }