/// <summary> /// Called when the service starts. /// </summary> /// <param name="args">The arguments.</param> protected override void OnStart(string[] args) { if (!AllowMultipleServiceStarts && !IsNewInstance) { return; } Modules = null; var assemblyFileLocation = Assembly.GetExecutingAssembly().Location; var assemblyFileInfo = new FileInfo(assemblyFileLocation); var path = assemblyFileInfo.Directory?.FullName; if (path == null) { return; } var executableDirectory = new DirectoryInfo(path); var moduleDirectory = new DirectoryInfo(Path.Combine(executableDirectory.FullName, "Modules")); using (var catalog = new AggregateCatalog(new DirectoryCatalog(executableDirectory.FullName))) { if (moduleDirectory.Exists) { catalog.Catalogs.Add(new DirectoryCatalog(moduleDirectory.FullName)); } using (var container = new CompositionContainer(catalog)) { container.ComposeParts(this); Modules = container.GetExportedValues <IServiceModule>(); } } Modules?.AsParallel().ForAll(w => w.OnStartAsync(args)); }
/// <summary> /// Called when the service stops. /// </summary> protected override void OnStop() { Modules?.AsParallel().ForAll(w => w.OnStopAsync()); }
/// <summary> /// Called when the service is paused. /// </summary> protected override void OnPause() { Modules?.AsParallel().ForAll(w => w.OnPauseAsync()); }
/// <summary> /// Called when service shutdown is encountered.. /// </summary> protected override void OnShutdown() { Modules?.AsParallel().ForAll(w => w.OnShutdownAsync()); }
/// <summary> /// Called when a custom command is encountered. /// </summary> /// <param name="command">The command code.</param> protected override void OnCustomCommand(int command) { Modules?.AsParallel().ForAll(w => w.OnCustomCommandAsync(command)); }