From d77c78f3ca43b79f5d67eca6997acd29e96b9771 Mon Sep 17 00:00:00 2001 From: Inga Lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Fri, 21 Aug 2020 21:45:45 +0300 Subject: [PATCH] Refactored MainHandler --- RadeonResetBugFixService/MainHandler.cs | 86 +------------------ RadeonResetBugFixService/Program.cs | 25 +++--- .../RadeonResetBugFixService.cs | 51 ++++------- .../RadeonResetBugFixService.csproj | 31 ++++--- .../{ => BasicTasks}/AbstractDevicesTask.cs | 2 +- .../{ => BasicTasks}/AbstractServiceTask.cs | 2 +- .../{ => BasicTasks}/DisableAmdVideoTask.cs | 2 +- .../DisableBasicDisplayStartupTask.cs | 2 +- .../DisableVirtualVideoTask.cs | 2 +- .../{ => BasicTasks}/EnableAmdVideoTask.cs | 2 +- .../EnableBasicDisplayStartupTask.cs | 2 +- .../EnableVirtualVideoTask.cs | 2 +- .../Tasks/{ => BasicTasks}/FixMonitorTask.cs | 2 +- .../LastResortDevicesRestoreTask.cs | 2 +- .../Tasks/{ => BasicTasks}/ListDevicesTask.cs | 2 +- .../Tasks/{ => BasicTasks}/SleepTask.cs | 2 +- .../{ => BasicTasks}/StopAudioServiceTask.cs | 2 +- .../ComplexTasks/AbstractSequentialTask.cs | 13 +++ .../Tasks/ComplexTasks/DiagnoseTask.cs | 16 ++++ .../Tasks/ComplexTasks/ShutdownTask.cs | 25 ++++++ .../Tasks/ComplexTasks/StartupTask.cs | 25 ++++++ RadeonResetBugFixService/TasksProcessor.cs | 2 +- 22 files changed, 145 insertions(+), 155 deletions(-) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/AbstractDevicesTask.cs (98%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/AbstractServiceTask.cs (98%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/DisableAmdVideoTask.cs (87%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/DisableBasicDisplayStartupTask.cs (96%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/DisableVirtualVideoTask.cs (88%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/EnableAmdVideoTask.cs (87%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/EnableBasicDisplayStartupTask.cs (88%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/EnableVirtualVideoTask.cs (88%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/FixMonitorTask.cs (96%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/LastResortDevicesRestoreTask.cs (98%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/ListDevicesTask.cs (92%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/SleepTask.cs (88%) rename RadeonResetBugFixService/Tasks/{ => BasicTasks}/StopAudioServiceTask.cs (87%) create mode 100644 RadeonResetBugFixService/Tasks/ComplexTasks/AbstractSequentialTask.cs create mode 100644 RadeonResetBugFixService/Tasks/ComplexTasks/DiagnoseTask.cs create mode 100644 RadeonResetBugFixService/Tasks/ComplexTasks/ShutdownTask.cs create mode 100644 RadeonResetBugFixService/Tasks/ComplexTasks/StartupTask.cs diff --git a/RadeonResetBugFixService/MainHandler.cs b/RadeonResetBugFixService/MainHandler.cs index 0e0e7cd..d95d051 100644 --- a/RadeonResetBugFixService/MainHandler.cs +++ b/RadeonResetBugFixService/MainHandler.cs @@ -24,97 +24,17 @@ $"radeonfix_{date:yyyyMMdd}_{date:HHmmss}.log"); } - public void HandleLog(string message) - { - using (ILogger fileLogger = new FileLogger(this.LogFilename)) - { - fileLogger.Log(message); - } - } - - public void HandleStartup(string reason) - { - using (var fileLogger = new FileLogger(this.LogFilename)) - { - using (ILogger logger = new TaskLoggerWrapper(fileLogger, "Startup")) - { - logger.Log($"Reason: {reason}"); - try - { - lock (this.Mutex) - { - TasksProcessor.ProcessTasks( - logger, - new ITask[] - { - new EnableBasicDisplayStartupTask(), - new SleepTask(TimeSpan.FromSeconds(40)), - new EnableAmdVideoTask(this.StartupDevicesStatus), - new DisableVirtualVideoTask(this.StartupDevicesStatus), - new SleepTask(TimeSpan.FromSeconds(20)), - new FixMonitorTask(), - new DisableVirtualVideoTask(this.StartupDevicesStatus), - new FixMonitorTask(), - }); - } - } - catch (Exception e) - { - logger.LogError(e.ToString()); - } - } - } - } - - public void HandleShutdown(string reason) - { - using (var fileLogger = new FileLogger(this.LogFilename)) - { - using (ILogger logger = new TaskLoggerWrapper(fileLogger, "Shutdown")) - { - logger.Log($"Reason: {reason}"); - try - { - lock (this.Mutex) - { - TasksProcessor.ProcessTasks( - logger, - new ITask[] - { - new StopAudioServiceTask(), - new EnableVirtualVideoTask(this.ShutdownDevicesStatus), - new DisableAmdVideoTask(this.ShutdownDevicesStatus), - new LastResortDevicesRestoreTask(this.StartupDevicesStatus), - new LastResortDevicesRestoreTask(this.StartupDevicesStatus), // just in case - new DisableBasicDisplayStartupTask(this.StartupDevicesStatus), - }); - } - } - catch (Exception e) - { - logger.LogError(e.ToString()); - } - } - } - } - - public void HandleDiagnose(string reason) + public void HandleEntryPoint(string name, Action handle) { using (var fileLogger = new FileLogger(this.LogFilename)) { - using (ILogger logger = new TaskLoggerWrapper(fileLogger, "Diagnose")) + using (ILogger logger = new TaskLoggerWrapper(fileLogger, name)) { - logger.Log($"Reason: {reason}"); try { lock (this.Mutex) { - TasksProcessor.ProcessTasks( - logger, - new ITask[] - { - new ListDevicesTask(), - }); + handle(logger); } } catch (Exception e) diff --git a/RadeonResetBugFixService/Program.cs b/RadeonResetBugFixService/Program.cs index 873fee2..6163390 100644 --- a/RadeonResetBugFixService/Program.cs +++ b/RadeonResetBugFixService/Program.cs @@ -2,6 +2,7 @@ { using System; using System.ServiceProcess; + using Tasks.ComplexTasks; using ThirdParty.ServiceHelpers; public static class Program @@ -133,19 +134,19 @@ DoInstall(); } - private static void DoStartup() - { - new MainHandler().HandleStartup("Program.DoStartup"); - } + private static void DoStartup() => new MainHandler().HandleEntryPoint( + "Program.DoStartup", + (logger) => TasksProcessor.ProcessTask(logger, new StartupTask()) + ); - private static void DoShutdown() - { - new MainHandler().HandleShutdown("Program.DoShutdown"); - } + private static void DoShutdown() => new MainHandler().HandleEntryPoint( + "Program.DoShutdown", + (logger) => TasksProcessor.ProcessTask(logger, new ShutdownTask()) + ); - private static void DoDiagnose() - { - new MainHandler().HandleDiagnose("Program.DoDiagnose"); - } + private static void DoDiagnose() => new MainHandler().HandleEntryPoint( + "Program.DoDiagnose", + (logger) => TasksProcessor.ProcessTask(logger, new DiagnoseTask()) + ); } } diff --git a/RadeonResetBugFixService/RadeonResetBugFixService.cs b/RadeonResetBugFixService/RadeonResetBugFixService.cs index 9062787..42c76e8 100644 --- a/RadeonResetBugFixService/RadeonResetBugFixService.cs +++ b/RadeonResetBugFixService/RadeonResetBugFixService.cs @@ -4,6 +4,7 @@ using System.Reflection; using System.ServiceProcess; using Microsoft.Win32; + using Tasks.ComplexTasks; public partial class RadeonResetBugFixService : ServiceBase { @@ -35,38 +36,22 @@ deferredStopMethodInfo.Invoke(this, null); } - private void Process(string reason, Action handle) - { - this.Handler.HandleLog($"{reason} initiated"); - try - { - handle(reason); - this.Handler.HandleLog($"{reason} successfully finished"); - } - catch (Exception e) - { - this.Handler.HandleLog($"{reason} error: {e}"); - } - } - protected override void OnShutdown() { - this.Process( + this.Handler.HandleEntryPoint( "ServiceBase.OnShutdown", - (string reason) => - { - this.CallStop(); - }); + (logger) => this.CallStop() + ); } protected override void OnStart(string[] args) { - this.Process( + this.Handler.HandleEntryPoint( "ServiceBase.OnStart", - (string reason) => + (logger) => { this.RequestAdditionalTime((int)Constants.ServiceTimeout.TotalMilliseconds); - this.Handler.HandleStartup(reason); + TasksProcessor.ProcessTask(logger, new StartupTask()); this.EnablePreshutdown(); SystemEvents.SessionEnding += this.OnSessionEnding; }); @@ -74,12 +59,12 @@ protected override void OnStop() { - this.Process( + this.Handler.HandleEntryPoint( "ServiceBase.OnStop", - (string reason) => + (logger) => { this.RequestAdditionalTime((int)Constants.ServiceTimeout.TotalMilliseconds); - this.Handler.HandleShutdown(reason); + TasksProcessor.ProcessTask(logger, new ShutdownTask()); SystemEvents.SessionEnding -= this.OnSessionEnding; }); } @@ -88,33 +73,33 @@ { const int SERVICE_CONTROL_PRESHUTDOWN = 0xf; - this.Process( + this.Handler.HandleEntryPoint( "ServiceBase.OnCustomCommand", - (string reason) => + (logger) => { if (command == SERVICE_CONTROL_PRESHUTDOWN) { - this.Handler.HandleLog($"Custom command: preshutdown"); + logger.Log("Custom command: preshutdown"); this.CallStop(); } else { - this.Handler.HandleLog($"Unknown custom command: {command}"); + logger.Log("Unknown custom command: {command}"); } }); } private void OnSessionEnding(object sender, SessionEndingEventArgs args) { - this.Process( + this.Handler.HandleEntryPoint( "SystemEvents.OnSessionEnding", - (string reason) => + (logger) => { - this.Handler.HandleLog($"Session end reason: ${args.Reason}"); + logger.Log($"Session end reason: ${args.Reason}"); if (args.Reason == SessionEndReasons.SystemShutdown) { - this.Handler.HandleShutdown(reason); + TasksProcessor.ProcessTask(logger, new ShutdownTask()); } }); } diff --git a/RadeonResetBugFixService/RadeonResetBugFixService.csproj b/RadeonResetBugFixService/RadeonResetBugFixService.csproj index eceb122..2f340fc 100644 --- a/RadeonResetBugFixService/RadeonResetBugFixService.csproj +++ b/RadeonResetBugFixService/RadeonResetBugFixService.csproj @@ -85,23 +85,27 @@ - - - - - - + + + + + + + + + + - - - - - - + + + + + + - + @@ -131,6 +135,7 @@ + diff --git a/RadeonResetBugFixService/Tasks/AbstractDevicesTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/AbstractDevicesTask.cs similarity index 98% rename from RadeonResetBugFixService/Tasks/AbstractDevicesTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/AbstractDevicesTask.cs index 230e86b..e58e5a1 100644 --- a/RadeonResetBugFixService/Tasks/AbstractDevicesTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/AbstractDevicesTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using System; using System.Linq; diff --git a/RadeonResetBugFixService/Tasks/AbstractServiceTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/AbstractServiceTask.cs similarity index 98% rename from RadeonResetBugFixService/Tasks/AbstractServiceTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/AbstractServiceTask.cs index fb3eb4b..86f1cfb 100644 --- a/RadeonResetBugFixService/Tasks/AbstractServiceTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/AbstractServiceTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using System; using System.ServiceProcess; diff --git a/RadeonResetBugFixService/Tasks/DisableAmdVideoTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/DisableAmdVideoTask.cs similarity index 87% rename from RadeonResetBugFixService/Tasks/DisableAmdVideoTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/DisableAmdVideoTask.cs index ff977c8..6def5ca 100644 --- a/RadeonResetBugFixService/Tasks/DisableAmdVideoTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/DisableAmdVideoTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using Contracts; using Devices; diff --git a/RadeonResetBugFixService/Tasks/DisableBasicDisplayStartupTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/DisableBasicDisplayStartupTask.cs similarity index 96% rename from RadeonResetBugFixService/Tasks/DisableBasicDisplayStartupTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/DisableBasicDisplayStartupTask.cs index 6456de3..3cbd906 100644 --- a/RadeonResetBugFixService/Tasks/DisableBasicDisplayStartupTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/DisableBasicDisplayStartupTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using System; using Contracts; diff --git a/RadeonResetBugFixService/Tasks/DisableVirtualVideoTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/DisableVirtualVideoTask.cs similarity index 88% rename from RadeonResetBugFixService/Tasks/DisableVirtualVideoTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/DisableVirtualVideoTask.cs index 4351e28..7adeb9c 100644 --- a/RadeonResetBugFixService/Tasks/DisableVirtualVideoTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/DisableVirtualVideoTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using Contracts; using Devices; diff --git a/RadeonResetBugFixService/Tasks/EnableAmdVideoTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/EnableAmdVideoTask.cs similarity index 87% rename from RadeonResetBugFixService/Tasks/EnableAmdVideoTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/EnableAmdVideoTask.cs index 723f75c..16fa751 100644 --- a/RadeonResetBugFixService/Tasks/EnableAmdVideoTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/EnableAmdVideoTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using Contracts; using Devices; diff --git a/RadeonResetBugFixService/Tasks/EnableBasicDisplayStartupTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/EnableBasicDisplayStartupTask.cs similarity index 88% rename from RadeonResetBugFixService/Tasks/EnableBasicDisplayStartupTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/EnableBasicDisplayStartupTask.cs index 6e5a001..3afc4f9 100644 --- a/RadeonResetBugFixService/Tasks/EnableBasicDisplayStartupTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/EnableBasicDisplayStartupTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using Contracts; diff --git a/RadeonResetBugFixService/Tasks/EnableVirtualVideoTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/EnableVirtualVideoTask.cs similarity index 88% rename from RadeonResetBugFixService/Tasks/EnableVirtualVideoTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/EnableVirtualVideoTask.cs index ddbfdf0..f4d6e01 100644 --- a/RadeonResetBugFixService/Tasks/EnableVirtualVideoTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/EnableVirtualVideoTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using Contracts; using Devices; diff --git a/RadeonResetBugFixService/Tasks/FixMonitorTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/FixMonitorTask.cs similarity index 96% rename from RadeonResetBugFixService/Tasks/FixMonitorTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/FixMonitorTask.cs index 8e12ab3..6e72c56 100644 --- a/RadeonResetBugFixService/Tasks/FixMonitorTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/FixMonitorTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using System; using System.Collections.Generic; diff --git a/RadeonResetBugFixService/Tasks/LastResortDevicesRestoreTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/LastResortDevicesRestoreTask.cs similarity index 98% rename from RadeonResetBugFixService/Tasks/LastResortDevicesRestoreTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/LastResortDevicesRestoreTask.cs index 4bd553d..26aa77d 100644 --- a/RadeonResetBugFixService/Tasks/LastResortDevicesRestoreTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/LastResortDevicesRestoreTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using System; using Contracts; diff --git a/RadeonResetBugFixService/Tasks/ListDevicesTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/ListDevicesTask.cs similarity index 92% rename from RadeonResetBugFixService/Tasks/ListDevicesTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/ListDevicesTask.cs index 505a11d..7bcf413 100644 --- a/RadeonResetBugFixService/Tasks/ListDevicesTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/ListDevicesTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using System.Linq; using Contracts; diff --git a/RadeonResetBugFixService/Tasks/SleepTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/SleepTask.cs similarity index 88% rename from RadeonResetBugFixService/Tasks/SleepTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/SleepTask.cs index 5f8de2e..8f92e80 100644 --- a/RadeonResetBugFixService/Tasks/SleepTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/SleepTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using System; using System.Threading; diff --git a/RadeonResetBugFixService/Tasks/StopAudioServiceTask.cs b/RadeonResetBugFixService/Tasks/BasicTasks/StopAudioServiceTask.cs similarity index 87% rename from RadeonResetBugFixService/Tasks/StopAudioServiceTask.cs rename to RadeonResetBugFixService/Tasks/BasicTasks/StopAudioServiceTask.cs index a304377..7c0735b 100644 --- a/RadeonResetBugFixService/Tasks/StopAudioServiceTask.cs +++ b/RadeonResetBugFixService/Tasks/BasicTasks/StopAudioServiceTask.cs @@ -1,4 +1,4 @@ -namespace RadeonResetBugFixService.Tasks +namespace RadeonResetBugFixService.Tasks.BasicTasks { using System; using System.ServiceProcess; diff --git a/RadeonResetBugFixService/Tasks/ComplexTasks/AbstractSequentialTask.cs b/RadeonResetBugFixService/Tasks/ComplexTasks/AbstractSequentialTask.cs new file mode 100644 index 0000000..5c3eabf --- /dev/null +++ b/RadeonResetBugFixService/Tasks/ComplexTasks/AbstractSequentialTask.cs @@ -0,0 +1,13 @@ +namespace RadeonResetBugFixService.Tasks.ComplexTasks +{ + using Contracts; + + abstract class AbstractSequentialTask : ITask + { + public abstract string TaskName { get; } + + protected abstract ITask[] Subtasks { get; } + + void ITask.Run(ILogger logger) => TasksProcessor.ProcessTasks(logger, this.Subtasks); + } +} diff --git a/RadeonResetBugFixService/Tasks/ComplexTasks/DiagnoseTask.cs b/RadeonResetBugFixService/Tasks/ComplexTasks/DiagnoseTask.cs new file mode 100644 index 0000000..cfbfdd4 --- /dev/null +++ b/RadeonResetBugFixService/Tasks/ComplexTasks/DiagnoseTask.cs @@ -0,0 +1,16 @@ +namespace RadeonResetBugFixService.Tasks.ComplexTasks +{ + using BasicTasks; + using Contracts; + using System; + + class DiagnoseTask : AbstractSequentialTask + { + public override string TaskName => "Diagnose"; + + protected override ITask[] Subtasks => new ITask[] + { + new ListDevicesTask(), + }; + } +} diff --git a/RadeonResetBugFixService/Tasks/ComplexTasks/ShutdownTask.cs b/RadeonResetBugFixService/Tasks/ComplexTasks/ShutdownTask.cs new file mode 100644 index 0000000..ca88bf8 --- /dev/null +++ b/RadeonResetBugFixService/Tasks/ComplexTasks/ShutdownTask.cs @@ -0,0 +1,25 @@ +namespace RadeonResetBugFixService.Tasks.ComplexTasks +{ + using BasicTasks; + using Contracts; + using System; + + class ShutdownTask : AbstractSequentialTask + { + private DevicesStatus ShutdownDevicesStatus { get; } = new DevicesStatus(); + + public override string TaskName => "Shutdown"; + + protected override ITask[] Subtasks => new ITask[] + { + new EnableBasicDisplayStartupTask(), + new SleepTask(TimeSpan.FromSeconds(40)), + new EnableAmdVideoTask(this.ShutdownDevicesStatus), + new DisableVirtualVideoTask(this.ShutdownDevicesStatus), + new SleepTask(TimeSpan.FromSeconds(20)), + new FixMonitorTask(), + new DisableVirtualVideoTask(this.ShutdownDevicesStatus), + new FixMonitorTask() + }; + } +} diff --git a/RadeonResetBugFixService/Tasks/ComplexTasks/StartupTask.cs b/RadeonResetBugFixService/Tasks/ComplexTasks/StartupTask.cs new file mode 100644 index 0000000..a218276 --- /dev/null +++ b/RadeonResetBugFixService/Tasks/ComplexTasks/StartupTask.cs @@ -0,0 +1,25 @@ +namespace RadeonResetBugFixService.Tasks.ComplexTasks +{ + using BasicTasks; + using Contracts; + using System; + + class StartupTask : AbstractSequentialTask + { + private DevicesStatus StartupDevicesStatus { get; } = new DevicesStatus(); + + public override string TaskName => "Startup"; + + protected override ITask[] Subtasks => new ITask[] + { + new EnableBasicDisplayStartupTask(), + new SleepTask(TimeSpan.FromSeconds(40)), + new EnableAmdVideoTask(this.StartupDevicesStatus), + new DisableVirtualVideoTask(this.StartupDevicesStatus), + new SleepTask(TimeSpan.FromSeconds(20)), + new FixMonitorTask(), + new DisableVirtualVideoTask(this.StartupDevicesStatus), + new FixMonitorTask() + }; + } +} diff --git a/RadeonResetBugFixService/TasksProcessor.cs b/RadeonResetBugFixService/TasksProcessor.cs index 2b9c706..2840e81 100644 --- a/RadeonResetBugFixService/TasksProcessor.cs +++ b/RadeonResetBugFixService/TasksProcessor.cs @@ -8,7 +8,7 @@ static class TasksProcessor { - private static void ProcessTask(ILogger logger, ITask task) + public static void ProcessTask(ILogger logger, ITask task) { using (ILogger taskLogger = new TaskLoggerWrapper(logger, task.TaskName)) {