diff --git a/02_Windows_App/Perun_v1/01_Classes/Globals.cs b/02_Windows_App/Perun_v1/01_Classes/Globals.cs index bc5112b..1ba68e1 100644 --- a/02_Windows_App/Perun_v1/01_Classes/Globals.cs +++ b/02_Windows_App/Perun_v1/01_Classes/Globals.cs @@ -6,62 +6,50 @@ using System.Management; class HardwareMonitorClass { + // Class for HW monitoring + protected PerformanceCounter PerformanceCounterCPU; + protected PerformanceCounter PerformanceCounterRAM; - protected PerformanceCounter cpuCounter; - protected PerformanceCounter ramCounter; - + public string LastCurrentCpuUsage = "-1"; // Last measured CPU usage + public string LastCurrentRamUsage = "-1"; // Last measured RAM usage public HardwareMonitorClass() { // Prepare CPU counter - cpuCounter = new PerformanceCounter(); - cpuCounter.CategoryName = "Processor"; - cpuCounter.CounterName = "% Processor Time"; - cpuCounter.InstanceName = "_Total"; + PerformanceCounterCPU = new PerformanceCounter(); + PerformanceCounterCPU.CategoryName = "Processor"; + PerformanceCounterCPU.CounterName = "% Processor Time"; + PerformanceCounterCPU.InstanceName = "_Total"; // Prepare RAM counter - ramCounter = new PerformanceCounter(); - ramCounter.CategoryName = "Memory"; - ramCounter.CounterName = "% Committed Bytes In Use"; - + PerformanceCounterRAM = new PerformanceCounter(); + PerformanceCounterRAM.CategoryName = "Memory"; + PerformanceCounterRAM.CounterName = "% Committed Bytes In Use"; } // Get CPU usage public string getCurrentCpuUsage() { - return cpuCounter.NextValue().ToString("0.00"); + LastCurrentCpuUsage = PerformanceCounterCPU.NextValue().ToString("0.00"); + return LastCurrentCpuUsage; } // Get available RAM memory - public string getAvailableRAM() + public string getCurrentRamUsage() { - return ramCounter.NextValue().ToString("0.00"); + LastCurrentRamUsage = PerformanceCounterRAM.NextValue().ToString("0.00"); + return LastCurrentRamUsage; } - } class CurrentMissionClass { - + // Class holding current mission/DCS server status public string Theatre = ""; // Mission theathre public string Mission = ""; // Mission name public string Pause = ""; // Mission pause public int PlayerCount = 0; // Actual player time - public string ModelTime = ""; - public string RealTime = ""; - - public string ToInfoString() - { - // Return mission information as string - if (this.Mission != "") - { - // Return mission information as string - return "Mission: " + this.Mission + "(" + this.Theatre + ") Pause:" + this.Pause + " Players: " + this.PlayerCount; - } else - { - // Mission information is not available - return "Mission: Unknown"; - } - } + public string ModelTime = ""; // Mission time + public string RealTime = ""; // Server time } internal class Globals @@ -88,8 +76,8 @@ internal class Globals public static string VersionDatabase = ""; // Version - Database public static string VersionPerun = "DEBUG"; // Version - Perun - public static CurrentMissionClass CurrentMission = new CurrentMissionClass(); // Actual mission information + public static CurrentMissionClass CurrentMission = new CurrentMissionClass(); // Actual mission information single ton - public static HardwareMonitorClass HardwareMonitor = new HardwareMonitorClass(); + public static HardwareMonitorClass HardwareMonitor = new HardwareMonitorClass(); // Hardware monitor singleton } diff --git a/02_Windows_App/Perun_v1/01_Classes/LogController.cs b/02_Windows_App/Perun_v1/01_Classes/LogController.cs index 177bc12..83b6481 100644 --- a/02_Windows_App/Perun_v1/01_Classes/LogController.cs +++ b/02_Windows_App/Perun_v1/01_Classes/LogController.cs @@ -1,9 +1,9 @@ using System; using System.IO; -// Singleton class - log controller class LogController { + // Singleton class - log controller private static LogController _instance = new LogController(); // Singleton instance public int level; // Level of logging @@ -17,8 +17,10 @@ class LogController public void WriteLog(int logLevel, string strLog) { + // Write log entry to file if (logLevel > this.level) return; // Check if we shall log it with the current log level, if not - exit + // Declare variables StreamWriter LogStreamWriter; FileStream LogFileStream = null; DirectoryInfo LogDirectoryInfo = null; @@ -41,7 +43,7 @@ class LogController } catch { - // Do nothing + // Do nothing - TBD error handling } } try @@ -52,7 +54,7 @@ class LogController } catch { - // Do nothing + // Do nothing - TBD error handling } // TBD: log rotation diff --git a/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs b/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs index b3afecb..6bb6b58 100644 --- a/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs +++ b/02_Windows_App/Perun_v1/01_Classes/PerunHelper.cs @@ -35,6 +35,7 @@ internal class PerunHelper // Declare values string LogDirection; string LogMarker; + // Set direction marker switch (intDirection) { @@ -76,7 +77,7 @@ internal class PerunHelper // Set frame type strType = strType.PadLeft(3, ' '); - if (!bSkipGui) + if (!bSkipGui) // Shall we skip GUI? { // Rotate log history for (int i = 0; i < arrLogHistory.Length - 1; i++) @@ -85,13 +86,13 @@ internal class PerunHelper } // Add new entry - arrLogHistory[arrLogHistory.Length - 1] = DateTime.Now.ToString("HH:mm:ss") + " " + LogDirection + " " + LogType + " " + strEntryToAdd; // Add entry at the last position + arrLogHistory[arrLogHistory.Length - 1] = DateTime.Now.ToString("HH:mm:ss.fff") + " " + LogDirection + " " + LogType + " " + strEntryToAdd; // Add entry at the last position // Update control at my window Globals.AppUpdateGUI = true; } // Add the entry to log file - LogController.instance.WriteLog(logLevel, DateTime.Now.ToString("yyyy-MM-dd ") + " " + DateTime.Now.ToString("HH:mm:ss") + " | Instance: " + Globals.AppInstanceID + " | " + LogMarker + " | " + LogDirection + " | " + strType + " | " + strEntryToAdd); + LogController.instance.WriteLog(logLevel, DateTime.Now.ToString("yyyy-MM-dd ") + " " + DateTime.Now.ToString("HH:mm:ss.fff") + " | Instance: " + Globals.AppInstanceID + " | " + LogMarker + " | " + LogDirection + " | " + strType + " | " + strEntryToAdd); } // Gets build version @@ -141,7 +142,7 @@ internal class PerunHelper } public static string ConvertSecoundsToString (Double NumberOfSecounds){ - // TBD + // TBD - convert number of secounds to HHhMMm format return NumberOfSecounds.ToString(); } } \ No newline at end of file diff --git a/02_Windows_App/Perun_v1/02_Forms/form_Main.cs b/02_Windows_App/Perun_v1/02_Forms/form_Main.cs index f870479..4c4da5e 100644 --- a/02_Windows_App/Perun_v1/02_Forms/form_Main.cs +++ b/02_Windows_App/Perun_v1/02_Forms/form_Main.cs @@ -11,7 +11,7 @@ namespace Perun_v1 public partial class form_Main : Form { // Variable definitions - public string[] DatabaseSendBuffer = new string[50]; // MySQL send buffer + public string[] DatabaseSendBuffer = new string[50]; // MySQL send buffer public bool AppCanClose = false; // Helper to handle system tray - true needed to quit the app public DatabaseController DatabaseConnection = new DatabaseController(); // Main MySQL controller @@ -739,7 +739,7 @@ namespace Perun_v1 { //Handle getting of system status label28.Text = Globals.HardwareMonitor.getCurrentCpuUsage() + "%"; - label29.Text = Globals.HardwareMonitor.getAvailableRAM() + "%"; + label29.Text = Globals.HardwareMonitor.getCurrentRamUsage() + "%"; } private void TIM_Autostart_Tick(object sender, EventArgs e)