diff --git a/CHANGELOG.md b/CHANGELOG.md
index e86785b..a4d9651 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/ICD.Common.Utils/Attributes/RangeAttribute.cs b/ICD.Common.Utils/Attributes/RangeAttribute.cs
index deb9813..1574f9e 100644
--- a/ICD.Common.Utils/Attributes/RangeAttribute.cs
+++ b/ICD.Common.Utils/Attributes/RangeAttribute.cs
@@ -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
- ///
- /// Returns true if the given value is within the range of Min to Max.
- ///
- ///
- ///
+ public T GetMin()
+ {
+ return (T)Convert.ChangeType(Min, typeof(T), null);
+ }
+
+ public T GetMax()
+ {
+ 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() && castVal <= GetMax());
}
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() && castVal <= GetMax());
}
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() && castVal <= GetMax());
}
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() && castVal <= GetMax());
}
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() && castVal <= GetMax());
}
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() && castVal <= GetMax());
}
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() && castVal <= GetMax());
}
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() && castVal <= GetMax());
}
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() && castVal <= GetMax());
}
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() && castVal <= GetMax());
}
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() && castVal <= GetMax());
}
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(), GetMax(), 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(), GetMax(), 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(), GetMax(), 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(), GetMax(), 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(), GetMax(), value);
+ }
+
+ if (Min is short)
+ {
+ var castVal = (short)value;
+ return (short)MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin(), GetMax(), castVal);
+ }
+
+ if (Min is uint)
+ {
+ var castVal = (uint)value;
+ return (uint)MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin(), GetMax(), castVal);
+ }
+
+ if (Min is int)
+ {
+ var castVal = (int)value;
+ return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin(), GetMax(), castVal);
+ }
+
+ if (Min is ulong)
+ {
+ var castVal = (ulong)value;
+ return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin(), GetMax(), castVal);
+ }
+
+ if (Min is long)
+ {
+ var castVal = (long)value;
+ return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin(), GetMax(), castVal);
+ }
+
+ if (Min is float)
+ {
+ var castVal = (float)value;
+ return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin(), GetMax(), castVal);
+ }
+
+ if (Min is double)
+ {
+ var castVal = (double)value;
+ return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin(), GetMax(), castVal);
+ }
+
+ if (Min is decimal)
+ {
+ var castVal = (decimal)value;
+ return MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin(), GetMax(), castVal);
+ }
+
+ if (Min is byte)
+ {
+ var castVal = (byte)value;
+ return (byte)MathUtils.MapRange(ushort.MinValue, ushort.MaxValue, GetMin(), GetMax(), castVal);
+ }
+
+ throw new NotSupportedException("Value type of range attribute is not supported.");
+ }
+
+ #endregion
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/ICD.Common.Utils/Extensions/StringExtensions.cs b/ICD.Common.Utils/Extensions/StringExtensions.cs
index d1828e3..e1be90e 100644
--- a/ICD.Common.Utils/Extensions/StringExtensions.cs
+++ b/ICD.Common.Utils/Extensions/StringExtensions.cs
@@ -221,5 +221,29 @@ namespace ICD.Common.Utils.Extensions
return extends.Contains(character.ToString());
}
+
+ ///
+ /// Generates a hashcode that is consistent between program executions.
+ ///
+ ///
+ ///
+ 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);
+ }
+ }
}
}
diff --git a/ICD.Common.Utils/GuidUtils.cs b/ICD.Common.Utils/GuidUtils.cs
new file mode 100644
index 0000000..d68feb6
--- /dev/null
+++ b/ICD.Common.Utils/GuidUtils.cs
@@ -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);
+ }
+ }
+}
diff --git a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj
index 81bee20..c1ce469 100644
--- a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj
+++ b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj
@@ -117,6 +117,7 @@
+
diff --git a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs
index 3452213..b85dc8f 100644
--- a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs
+++ b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs
@@ -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;
+ }
+ }
+
+ ///
+ /// Gets the dhcp status of the processor.
+ ///
+ [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;
+ }
+ }
+ }
+
+ ///
+ /// Gets the hostname of the processor.
+ ///
+ [PublicAPI]
+ public static IEnumerable 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;
}
}
diff --git a/ICD.Common.Utils/IcdEnvironment.Standard.cs b/ICD.Common.Utils/IcdEnvironment.Standard.cs
index e852ba6..a7a618a 100644
--- a/ICD.Common.Utils/IcdEnvironment.Standard.cs
+++ b/ICD.Common.Utils/IcdEnvironment.Standard.cs
@@ -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; } }
///
@@ -53,6 +49,36 @@ namespace ICD.Common.Utils
}
}
+ ///
+ /// Gets the dhcp status of the processor.
+ ///
+ [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();
+ }
+ }
+
+ ///
+ /// Gets the hostname of the processor.
+ ///
+ [PublicAPI]
+ public static IEnumerable Hostname { get { yield return Dns.GetHostName(); } }
+
+ public static DateTime GetLocalTime()
+ {
+ return DateTime.Now;
+ }
+
///
/// Converts 12 digit address to XX:XX:XX... format
///
diff --git a/ICD.Common.Utils/MathUtils.cs b/ICD.Common.Utils/MathUtils.cs
index 1f44412..e4427ac 100644
--- a/ICD.Common.Utils/MathUtils.cs
+++ b/ICD.Common.Utils/MathUtils.cs
@@ -78,6 +78,24 @@ namespace ICD.Common.Utils
return outputStart + slope * (value - inputStart);
}
+ ///
+ /// Returns the value after the input range has been mapped to a new range
+ ///
+ /// Input start.
+ /// Input end.
+ /// Output start.
+ /// Output end.
+ /// Value.
+ /// The newly mapped value
+ 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);
+ }
+
///
/// Returns the value after the input range has been mapped to a new range
///
@@ -120,6 +138,42 @@ namespace ICD.Common.Utils
return (ushort)MapRange((double)inputStart, inputEnd, outputStart, outputEnd, value);
}
+ ///
+ /// Returns the value after the input range has been mapped to a new range
+ ///
+ /// Input start.
+ /// Input end.
+ /// Output start.
+ /// Output end.
+ /// Value.
+ /// The newly mapped value
+ 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);
+ }
+
+ ///
+ /// Returns the value after the input range has been mapped to a new range
+ ///
+ /// Input start.
+ /// Input end.
+ /// Output start.
+ /// Output end.
+ /// Value.
+ /// The newly mapped value
+ 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);
+ }
+
///
/// 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.
diff --git a/ICD.Common.Utils/PathUtils.cs b/ICD.Common.Utils/PathUtils.cs
index 338a9aa..bf53748 100644
--- a/ICD.Common.Utils/PathUtils.cs
+++ b/ICD.Common.Utils/PathUtils.cs
@@ -58,29 +58,29 @@ namespace ICD.Common.Utils
///
///
[PublicAPI]
- public static string ProgramConfigPath
+ public static string ProgramConfigPath { get { return Join(RootConfigPath, ProgramConfigDirectory); } }
+
+ ///
+ /// Returns the name of the program config directory.
+ ///
+ [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.
///
[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"; }}
///
/// Returns the absolute path to the common config library directory.
diff --git a/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs b/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs
index 7c68f2b..f2ac4f7 100644
--- a/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs
+++ b/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs
@@ -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()
@@ -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()
@@ -88,6 +92,51 @@ namespace ICD.Common.Utils
}
}
+ ///
+ /// Gets the date that the firmware was updated.
+ ///
+ [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()
+ .AddEntry(eSeverity.Warning, "Unable to get model version date from \"{0}\"", VersionResult);
+
+ return string.Empty;
+ }
+ }
+
+ ///
+ /// Gets the serial number of the processor
+ ///
+ [PublicAPI]
+ public static string ProcessorSerialNumber
+ {
+ get
+ {
+ Regex regex = new Regex(VER_REGEX);
+ Match match = regex.Match(VersionResult);
+
+ if (!match.Success)
+ {
+ ServiceProvider.TryGetService()
+ .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();
+ }
+ }
+
///
/// Gets the ram usage in the range 0 - 1.
///
@@ -178,6 +227,31 @@ namespace ICD.Common.Utils
IcdConsole.SendControlSystemCommand("reboot", ref consoleResult);
}
+ ///
+ /// Gets the uptime for the system
+ ///
+ ///
+ [PublicAPI]
+ public static string GetSystemUptime()
+ {
+ string uptime = GetUptime();
+ Match match = Regex.Match(uptime, UPTIME_REGEX);
+ return match.Groups["uptime"].Value;
+ }
+
+ ///
+ /// Gets the uptime
+ ///
+ ///
+ ///
+ [PublicAPI]
+ public static string GetProgramUptime(int progslot)
+ {
+ string uptime = GetUptime(progslot);
+ Match match = Regex.Match(uptime, UPTIME_REGEX);
+ return match.Groups["uptime"].Value;
+ }
+
#endregion
///
@@ -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()
+ .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()
+ .AddEntry(eSeverity.Warning, "{0} - Failed to send console command \"{1}\"",
+ typeof(ProcessorUtils).Name, UPTIME_COMMAND);
+ }
+ return uptime;
+ }
}
}
diff --git a/ICD.Common.Utils/ProcessorUtils.Standard.cs b/ICD.Common.Utils/ProcessorUtils.Standard.cs
index d3fd703..619dc75 100644
--- a/ICD.Common.Utils/ProcessorUtils.Standard.cs
+++ b/ICD.Common.Utils/ProcessorUtils.Standard.cs
@@ -27,6 +27,32 @@ namespace ICD.Common.Utils
}
}
+ ///
+ /// Gets the date that the firmware was updated.
+ ///
+ [PublicAPI]
+ public static string ModelVersionDate
+ {
+ get
+ {
+ // TODO
+ return null;
+ }
+ }
+
+ ///
+ /// Gets the serial number of the processor
+ ///
+ [PublicAPI]
+ public static string ProcessorSerialNumber
+ {
+ get
+ {
+ // TODO
+ return null;
+ }
+ }
+
///
/// Gets the ram usage in the range 0 - 1.
///
@@ -109,6 +135,29 @@ namespace ICD.Common.Utils
throw new NotSupportedException();
}
+ ///
+ /// Gets the uptime for the system
+ ///
+ ///
+ [PublicAPI]
+ public static string GetSystemUptime()
+ {
+ // TODO
+ return null;
+ }
+
+ ///
+ /// Gets the uptime
+ ///
+ ///
+ ///
+ [PublicAPI]
+ public static string GetProgramUptime(int progslot)
+ {
+ // TODO
+ return null;
+ }
+
#endregion
}
}