Пример #1
0
 private void LoadController(IApplication application)
 {
     Utils.LoadAssembly(a =>
     {
         foreach (Type type in a.GetTypes())
         {
             if (IKende.IKendeCore.GetTypeAttributes <ControllerAttribute>(type, false).Length > 0 && !type.IsAbstract)
             {
                 "load {0} controller".Log4Info(type);
                 object controller = Activator.CreateInstance(type);
                 Controllers.Add(controller);
                 foreach (System.Reflection.MethodInfo method in type.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
                 {
                     try
                     {
                         ParameterInfo[] pis = method.GetParameters();
                         if (pis.Length == 2 && (pis[0].ParameterType == typeof(ISession)))
                         {
                             IMethodHandler handler = new MethodHandler(controller, method, application);
                             mControllerHandlers[pis[1].ParameterType] = handler;
                             "load {0}->{1} action success".Log4Info(type, method.Name);
                         }
                     }
                     catch (Exception e_)
                     {
                         "load {0}->{1} action error".Log4Error(e_, type, method.Name);
                     }
                 }
             }
         }
     });
 }
Пример #2
0
 private void LoadSoa(IApplication application)
 {
     Utils.LoadAssembly(a =>
     {
         foreach (Type type in a.GetTypes())
         {
             SOAServiceAttribute[] soa = IKende.IKendeCore.GetTypeAttributes <SOAServiceAttribute>(type, false);
             if (soa.Length > 0 && !type.IsAbstract)
             {
                 foreach (Type itype in soa[0].Services)
                 {
                     if (itype.IsInterface)
                     {
                         object service = Activator.CreateInstance(type);
                         foreach (MethodInfo method in itype.GetMembers())
                         {
                             StringBuilder key = new StringBuilder();
                             List <Type> pst   = new List <Type>();
                             key.Append(itype.Name).Append(".").Append(method.Name);
                             key.Append("(");
                             ParameterInfo[] pis = method.GetParameters();
                             for (int i = 0; i < pis.Length; i++)
                             {
                                 pst.Add(pis[i].ParameterType);
                                 if (i > 0)
                                 {
                                     key.Append(",");
                                 }
                                 key.Append(pis[i].ParameterType.Name);
                             }
                             key.Append(")");
                             MethodInfo implMethod = service.GetType().GetMethod(method.Name, pst.ToArray());
                             if (implMethod != null)
                             {
                                 MethodHandler handler        = new MethodHandler(service, implMethod, mApplication);
                                 handler.Parameters           = implMethod.GetParameters();
                                 mSoaHandlers[key.ToString()] = handler;
                             }
                             "Load SOA Service {0}".Log4Info(key);
                         }
                     }
                 }
             }
         }
     });
 }
Пример #3
0
 private void Register(object service, SOAServiceAttribute[] soa)
 {
     if (soa.Length > 0)
     {
         foreach (Type itype in soa[0].Services)
         {
             if (itype.IsInterface)
             {
                 foreach (MethodInfo method in itype.GetMembers())
                 {
                     StringBuilder key = new StringBuilder();
                     List <Type>   pst = new List <Type>();
                     key.Append(itype.Name).Append(".").Append(method.Name);
                     key.Append("(");
                     ParameterInfo[] pis = method.GetParameters();
                     for (int i = 0; i < pis.Length; i++)
                     {
                         pst.Add(pis[i].ParameterType);
                         if (i > 0)
                         {
                             key.Append(",");
                         }
                         key.Append(pis[i].ParameterType.Name);
                     }
                     key.Append(")");
                     MethodInfo implMethod = service.GetType().GetMethod(method.Name, pst.ToArray());
                     if (implMethod != null)
                     {
                         MethodHandler handler = new MethodHandler {
                             Obj = service, Method = implMethod, Parameters = pis
                         };
                         mHandlers[key.ToString()] = handler;
                     }
                 }
             }
         }
     }
 }