mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
feat: Changed ProcessorUtils Uptimes to StartTime
This commit is contained in:
@@ -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).
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Changed
|
||||||
|
- ProcessorUtils Uptime methods changed to StartTime
|
||||||
|
|
||||||
## [14.1.0] - 2021-01-21
|
## [14.1.0] - 2021-01-21
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -228,21 +228,6 @@ namespace ICD.Common.Utils
|
|||||||
IcdConsole.SendControlSystemCommand("reboot", ref consoleResult);
|
IcdConsole.SendControlSystemCommand("reboot", ref consoleResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the uptime for the system
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[PublicAPI]
|
|
||||||
public static TimeSpan GetSystemUptime()
|
|
||||||
{
|
|
||||||
if (s_SystemUptimeStartTimeUtc == null)
|
|
||||||
UpdateSystemStartTime();
|
|
||||||
|
|
||||||
if (s_SystemUptimeStartTimeUtc != null)
|
|
||||||
return IcdEnvironment.GetUtcTime() - s_SystemUptimeStartTimeUtc.Value;
|
|
||||||
return default(TimeSpan);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the time the system was started
|
/// Gets the time the system was started
|
||||||
/// DateTime that uptime starts
|
/// DateTime that uptime starts
|
||||||
@@ -262,26 +247,27 @@ namespace ICD.Common.Utils
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static TimeSpan GetProgramUptime()
|
public static DateTime? GetProgramStartTime()
|
||||||
{
|
{
|
||||||
if (s_ProgramUptimeStartTimeUtc == null)
|
if (s_ProgramUptimeStartTimeUtc != null)
|
||||||
{
|
return s_ProgramUptimeStartTimeUtc;
|
||||||
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);
|
string uptime = GetProgramUptimeFeedback((int)ProgramUtils.ProgramNumber);
|
||||||
s_ProgramUptimeStartTimeUtc = IcdEnvironment.GetUtcTime() - span;
|
Match match = Regex.Match(uptime, UPTIME_REGEX);
|
||||||
}
|
if (!match.Success)
|
||||||
|
return null;
|
||||||
|
|
||||||
return IcdEnvironment.GetUtcTime() - s_ProgramUptimeStartTimeUtc.Value;
|
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_ProgramUptimeStartTimeUtc = IcdEnvironment.GetUtcTime() - span;
|
||||||
|
|
||||||
|
return s_ProgramUptimeStartTimeUtc;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -137,16 +137,6 @@ namespace ICD.Common.Utils
|
|||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the uptime for the system
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[PublicAPI]
|
|
||||||
public static TimeSpan GetSystemUptime()
|
|
||||||
{
|
|
||||||
return TimeSpan.FromMilliseconds(Environment.TickCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the time the system was started
|
/// Gets the time the system was started
|
||||||
/// DateTime that uptime starts
|
/// DateTime that uptime starts
|
||||||
@@ -162,14 +152,14 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the uptime
|
/// Gets the time the program was started
|
||||||
|
/// Datetime the program starts
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static TimeSpan GetProgramUptime()
|
public static DateTime? GetProgramStartTime()
|
||||||
{
|
{
|
||||||
var current = System.Diagnostics.Process.GetCurrentProcess();
|
return GetSystemStartTime();
|
||||||
return IcdEnvironment.GetLocalTime() - current.StartTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user