From 9680c5d65e8df9293a28fde263bd491fb26b4125 Mon Sep 17 00:00:00 2001
From: Inga Lovinde <52715130+inga-lovinde@users.noreply.github.com>
Date: Fri, 21 Aug 2020 00:14:49 +0300
Subject: [PATCH] Implemented diagnose command
---
RadeonResetBugFixService/MainHandler.cs | 27 +++++++++++++++++++
RadeonResetBugFixService/Program.cs | 11 ++++++++
.../RadeonResetBugFixService.csproj | 1 +
.../Tasks/ListDevicesTask.cs | 19 +++++++++++++
4 files changed, 58 insertions(+)
create mode 100644 RadeonResetBugFixService/Tasks/ListDevicesTask.cs
diff --git a/RadeonResetBugFixService/MainHandler.cs b/RadeonResetBugFixService/MainHandler.cs
index 0b3b474..0e0e7cd 100644
--- a/RadeonResetBugFixService/MainHandler.cs
+++ b/RadeonResetBugFixService/MainHandler.cs
@@ -97,5 +97,32 @@
}
}
}
+
+ public void HandleDiagnose(string reason)
+ {
+ using (var fileLogger = new FileLogger(this.LogFilename))
+ {
+ using (ILogger logger = new TaskLoggerWrapper(fileLogger, "Diagnose"))
+ {
+ logger.Log($"Reason: {reason}");
+ try
+ {
+ lock (this.Mutex)
+ {
+ TasksProcessor.ProcessTasks(
+ logger,
+ new ITask[]
+ {
+ new ListDevicesTask(),
+ });
+ }
+ }
+ catch (Exception e)
+ {
+ logger.LogError(e.ToString());
+ }
+ }
+ }
+ }
}
}
diff --git a/RadeonResetBugFixService/Program.cs b/RadeonResetBugFixService/Program.cs
index cb1ed5a..873fee2 100644
--- a/RadeonResetBugFixService/Program.cs
+++ b/RadeonResetBugFixService/Program.cs
@@ -72,6 +72,10 @@
{
DoShutdown();
}
+ else if (command.Equals("diagnose", StringComparison.OrdinalIgnoreCase))
+ {
+ DoDiagnose();
+ }
else
{
ShowHelp();
@@ -92,6 +96,8 @@
Console.WriteLine("\t\tPerforms startup sequence (development command, does not affect services)");
Console.WriteLine($"\t{exeName} shutdown");
Console.WriteLine("\t\tPerforms shutdown sequence (development command, does not affect services)");
+ Console.WriteLine($"\t{exeName} diagnose");
+ Console.WriteLine("\t\tPerforms diagnose (see result file in logs folder)");
}
private static void DoInstall()
@@ -136,5 +142,10 @@
{
new MainHandler().HandleShutdown("Program.DoShutdown");
}
+
+ private static void DoDiagnose()
+ {
+ new MainHandler().HandleDiagnose("Program.DoDiagnose");
+ }
}
}
diff --git a/RadeonResetBugFixService/RadeonResetBugFixService.csproj b/RadeonResetBugFixService/RadeonResetBugFixService.csproj
index b6e6e21..eceb122 100644
--- a/RadeonResetBugFixService/RadeonResetBugFixService.csproj
+++ b/RadeonResetBugFixService/RadeonResetBugFixService.csproj
@@ -89,6 +89,7 @@
+
diff --git a/RadeonResetBugFixService/Tasks/ListDevicesTask.cs b/RadeonResetBugFixService/Tasks/ListDevicesTask.cs
new file mode 100644
index 0000000..fa9c5c4
--- /dev/null
+++ b/RadeonResetBugFixService/Tasks/ListDevicesTask.cs
@@ -0,0 +1,19 @@
+namespace RadeonResetBugFixService.Tasks
+{
+ using System.Linq;
+ using Contracts;
+ using Devices;
+
+ class ListDevicesTask : ITask
+ {
+ string ITask.TaskName => "Listing devices";
+
+ void ITask.Run(ILogger logger)
+ {
+ foreach (var device in DeviceHelper.GetDevices().ToArray())
+ {
+ logger.Log($"Found device {device.Description}: manufacturer='{device.Manufacturer}', service='{device.Service}', class='{device.ClassName}'");
+ }
+ }
+ }
+}