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.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(

@ -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));
}
});
}

@ -61,6 +61,7 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="Contracts\ServiceContext.cs" />
<Compile Include="Devices\DeviceHelper.cs" />
<Compile Include="EnvironmentHelper.cs" />
<Compile Include="Constants.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),
};
}
}

@ -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()
};
}

Loading…
Cancel
Save