public static void LoadAttribute(List<string> BusinessDll,ModulePlugin mp)
        {
            List<WinformControllerAttributeInfo> cmdControllerList = new List<WinformControllerAttributeInfo>();

            for (int k = 0; k < BusinessDll.Count; k++)
            {
                System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(BusinessDll[k]);
                Type[] types = assembly.GetTypes();
                for (int i = 0; i < types.Length; i++)
                {
                    WinformControllerAttribute[] winC = ((WinformControllerAttribute[])types[i].GetCustomAttributes(typeof(WinformControllerAttribute), true));

                    if (winC.Length > 0)
                    {
                        WinformControllerAttributeInfo cmdC = new WinformControllerAttributeInfo();
                        cmdC.controllerName = types[i].Name;
                        cmdC.defaultViewName = winC[0].DefaultViewName;
                        //cmdC.winformController = (AbstractController)Activator.CreateInstance(types[i], null);
                        cmdC.winformController = (AbstractController)FactoryModel.GetObject(types[i], mp.database, mp.container, mp.cache, mp.plugin.name, null);
                        cmdC.MethodList = new List<WinformMethodAttributeInfo>();
                        cmdC.ViewList = new List<WinformViewAttributeInfo>();

                        MethodInfo[] property = types[i].GetMethods();
                        for (int n = 0; n < property.Length; n++)
                        {
                            WinformMethodAttribute[] WinM = (WinformMethodAttribute[])property[n].GetCustomAttributes(typeof(WinformMethodAttribute), true);
                            if (WinM.Length > 0)
                            {
                                WinformMethodAttributeInfo cmdM = new WinformMethodAttributeInfo();
                                cmdM.methodName = property[n].Name;
                                cmdM.methodInfo = property[n];
                                if (WinM[0].OpenDBKeys != null && WinM[0].OpenDBKeys.ToString().Trim() != "")
                                    cmdM.dbkeys = WinM[0].OpenDBKeys.Split(new char[] { ',' }).ToList();
                                cmdC.MethodList.Add(cmdM);
                            }
                        }

                        WinformViewAttribute[] viewAttribute = (WinformViewAttribute[])types[i].GetCustomAttributes(typeof(WinformViewAttribute), true);
                        for (int n = 0; n < viewAttribute.Length; n++)
                        {
                            WinformViewAttributeInfo winView = new WinformViewAttributeInfo();
                            winView.Name = viewAttribute[n].Name;
                            winView.DllName = viewAttribute[n].DllName;
                            winView.ViewTypeName = viewAttribute[n].ViewTypeName;
                            winView.IsDefaultView = winView.Name == cmdC.defaultViewName ? true : false;

                            Assembly _assembly = Assembly.LoadFrom(winView.DllName);
                            winView.ViewType = _assembly.GetType(winView.ViewTypeName, false, true);
                            cmdC.ViewList.Add(winView);
                        }
                        cmdControllerList.Add(cmdC);
                    }
                }
            }

            mp.cache.Add(mp.plugin.name+"@"+GetCacheKey(), cmdControllerList);
        }
Beispiel #2
0
        /// <summary>
        /// 执行WCF服务,返回结果
        /// </summary>
        /// <param name="mp"></param>
        /// <param name="controllername"></param>
        /// <param name="methodname"></param>
        /// <param name="paramValue"></param>
        /// <param name="requestData"></param>
        /// <returns></returns>
        public static Object WcfServerExecuteMethod(this ModulePlugin mp, string controllername, string methodname, object[] paramValue, ClientRequestData requestData)
        {
            if (mp.helper == null)
            {
                mp.helper = new WcfFrame.ServerController.ControllerHelper();
            }
            EFWCoreLib.WcfFrame.ServerController.WcfServerController wscontroller = mp.helper.CreateController(mp.plugin.name, controllername) as EFWCoreLib.WcfFrame.ServerController.WcfServerController;
            wscontroller.requestData  = requestData;
            wscontroller.responseData = new ServiceResponseData(requestData.Iscompressjson, requestData.Isencryptionjson, requestData.Serializetype);
            wscontroller.BindLoginRight(requestData.LoginRight);
            MethodInfo methodinfo = mp.helper.CreateMethodInfo(mp.plugin.name, controllername, methodname, wscontroller);

            return(methodinfo.Invoke(wscontroller, paramValue));
        }
        public static void LoadAttribute(List<string> BusinessDll, ModulePlugin mp)
        {
            List<WcfControllerAttributeInfo> cmdControllerList = new List<WcfControllerAttributeInfo>();

            for (int k = 0; k < BusinessDll.Count; k++)
            {
                System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(BusinessDll[k]);
                Type[] types = assembly.GetTypes();
                for (int i = 0; i < types.Length; i++)
                {
                    WCFControllerAttribute[] webC = ((WCFControllerAttribute[])types[i].GetCustomAttributes(typeof(WCFControllerAttribute), true));

                    if (webC.Length > 0)
                    {
                        WcfControllerAttributeInfo cmdC = new WcfControllerAttributeInfo();
                        cmdC.controllerName = types[i].Name;
                        //cmdC.wcfController = (AbstractController)Activator.CreateInstance(types[i], null);
                        //cmdC.wcfController = (AbstractController)FactoryModel.GetObject(types[i], mp.database, mp.container, mp.cache, mp.plugin.name, null);
                        cmdC.wcfControllerType = types[i];
                        cmdC.MethodList = new List<WcfMethodAttributeInfo>();

                        MethodInfo[] property = types[i].GetMethods();
                        for (int n = 0; n < property.Length; n++)
                        {
                            WCFMethodAttribute[] WcfM = (WCFMethodAttribute[])property[n].GetCustomAttributes(typeof(WCFMethodAttribute), true);
                            if (WcfM.Length > 0)
                            {
                                WcfMethodAttributeInfo cmdM = new WcfMethodAttributeInfo();
                                cmdM.methodName = property[n].Name;
                                cmdM.methodInfo = property[n];
                                if (WcfM[0].OpenDBKeys != null && WcfM[0].OpenDBKeys.ToString().Trim() != "")
                                    cmdM.dbkeys = WcfM[0].OpenDBKeys.Split(new char[] { ',' }).ToList();
                                cmdC.MethodList.Add(cmdM);
                            }
                        }

                        cmdControllerList.Add(cmdC);
                    }
                }
            }

            mp.cache.Add(mp.plugin.name+"@"+GetCacheKey(), cmdControllerList);
        }
        public static void AddPlugin(string plugfile)
        {
            if (PluginDic == null)
                PluginDic = new Dictionary<string, ModulePlugin>();

            ModulePlugin mp = new ModulePlugin();
            mp.LoadPlugin(plugfile);

            if (PluginDic.ContainsKey(mp.plugin.name) == false)
            {
                PluginDic.Add(mp.plugin.name, mp);
                List<string> dllList = new List<string>();
                switch (AppGlobal.appType)
                {
                    case AppType.Web:
                        foreach (businessinfoDll dll in mp.plugin.businessinfoDllList)
                        {
                            dllList.Add(AppGlobal.AppRootPath + "bin\\" + dll.name);
                        }
                        if (dllList.Count > 0)
                        {
                            EntityManager.LoadAttribute(dllList, mp.cache, mp.plugin.name);
                            WebControllerManager.LoadAttribute(dllList, mp);
                            WebServicesManager.LoadAttribute(dllList, mp.cache, mp.plugin.name);
                        }
                        break;
                    case AppType.Winform:
                        foreach (businessinfoDll dll in mp.plugin.businessinfoDllList)
                        {
                            dllList.Add(AppGlobal.AppRootPath + dll.name);
                        }
                        if (dllList.Count > 0)
                        {
                            EntityManager.LoadAttribute(dllList, mp.cache, mp.plugin.name);
                            WinformControllerManager.LoadAttribute(dllList, mp);
                        }
                        break;
                    case AppType.WCF:
                        foreach (businessinfoDll dll in mp.plugin.businessinfoDllList)
                        {
                            dllList.Add(AppGlobal.AppRootPath + dll.name);
                        }
                        if (dllList.Count > 0)
                        {
                            EntityManager.LoadAttribute(dllList, mp.cache, mp.plugin.name);
                            WcfControllerManager.LoadAttribute(dllList, mp);
                        }
                        break;
                    case AppType.WCFClient:
                        foreach (businessinfoDll dll in mp.plugin.businessinfoDllList)
                        {
                            dllList.Add(AppGlobal.AppRootPath + dll.name);
                        }
                        if (dllList.Count > 0)
                        {
                            WinformControllerManager.LoadAttribute(dllList, mp);
                        }
                        break;
                }
            }
        }
 public static WebServicesAttributeInfo GetPluginWebServicesAttributeInfo(string name, out ModulePlugin mp)
 {
     foreach (KeyValuePair<string, ModulePlugin> val in PluginDic)
     {
         List<WebServicesAttributeInfo> list = (List<WebServicesAttributeInfo>)WebServicesManager.GetAttributeInfo(val.Value.cache, val.Value.plugin.name);
         if (list.FindIndex(x => x.ServiceName == name) > -1)
         {
             mp = val.Value;
             return list.Find(x => x.ServiceName == name);
         }
     }
     mp = null;
     return null;
 }
        public static WcfControllerAttributeInfo GetPluginWcfControllerAttributeInfo(string pluginname, string name, out ModulePlugin mp)
        {
            mp = PluginDic[pluginname];
            if (mp != null)
            {
                List<WcfControllerAttributeInfo> list = (List<WcfControllerAttributeInfo>)WcfControllerManager.GetAttributeInfo(mp.cache, mp.plugin.name);
                if (list.FindIndex(x => x.controllerName == name) > -1)
                {
                    return list.Find(x => x.controllerName == name);
                }
            }
            return null;


            //foreach (KeyValuePair<string, ModulePlugin> val in PluginDic)
            //{
            //    List<WcfControllerAttributeInfo> list = (List<WcfControllerAttributeInfo>)WcfControllerManager.GetAttributeInfo(val.Value.cache, val.Value.plugin.name);
            //    if (list.FindIndex(x => x.controllerName == name) > -1)
            //    {
            //        mp = val.Value;
            //        return list.Find(x => x.controllerName == name);
            //    }
            //}
            //mp = null;
            //return null;
        }
 public static WebControllerAttributeInfo GetPluginWebControllerAttributeInfo(string pluginname, string name, out ModulePlugin mp)
 {
     mp = PluginDic[pluginname];
     if (mp != null)
     {
         List<WebControllerAttributeInfo> list = (List<WebControllerAttributeInfo>)WebControllerManager.GetAttributeInfo(mp.cache, mp.plugin.name);
         if (list.FindIndex(x => x.controllerName == name) > -1)
         {
             return list.Find(x => x.controllerName == name);
         }
     }
     return null;
 }
Beispiel #8
0
        public static string ProcessRequest(string clientId, string plugin, string controller, string method, string jsondata, HeaderParameter para)
        {
            string retJson = null;

            try
            {
                if (plugin == null || controller == null)
                {
                    throw new Exception("插件名称或控制器名称不能为空!");
                }

                if (ClientManage.ClientDic.ContainsKey(clientId) == false)
                {
                    throw new Exception("客户端不存在,正在创建新的连接!");
                }

                if (ClientManage.IsToken == true)//非调试模式下才验证
                {
                    //验证身份,创建连接的时候验证,请求不验证
                    IsAuth(plugin, controller, method, para.token);
                }

                //显示调试信息
                if (WcfGlobal.IsDebug == true)
                {
                    ShowHostMsg(Color.Black, DateTime.Now, "客户端[" + clientId + "]正在执行:" + controller + "." + method + "(" + jsondata + ")");
                }


                begintime();

                #region 执行插件控制器的核心算法
                object[]            paramValue  = null;//jsondata?
                ServiceResponseData retObj      = null;
                LocalPlugin         localPlugin = RemotePluginManage.GetLocalPlugin();
                if (string.IsNullOrEmpty(para.replyidentify) || localPlugin.ServerIdentify == para.replyidentify)
                {
                    if (localPlugin.PluginDic.ContainsKey(plugin) == true)
                    {
                        //先解密再解压
                        string _jsondata = jsondata;
                        //解密参数
                        if (para.isencryptionjson)
                        {
                            DESEncryptor des = new DESEncryptor();
                            des.InputString = _jsondata;
                            des.DesDecrypt();
                            _jsondata = des.OutString;
                        }
                        //解压参数
                        if (para.iscompressjson)
                        {
                            _jsondata = ZipComporessor.Decompress(_jsondata);
                        }

                        ClientRequestData requestData = new ClientRequestData(para.iscompressjson, para.isencryptionjson, para.serializetype);
                        requestData.SetJsonData(_jsondata);
                        requestData.LoginRight = para.LoginRight;

                        EFWCoreLib.CoreFrame.Plugin.ModulePlugin moduleplugin = localPlugin.PluginDic[plugin];
                        retObj = (ServiceResponseData)moduleplugin.WcfServerExecuteMethod(controller, method, paramValue, requestData);

                        if (retObj != null)
                        {
                            retJson = retObj.GetJsonData();
                        }
                        else
                        {
                            retObj = new ServiceResponseData();
                            retObj.Iscompressjson   = para.iscompressjson;
                            retObj.Isencryptionjson = para.isencryptionjson;
                            retObj.Serializetype    = para.serializetype;

                            retJson = retObj.GetJsonData();
                        }

                        retJson = "{\"flag\":0,\"msg\":" + "\"\"" + ",\"data\":" + retJson + "}";
                        //先压缩再加密
                        //压缩结果
                        if (para.iscompressjson)
                        {
                            retJson = ZipComporessor.Compress(retJson);
                        }
                        //加密结果
                        if (para.isencryptionjson)
                        {
                            DESEncryptor des = new DESEncryptor();
                            des.InputString = retJson;
                            des.DesEncrypt();
                            retJson = des.OutString;
                        }
                    }
                    else
                    {
                        throw new Exception("本地插件找不到指定的插件");
                    }
                }
                else//本地插件找不到,就执行远程插件
                {
                    if (RemotePluginManage.GetRemotePlugin().FindIndex(x => x.ServerIdentify == para.replyidentify) > -1)
                    {
                        RemotePlugin rp = RemotePluginManage.GetRemotePlugin().Find(x => x.ServerIdentify == para.replyidentify);
                        string[]     ps = rp.plugin;

                        if (ps.ToList().FindIndex(x => x == plugin) > -1)
                        {
                            retJson = rp.callback.ReplyProcessRequest(para, plugin, controller, method, jsondata);
                        }
                        else
                        {
                            throw new Exception("远程插件找不到指定的插件");
                        }
                    }
                    else
                    {
                        throw new Exception("远程插件找不到指定的回调中间件");
                    }
                }
                #endregion

                double outtime = endtime();
                //记录超时的方法
                if (ClientManage.IsOverTime == true)
                {
                    if (outtime > Convert.ToDouble(ClientManage.OverTime * 1000))
                    {
                        WriterOverTimeLog(outtime, controller + "." + method + "(" + jsondata + ")");
                    }
                }
                //显示调试信息
                if (WcfGlobal.IsDebug == true)
                {
                    ShowHostMsg(Color.Green, DateTime.Now, "客户端[" + clientId + "]收到结果(耗时[" + outtime + "]):" + retJson);
                }

                //更新客户端信息
                ClientManage.UpdateRequestClient(clientId, jsondata == null ? 0 : jsondata.Length, retJson == null ? 0 : retJson.Length);


                if (retJson == null)
                {
                    throw new Exception("插件执行未返回有效数据");
                }

                return(retJson);
            }
            catch (Exception err)
            {
                //记录错误日志
                if (err.InnerException == null)
                {
                    retJson = "{\"flag\":1,\"msg\":" + "\"" + err.Message + "\"" + "}";
                    if (para.iscompressjson)
                    {
                        retJson = ZipComporessor.Compress(retJson);
                    }
                    ShowHostMsg(Color.Red, DateTime.Now, "客户端[" + clientId + "]执行失败:" + err.Message);
                    return(retJson);
                }
                else
                {
                    retJson = "{\"flag\":1,\"msg\":" + "\"" + err.InnerException.Message + "\"" + "}";
                    if (para.iscompressjson)
                    {
                        retJson = ZipComporessor.Compress(retJson);
                    }
                    ShowHostMsg(Color.Red, DateTime.Now, "客户端[" + clientId + "]执行失败:" + err.InnerException.Message);
                    return(retJson);
                }
            }
        }
Beispiel #9
0
        public static string ReplyProcessRequest(string plugin, string controller, string method, string jsondata, HeaderParameter para)
        {
            string retJson = null;

            try
            {
                //显示调试信息
                if (WcfGlobal.IsDebug == true)
                {
                    ShowHostMsg(Color.Black, DateTime.Now, "客户端[本地回调]正在执行:" + controller + "." + method + "(" + jsondata + ")");
                }

                begintime();

                #region 执行插件控制器的核心算法
                object[]            paramValue  = null;//jsondata?
                ServiceResponseData retObj      = null;
                LocalPlugin         localPlugin = RemotePluginManage.GetLocalPlugin();
                if (string.IsNullOrEmpty(para.replyidentify) || localPlugin.ServerIdentify == para.replyidentify)
                {
                    if (localPlugin.PluginDic.ContainsKey(plugin) == true)
                    {
                        //先解密再解压
                        string _jsondata = jsondata;
                        //解密参数
                        if (para.isencryptionjson)
                        {
                            DESEncryptor des = new DESEncryptor();
                            des.InputString = _jsondata;
                            des.DesDecrypt();
                            _jsondata = des.OutString;
                        }
                        //解压参数
                        if (para.iscompressjson)
                        {
                            _jsondata = ZipComporessor.Decompress(_jsondata);
                        }

                        ClientRequestData requestData = new ClientRequestData(para.iscompressjson, para.isencryptionjson, para.serializetype);
                        requestData.SetJsonData(_jsondata);
                        requestData.LoginRight = para.LoginRight;

                        EFWCoreLib.CoreFrame.Plugin.ModulePlugin moduleplugin = localPlugin.PluginDic[plugin];
                        retObj = (ServiceResponseData)moduleplugin.WcfServerExecuteMethod(controller, method, paramValue, requestData);

                        if (retObj != null)
                        {
                            retJson = retObj.GetJsonData();
                        }
                        else
                        {
                            retObj = new ServiceResponseData();
                            retObj.Iscompressjson   = para.iscompressjson;
                            retObj.Isencryptionjson = para.isencryptionjson;
                            retObj.Serializetype    = para.serializetype;

                            retJson = retObj.GetJsonData();
                        }

                        retJson = "{\"flag\":0,\"msg\":" + "\"\"" + ",\"data\":" + retJson + "}";
                        //先压缩再加密
                        //压缩结果
                        if (para.iscompressjson)
                        {
                            retJson = ZipComporessor.Compress(retJson);
                        }
                        //加密结果
                        if (para.isencryptionjson)
                        {
                            DESEncryptor des = new DESEncryptor();
                            des.InputString = retJson;
                            des.DesEncrypt();
                            retJson = des.OutString;
                        }
                    }
                    else
                    {
                        throw new Exception("本地插件找不到指定的插件");
                    }
                }
                else//本地插件找不到,就执行远程插件
                {
                    if (RemotePluginManage.GetRemotePlugin().FindIndex(x => x.ServerIdentify == para.replyidentify) > -1)
                    {
                        RemotePlugin rp = RemotePluginManage.GetRemotePlugin().Find(x => x.ServerIdentify == para.replyidentify);
                        string[]     ps = rp.plugin;

                        if (ps.ToList().FindIndex(x => x == plugin) > -1)
                        {
                            retJson = rp.callback.ReplyProcessRequest(para, plugin, controller, method, jsondata);
                        }
                        else
                        {
                            throw new Exception("远程插件找不到指定的插件");
                        }
                    }
                    else
                    {
                        throw new Exception("远程插件找不到指定的回调中间件");
                    }
                }
                #endregion

                //System.Threading.Thread.Sleep(20000);//测试并发问题,此处也没有问题
                double outtime = endtime();
                //记录超时的方法
                if (ClientManage.IsOverTime == true)
                {
                    if (outtime > Convert.ToDouble(ClientManage.OverTime * 1000))
                    {
                        WriterOverTimeLog(outtime, controller + "." + method + "(" + jsondata + ")");
                    }
                }
                //显示调试信息
                if (WcfGlobal.IsDebug == true)
                {
                    ShowHostMsg(Color.Green, DateTime.Now, "客户端[本地回调]收到结果(耗时[" + outtime + "]):" + retJson);
                }

                if (retJson == null)
                {
                    throw new Exception("请求的插件未获取到有效数据");
                }

                return(retJson);
            }
            catch (Exception err)
            {
                //记录错误日志
                //EFWCoreLib.CoreFrame.EntLib.ZhyContainer.CreateException().HandleException(err, "HISPolicy");

                if (err.InnerException == null)
                {
                    retJson = "{\"flag\":1,\"msg\":" + "\"" + err.Message + "\"" + "}";
                    if (para.iscompressjson)
                    {
                        retJson = ZipComporessor.Compress(retJson);
                    }
                    ShowHostMsg(Color.Red, DateTime.Now, "客户端[本地回调]执行失败:" + err.Message);
                    return(retJson);
                }
                else
                {
                    retJson = "{\"flag\":1,\"msg\":" + "\"" + err.InnerException.Message + "\"" + "}";
                    if (para.iscompressjson)
                    {
                        retJson = ZipComporessor.Compress(retJson);
                    }
                    ShowHostMsg(Color.Red, DateTime.Now, "客户端[本地回调]执行失败:" + err.InnerException.Message);
                    return(retJson);
                }
            }
        }
Beispiel #10
0
        //执行服务核心方法
        private static string ExecuteService(string plugin, string controller, string method, string jsondata, HeaderParameter para)
        {
            string retJson = null;

            try
            {
                #region 执行插件控制器的核心算法
                object[]            paramValue = null;//jsondata?
                ServiceResponseData retObj     = null;

                //先解密再解压
                string _jsondata = jsondata;
                //解密参数
                if (para.isencryptionjson)
                {
                    DESEncryptor des = new DESEncryptor();
                    des.InputString = _jsondata;
                    des.DesDecrypt();
                    _jsondata = des.OutString;
                }
                //解压参数
                if (para.iscompressjson)
                {
                    _jsondata = ZipComporessor.Decompress(_jsondata);
                }

                ClientRequestData requestData = new ClientRequestData(para.iscompressjson, para.isencryptionjson, para.serializetype);
                requestData.SetJsonData(_jsondata);
                requestData.LoginRight = para.LoginRight;
                //获取插件服务
                EFWCoreLib.CoreFrame.Plugin.ModulePlugin moduleplugin = CoreFrame.Init.AppPluginManage.PluginDic[plugin];
                retObj = (ServiceResponseData)moduleplugin.WcfServerExecuteMethod(controller, method, paramValue, requestData);

                if (retObj != null)
                {
                    retJson = retObj.GetJsonData();
                }
                else
                {
                    retObj = new ServiceResponseData();
                    retObj.Iscompressjson   = para.iscompressjson;
                    retObj.Isencryptionjson = para.isencryptionjson;
                    retObj.Serializetype    = para.serializetype;

                    retJson = retObj.GetJsonData();
                }

                retJson = "{\"flag\":0,\"msg\":" + "\"\"" + ",\"data\":" + retJson + "}";
                //先压缩再加密
                //压缩结果
                if (para.iscompressjson)
                {
                    retJson = ZipComporessor.Compress(retJson);
                }
                //加密结果
                if (para.isencryptionjson)
                {
                    DESEncryptor des = new DESEncryptor();
                    des.InputString = retJson;
                    des.DesEncrypt();
                    retJson = des.OutString;
                }


                #endregion

                return(retJson);
            }
            catch (Exception err)
            {
                throw err;
            }
        }