Exemple #1
0
        private static void ExecuteProcess(HttpListenerContext context, Message message)
        {
            Logger.DebugFormat("Entry Url={0}", context.Request.Url);
            IModule module = null;
            try
            {
                // Reflection
                var plusRoute = new HttpRoute
                {
                    Host = "+",
                    Path = context.Request.Url.LocalPath,
                    Port = context.Request.Url.Port
                };
                var route = new HttpRoute
                {
                    Host = context.Request.Url.Host,
                    Path = context.Request.Url.LocalPath,
                    Port = context.Request.Url.Port
                };
                Type type;
                if (!RoutesConfig.ConfiguredRoutes.TryGetValue(plusRoute, out type))
                    if (!RoutesConfig.ConfiguredRoutes.TryGetValue(route, out type))
                    {
                        throw new ModuleConfigurationException(String.Format("Could not find module for route={0}", route), null);
                    }

                Logger.DebugFormat("Configured Module={0}", type.FullName);
                var ctor = type.GetConstructor(new Type[0]);
                module = (IModule) ctor.Invoke(new object[0]);

                // Process
                Logger.DebugFormat("Message process executing.");
                module.Process(message);
                Logger.DebugFormat("Message process performed.");
            }
            catch (Exception e)
            {
                Logger.Error(message.ToString(), e);
                if (module != null)
                    module.ExceptionHandling(e, message);
                else
                    message.SetPayload(e.ToString());
            }
        }
Exemple #2
0
 public static void AddRoute(HttpRoute httpRoute, Type type)
 {
     if(httpRoute == null) return;
     ConfiguredRoutes[httpRoute] = type;
 }
 public ModuleConfiguration()
 {
     ModuleHttpRoute = new HttpRoute();
     PollingTimer = new Timer();
 }