public System.IO.Stream GetManifestResourceStream(IResourceUrl resourceUrl) { using (var wacth = new CodeWatch("GetManifestResourceStream", 1000, new Action<string, LoggerStrategyBase, int?, long>((tag, currentLog, wcount, execms) => currentLog.LogFormat(LoggerLevels.Warn, "\t{0}:资源({3})请求时间为({1})ms.已超过阀值({2})ms.", tag, execms, wcount, resourceUrl.ManifestResourceName)))) { if (!PlusAssemblysList.Any(p => p.Assembly.FullName == resourceUrl.AssemblyFullName)) throw new Exception("此插件已移除或者不存在。"); var ass = PlusAssemblysList.First(p => p.Assembly.FullName == resourceUrl.AssemblyFullName); return ass.Assembly.GetManifestResourceStream(resourceUrl.ManifestResourceName); } }
/// <summary> /// 初始化 /// </summary> public override void Initialize() { #region 初始化路由 this.RoutingManager = new RoutingManager(); this.RoutingManager.Initialize(); #endregion //初始化全局配置 GlobalConfigurationManager.Config(); using (var watch = new CodeWatch("Initialize", 20000)) { #region 【废弃】处理插件 using (new CodeWatch("LoadPlusAndPlusResource", 5000)) { //var taskDoingList = new List<Task>(); #region 【废弃】加载程序集资源 //foreach (var plus in PlusManager.InstalledPluginsList) //{ // var loadPlusTask = new Task((plusAss) => CurrentResourceHelper.LoadPlusAndPlusResource((IPlusInfo)plusAss), plus); // taskDoingList.Add(loadPlusTask); // loadPlusTask.Start(); //} //Task.WaitAll(taskDoingList.ToArray()); //taskDoingList.Clear(); #endregion #region 【废弃】初始化程序集 //foreach (var plus in PlusAssemblysList) //{ // //程序集初始化 // var initTask = new Task((plusInfo) => // { // var plu = (IPlusInfo)plusInfo; // CurrentResourceHelper.AssemblyInitialize(plu.Assembly, plu.PlusAssemblys); // }, plus); // taskDoingList.Add(initTask); // initTask.Start(); //} //Task.WaitAll(taskDoingList.ToArray()); //taskDoingList.Clear(); #endregion #region 【废弃】执行程序集初始化函数 //foreach (var plus in PlusManager.PluginsList) //{ // var loadingTask = new Task((plusInfo) => // { // var plu = (IPlusInfo)plusInfo; // //执行插件Loading函数 // plu.Assembly.GetTypes().Where(p => p.IsClass && p.GetInterface(typeof(IPlus).FullName) != null).Each( // t => // { // using (new CodeWatch("Plu Initialize", ApplicationLog, 3000)) // { // try // { // var type = (IPlus)Activator.CreateInstance(t); // type.Initialize(); // } // catch (Exception ex) // { // ApplicationLog.Log(LoggerLevels.Error, string.Format("Assembly:{0},Type:{1}{2}", plu.Assembly.FullName, t.FullName, Environment.NewLine), ex); // } // } // }); // }, plus); // taskDoingList.Add(loadingTask); // loadingTask.Start(); //} //Task.WaitAll(taskDoingList.ToArray()); //taskDoingList.Clear(); #endregion } #endregion } }
private void ProcessHander(HttpContext context, IWebHandlerInfo webHandlerInfo) { using (var codeWatch = new CodeWatch("IJsonHandler ProcessRequest", 2000, new Action<string, LoggerStrategyBase, int?, long>( (tag, currentLog, wcount, execms) => currentLog.LogFormat(LoggerLevels.Warn, "\t{0}:JSONHandler({3})执行时间为({1})ms.已超过阀值({2})ms.", tag, execms, wcount, context.Request.Url.AbsolutePath)))) { if (WebContext == null) WebContext = new WebContext(); switch (webHandlerInfo.WebHandlerType) { case WebHandlerTypes.JSONHandler: { var handler = (IJSONHandler)Activator.CreateInstance(webHandlerInfo.HandlerInstance); var jsonReturn = handler.ProcessJSONRequest(WebContext); if (jsonReturn != null && jsonReturn.IsResponseJsonObject) { context.Response.ContentType = "application/json"; //输出JSON对象 context.Response.Write(jsonReturn.HasSetJsonObject ? jsonReturn.JsonObject.ToJson(jsonReturn.JSONCommonFormatHanding) : new { IsSuccess = true }.ToJson(jsonReturn.JSONCommonFormatHanding)); } } break; case WebHandlerTypes.ResourceHandler: break; case WebHandlerTypes.WebAPIHandler: { context.Response.ContentType = "application/json"; var result = new OperationResult() { ResultType = OperationResultType.Success, Message = "操作成功!" }; var handler = (IWebAPI)Activator.CreateInstance(webHandlerInfo.HandlerInstance); handler.OperationResult = result; try { switch (WebContext.HttpContext.Request.HttpMethod) { case "GET": { var paramStrs = WebAPIHelper.GetUrlParams(webHandlerInfo.WebAPIName); if (paramStrs != null && paramStrs.Length > 0) { if (paramStrs.Length > 1) result = handler.Get(paramStrs); else result = handler.Get(paramStrs[0]); } else { result = handler.Get(paramStrs); } //输出JSON对象 context.Response.Write(result.Data.ToJsonWithDateFormatyyyyMMddHHmmss()); return; } case "POST": { result = handler.Post(WebAPIHelper.GetPostJSON()); break; } case "PUT": { var id = WebAPIHelper.GetUrlId(webHandlerInfo.WebAPIName); if (id.IsEmpty()) { result.ResultType = OperationResultType.ParamError; result.Message = "参数错误!"; result.LogMessage = "Id不能为空!"; } result = handler.Put(id, WebAPIHelper.GetPostJSON()); break; } case "DELETE": { var id = WebAPIHelper.GetUrlId(webHandlerInfo.WebAPIName); if (id.IsEmpty()) { result.ResultType = OperationResultType.ParamError; result.Message = "参数错误!"; result.LogMessage = "Id不能为空!"; } result = handler.Delete(id); break; } default: break; } } catch (NotImplementedException ex) { result.ResultType = OperationResultType.NoImplemented; result.Message = "该接口尚未实现!"; result.LogMessage = "该接口尚未实现!"; } catch (Exception ex) { result.ResultType = OperationResultType.Error; result.Message = "意外错误,请联系管理员!"; } //输出JSON对象 context.Response.Write(result.ToJsonWithDateFormatyyyyMMddHHmmss()); } break; default: break; } } }