Ejemplo n.º 1
0
 private void RegisterHandlers(RaspkateConfiguration config)
 {
     if (config.Modules != null && config.Modules.Count > 0)
     {
         var entryAssemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
         foreach (ModuleElement moduleElement in config.Modules)
         {
             var searchPath = moduleElement.IsRelative ?
                              Path.Combine(entryAssemblyPath, moduleElement.Path) :
                              moduleElement.Path;
             if (Directory.Exists(searchPath))
             {
                 foreach (var moduleAssemblyFile in Directory.EnumerateFiles(searchPath, "*.dll", SearchOption.AllDirectories))
                 {
                     try
                     {
                         var moduleAssembly = Assembly.LoadFile(moduleAssemblyFile);
                         if (moduleAssembly != null)
                         {
                             var moduleTypes = from type in moduleAssembly.GetTypes()
                                               where typeof(IRaspkateModule).IsAssignableFrom(type)
                                               select type;
                             foreach (var moduleType in moduleTypes)
                             {
                                 var context = new ModuleContext(entryAssemblyPath, Path.GetDirectoryName(moduleAssemblyFile));
                                 var module  = (IRaspkateModule)Activator.CreateInstance(moduleType, context);
                                 if (module != null && module.RegisteredHandlers != null)
                                 {
                                     foreach (var handler in module.RegisteredHandlers)
                                     {
                                         handler.OnRegistering();
                                         this.handlers.Add(handler);
                                         log.InfoFormat("Handler \"{0}\" registered successfully.", handler.Name);
                                     }
                                 }
                                 else
                                 {
                                     log.WarnFormat("No registered handlers being provided by type \"{0}\", skipping...", moduleType);
                                 }
                             }
                         }
                     }
                     catch (Exception ex)
                     {
                         log.Debug(string.Format("Unable to load assembly from file \"{0}\".", moduleAssemblyFile), ex);
                     }
                 }
             }
             else
             {
                 log.WarnFormat("Specified module path \"{0}\" does not exist.", searchPath);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public RaspkateServer(RaspkateConfiguration configuration)
 {
     this.configuration = configuration;
 }