/// <summary>
        /// Reads <see cref="Control"/> statement and modifies the context.
        /// </summary>
        /// <param name="statement">A statement to process.</param>
        /// <param name="context">Expression context.</param>
        /// <param name="validation">Validation.</param>
        /// <param name="validate">Validate.</param>
        public void Read(Control statement, EvaluationContext context, SpiceNetlistValidationResult validation, bool validate)
        {
            if (statement.Parameters == null)
            {
                throw new ArgumentNullException(nameof(statement));
            }

            foreach (Parameter param in statement.Parameters)
            {
                if (param is Models.Netlist.Spice.Objects.Parameters.AssignmentParameter assignmentParameter)
                {
                    if (!assignmentParameter.HasFunctionSyntax)
                    {
                        string parameterName       = assignmentParameter.Name;
                        string parameterExpression = assignmentParameter.Value;

                        try
                        {
                            SetParameter(parameterName, parameterExpression, context);
                        }
                        catch (Exception e)
                        {
                            if (validate)
                            {
                                validation.Add(
                                    new ValidationEntry(
                                        ValidationEntrySource.Reader,
                                        ValidationEntryLevel.Warning,
                                        $"Problem with setting param `{assignmentParameter.Name}` with expression =`{assignmentParameter.Value}`",
                                        statement.LineInfo,
                                        exception: e));
                            }
                        }
                    }
                    else
                    {
                        FunctionFactory factory = new FunctionFactory();

                        context.AddFunction(
                            assignmentParameter.Name,
                            assignmentParameter.Value,
                            assignmentParameter.Arguments,
                            factory.Create(
                                assignmentParameter.Name,
                                assignmentParameter.Arguments,
                                assignmentParameter.Value));
                    }
                }
                else
                {
                    validation.Add(
                        new ValidationEntry(
                            ValidationEntrySource.Reader,
                            ValidationEntryLevel.Warning,
                            ".PARAM supports only assignments",
                            statement.LineInfo));
                }
            }
        }
예제 #2
0
        public void TestAve()
        {
            IFunction func = FunctionFactory.Create(CalcEnum.Ave);

            func.Add(100);
            func.Add(200);
            Assert.AreEqual(func.GetValue(), 150);
        }
예제 #3
0
        public void TestCount()
        {
            IFunction func = FunctionFactory.Create(CalcEnum.Count);

            func.Add(1);
            func.Add(1);
            Assert.AreEqual(func.GetValue(), 2);
        }
        public void Given_Handler_Function_ShouldBe_Created()
        {
            var handler = this._fixture.ArrangeRegistrationHandler();
            var logger  = this._fixture.ArrangeLog();

            var factory = new FunctionFactory(handler);

            var function = factory.Create <IFooFunction>(logger);

            function.Log.Should().NotBeNull();
        }
예제 #5
0
        public void Given_ModuleTypeGeneric_Property_ShouldNotThrow_Exception()
        {
            var logger = new Mock <ILogger>();

            var factory = new FunctionFactory <FakeModule>();

            var service = factory.Create <IFakeFunctionWithILogger, ILogger>(logger.Object);

            service.Should().NotBeNull();
            service.Should().BeAssignableTo <IFakeFunctionWithILogger>();
            service.Log.Should().BeAssignableTo <ILogger>();
        }
예제 #6
0
        public void Given_TraceWriter_Property_ShouldNotThrow_Exception()
        {
            var logger = new FakeTraceWriter();

            var factory = new FunctionFactory(new FakeModule());

            var service = factory.Create <IFakeFunctionWithTraceWriter, TraceWriter>(logger);

            service.Should().NotBeNull();
            service.Should().BeAssignableTo <IFakeFunctionWithTraceWriter>();
            service.Log.Should().BeAssignableTo <TraceWriter>();
        }
예제 #7
0
        public void CreateTest()
        {
            IFunction bf = FunctionFactory.Create("DateTime");

            Assert.IsTrue(bf.GetType().Name == "DateTime");

            try
            {
                FunctionFactory.Create("jasd98asjd98ajd98a");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex is UnrecognizedFunctionException);
            }
        }
예제 #8
0
        public void Given_That_Function_ShouldBe_Created()
        {
            var handler = new RegistrationHandler()
            {
                RegisterTypeAsInstancePerDependency = p => p.RegisterType <FooFunction>()
                                                      .As <IFooFunction>()
                                                      .InstancePerDependency()
            };
            var factory = new FunctionFactory(handler);

            var logger   = new Mock <ILogger>();
            var function = factory.Create <IFooFunction>(logger.Object);

            function.Log.Should().NotBeNull();
            function.ServiceLocator.Should().NotBeNull();
        }
예제 #9
0
        private void DrawButton_Click(object sender, EventArgs e)
        {
            var functionName = this.FunctionsComboBox.Text;

            if (functionName == previousFunctionName || string.IsNullOrEmpty(functionName))
            {
                return;
            }
            previousFunctionName = functionName;

            var function = FunctionFactory.Create(functionName);

            graphics.Clear(Color.LightGray);
            function.Draw(graphics);

            Coordinates.DrawCoordinates(graphics);
        }
예제 #10
0
        public ValueWidget(XmlNode node) : base(node)
        {
            this.Width      = Convert.ToInt32(ReportReader.GetValue(node, "width"));
            this.Alignment  = (AlignmentEnum)Enum.Parse(typeof(AlignmentEnum), ReportReader.GetValue(node, "alignment"));
            this.CalcType   = (CalcEnum)Enum.Parse(typeof(CalcEnum), ReportReader.GetValue(node, "calc"));
            this.DataFormat = ReportReader.GetValue(node, "dataformat");
            this.DataType   = (TypeEnum)Enum.Parse(typeof(TypeEnum), ReportReader.GetValue(node, "datatype"));
            this.ResetType  = (ResetEnum)Enum.Parse(typeof(ResetEnum), ReportReader.GetValue(node, "reset"));
            this.ColumnName = ReportReader.GetValue(node, "datamember");
            this.TableName  = ReportReader.GetValue(node, "datasource");
            string arrIndex = ReportReader.GetValue(node, "arrayindex");

            if (arrIndex != "")
            {
                this.ArrayIndex = int.Parse(arrIndex);
            }
            this.NoDuplicates = bool.Parse(ReportReader.GetValue(node, "noduplicates"));
            m_calc            = FunctionFactory.Create(m_calcType);
        }
        /// <summary>
        /// 验证公式
        /// </summary>
        /// <param name="Formula"></param>
        /// <param name="SchemaCode">流程模板编码</param>
        /// <param name="RuleCode"></param>
        /// <returns></returns>
        public JsonResult Validate(string Formula, string SchemaCode, string RuleCode)
        {
            return(ExecuteFunctionRun(() =>
            {
                //校验结果
                ActionResult result = new ActionResult(true, "");

                Formula = Server.HtmlDecode(Formula);
                //错误项
                string[] errorItems = null;
                //错误信息
                List <string> Errors = new List <string>();

                if (!string.IsNullOrEmpty(Formula))
                {
                    // 所有数据项的名称
                    Dictionary <string, string> formulaItemNames = new Dictionary <string, string>();
                    string formulaId = Guid.NewGuid().ToString();
                    formulaItemNames.Add(formulaId, Formula);

                    //所有项名称:数据项、流程关键字
                    List <string> allItemNames = new List <string>();

                    //流程关键字
                    string[] words = OThinker.H3.Instance.Keywords.ParserFactory.GetKeywords();
                    allItemNames.AddRange(words);

                    //业务模型数据项
                    //string SchemaCode = CurrentParams[ConstantString.Param_SchemaCode];
                    if (!string.IsNullOrEmpty(SchemaCode))
                    {
                        DataModel.BizObjectSchema Schema = this.Engine.BizObjectManager.GetDraftSchema(SchemaCode);
                        //如果一个流程包含有多个流程模板的时候,需要重新计算一下shcema
                        if (Schema == null)
                        {
                            WorkflowTemplate.WorkflowClause clause = this.Engine.WorkflowManager.GetClause(SchemaCode);
                            if (clause != null)
                            {
                                Schema = this.Engine.BizObjectManager.GetDraftSchema(clause.BizSchemaCode);
                            }
                        }
                        if (Schema != null)
                        {
                            if (Schema.IsQuotePacket)
                            {
                                Schema = this.Engine.BizObjectManager.GetDraftSchema(Schema.BindPacket);
                            }
                            foreach (DataModel.PropertySchema item in Schema.Properties)
                            {
                                allItemNames.Add(item.Name);
                            }
                        }
                    }

                    //string RuleCode = CurrentContext.Request[ConstantString.Param_RuleCode];
                    // 业务规则数据项
                    if (!string.IsNullOrEmpty(RuleCode))
                    {
                        OThinker.H3.BizBus.BizRule.BizRuleTable rule = this.Engine.BizBus.GetBizRule(RuleCode);
                        if (rule != null)
                        {
                            if (rule.DataElements != null)
                            {
                                foreach (OThinker.H3.BizBus.BizRule.BizRuleDataElement RuleElement in rule.DataElements)
                                {
                                    allItemNames.Add(RuleElement.ElementName);
                                }
                            }
                        }
                    }

                    Function[] fs = FunctionFactory.Create(this.Engine.Organization, this.Engine.BizBus);
                    Dictionary <string, Function> fDic = new Dictionary <string, Function>();
                    if (fs != null)
                    {
                        foreach (OThinker.H3.Math.Function f in fs)
                        {
                            fDic.Add(f.FunctionName, f);
                        }
                    }

                    result.Success = FormulaParser.Validate(Formula, fDic, allItemNames, ref Errors);

                    result.Message = string.Join(";", Errors);
                }
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }