From 4d76abe046de20763f82207982d3ded9ffe03608 Mon Sep 17 00:00:00 2001 From: Austin Noska Date: Wed, 5 Jun 2019 14:15:53 -0400 Subject: [PATCH 1/4] fix: cache the uptime values and calculate the uptime from those values instead of polling the crestron processor each time its needed --- ICD.Common.Utils/ProcessorUtils.SimplSharp.cs | 58 ++++++++++++++----- ICD.Common.Utils/ProcessorUtils.Standard.cs | 2 +- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs b/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs index 5dff4ed..9e82a2e 100644 --- a/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs +++ b/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs @@ -14,13 +14,16 @@ namespace ICD.Common.Utils private const string UPTIME_COMMAND = "uptime"; private const string PROGUPTIME_COMMAND_ROOT = "proguptime:{0}"; - private const string UPTIME_REGEX = @".*(?'uptime'\d+ days \d{2}:\d{2}:\d{2}\.\d+)"; + private const string UPTIME_REGEX = @".*(?'uptime'(?'days'\d+) days (?'hours'\d{2}):(?'minutes'\d{2}):(?'seconds'\d{2})\.(?'milliseconds'\d+))"; private const string RAMFREE_COMMAND = "ramfree"; private const string RAMFREE_DIGITS_REGEX = @"^(\d*)"; private static string s_VersionResult; + private static DateTime? s_SystemUptimeStartTime; + private static DateTime? s_ProgramUptimeStartTime; + #region Properties /// @@ -224,24 +227,53 @@ namespace ICD.Common.Utils /// /// [PublicAPI] - public static string GetSystemUptime() + public static TimeSpan GetSystemUptime() { - string uptime = GetUptime(); - Match match = Regex.Match(uptime, UPTIME_REGEX); - return match.Groups["uptime"].Value; + if (s_SystemUptimeStartTime == null) + { + string uptime = GetSystemUptimeFeedback(); + Match match = Regex.Match(uptime, UPTIME_REGEX); + if (!match.Success) + return default(TimeSpan); + + int days = int.Parse(match.Groups["days"].Value); + int hours = int.Parse(match.Groups["hours"].Value); + int minutes = int.Parse(match.Groups["minutes"].Value); + int seconds = int.Parse(match.Groups["seconds"].Value); + int milliseconds = int.Parse(match.Groups["milliseconds"].Value); + + TimeSpan span = new TimeSpan(days, hours, minutes, seconds, milliseconds); + s_SystemUptimeStartTime = IcdEnvironment.GetLocalTime() - span; + } + + return IcdEnvironment.GetLocalTime() - s_SystemUptimeStartTime.Value; } /// - /// Gets the uptime + /// Gets the uptime of the current program. /// - /// /// [PublicAPI] - public static string GetProgramUptime(int progslot) + public static TimeSpan GetProgramUptimeFeedback() { - string uptime = GetUptime(progslot); - Match match = Regex.Match(uptime, UPTIME_REGEX); - return match.Groups["uptime"].Value; + if (s_ProgramUptimeStartTime == null) + { + string uptime = GetProgramUptimeFeedback((int)ProgramUtils.ProgramNumber); + Match match = Regex.Match(uptime, UPTIME_REGEX); + if (!match.Success) + return default(TimeSpan); + + int days = int.Parse(match.Groups["days"].Value); + int hours = int.Parse(match.Groups["hours"].Value); + int minutes = int.Parse(match.Groups["minutes"].Value); + int seconds = int.Parse(match.Groups["seconds"].Value); + int milliseconds = int.Parse(match.Groups["milliseconds"].Value); + + TimeSpan span = new TimeSpan(days, hours, minutes, seconds, milliseconds); + s_ProgramUptimeStartTime = IcdEnvironment.GetLocalTime() - span; + } + + return IcdEnvironment.GetLocalTime() - s_ProgramUptimeStartTime.Value; } #endregion @@ -262,7 +294,7 @@ namespace ICD.Common.Utils return ramfree; } - private static string GetUptime() + private static string GetSystemUptimeFeedback() { string uptime = null; if (!IcdConsole.SendControlSystemCommand(UPTIME_COMMAND, ref uptime)) @@ -274,7 +306,7 @@ namespace ICD.Common.Utils return uptime; } - private static string GetUptime(int programSlot) + private static string GetProgramUptimeFeedback(int programSlot) { string uptime = null; if (!IcdConsole.SendControlSystemCommand(string.Format(PROGUPTIME_COMMAND_ROOT, programSlot), ref uptime)) diff --git a/ICD.Common.Utils/ProcessorUtils.Standard.cs b/ICD.Common.Utils/ProcessorUtils.Standard.cs index 619dc75..ca16c55 100644 --- a/ICD.Common.Utils/ProcessorUtils.Standard.cs +++ b/ICD.Common.Utils/ProcessorUtils.Standard.cs @@ -152,7 +152,7 @@ namespace ICD.Common.Utils /// /// [PublicAPI] - public static string GetProgramUptime(int progslot) + public static string GetProgramUptimeFeedback(int progslot) { // TODO return null; From d649fb9dc45854bc33989efc22752aec78286dcb Mon Sep 17 00:00:00 2001 From: Austin Noska Date: Wed, 5 Jun 2019 14:18:53 -0400 Subject: [PATCH 2/4] docs: updating utils changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc7dfc7..fac8e3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed + - fixed cached the uptime values and calculate the uptime from those values instead of polling the crestron processor each time its needed ## [8.4.0] - 2019-05-15 ### Added From 02c18d152f2bc6aefb12291b6b466fb64fa26b93 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Wed, 5 Jun 2019 14:34:59 -0400 Subject: [PATCH 3/4] chore: Updating changelog, incrementing patch version --- CHANGELOG.md | 4 +++- ICD.Common.Utils/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fac8e3c..4f1ef1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [8.4.1] - 2019-06-05 ### Changed - - fixed cached the uptime values and calculate the uptime from those values instead of polling the crestron processor each time its needed + - Caching the program/processor start time and calculating the uptime from those values instead of polling the crestron processor ## [8.4.0] - 2019-05-15 ### Added diff --git a/ICD.Common.Utils/Properties/AssemblyInfo.cs b/ICD.Common.Utils/Properties/AssemblyInfo.cs index 97275b5..8cc5446 100644 --- a/ICD.Common.Utils/Properties/AssemblyInfo.cs +++ b/ICD.Common.Utils/Properties/AssemblyInfo.cs @@ -4,4 +4,4 @@ using System.Reflection; [assembly: AssemblyCompany("ICD Systems")] [assembly: AssemblyProduct("ICD.Common.Utils")] [assembly: AssemblyCopyright("Copyright © ICD Systems 2019")] -[assembly: AssemblyVersion("8.4.0.0")] +[assembly: AssemblyVersion("8.4.1.0")] From 1c38d9f04ae222e55545883f450ecd51c26fb7f6 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Wed, 5 Jun 2019 15:01:07 -0400 Subject: [PATCH 4/4] fix: Fixing Net Standard build, changing method name --- ICD.Common.Utils/ProcessorUtils.SimplSharp.cs | 2 +- ICD.Common.Utils/ProcessorUtils.Standard.cs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs b/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs index 9e82a2e..ba6d97d 100644 --- a/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs +++ b/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs @@ -254,7 +254,7 @@ namespace ICD.Common.Utils /// /// [PublicAPI] - public static TimeSpan GetProgramUptimeFeedback() + public static TimeSpan GetProgramUptime() { if (s_ProgramUptimeStartTime == null) { diff --git a/ICD.Common.Utils/ProcessorUtils.Standard.cs b/ICD.Common.Utils/ProcessorUtils.Standard.cs index ca16c55..5755431 100644 --- a/ICD.Common.Utils/ProcessorUtils.Standard.cs +++ b/ICD.Common.Utils/ProcessorUtils.Standard.cs @@ -140,22 +140,21 @@ namespace ICD.Common.Utils /// /// [PublicAPI] - public static string GetSystemUptime() + public static TimeSpan GetSystemUptime() { // TODO - return null; + return default(TimeSpan); } /// /// Gets the uptime /// - /// /// [PublicAPI] - public static string GetProgramUptimeFeedback(int progslot) + public static TimeSpan GetProgramUptime() { // TODO - return null; + return default(TimeSpan); } #endregion