mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 21:24:58 +00:00
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:
10
CHANGELOG.md
10
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
|
- Better VC-4 support for IcdConsole
|
||||||
- JSON refactoring for simpler deserialization
|
- 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
|
## [8.3.2] - 2019-05-02
|
||||||
### Changed
|
### Changed
|
||||||
- Fixed PriorityQueue IndexOutOfRange exception when an inner queue becomes depleted
|
- Fixed PriorityQueue IndexOutOfRange exception when an inner queue becomes depleted
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using ICD.Common.Properties;
|
|
||||||
|
|
||||||
namespace ICD.Common.Utils.Attributes
|
namespace ICD.Common.Utils.Attributes
|
||||||
{
|
{
|
||||||
@@ -16,15 +15,9 @@ namespace ICD.Common.Utils.Attributes
|
|||||||
{
|
{
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
[NotNull]
|
|
||||||
public object Min { get; private set; }
|
public object Min { get; private set; }
|
||||||
|
|
||||||
[NotNull]
|
|
||||||
public object Max { get; private set; }
|
public object Max { get; private set; }
|
||||||
|
|
||||||
[NotNull]
|
|
||||||
private Type Type { get { return Min.GetType(); } }
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@@ -99,130 +92,212 @@ namespace ICD.Common.Utils.Attributes
|
|||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
/// <summary>
|
public T GetMin<T>()
|
||||||
/// Returns true if the given value is within the range of Min to Max.
|
{
|
||||||
/// </summary>
|
return (T)Convert.ChangeType(Min, typeof(T), null);
|
||||||
/// <param name="value"></param>
|
}
|
||||||
/// <returns></returns>
|
|
||||||
|
public T GetMax<T>()
|
||||||
|
{
|
||||||
|
return (T)Convert.ChangeType(Max, typeof(T), null);
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsInRange(object value)
|
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)
|
if (value is ushort)
|
||||||
{
|
{
|
||||||
var castMin = (ushort)Min;
|
if (!(Min is ushort))
|
||||||
var castMax = (ushort)Max;
|
throw new ArgumentException("the type of value does not match the type of min / max");
|
||||||
|
|
||||||
var castVal = (ushort)value;
|
var castVal = (ushort)value;
|
||||||
return (castVal >= castMin && castVal <= castMax);
|
return (castVal >= GetMin<ushort>() && castVal <= GetMax<ushort>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is short)
|
if (value is short)
|
||||||
{
|
{
|
||||||
var castMin = (short)Min;
|
if (!(Min is short))
|
||||||
var castMax = (short)Max;
|
throw new ArgumentException("the type of value does not match the type of min / max");
|
||||||
|
|
||||||
var castVal = (short)value;
|
var castVal = (short)value;
|
||||||
return (castVal >= castMin && castVal <= castMax);
|
return (castVal >= GetMin<short>() && castVal <= GetMax<short>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is uint)
|
if (value is uint)
|
||||||
{
|
{
|
||||||
var castMin = (uint)Min;
|
if (!(Min is uint))
|
||||||
var castMax = (uint)Max;
|
throw new ArgumentException("the type of value does not match the type of min / max");
|
||||||
|
|
||||||
var castVal = (uint)value;
|
var castVal = (uint)value;
|
||||||
return (castVal >= castMin && castVal <= castMax);
|
return (castVal >= GetMin<uint>() && castVal <= GetMax<uint>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is int)
|
if (value is int)
|
||||||
{
|
{
|
||||||
var castMin = (int)Min;
|
if (!(Min is int))
|
||||||
var castMax = (int)Max;
|
throw new ArgumentException("the type of value does not match the type of min / max");
|
||||||
|
|
||||||
var castVal = (int)value;
|
var castVal = (int)value;
|
||||||
return (castVal >= castMin && castVal <= castMax);
|
return (castVal >= GetMin<int>() && castVal <= GetMax<int>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is ulong)
|
if (value is ulong)
|
||||||
{
|
{
|
||||||
var castMin = (ulong)Min;
|
if (!(Min is ulong))
|
||||||
var castMax = (ulong)Max;
|
throw new ArgumentException("the type of value does not match the type of min / max");
|
||||||
|
|
||||||
var castVal = (ulong)value;
|
var castVal = (ulong)value;
|
||||||
return (castVal >= castMin && castVal <= castMax);
|
return (castVal >= GetMin<ulong>() && castVal <= GetMax<ulong>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is long)
|
if (value is long)
|
||||||
{
|
{
|
||||||
var castMin = (long)Min;
|
if (!(Min is long))
|
||||||
var castMax = (long)Max;
|
throw new ArgumentException("the type of value does not match the type of min / max");
|
||||||
|
|
||||||
var castVal = (long)value;
|
var castVal = (long)value;
|
||||||
return (castVal >= castMin && castVal <= castMax);
|
return (castVal >= GetMin<long>() && castVal <= GetMax<long>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is float)
|
if (value is float)
|
||||||
{
|
{
|
||||||
var castMin = (float)Min;
|
if (!(Min is float))
|
||||||
var castMax = (float)Max;
|
throw new ArgumentException("the type of value does not match the type of min / max");
|
||||||
|
|
||||||
var castVal = (float)value;
|
var castVal = (float)value;
|
||||||
return (castVal >= castMin && castVal <= castMax);
|
return (castVal >= GetMin<float>() && castVal <= GetMax<float>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is double)
|
if (value is double)
|
||||||
{
|
{
|
||||||
var castMin = (double)Min;
|
if (!(Min is double))
|
||||||
var castMax = (double)Max;
|
throw new ArgumentException("the type of value does not match the type of min / max");
|
||||||
|
|
||||||
var castVal = (double)value;
|
var castVal = (double)value;
|
||||||
return (castVal >= castMin && castVal <= castMax);
|
return (castVal >= GetMin<double>() && castVal <= GetMax<double>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is decimal)
|
if (value is decimal)
|
||||||
{
|
{
|
||||||
var castMin = (decimal)Min;
|
if (!(Min is decimal))
|
||||||
var castMax = (decimal)Max;
|
throw new ArgumentException("the type of value does not match the type of min / max");
|
||||||
|
|
||||||
var castVal = (decimal)value;
|
var castVal = (decimal)value;
|
||||||
return (castVal >= castMin && castVal <= castMax);
|
return (castVal >= GetMin<decimal>() && castVal <= GetMax<decimal>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is byte)
|
if (value is byte)
|
||||||
{
|
{
|
||||||
var castMin = (byte)Min;
|
if (!(Min is byte))
|
||||||
var castMax = (byte)Max;
|
throw new ArgumentException("the type of value does not match the type of min / max");
|
||||||
|
|
||||||
var castVal = (byte)value;
|
var castVal = (byte)value;
|
||||||
return (castVal >= castMin && castVal <= castMax);
|
return (castVal >= GetMin<byte>() && castVal <= GetMax<byte>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is sbyte)
|
if (value is sbyte)
|
||||||
{
|
{
|
||||||
var castMin = (sbyte)Min;
|
if (!(Min is sbyte))
|
||||||
var castMax = (sbyte)Max;
|
throw new ArgumentException("the type of value does not match the type of min / max");
|
||||||
|
|
||||||
var castVal = (sbyte)value;
|
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.");
|
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
|
#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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,5 +221,29 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
|
|
||||||
return extends.Contains(character.ToString());
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
ICD.Common.Utils/GuidUtils.cs
Normal file
17
ICD.Common.Utils/GuidUtils.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -117,6 +117,7 @@
|
|||||||
<Compile Include="Extensions\UriExtensions.cs" />
|
<Compile Include="Extensions\UriExtensions.cs" />
|
||||||
<Compile Include="Extensions\UShortExtensions.cs" />
|
<Compile Include="Extensions\UShortExtensions.cs" />
|
||||||
<Compile Include="Globalization\IcdCultureInfo.cs" />
|
<Compile Include="Globalization\IcdCultureInfo.cs" />
|
||||||
|
<Compile Include="GuidUtils.cs" />
|
||||||
<Compile Include="IcdUriBuilder.cs" />
|
<Compile Include="IcdUriBuilder.cs" />
|
||||||
<Compile Include="IO\Compression\IcdZipEntry.cs" />
|
<Compile Include="IO\Compression\IcdZipEntry.cs" />
|
||||||
<Compile Include="IO\IcdBinaryReader.cs" />
|
<Compile Include="IO\IcdBinaryReader.cs" />
|
||||||
|
|||||||
@@ -30,9 +30,36 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
const CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET param =
|
const CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET param =
|
||||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS;
|
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS;
|
||||||
const EthernetAdapterType type = EthernetAdapterType.EthernetLANAdapter;
|
const EthernetAdapterType primaryType = EthernetAdapterType.EthernetLANAdapter;
|
||||||
short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type);
|
const EthernetAdapterType secondaryType = EthernetAdapterType.EthernetLAN2Adapter;
|
||||||
yield return CrestronEthernetHelper.GetEthernetParameter(param, id);
|
|
||||||
|
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 =
|
const CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET param =
|
||||||
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_MAC_ADDRESS;
|
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;
|
const EthernetAdapterType type = EthernetAdapterType.EthernetLANAdapter;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type);
|
short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type);
|
||||||
yield return CrestronEthernetHelper.GetEthernetParameter(param, id);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -13,11 +14,6 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
public static string NewLine { get { return Environment.NewLine; } }
|
public static string NewLine { get { return Environment.NewLine; } }
|
||||||
|
|
||||||
public static DateTime GetLocalTime()
|
|
||||||
{
|
|
||||||
return DateTime.Now;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static eRuntimeEnvironment RuntimeEnvironment { get { return eRuntimeEnvironment.Standard; } }
|
public static eRuntimeEnvironment RuntimeEnvironment { get { return eRuntimeEnvironment.Standard; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// <summary>
|
||||||
/// Converts 12 digit address to XX:XX:XX... format
|
/// Converts 12 digit address to XX:XX:XX... format
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -78,6 +78,24 @@ namespace ICD.Common.Utils
|
|||||||
return outputStart + slope * (value - 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 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>
|
/// <summary>
|
||||||
/// Returns the value after the input range has been mapped to a new range
|
/// Returns the value after the input range has been mapped to a new range
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -120,6 +138,42 @@ namespace ICD.Common.Utils
|
|||||||
return (ushort)MapRange((double)inputStart, inputEnd, outputStart, outputEnd, value);
|
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>
|
/// <summary>
|
||||||
/// Maps the date in the given range to the float range 0.0f to 1.0f.
|
/// 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.
|
/// 0.5f - The date is half way between the end points.
|
||||||
|
|||||||
@@ -58,29 +58,29 @@ namespace ICD.Common.Utils
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
[PublicAPI]
|
[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
|
get
|
||||||
{
|
{
|
||||||
string directoryName;
|
|
||||||
|
|
||||||
switch (IcdEnvironment.RuntimeEnvironment)
|
switch (IcdEnvironment.RuntimeEnvironment)
|
||||||
{
|
{
|
||||||
case IcdEnvironment.eRuntimeEnvironment.SimplSharp:
|
case IcdEnvironment.eRuntimeEnvironment.SimplSharp:
|
||||||
case IcdEnvironment.eRuntimeEnvironment.SimplSharpPro:
|
case IcdEnvironment.eRuntimeEnvironment.SimplSharpPro:
|
||||||
case IcdEnvironment.eRuntimeEnvironment.Standard:
|
case IcdEnvironment.eRuntimeEnvironment.Standard:
|
||||||
directoryName = string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber);
|
return string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber);
|
||||||
break;
|
|
||||||
|
|
||||||
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono:
|
case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono:
|
||||||
directoryName = "ProgramConfig";
|
return "ProgramConfig";
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Join(RootConfigPath, directoryName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +88,10 @@ namespace ICD.Common.Utils
|
|||||||
/// Returns the absolute path to the common configuration directory.
|
/// Returns the absolute path to the common configuration directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[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>
|
/// <summary>
|
||||||
/// Returns the absolute path to the common config library directory.
|
/// Returns the absolute path to the common config library directory.
|
||||||
|
|||||||
@@ -9,8 +9,12 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
public static partial class ProcessorUtils
|
public static partial class ProcessorUtils
|
||||||
{
|
{
|
||||||
private const string MODEL_NAME_REGEX = @"^(\S*)";
|
private const string VER_REGEX =
|
||||||
private const string MODEL_VERSION_REGEX = @" [[]v(\S*)";
|
@"(?'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_COMMAND = "ramfree";
|
||||||
private const string RAMFREE_DIGITS_REGEX = @"^(\d*)";
|
private const string RAMFREE_DIGITS_REGEX = @"^(\d*)";
|
||||||
@@ -51,11 +55,11 @@ namespace ICD.Common.Utils
|
|||||||
string versionResult = VersionResult;
|
string versionResult = VersionResult;
|
||||||
if (!String.IsNullOrEmpty(versionResult))
|
if (!String.IsNullOrEmpty(versionResult))
|
||||||
{
|
{
|
||||||
Regex regex = new Regex(MODEL_NAME_REGEX);
|
Regex regex = new Regex(VER_REGEX);
|
||||||
Match match = regex.Match(versionResult);
|
Match match = regex.Match(versionResult);
|
||||||
|
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
return match.Groups[1].Value;
|
return match.Groups["model"].Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceProvider.TryGetService<ILoggerService>()
|
ServiceProvider.TryGetService<ILoggerService>()
|
||||||
@@ -75,11 +79,11 @@ namespace ICD.Common.Utils
|
|||||||
string versionResult = VersionResult;
|
string versionResult = VersionResult;
|
||||||
if (!String.IsNullOrEmpty(versionResult))
|
if (!String.IsNullOrEmpty(versionResult))
|
||||||
{
|
{
|
||||||
Regex regex = new Regex(MODEL_VERSION_REGEX);
|
Regex regex = new Regex(VER_REGEX);
|
||||||
Match match = regex.Match(VersionResult);
|
Match match = regex.Match(VersionResult);
|
||||||
|
|
||||||
if (match.Success)
|
if (match.Success)
|
||||||
return new Version(match.Groups[1].Value);
|
return new Version(match.Groups["version"].Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceProvider.TryGetService<ILoggerService>()
|
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>
|
/// <summary>
|
||||||
/// Gets the ram usage in the range 0 - 1.
|
/// Gets the ram usage in the range 0 - 1.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -178,6 +227,31 @@ 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 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
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -195,6 +269,30 @@ namespace ICD.Common.Utils
|
|||||||
}
|
}
|
||||||
return ramfree;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
/// <summary>
|
||||||
/// Gets the ram usage in the range 0 - 1.
|
/// Gets the ram usage in the range 0 - 1.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -109,6 +135,29 @@ namespace ICD.Common.Utils
|
|||||||
throw new NotSupportedException();
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user