From c9900e6afff8dfb020040d4d1bb3d39d08ce72bb Mon Sep 17 00:00:00 2001
From: Inga Lovinde <52715130+inga-lovinde@users.noreply.github.com>
Date: Fri, 21 Aug 2020 22:22:35 +0300
Subject: [PATCH] Fixed shutdown task
---
.../Contracts/ServiceContext.cs | 9 ++++++++
RadeonResetBugFixService/Program.cs | 5 +++--
.../RadeonResetBugFixService.cs | 9 +++++---
.../RadeonResetBugFixService.csproj | 1 +
.../Tasks/ComplexTasks/ShutdownTask.cs | 21 +++++++++++--------
.../Tasks/ComplexTasks/StartupTask.cs | 13 ++++++++----
6 files changed, 40 insertions(+), 18 deletions(-)
create mode 100644 RadeonResetBugFixService/Contracts/ServiceContext.cs
diff --git a/RadeonResetBugFixService/Contracts/ServiceContext.cs b/RadeonResetBugFixService/Contracts/ServiceContext.cs
new file mode 100644
index 0000000..bfa9abf
--- /dev/null
+++ b/RadeonResetBugFixService/Contracts/ServiceContext.cs
@@ -0,0 +1,9 @@
+namespace RadeonResetBugFixService.Contracts
+{
+ class ServiceContext
+ {
+ public DevicesStatus StartupDevicesStatus { get; } = new DevicesStatus();
+
+ public DevicesStatus ShutdownDevicesStatus { get; } = new DevicesStatus();
+ }
+}
diff --git a/RadeonResetBugFixService/Program.cs b/RadeonResetBugFixService/Program.cs
index 1dea901..f27c7fc 100644
--- a/RadeonResetBugFixService/Program.cs
+++ b/RadeonResetBugFixService/Program.cs
@@ -2,6 +2,7 @@
{
using System;
using System.ServiceProcess;
+ using Contracts;
using Tasks.ComplexTasks;
using ThirdParty.ServiceHelpers;
@@ -138,12 +139,12 @@
private static void DoStartup() => new MainHandler().HandleEntryPoint(
"Program.DoStartup",
- (logger) => TasksProcessor.ProcessTask(logger, new StartupTask())
+ (logger) => TasksProcessor.ProcessTask(logger, new StartupTask(new ServiceContext()))
);
private static void DoShutdown() => new MainHandler().HandleEntryPoint(
"Program.DoShutdown",
- (logger) => TasksProcessor.ProcessTask(logger, new ShutdownTask())
+ (logger) => TasksProcessor.ProcessTask(logger, new ShutdownTask(new ServiceContext()))
);
private static void DoDiagnose() => new MainHandler().HandleEntryPoint(
diff --git a/RadeonResetBugFixService/RadeonResetBugFixService.cs b/RadeonResetBugFixService/RadeonResetBugFixService.cs
index 42c76e8..190413d 100644
--- a/RadeonResetBugFixService/RadeonResetBugFixService.cs
+++ b/RadeonResetBugFixService/RadeonResetBugFixService.cs
@@ -4,10 +4,13 @@
using System.Reflection;
using System.ServiceProcess;
using Microsoft.Win32;
+ using Contracts;
using Tasks.ComplexTasks;
public partial class RadeonResetBugFixService : ServiceBase
{
+ private ServiceContext Context { get; } = new ServiceContext();
+
private MainHandler Handler { get; } = new MainHandler();
public RadeonResetBugFixService()
@@ -51,7 +54,7 @@
(logger) =>
{
this.RequestAdditionalTime((int)Constants.ServiceTimeout.TotalMilliseconds);
- TasksProcessor.ProcessTask(logger, new StartupTask());
+ TasksProcessor.ProcessTask(logger, new StartupTask(this.Context));
this.EnablePreshutdown();
SystemEvents.SessionEnding += this.OnSessionEnding;
});
@@ -64,7 +67,7 @@
(logger) =>
{
this.RequestAdditionalTime((int)Constants.ServiceTimeout.TotalMilliseconds);
- TasksProcessor.ProcessTask(logger, new ShutdownTask());
+ TasksProcessor.ProcessTask(logger, new ShutdownTask(this.Context));
SystemEvents.SessionEnding -= this.OnSessionEnding;
});
}
@@ -99,7 +102,7 @@
if (args.Reason == SessionEndReasons.SystemShutdown)
{
- TasksProcessor.ProcessTask(logger, new ShutdownTask());
+ TasksProcessor.ProcessTask(logger, new ShutdownTask(this.Context));
}
});
}
diff --git a/RadeonResetBugFixService/RadeonResetBugFixService.csproj b/RadeonResetBugFixService/RadeonResetBugFixService.csproj
index dc9e6df..c584c29 100644
--- a/RadeonResetBugFixService/RadeonResetBugFixService.csproj
+++ b/RadeonResetBugFixService/RadeonResetBugFixService.csproj
@@ -61,6 +61,7 @@
+
diff --git a/RadeonResetBugFixService/Tasks/ComplexTasks/ShutdownTask.cs b/RadeonResetBugFixService/Tasks/ComplexTasks/ShutdownTask.cs
index ca88bf8..7a62ac2 100644
--- a/RadeonResetBugFixService/Tasks/ComplexTasks/ShutdownTask.cs
+++ b/RadeonResetBugFixService/Tasks/ComplexTasks/ShutdownTask.cs
@@ -6,20 +6,23 @@
class ShutdownTask : AbstractSequentialTask
{
- private DevicesStatus ShutdownDevicesStatus { get; } = new DevicesStatus();
+ public ShutdownTask(ServiceContext context)
+ {
+ this.Context = context;
+ }
+
+ private ServiceContext Context { get; }
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()
+ new StopAudioServiceTask(),
+ new EnableVirtualVideoTask(this.Context.ShutdownDevicesStatus),
+ new DisableAmdVideoTask(this.Context.ShutdownDevicesStatus),
+ new LastResortDevicesRestoreTask(this.Context.StartupDevicesStatus),
+ new LastResortDevicesRestoreTask(this.Context.StartupDevicesStatus), // just in case
+ new DisableBasicDisplayStartupTask(this.Context.StartupDevicesStatus),
};
}
}
diff --git a/RadeonResetBugFixService/Tasks/ComplexTasks/StartupTask.cs b/RadeonResetBugFixService/Tasks/ComplexTasks/StartupTask.cs
index a218276..37b3148 100644
--- a/RadeonResetBugFixService/Tasks/ComplexTasks/StartupTask.cs
+++ b/RadeonResetBugFixService/Tasks/ComplexTasks/StartupTask.cs
@@ -6,7 +6,12 @@
class StartupTask : AbstractSequentialTask
{
- private DevicesStatus StartupDevicesStatus { get; } = new DevicesStatus();
+ public StartupTask(ServiceContext context)
+ {
+ this.Context = context;
+ }
+
+ private ServiceContext Context { get; }
public override string TaskName => "Startup";
@@ -14,11 +19,11 @@
{
new EnableBasicDisplayStartupTask(),
new SleepTask(TimeSpan.FromSeconds(40)),
- new EnableAmdVideoTask(this.StartupDevicesStatus),
- new DisableVirtualVideoTask(this.StartupDevicesStatus),
+ new EnableAmdVideoTask(this.Context.StartupDevicesStatus),
+ new DisableVirtualVideoTask(this.Context.StartupDevicesStatus),
new SleepTask(TimeSpan.FromSeconds(20)),
new FixMonitorTask(),
- new DisableVirtualVideoTask(this.StartupDevicesStatus),
+ new DisableVirtualVideoTask(this.Context.StartupDevicesStatus),
new FixMonitorTask()
};
}