Fixed shutdown task

master
Inga 🏳‍🌈 4 years ago
parent 52c113af8f
commit c9900e6aff
  1. 9
      RadeonResetBugFixService/Contracts/ServiceContext.cs
  2. 5
      RadeonResetBugFixService/Program.cs
  3. 9
      RadeonResetBugFixService/RadeonResetBugFixService.cs
  4. 1
      RadeonResetBugFixService/RadeonResetBugFixService.csproj
  5. 21
      RadeonResetBugFixService/Tasks/ComplexTasks/ShutdownTask.cs
  6. 13
      RadeonResetBugFixService/Tasks/ComplexTasks/StartupTask.cs

@ -0,0 +1,9 @@
namespace RadeonResetBugFixService.Contracts
{
class ServiceContext
{
public DevicesStatus StartupDevicesStatus { get; } = new DevicesStatus();
public DevicesStatus ShutdownDevicesStatus { get; } = new DevicesStatus();
}
}

@ -2,6 +2,7 @@
{ {
using System; using System;
using System.ServiceProcess; using System.ServiceProcess;
using Contracts;
using Tasks.ComplexTasks; using Tasks.ComplexTasks;
using ThirdParty.ServiceHelpers; using ThirdParty.ServiceHelpers;
@ -138,12 +139,12 @@
private static void DoStartup() => new MainHandler().HandleEntryPoint( private static void DoStartup() => new MainHandler().HandleEntryPoint(
"Program.DoStartup", "Program.DoStartup",
(logger) => TasksProcessor.ProcessTask(logger, new StartupTask()) (logger) => TasksProcessor.ProcessTask(logger, new StartupTask(new ServiceContext()))
); );
private static void DoShutdown() => new MainHandler().HandleEntryPoint( private static void DoShutdown() => new MainHandler().HandleEntryPoint(
"Program.DoShutdown", "Program.DoShutdown",
(logger) => TasksProcessor.ProcessTask(logger, new ShutdownTask()) (logger) => TasksProcessor.ProcessTask(logger, new ShutdownTask(new ServiceContext()))
); );
private static void DoDiagnose() => new MainHandler().HandleEntryPoint( private static void DoDiagnose() => new MainHandler().HandleEntryPoint(

@ -4,10 +4,13 @@
using System.Reflection; using System.Reflection;
using System.ServiceProcess; using System.ServiceProcess;
using Microsoft.Win32; using Microsoft.Win32;
using Contracts;
using Tasks.ComplexTasks; using Tasks.ComplexTasks;
public partial class RadeonResetBugFixService : ServiceBase public partial class RadeonResetBugFixService : ServiceBase
{ {
private ServiceContext Context { get; } = new ServiceContext();
private MainHandler Handler { get; } = new MainHandler(); private MainHandler Handler { get; } = new MainHandler();
public RadeonResetBugFixService() public RadeonResetBugFixService()
@ -51,7 +54,7 @@
(logger) => (logger) =>
{ {
this.RequestAdditionalTime((int)Constants.ServiceTimeout.TotalMilliseconds); this.RequestAdditionalTime((int)Constants.ServiceTimeout.TotalMilliseconds);
TasksProcessor.ProcessTask(logger, new StartupTask()); TasksProcessor.ProcessTask(logger, new StartupTask(this.Context));
this.EnablePreshutdown(); this.EnablePreshutdown();
SystemEvents.SessionEnding += this.OnSessionEnding; SystemEvents.SessionEnding += this.OnSessionEnding;
}); });
@ -64,7 +67,7 @@
(logger) => (logger) =>
{ {
this.RequestAdditionalTime((int)Constants.ServiceTimeout.TotalMilliseconds); this.RequestAdditionalTime((int)Constants.ServiceTimeout.TotalMilliseconds);
TasksProcessor.ProcessTask(logger, new ShutdownTask()); TasksProcessor.ProcessTask(logger, new ShutdownTask(this.Context));
SystemEvents.SessionEnding -= this.OnSessionEnding; SystemEvents.SessionEnding -= this.OnSessionEnding;
}); });
} }
@ -99,7 +102,7 @@
if (args.Reason == SessionEndReasons.SystemShutdown) if (args.Reason == SessionEndReasons.SystemShutdown)
{ {
TasksProcessor.ProcessTask(logger, new ShutdownTask()); TasksProcessor.ProcessTask(logger, new ShutdownTask(this.Context));
} }
}); });
} }

@ -61,6 +61,7 @@
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Contracts\ServiceContext.cs" />
<Compile Include="Devices\DeviceHelper.cs" /> <Compile Include="Devices\DeviceHelper.cs" />
<Compile Include="EnvironmentHelper.cs" /> <Compile Include="EnvironmentHelper.cs" />
<Compile Include="Constants.cs" /> <Compile Include="Constants.cs" />

@ -6,20 +6,23 @@
class ShutdownTask : AbstractSequentialTask 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"; public override string TaskName => "Shutdown";
protected override ITask[] Subtasks => new ITask[] protected override ITask[] Subtasks => new ITask[]
{ {
new EnableBasicDisplayStartupTask(), new StopAudioServiceTask(),
new SleepTask(TimeSpan.FromSeconds(40)), new EnableVirtualVideoTask(this.Context.ShutdownDevicesStatus),
new EnableAmdVideoTask(this.ShutdownDevicesStatus), new DisableAmdVideoTask(this.Context.ShutdownDevicesStatus),
new DisableVirtualVideoTask(this.ShutdownDevicesStatus), new LastResortDevicesRestoreTask(this.Context.StartupDevicesStatus),
new SleepTask(TimeSpan.FromSeconds(20)), new LastResortDevicesRestoreTask(this.Context.StartupDevicesStatus), // just in case
new FixMonitorTask(), new DisableBasicDisplayStartupTask(this.Context.StartupDevicesStatus),
new DisableVirtualVideoTask(this.ShutdownDevicesStatus),
new FixMonitorTask()
}; };
} }
} }

@ -6,7 +6,12 @@
class StartupTask : AbstractSequentialTask 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"; public override string TaskName => "Startup";
@ -14,11 +19,11 @@
{ {
new EnableBasicDisplayStartupTask(), new EnableBasicDisplayStartupTask(),
new SleepTask(TimeSpan.FromSeconds(40)), new SleepTask(TimeSpan.FromSeconds(40)),
new EnableAmdVideoTask(this.StartupDevicesStatus), new EnableAmdVideoTask(this.Context.StartupDevicesStatus),
new DisableVirtualVideoTask(this.StartupDevicesStatus), new DisableVirtualVideoTask(this.Context.StartupDevicesStatus),
new SleepTask(TimeSpan.FromSeconds(20)), new SleepTask(TimeSpan.FromSeconds(20)),
new FixMonitorTask(), new FixMonitorTask(),
new DisableVirtualVideoTask(this.StartupDevicesStatus), new DisableVirtualVideoTask(this.Context.StartupDevicesStatus),
new FixMonitorTask() new FixMonitorTask()
}; };
} }

Loading…
Cancel
Save