Beispiel #1
0
        /// <summary>
        /// 结束计算任务,清理
        /// </summary>
        /// <returns></returns>
        public static bool StopCalcTask()
        {
            string taskId = FuncCalcTask.GetTaskId();

            //清理缓存
            return(FuncCache.Clear(taskId));
        }
Beispiel #2
0
        /// <summary>
        /// 开始计算任务
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static bool StartCalcTask(FuncContext context)
        {
            string taskId = FuncCalcTask.GetTaskId();

            return(FuncCache.AddContext(taskId, context));
        }
Beispiel #3
0
        //报表格式有可能会产生变化
        internal static FuncCalcResult GetFuncValue(FuncInfo func)
        {
            if (func == null)
            {
                throw new FuncException("要进行计算的函数为空");
            }

            FuncCalcResult calcResult = null;

            //本次计算KEY
            string taskId = FuncCalcTask.GetTaskId();

            if (string.IsNullOrEmpty(taskId))
            {
                throw new FuncException("函数计算任务的taskId不能为空");
            }

            var funcInfoMateData = FuncCache.GetFuncInfoMetaData(func.Name);

            if (funcInfoMateData == null)
            {
                //计算结果
                calcResult = new FuncCalcResult {
                    Status = EnumFuncActionStatus.Failure
                };
                calcResult.Fault = FaultBuilder.Fault("错误", func.Name + "没有注册函数信息");
                return(calcResult);
            }


            //没有缓存则计算
            var refInfo = FuncConfigure.GetFuncRefInfo(func);

            if (refInfo == null)
            {
                //计算结果
                calcResult = new FuncCalcResult {
                    Status = EnumFuncActionStatus.Failure
                };
                calcResult.Fault = FaultBuilder.Fault("错误", func.Name + "没有注册函数实现类信息");
                return(calcResult);
            }

            try
            {
                //反射调用
                var assembly = Assembly.Load(refInfo.AssemblyName);
                var clazz    = assembly.GetType(refInfo.ClassName);

                //使用新封装的接口,所有的参数都是通过request取
                var calcObject = Activator.CreateInstance(clazz) as IFunction;
                if (calcObject == null)
                {
                    //计算结果
                    calcResult = new FuncCalcResult {
                        Status = EnumFuncActionStatus.Failure
                    };

                    calcResult.Fault = FaultBuilder.Fault("错误", func.Name + "没有实现接口IFuncCalc");
                    return(calcResult);
                }

                if (calcObject != null)
                {
                    calcObject.Func = func;
                    var funcInfo = calcObject.PreHandle(); //返回预处理结果,主要是参数的处理

                    var cache = FuncCache.GetFunc(taskId, funcInfo);
                    if (cache != null)
                    {
                        //已经有值,表示已经缓存,则直接取数
                        return(cache.CalcResult);
                    }
                    else
                    {
                        var funcCalc = calcObject as IFuncCalc;
                        var result   = funcCalc.GetValue();

                        //同时加入到缓存中,对象是否要clone
                        funcInfo.CalcResult = result;
                        FuncCache.AddFunc(taskId, funcInfo);
                        return(result);
                    }
                }
            }
            catch (Exception ex)
            {
                //计算结果
                calcResult = new FuncCalcResult {
                    Status = EnumFuncActionStatus.Failure
                };
                calcResult.Fault = FaultBuilder.Fault("错误", func.Name + "反射调用异常");
            }

            return(calcResult);
        }