Example #1
0
        //函数追踪
        internal static FuncTrackResult GetFuncTrack(FuncInfo func)
        {
            if (func == null)
            {
                return(null);
            }

            //函数分解不进行缓存
            var refInfo = FuncConfigure.GetFuncRefInfo(func);

            if (refInfo == null)
            {
                //计算结果
                FuncTrackResult trackResult = new FuncTrackResult();
                trackResult.Fault = FaultBuilder.Fault("错误", func.Name + "没有注册实现类信息");
                return(trackResult);
            }

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

                //使用新封装的接口,所有的参数都是通过request取
                var trackObject = Activator.CreateInstance(clazz) as IFuncTrack;
                if (trackObject == null)
                {
                    //计算结果
                    FuncTrackResult trackResult = new FuncTrackResult();
                    trackResult.Fault = FaultBuilder.Fault("错误", func.Name + "没有实现接口IFuncTrack");
                    return(trackResult);
                }
                else
                {
                    var result = trackObject.Track();
                    return(result);
                }
            }
            catch (Exception ex)
            {
                FuncTrackResult trackResult = new FuncTrackResult();
                trackResult.Fault = FaultBuilder.Fault("错误", func.Name + "反射调用异常" + ex.Message);
                return(trackResult);
            }
        }
Example #2
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);
        }
Example #3
0
        /// <summary>
        /// 生成supcan报表控件函数的描述信息
        /// </summary>
        /// <returns></returns>
        public static string SupcanFuncsXmlDescriptor(string catalogs)
        {
            if (string.IsNullOrEmpty(catalogs))
            {
                return(string.Empty);
            }

            FuncConfigure.LoadFuncs(catalogs);
            string[] catalog = catalogs.Split(',');

            IList <DropDownList> dropLists = new List <DropDownList>();

            var xmlDoc = new XmlDocument();

            var xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "");

            xmlDoc.AppendChild(xmlDecl);

            var xmlRoot  = xmlDoc.CreateElement("root");
            var xmlFuncs = xmlDoc.CreateElement("functions");

            xmlRoot.AppendChild(xmlFuncs);
            xmlDoc.AppendChild(xmlRoot);

            foreach (var s in catalog)
            {
                //取得所有的函数
                var funcList = FuncCache.GetFuncInfoMetaDataByCatalog(s);
                if (funcList == null)
                {
                    continue;
                }
                //catalogid对应的目录名
                if (funcList.Count > 0)
                {
                    string catalogName = funcList[0].Module;
                    //输出XML
                    var xmlCatalog = xmlDoc.CreateElement("catagory");
                    xmlCatalog.SetAttribute("name", catalogName);
                    xmlFuncs.AppendChild(xmlCatalog);

                    funcList.ToList().ForEach(p => {
                        var xmlFunc = xmlDoc.CreateElement("function");
                        xmlFunc.SetAttribute("name", p.Name);
                        xmlCatalog.AppendChild(xmlFunc);

                        var xmlUsage       = xmlDoc.CreateElement("usage");
                        xmlUsage.InnerText = p.Usage;
                        xmlFunc.AppendChild(xmlUsage);

                        var xmlDetail       = xmlDoc.CreateElement("detail");
                        xmlDetail.InnerText = p.Detail;
                        xmlFunc.AppendChild(xmlDetail);

                        //函数参数
                        p.Paras.ToList().ForEach(parm =>
                        {
                            var xmlParam = xmlDoc.CreateElement("para");
                            xmlParam.SetAttribute("datatype", parm.ParamType);
                            xmlParam.SetAttribute("droplistID", parm.DroplistCode);
                            xmlParam.SetAttribute("edittype", parm.EditType);
                            xmlParam.InnerText = parm.Name;

                            //
                            xmlFunc.AppendChild(xmlParam);
                        });

                        var xmlExample       = xmlDoc.CreateElement("example");
                        xmlExample.InnerText = p.Example;
                        xmlFunc.AppendChild(xmlExample);
                    });
                }

                //不同的模块的函数,下拉列表也有可能是一样的
                var dropList = FuncCache.GetDropDownList(s);
                dropList.ToList().ForEach(p => { dropLists.Add(p); });
            }
            //输出dropDwonList
            var xmlDroplists = xmlDoc.CreateElement("DropLists");

            xmlRoot.AppendChild(xmlDroplists);


            dropLists.Distinct().ToList().ForEach(p =>
            {
                var xmlDropList = xmlDoc.CreateElement("DropList");
                xmlDropList.SetAttribute("DisplayCol", p.DisplayCol);
                xmlDropList.SetAttribute("DataCol", p.DataCol);
                xmlDropList.SetAttribute("dataUrl", p.DataUrl);
                xmlDropList.SetAttribute("treelist", p.TreelistUrl);
                xmlDropList.SetAttribute("id", p.Id);

                //多个字符串参数解析
                foreach (var key in p.ParamsDic.AllKeys)
                {
                    xmlDropList.SetAttribute(key, p.ParamsDic[key]);
                }
                xmlDroplists.AppendChild(xmlDropList);
            });

            return(ConvertXmlToString(xmlDoc));
        }