internal DbDriver GetDefaultDriver() { if (InnerDict.Count == 0) { foreach (ConnectionStringSettings item in ConfigurationManager.ConnectionStrings) { if (!string.IsNullOrEmpty(item.ConnectionString) && !string.IsNullOrEmpty(item.ProviderName) && item.ElementInformation.IsPresent) { GeneralUtil.CatchAll(() => { RegisterDbDriver(item.Name, item.ProviderName, item.ConnectionString); } , true ); } } } // 获取去第一个 foreach (string item in InnerDict.Keys) { return(InnerDict[item]); } return(null); }
public void Start() { ThreadPool.QueueUserWorkItem(delegate { GeneralUtil.CatchAll(() => { Run(); }); }); }
public void Dispose() { GeneralUtil.CatchAll(delegate { if (this.writer != null) { this.writer.Close(); this.writer = null; } }); }
private static void CoreExecuteAction(HttpContext httpContext, string controllerName, string actionName, BeeDataAdapter dataAdapter) { if (dataAdapter == null) { dataAdapter = new BeeDataAdapter(); } //HttpContext httpContext = HttpContextUtil.CurrentHttpContext; // 加入Area特性 string areaName = dataAdapter.TryGetValue <string>(Constants.BeeAreaName, string.Empty); if (!string.IsNullOrEmpty(areaName)) { controllerName = "{0}|{1}".FormatWith(areaName, controllerName); } ControllerInfo controllerInfo = ControllerManager.Instance.GetControllerInfo(controllerName); if (controllerInfo == null) { throw new MvcException(string.Format("Cannot find {0} controller.", controllerName)); } ControllerBase instance = controllerInfo.CreateInstance() as ControllerBase; //ReflectionUtil.CreateInstance(controllerInfo.Type) as ControllerBase; instance.Init(httpContext, controllerInfo, dataAdapter, actionName); GeneralUtil.CatchAll(delegate { instance.OnBeforeAction(actionName, dataAdapter); }); object result = null; try { // 假如不匹配任何方法, 则会抛出CoreException result = controllerInfo.Invoke(instance, actionName, dataAdapter); } catch (Exception e) { Logger.Error("Invoke {0}.{1} error.\r\n{2}" .FormatWith(controllerName, actionName, dataAdapter), e); throw; } GeneralUtil.CatchAll(delegate { instance.OnAfterAction(actionName, dataAdapter); }); // 加入ControllerName及ActionName信息 dataAdapter.Add(Constants.BeeControllerName, controllerName); dataAdapter.Add(Constants.BeeActionName, actionName); if (result != null) { ActionResult actionResult = result as ActionResult; if (actionResult != null) { if (string.IsNullOrEmpty(actionResult.ControllerName)) { actionResult.ControllerName = controllerName; } if (string.IsNullOrEmpty(actionResult.ActionName)) { actionResult.ActionName = actionName; } actionResult.Init(instance, dataAdapter); try { actionResult.Ouput(httpContext); } catch (Exception ex) { Logger.Error("Rend {0}.{1} error.\r\n{2}" .FormatWith(controllerName, actionName, dataAdapter), ex); throw new MvcException(ex.Message, ex); } } else { BeeMvcResult mvcResult = new BeeMvcResult(); mvcResult.data = result; mvcResult.code = 200; WriteMvcResult(httpContext, mvcResult); } } else { httpContext.Response.AppendHeader("Content-Type", "application/json; charset=utf-8"); BeeMvcResult mvcResult = new BeeMvcResult(); mvcResult.code = 200; WriteMvcResult(httpContext, mvcResult); } }