예제 #1
0
 public void Register(Type type, ControllerAttribute ca, Action <EventActionRegistingArgs> callback = null)
 {
     try
     {
         EventControllerInstanceArgs e = new EventControllerInstanceArgs();
         e.Type = type;
         OnControllerInstance(e);
         if (e.Controller == null)
         {
             Register(Server.Options, type, Activator.CreateInstance(type), ca.BaseUrl, Server, ca, callback);
         }
         else
         {
             Register(Server.Options, type, e.Controller, ca.BaseUrl, Server, ca, callback);
         }
     }
     catch (Exception e_)
     {
         if (Server.EnableLog(EventArgs.LogType.Error))
         {
             string msg = $"{type} controller register error {e_.Message} {e_.StackTrace}";
             Server.Log(EventArgs.LogType.Error, msg);
         }
     }
 }
 public void Register(HttpConfig config, HttpApiServer server, params Assembly[] assemblies)
 {
     foreach (Assembly item in assemblies)
     {
         Type[] types = item.GetTypes();
         foreach (Type type in types)
         {
             ControllerAttribute ca = type.GetCustomAttribute <ControllerAttribute>(false);
             if (ca != null)
             {
                 EventControllerInstanceArgs e = new EventControllerInstanceArgs();
                 e.Type = type;
                 OnControllerInstance(e);
                 if (e.Controller == null)
                 {
                     Register(config, type, Activator.CreateInstance(type), ca.BaseUrl, server, ca);
                 }
                 else
                 {
                     Register(config, type, e.Controller, ca.BaseUrl, server, ca);
                 }
             }
         }
     }
 }
예제 #3
0
        public object GetController(Type type)
        {
            EventControllerInstanceArgs e = new EventControllerInstanceArgs();

            e.Type = type;
            OnControllerInstance(e);
            return(e.Controller);
        }
예제 #4
0
        public object GetController(Type type, IHttpContext context)
        {
            EventControllerInstanceArgs e = new EventControllerInstanceArgs();

            e.Type    = type;
            e.Context = context;
            OnControllerInstance(e);
            return(e.Controller);
        }
예제 #5
0
 public void Register(params Assembly[] assemblies)
 {
     AssembliesLoading?.Invoke(assemblies);
     foreach (Assembly item in assemblies)
     {
         Type[] types = item.GetTypes();
         foreach (Type type in types)
         {
             PMapper mapper = type.GetCustomAttribute <PMapper>(false);
             if (mapper != null)
             {
                 RegisterParameterBinder(mapper.ParameterType, type);
             }
         }
     }
     foreach (Assembly item in assemblies)
     {
         Type[] types = item.GetTypes();
         foreach (Type type in types)
         {
             ControllerAttribute ca = type.GetCustomAttribute <ControllerAttribute>(false);
             if (ca != null)
             {
                 try
                 {
                     EventControllerInstanceArgs e = new EventControllerInstanceArgs();
                     e.Type = type;
                     OnControllerInstance(e);
                     if (e.Controller == null)
                     {
                         Register(Server.Options, type, Activator.CreateInstance(type), ca.BaseUrl, Server, ca, null);
                     }
                     else
                     {
                         Register(Server.Options, type, e.Controller, ca.BaseUrl, Server, ca, null);
                     }
                 }
                 catch (Exception e_)
                 {
                     if (Server.EnableLog(EventArgs.LogType.Error))
                     {
                         string msg = $"{type} controller register error {e_.Message} {e_.StackTrace}";
                         Server.Log(EventArgs.LogType.Error, msg);
                     }
                 }
             }
         }
     }
 }
예제 #6
0
 protected virtual void OnControllerInstance(EventControllerInstanceArgs e)
 {
     ControllerInstance?.Invoke(this, e);
 }