Esempio n. 1
0
        /*protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
         * {
         *  var isSuspending = powerStatus == PowerBroadcastStatus.Suspend;
         *  var isResuming = powerStatus == PowerBroadcastStatus.ResumeSuspend;
         *
         *  Logger.Debug($"Changing power state: {powerStatus}, isSuspending: {isSuspending}, isResuming: {isResuming}");
         *
         *  if (isSuspending)
         *  {
         *      _engine.Stop();
         *  }
         *  else if (isResuming)
         *  {
         *      var isRunning = _settingsService.GetSetting<bool>(Globals.SettingKeys.IsEngineRunning);
         *
         *      if (isRunning)
         *      {
         *          var delay = _settingsService.GetSetting<int>(Globals.SettingKeys.ResumeDelay);
         *
         *          Logger.Debug($"Delaying for {delay} seconds before starting the engine.");
         *
         *          Task.Run(async () =>
         *          {
         *              await Task.Delay(delay * 1000).ConfigureAwait(false);
         *              _engine.Start();
         *          }).ConfigureAwait(false);
         *      }
         *  }
         *
         *  if (isSuspending || isResuming)
         *  {
         *      PowerEvents.OnPowerStateChanged(new PowerStateEventArgs(isSuspending, isResuming));
         *  }
         *
         *  return base.OnPowerEvent(powerStatus);
         * }*/

        private void LoadPlugins(IContainerProvider container)
        {
            Logger.Info("Loading plugins");

            _plugins.Clear();

            _plugins.Add(new EngineModule());
            _plugins.Add(new InfrastructureModule());

            var executingFile = new FileInfo(Assembly.GetExecutingAssembly().Location);

            foreach (var moduleFile in executingFile.Directory.GetFiles(Globals.PluginSearchPattern))
            {
                try
                {
                    var assembly    = Assembly.LoadFile(moduleFile.FullName);
                    var moduleTypes = assembly.GetExportedTypes().Where(t => typeof(IEngineModule).IsAssignableFrom(t));
                    container.RegisterSingletons <IEngineModule>(moduleTypes);
                    var modules = container.ResolveAll <IEngineModule>();
                    foreach (var engineModule in modules)
                    {
                        _plugins.Add(engineModule);
                        Logger.Info($"Loading plugin {engineModule.GetType().AssemblyQualifiedName}");
                    }
                }
                catch (Exception ex)
                {
                    Logger.Debug(ex);
                }
            }

            foreach (var engineModule in _plugins)
            {
                engineModule.RegisterTypes(container);
            }

            foreach (var engineModule in _plugins)
            {
                engineModule.OnInitialized(container);
            }

            Logger.Info("Plugins loaded");
        }
 public static IEnumerable <T> ResolveAll <T>(this IContainerProvider container)
 {
     return(container.ResolveAll(typeof(T)).Cast <T>());
 }