示例#1
0
        public object Execute(VariableContext context = null)
        {
            if (Names.Count == 1)
            {
                var funcVar = VariableContextHelper.RetrieveFunctionInput(context, Names[0], false);
                if (funcVar != null)
                {
                    return(funcVar);
                }

                var outVar = VariableContextHelper.RetrieveInputVariable(context, Names[0], false);
                if (outVar != null)
                {
                    return(outVar);
                }
                outVar = VariableContextHelper.RetrieveGlobalVariable(context, Names[0], false);
                if (outVar != null)
                {
                    return(outVar);
                }

                var decisionVar = DMNDoerHelper.EvaluateDecisionByName(context, Names[0]);
                if (decisionVar != null)
                {
                    //all the values that override is always string variable
                    var overrideVar = VariableContextHelper.RetrieveInputVariable(context, Names[0], false);
                    if (overrideVar != null)
                    {
                        return(VariableHelper.MakeVariable(overrideVar.StringVal, decisionVar.ValueType));
                    }
                    return(decisionVar);
                }

                return(new Variable(Names[0]));
            }

            //Context parent child layers
            var ctxVar = VariableContextHelper.RetrieveInputVariable(context, Names[0], false);

            if (ctxVar == null)
            {
                ctxVar = VariableContextHelper.RetrieveGlobalVariable(context, Names[0], false);
            }

            if (ctxVar == null)
            {
                ctxVar = DMNDoerHelper.EvaluateDecisionByName(context, Names[0]);
                //all the values that override is always string variable
                var overrideVar = VariableContextHelper.RetrieveInputVariable(context, Names[0], false);
                if (overrideVar != null)
                {
                    var overrideTyped = VariableHelper.MakeVariable(overrideVar.StringVal, ctxVar.ValueType);
                    ctxVar = overrideTyped;
                }
            }

            if (ctxVar == null && ctxVar.ValueType != DataTypeEnum.Context)
            {
                throw new FEELException("Failed finding a context variable");
            }

            for (int i = 1; i < Names.Count; i++)
            {
                switch (ctxVar.ValueType)
                {
                case DataTypeEnum.Context:
                    ctxVar = FindContextVariable(Names[i], ctxVar);
                    break;

                case DataTypeEnum.Date:
                    return(DateAndTimeHelper.DatePropEvals(ctxVar, Names[i]));

                case DataTypeEnum.DateTime:
                    return(DateAndTimeHelper.DateTimePropEvals(ctxVar, Names[i]));

                case DataTypeEnum.Time:
                    return(DateAndTimeHelper.TimePropEvals(ctxVar, Names[i]));

                case DataTypeEnum.YearMonthDuration:
                case DataTypeEnum.DayTimeDuration:
                    return(DateAndTimeHelper.DurationPropEvals(ctxVar, Names[i]));

                default:
                    throw new FEELException($"Path expression for {ctxVar.ValueType} is not supported");
                }
            }

            return(ctxVar);
        }
示例#2
0
        public object Execute(VariableContext context = null)
        {
            var parentVal = Parent.Execute(context);

            if (parentVal is Variable parentVar)
            {
                switch (parentVar.ValueType)
                {
                case DataTypeEnum.Context:
                    parentVar.ContextInputs.ContextDict.TryGetValue(Child, out Variable contextOut);
                    return(contextOut);

                case DataTypeEnum.List:
                    if (parentVar.ListVal.Count == 1)
                    {
                        if (parentVar.ListVal[0].ValueType != DataTypeEnum.Context)
                        {
                            throw new FEELException("List of context types is supported for path expressions");
                        }
                        var ctx = parentVar.ListVal[0].ContextInputs;
                        ctx.ContextDict.TryGetValue(Child, out Variable lCtx);
                        return(lCtx);
                    }
                    if (parentVar.ListVal.Count > 1)
                    {
                        var outList = new List <Variable> ();

                        foreach (var item in parentVar.ListVal)
                        {
                            if (item.ValueType != DataTypeEnum.Context)
                            {
                                throw new FEELException("List of context types is supported for path expressions");
                            }
                            var ctx = item.ContextInputs;
                            ctx.ContextDict.TryGetValue(Child, out Variable lCtx);
                            outList.Add(lCtx);
                        }
                        return(new Variable(outList));
                    }
                    throw new FEELException("Empty list for path expression");

                case DataTypeEnum.Date:
                    return(DateAndTimeHelper.DatePropEvals(parentVar, Child));

                case DataTypeEnum.DateTime:
                    return(DateAndTimeHelper.DateTimePropEvals(parentVar, Child));

                case DataTypeEnum.Time:
                    return(DateAndTimeHelper.TimePropEvals(parentVar, Child));

                case DataTypeEnum.YearMonthDuration:
                case DataTypeEnum.DayTimeDuration:
                    return(DateAndTimeHelper.DurationPropEvals(parentVar, Child));

                default:
                    throw new FEELException($"Path expression for {parentVar.ValueType} is not supported");
                }
            }

            throw new FEELException("Parent source is not a variable type");
        }