Merge remote-tracking branch 'origin/ConnectPro_v1.1' into ConnectPro_v1.2

# Conflicts:
#	CHANGELOG.md
#	ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj
#	ICD.Common.Utils/PathUtils.cs
#	ICD.Common.Utils/ProcessorUtils.SimplSharp.cs
#	ICD.Common.Utils/Properties/AssemblyInfo.cs
This commit is contained in:
Chris Cameron
2019-05-16 09:56:43 -04:00
11 changed files with 564 additions and 85 deletions

View File

@@ -59,6 +59,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Better VC-4 support for IcdConsole
- JSON refactoring for simpler deserialization
## [8.4.0] - 2019-05-15
### Added
- Added GUID utils for generating seeded GUIDs
- Added extension method for getting stable hashcodes from strings
- Added environment and processor utilities for determining DNS status and hostname
### Changed
- RangeAttribute improvements for better type safety
- PathUtils breaking out ProgramConfigDirectory and CommonConfigDirectory from the full paths
## [8.3.2] - 2019-05-02
### Changed
- Fixed PriorityQueue IndexOutOfRange exception when an inner queue becomes depleted

View File

@@ -1,5 +1,4 @@
using System;
using ICD.Common.Properties;
namespace ICD.Common.Utils.Attributes
{
@@ -16,15 +15,9 @@ namespace ICD.Common.Utils.Attributes
{
#region Properties
[NotNull]
public object Min { get; private set; }
[NotNull]
public object Max { get; private set; }
[NotNull]
private Type Type { get { return Min.GetType(); } }
#endregion
#region Constructors
@@ -99,130 +92,212 @@ namespace ICD.Common.Utils.Attributes
#region Methods
/// <summary>
/// Returns true if the given value is within the range of Min to Max.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public T GetMin<T>()
{
return (T)Convert.ChangeType(Min, typeof(T), null);
}
public T GetMax<T>()
{
return (T)Convert.ChangeType(Max, typeof(T), null);
}
public bool IsInRange(object value)
{
if (value == null)
throw new ArgumentNullException("value");
if (value.GetType() != Type)
throw new ArgumentException("the type of value does not match the type of min / max");
if (value is ushort)
{
var castMin = (ushort)Min;
var castMax = (ushort)Max;
if (!(Min is ushort))
throw new ArgumentException("the type of value does not match the type of min / max");
var castVal = (ushort)value;
return (castVal >= castMin && castVal <= castMax);
return (castVal >= GetMin<ushort>() && castVal <= GetMax<ushort>());
}
if (value is short)
{
var castMin = (short)Min;
var castMax = (short)Max;
if (!(Min is short))
throw new ArgumentException("the type of value does not match the type of min / max");
var castVal = (short)value;
return (castVal >= castMin && castVal <= castMax);
return (castVal >= GetMin<short>() && castVal <= GetMax<short>());
}
if (value is uint)
{
var castMin = (uint)Min;
var castMax = (uint)Max;
if (!(Min is uint))
throw new ArgumentException("the type of value does not match the type of min / max");
var castVal = (uint)value;
return (castVal >= castMin && castVal <= castMax);
return (castVal >= GetMin<uint>() && castVal <= GetMax<uint>());
}
if (value is int)
{
var castMin = (int)Min;
var castMax = (int)Max;
if (!(Min is int))
throw new ArgumentException("the type of value does not match the type of min / max");
var castVal = (int)value;
return (castVal >= castMin && castVal <= castMax);
return (castVal >= GetMin<int>() && castVal <= GetMax<int>());
}
if (value is ulong)
{
var castMin = (ulong)Min;
var castMax = (ulong)Max;
if (!(Min is ulong))
throw new ArgumentException("the type of value does not match the type of min / max");
var castVal = (ulong)value;
return (castVal >= castMin && castVal <= castMax);
return (castVal >= GetMin<ulong>() && castVal <= GetMax<ulong>());
}
if (value is long)
{
var castMin = (long)Min;
var castMax = (long)Max;
if (!(Min is long))
throw new ArgumentException("the type of value does not match the type of min / max");
var castVal = (long)value;
return (castVal >= castMin && castVal <= castMax);
return (castVal >= GetMin<long>() && castVal <= GetMax<long>());
}
if (value is float)
{
var castMin = (float)Min;
var castMax = (float)Max;
if (!(Min is float))
throw new ArgumentException("the type of value does not match the type of min / max");
var castVal = (float)value;
return (castVal >= castMin && castVal <= castMax);
return (castVal >= GetMin<float>() && castVal <= GetMax<float>());
}
if (value is double)
{
var castMin = (double)Min;
var castMax = (double)Max;
if (!(Min is double))
throw new ArgumentException("the type of value does not match the type of min / max");
var castVal = (double)value;
return (castVal >= castMin && castVal <= castMax);
return (castVal >= GetMin<double>() && castVal <= GetMax<double>());
}
if (value is decimal)
{
var castMin = (decimal)Min;
var castMax = (decimal)Max;
if (!(Min is decimal))
throw new ArgumentException("the type of value does not match the type of min / max");
var castVal = (decimal)value;
return (castVal >= castMin && castVal <= castMax);
return (castVal >= GetMin<decimal>() && castVal <= GetMax<decimal>());
}
if (value is byte)
{
var castMin = (byte)Min;
var castMax = (byte)Max;
if (!(Min is byte))
throw new ArgumentException("the type of value does not match the type of min / max");
var castVal = (byte)value;
return (castVal >= castMin && castVal <= castMax);
return (castVal >= GetMin<byte>() && castVal <= GetMax<byte>());
}
if (value is sbyte)
{
var castMin = (sbyte)Min;
var castMax = (sbyte)Max;
if (!(Min is sbyte))
throw new ArgumentException("the type of value does not match the type of min / max");
var castVal = (sbyte)value;
return (castVal >= castMin && castVal <= castMax);
return (castVal >= GetMin<sbyte>() && castVal <= GetMax<sbyte>());
}
throw new ArgumentException("the type of value is not a numeric type.");
}
public ushort RemapRangeToUShort(double value)
#region Range -> UShort
public ushort RemapRangeToUshort(double value)
{
return (ushort)MathUtils.MapRange((double)Min, (double)Max, ushort.MinValue, ushort.MaxValue, value);
return (ushort)MathUtils.MapRange(GetMin<double>(), GetMax<double>(), ushort.MinValue, ushort.MaxValue, value);
}
public ushort RemapRangeToUShort(float value)
public ushort RemapRangeToUshort(float value)
{
return (ushort)MathUtils.MapRange((float)Min, (float)Max, ushort.MinValue, ushort.MaxValue, value);
return (ushort)MathUtils.MapRange(GetMin<float>(), GetMax<float>(), ushort.MinValue, ushort.MaxValue, value);
}
public ushort RemapRangeToUShort(int value)
public ushort RemapRangeToUshort(int value)
{
return (ushort)MathUtils.MapRange((int)Min, (int)Max, ushort.MinValue, ushort.MaxValue, value);
return (ushort)MathUtils.MapRange(GetMin<int>(), GetMax<int>(), ushort.MinValue, ushort.MaxValue, value);
}
public ushort RemapRangeToUShort(ushort value)
public ushort RemapRangeToUshort(ushort value)
{
return MathUtils.MapRange((ushort)Min, (ushort)Max, ushort.MinValue, ushort.MaxValue, value);
return MathUtils.MapRange(GetMin<ushort>(), GetMax<ushort>(), ushort.MinValue, ushort.MaxValue, value);
}
#endregion
#region UShort -> Range
public object RemapUshortToRange(ushort value)
{
if (Min is ushort)
{
return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin<ushort>(), GetMax<ushort>(), value);
}
if (Min is short)
{
var castVal = (short)value;
return (short)MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin<short>(), GetMax<short>(), castVal);
}
if (Min is uint)
{
var castVal = (uint)value;
return (uint)MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin<uint>(), GetMax<uint>(), castVal);
}
if (Min is int)
{
var castVal = (int)value;
return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin<int>(), GetMax<int>(), castVal);
}
if (Min is ulong)
{
var castVal = (ulong)value;
return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin<ulong>(), GetMax<ulong>(), castVal);
}
if (Min is long)
{
var castVal = (long)value;
return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin<long>(), GetMax<long>(), castVal);
}
if (Min is float)
{
var castVal = (float)value;
return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin<float>(), GetMax<float>(), castVal);
}
if (Min is double)
{
var castVal = (double)value;
return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin<double>(), GetMax<double>(), castVal);
}
if (Min is decimal)
{
var castVal = (decimal)value;
return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin<decimal>(), GetMax<decimal>(), castVal);
}
if (Min is byte)
{
var castVal = (byte)value;
return (byte)MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin<byte>(), GetMax<byte>(), castVal);
}
throw new NotSupportedException("Value type of range attribute is not supported.");
}
#endregion
#endregion
}
}

View File

@@ -221,5 +221,29 @@ namespace ICD.Common.Utils.Extensions
return extends.Contains(character.ToString());
}
/// <summary>
/// Generates a hashcode that is consistent between program executions.
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static int GetStableHashCode(this string extends)
{
unchecked
{
int hash1 = 5381;
int hash2 = hash1;
for (int i = 0; i < extends.Length && extends[i] != '\0'; i += 2)
{
hash1 = ((hash1 << 5) + hash1) ^ extends[i];
if (i == extends.Length - 1 || extends[i + 1] == '\0')
break;
hash2 = ((hash2 << 5) + hash2) ^ extends[i + 1];
}
return hash1 + (hash2 * 1566083941);
}
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
namespace ICD.Common.Utils
{
public static class GuidUtils
{
public static Guid GenerateSeeded(int seed)
{
Random seeded = new Random(seed);
byte[] bytes = new byte[16];
seeded.NextBytes(bytes);
return new Guid(bytes);
}
}
}

View File

@@ -117,6 +117,7 @@
<Compile Include="Extensions\UriExtensions.cs" />
<Compile Include="Extensions\UShortExtensions.cs" />
<Compile Include="Globalization\IcdCultureInfo.cs" />
<Compile Include="GuidUtils.cs" />
<Compile Include="IcdUriBuilder.cs" />
<Compile Include="IO\Compression\IcdZipEntry.cs" />
<Compile Include="IO\IcdBinaryReader.cs" />

View File

@@ -30,9 +30,36 @@ namespace ICD.Common.Utils
{
const CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET param =
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS;
const EthernetAdapterType type = EthernetAdapterType.EthernetLANAdapter;
short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type);
yield return CrestronEthernetHelper.GetEthernetParameter(param, id);
const EthernetAdapterType primaryType = EthernetAdapterType.EthernetLANAdapter;
const EthernetAdapterType secondaryType = EthernetAdapterType.EthernetLAN2Adapter;
string address1 = null;
try
{
short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(primaryType);
address1 = CrestronEthernetHelper.GetEthernetParameter(param, id);
}
catch (ArgumentException)
{
}
if (!string.IsNullOrEmpty(address1))
yield return address1;
string address2 = null;
try
{
short adapter2Type = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(secondaryType);
address2 = CrestronEthernetHelper.GetEthernetParameter(param, adapter2Type);
}
catch (ArgumentException)
{
}
if (!string.IsNullOrEmpty(address2))
yield return address2;
}
}
@@ -46,9 +73,104 @@ namespace ICD.Common.Utils
{
const CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET param =
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS;
const EthernetAdapterType primaryType = EthernetAdapterType.EthernetLANAdapter;
const EthernetAdapterType secondaryType = EthernetAdapterType.EthernetLAN2Adapter;
string macAddress1 = null;
try
{
short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(primaryType);
macAddress1 = CrestronEthernetHelper.GetEthernetParameter(param, id);
}
catch (ArgumentException)
{
}
if (!string.IsNullOrEmpty(macAddress1))
yield return macAddress1;
string macAddress2 = null;
try
{
short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(secondaryType);
macAddress2 = CrestronEthernetHelper.GetEthernetParameter(param, id);
}
catch (ArgumentException)
{
}
if (!string.IsNullOrEmpty(macAddress2))
yield return macAddress2;
}
}
/// <summary>
/// Gets the dhcp status of the processor.
/// </summary>
[PublicAPI]
public static string DhcpStatus
{
get
{
const CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET param =
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_DHCP_STATE;
const EthernetAdapterType type = EthernetAdapterType.EthernetLANAdapter;
short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type);
yield return CrestronEthernetHelper.GetEthernetParameter(param, id);
try
{
short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type);
return CrestronEthernetHelper.GetEthernetParameter(param, id);
}
catch (ArgumentException)
{
return null;
}
}
}
/// <summary>
/// Gets the hostname of the processor.
/// </summary>
[PublicAPI]
public static IEnumerable<string> Hostname
{
get
{
const CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET param =
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME;
const EthernetAdapterType primaryType = EthernetAdapterType.EthernetLANAdapter;
const EthernetAdapterType secondaryType = EthernetAdapterType.EthernetLAN2Adapter;
string address1 = null;
try
{
short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(primaryType);
address1 = CrestronEthernetHelper.GetEthernetParameter(param, id);
}
catch (ArgumentException)
{
}
if (!string.IsNullOrEmpty(address1))
yield return address1;
string address2 = null;
try
{
short adapter2Type = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(secondaryType);
address2 = CrestronEthernetHelper.GetEthernetParameter(param, adapter2Type);
}
catch (ArgumentException)
{
}
if (!string.IsNullOrEmpty(address2))
yield return address2;
}
}

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text.RegularExpressions;
@@ -13,11 +14,6 @@ namespace ICD.Common.Utils
{
public static string NewLine { get { return Environment.NewLine; } }
public static DateTime GetLocalTime()
{
return DateTime.Now;
}
public static eRuntimeEnvironment RuntimeEnvironment { get { return eRuntimeEnvironment.Standard; } }
/// <summary>
@@ -53,6 +49,36 @@ namespace ICD.Common.Utils
}
}
/// <summary>
/// Gets the dhcp status of the processor.
/// </summary>
[PublicAPI]
public static string DhcpStatus
{
get
{
bool enabled =
NetworkInterface.GetAllNetworkInterfaces()
.Where(ni => ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
.Select(ni => ni.GetIPProperties().GetIPv4Properties().IsDhcpEnabled)
.FirstOrDefault();
return enabled.ToString();
}
}
/// <summary>
/// Gets the hostname of the processor.
/// </summary>
[PublicAPI]
public static IEnumerable<string> Hostname { get { yield return Dns.GetHostName(); } }
public static DateTime GetLocalTime()
{
return DateTime.Now;
}
/// <summary>
/// Converts 12 digit address to XX:XX:XX... format
/// </summary>

View File

@@ -78,6 +78,24 @@ namespace ICD.Common.Utils
return outputStart + slope * (value - inputStart);
}
/// <summary>
/// Returns the value after the input range has been mapped to a new range
/// </summary>
/// <param name="inputStart">Input start.</param>
/// <param name="inputEnd">Input end.</param>
/// <param name="outputStart">Output start.</param>
/// <param name="outputEnd">Output end.</param>
/// <param name="value">Value.</param>
/// <returns>The newly mapped value</returns>
public static decimal MapRange(decimal inputStart, decimal inputEnd, decimal outputStart, decimal outputEnd, decimal value)
{
if (inputStart.Equals(inputEnd))
throw new DivideByZeroException();
decimal slope = (outputEnd - outputStart) / (inputEnd - inputStart);
return outputStart + slope * (value - inputStart);
}
/// <summary>
/// Returns the value after the input range has been mapped to a new range
/// </summary>
@@ -120,6 +138,42 @@ namespace ICD.Common.Utils
return (ushort)MapRange((double)inputStart, inputEnd, outputStart, outputEnd, value);
}
/// <summary>
/// Returns the value after the input range has been mapped to a new range
/// </summary>
/// <param name="inputStart">Input start.</param>
/// <param name="inputEnd">Input end.</param>
/// <param name="outputStart">Output start.</param>
/// <param name="outputEnd">Output end.</param>
/// <param name="value">Value.</param>
/// <returns>The newly mapped value</returns>
public static ulong MapRange(ulong inputStart, ulong inputEnd, ulong outputStart, ulong outputEnd, ulong value)
{
if (inputStart.Equals(inputEnd))
throw new DivideByZeroException();
ulong slope = (outputEnd - outputStart) / (inputEnd - inputStart);
return outputStart + slope * (value - inputStart);
}
/// <summary>
/// Returns the value after the input range has been mapped to a new range
/// </summary>
/// <param name="inputStart">Input start.</param>
/// <param name="inputEnd">Input end.</param>
/// <param name="outputStart">Output start.</param>
/// <param name="outputEnd">Output end.</param>
/// <param name="value">Value.</param>
/// <returns>The newly mapped value</returns>
public static long MapRange(long inputStart, long inputEnd, long outputStart, long outputEnd, long value)
{
if (inputStart.Equals(inputEnd))
throw new DivideByZeroException();
long slope = (outputEnd - outputStart) / (inputEnd - inputStart);
return outputStart + slope * (value - inputStart);
}
/// <summary>
/// Maps the date in the given range to the float range 0.0f to 1.0f.
/// 0.5f - The date is half way between the end points.

View File

@@ -58,29 +58,29 @@ namespace ICD.Common.Utils
/// </summary>
/// <value></value>
[PublicAPI]
public static string ProgramConfigPath
public static string ProgramConfigPath { get { return Join(RootConfigPath, ProgramConfigDirectory); } }
/// <summary>
/// Returns the name of the program config directory.
/// </summary>
[PublicAPI]
public static string ProgramConfigDirectory
{
get
{
string directoryName;
switch (IcdEnvironment.RuntimeEnvironment)
{
case IcdEnvironment.eRuntimeEnvironment.SimplSharp:
case IcdEnvironment.eRuntimeEnvironment.SimplSharpPro:
case IcdEnvironment.eRuntimeEnvironment.Standard:
directoryName = string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber);
break;
return string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber);
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono:
directoryName = "ProgramConfig";
break;
return "ProgramConfig";
default:
throw new ArgumentOutOfRangeException();
}
return Join(RootConfigPath, directoryName);
}
}
@@ -88,7 +88,10 @@ namespace ICD.Common.Utils
/// Returns the absolute path to the common configuration directory.
/// </summary>
[PublicAPI]
public static string CommonConfigPath { get { return Join(RootConfigPath, "CommonConfig"); } }
public static string CommonConfigPath { get { return Join(RootConfigPath, CommonConfigDirectory); } }
[PublicAPI]
public static string CommonConfigDirectory { get { return "CommonConfig"; }}
/// <summary>
/// Returns the absolute path to the common config library directory.

View File

@@ -9,8 +9,12 @@ namespace ICD.Common.Utils
{
public static partial class ProcessorUtils
{
private const string MODEL_NAME_REGEX = @"^(\S*)";
private const string MODEL_VERSION_REGEX = @" [[]v(\S*)";
private const string VER_REGEX =
@"(?'model'\S+) (?'type'\S+) (?'lang'\S+) \[v(?'version'\d+.\d+.\d+.\d+) \((?'date'\S+ \d+ \d+)\), #(?'serial'[A-F0-9]+)\] @E-(?'mac'[a-z0-9]+)";
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 RAMFREE_COMMAND = "ramfree";
private const string RAMFREE_DIGITS_REGEX = @"^(\d*)";
@@ -51,11 +55,11 @@ namespace ICD.Common.Utils
string versionResult = VersionResult;
if (!String.IsNullOrEmpty(versionResult))
{
Regex regex = new Regex(MODEL_NAME_REGEX);
Regex regex = new Regex(VER_REGEX);
Match match = regex.Match(versionResult);
if (match.Success)
return match.Groups[1].Value;
return match.Groups["model"].Value;
}
ServiceProvider.TryGetService<ILoggerService>()
@@ -75,11 +79,11 @@ namespace ICD.Common.Utils
string versionResult = VersionResult;
if (!String.IsNullOrEmpty(versionResult))
{
Regex regex = new Regex(MODEL_VERSION_REGEX);
Regex regex = new Regex(VER_REGEX);
Match match = regex.Match(VersionResult);
if (match.Success)
return new Version(match.Groups[1].Value);
return new Version(match.Groups["version"].Value);
}
ServiceProvider.TryGetService<ILoggerService>()
@@ -88,6 +92,51 @@ namespace ICD.Common.Utils
}
}
/// <summary>
/// Gets the date that the firmware was updated.
/// </summary>
[PublicAPI]
public static string ModelVersionDate
{
get
{
Regex regex = new Regex(VER_REGEX);
Match match = regex.Match(VersionResult);
if (match.Success)
return match.Groups["date"].Value;
ServiceProvider.TryGetService<ILoggerService>()
.AddEntry(eSeverity.Warning, "Unable to get model version date from \"{0}\"", VersionResult);
return string.Empty;
}
}
/// <summary>
/// Gets the serial number of the processor
/// </summary>
[PublicAPI]
public static string ProcessorSerialNumber
{
get
{
Regex regex = new Regex(VER_REGEX);
Match match = regex.Match(VersionResult);
if (!match.Success)
{
ServiceProvider.TryGetService<ILoggerService>()
.AddEntry(eSeverity.Warning, "Unable to get serial number from \"{0}\"", VersionResult);
return string.Empty;
}
int decValue = int.Parse(match.Groups["serial"].Value, System.Globalization.NumberStyles.HexNumber);
return decValue.ToString();
}
}
/// <summary>
/// Gets the ram usage in the range 0 - 1.
/// </summary>
@@ -178,6 +227,31 @@ namespace ICD.Common.Utils
IcdConsole.SendControlSystemCommand("reboot", ref consoleResult);
}
/// <summary>
/// Gets the uptime for the system
/// </summary>
/// <returns></returns>
[PublicAPI]
public static string GetSystemUptime()
{
string uptime = GetUptime();
Match match = Regex.Match(uptime, UPTIME_REGEX);
return match.Groups["uptime"].Value;
}
/// <summary>
/// Gets the uptime
/// </summary>
/// <param name="progslot"></param>
/// <returns></returns>
[PublicAPI]
public static string GetProgramUptime(int progslot)
{
string uptime = GetUptime(progslot);
Match match = Regex.Match(uptime, UPTIME_REGEX);
return match.Groups["uptime"].Value;
}
#endregion
/// <summary>
@@ -195,6 +269,30 @@ namespace ICD.Common.Utils
}
return ramfree;
}
private static string GetUptime()
{
string uptime = null;
if (!IcdConsole.SendControlSystemCommand(UPTIME_COMMAND, ref uptime))
{
ServiceProvider.TryGetService<ILoggerService>()
.AddEntry(eSeverity.Warning, "{0} - Failed to send console command \"{1}\"",
typeof(ProcessorUtils).Name, UPTIME_COMMAND);
}
return uptime;
}
private static string GetUptime(int programSlot)
{
string uptime = null;
if (!IcdConsole.SendControlSystemCommand(string.Format(PROGUPTIME_COMMAND_ROOT, programSlot), ref uptime))
{
ServiceProvider.TryGetService<ILoggerService>()
.AddEntry(eSeverity.Warning, "{0} - Failed to send console command \"{1}\"",
typeof(ProcessorUtils).Name, UPTIME_COMMAND);
}
return uptime;
}
}
}

View File

@@ -27,6 +27,32 @@ namespace ICD.Common.Utils
}
}
/// <summary>
/// Gets the date that the firmware was updated.
/// </summary>
[PublicAPI]
public static string ModelVersionDate
{
get
{
// TODO
return null;
}
}
/// <summary>
/// Gets the serial number of the processor
/// </summary>
[PublicAPI]
public static string ProcessorSerialNumber
{
get
{
// TODO
return null;
}
}
/// <summary>
/// Gets the ram usage in the range 0 - 1.
/// </summary>
@@ -109,6 +135,29 @@ namespace ICD.Common.Utils
throw new NotSupportedException();
}
/// <summary>
/// Gets the uptime for the system
/// </summary>
/// <returns></returns>
[PublicAPI]
public static string GetSystemUptime()
{
// TODO
return null;
}
/// <summary>
/// Gets the uptime
/// </summary>
/// <param name="progslot"></param>
/// <returns></returns>
[PublicAPI]
public static string GetProgramUptime(int progslot)
{
// TODO
return null;
}
#endregion
}
}