internal static async Task <MiddlewareData> RouteAsync(MiddlewareData Data) { for (int j = (int)MiddlewarePriority.Crital; j <= (int)MiddlewarePriority.Low; j++) { MiddlewarePriority p = (MiddlewarePriority)j; if (Middlewares.ContainsKey(p)) { for (int i = 0; i < Middlewares[p].Count; i++) { var Middleware = Middlewares[p][i]; try { var data = await Middleware.Start(Data); if (data != null) { Data = data; } if (data.IsAbort) { return(data); } } catch (Exception ex) { throw new MiddlewareException(Middleware, ex); } } } } return(Data); }
public static bool Add(IMiddleware MiddleWare, string Name, MiddlewarePriority Priority = MiddlewarePriority.Normal) { string name = Name == null?MiddleWare.GetType().Name : Name; try { MiddleWare.Attach(Language); if (!Middlewares.ContainsKey(Priority)) { Middlewares.Add(Priority, new List <IMiddleware>()); } Middlewares[Priority].Add(MiddleWare); Adding?.Invoke(string.Format("[{0}] MiddleWare: {{ {1} ({2}) }}, Priority={3} }}", Language["STR_SUCCESS"], name, MiddleWare.GetType().Name, Priority), null); return(true); } catch (Exception ex) { Adding?.Invoke(string.Format("[{0}] MiddleWare: {{ {1} ({2}) }}, Priority={3} }} ({4})", Language["STR_ERROR"], name, MiddleWare.GetType().Name, Priority, ex.Message), null); return(false); } }
/// <summary> /// /// </summary> /// <param name="Name">미들웨어 이름</param> /// <param name="Priority">미들웨어 등록(초기화) 우선순위</param> /// <param name="AutoRegister">미들웨어 초기화시 자동 등록 여부</param> public MiddlewareAttribute(string Name, MiddlewarePriority Priority = MiddlewarePriority.Normal, bool AutoRegister = true) { this.Name = Name; this.Priority = Priority; this.AutoRegister = AutoRegister; ID = (uint)Random.Next(int.MinValue, int.MaxValue); }