Example #1
0
        public void SetUp()
        {
            // Set up sum view and a test child view
            EventType type = WeightedAverageView.CreateEventType(SupportStatementContextFactory.MakeContext(), null, 1);

            WeightedAverageViewFactory factory = new WeightedAverageViewFactory();

            factory.FieldNameX      = SupportExprNodeFactory.MakeIdentNodeMD("Price");
            factory.EventType       = type;
            factory.FieldNameWeight = SupportExprNodeFactory.MakeIdentNodeMD("Volume");
            _myView = new WeightedAverageView(factory, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext());

            _childView = new SupportBeanClassView(typeof(SupportMarketDataBean));
            _myView.AddView(_childView);
        }
        public void TestCanReuse()
        {
            _factory.SetViewParameters(_viewFactoryContext, TestViewSupport.ToExprListMD(new Object[] { "Price", "Volume" }));
            _factory.Attach(SupportEventTypeFactory.CreateBeanType(typeof(SupportMarketDataBean)), SupportStatementContextFactory.MakeContext(), null, null);
            Assert.IsFalse(_factory.CanReuse(new FirstElementView(null)));
            EventType type = WeightedAverageView.CreateEventType(SupportStatementContextFactory.MakeContext(), null, 1);
            WeightedAverageViewFactory factoryTwo = new WeightedAverageViewFactory();

            factoryTwo.FieldNameX      = SupportExprNodeFactory.MakeIdentNodeMD("Price");
            factoryTwo.EventType       = type;
            factoryTwo.FieldNameWeight = SupportExprNodeFactory.MakeIdentNodeMD("Price");
            Assert.IsFalse(_factory.CanReuse(new WeightedAverageView(factoryTwo, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext())));
            factoryTwo.FieldNameWeight = SupportExprNodeFactory.MakeIdentNodeMD("Volume");
            Assert.IsTrue(_factory.CanReuse(new WeightedAverageView(factoryTwo, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext())));
        }
        public void Attach(EventType parentEventType, StatementContext statementContext, ViewFactory optionalParentFactory, IList <ViewFactory> parentViewFactories)
        {
            ExprNode[] validated = ViewFactorySupport.Validate(ViewName, parentEventType, statementContext, _viewParameters, true);

            if (validated.Length < 2)
            {
                throw new ViewParameterException(ViewParamMessage);
            }
            if ((!validated[0].ExprEvaluator.ReturnType.IsNumeric()) || (!validated[1].ExprEvaluator.ReturnType.IsNumeric()))
            {
                throw new ViewParameterException(ViewParamMessage);
            }

            _fieldNameX      = validated[0];
            _fieldNameWeight = validated[1];
            _additionalProps = StatViewAdditionalProps.Make(validated, 2, parentEventType);
            _eventType       = WeightedAverageView.CreateEventType(statementContext, _additionalProps, _streamNumber);
        }