From 49f8f116fd45a8db561625a072d2f8e69c251e6c Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 16 Jan 2020 15:49:40 -0500 Subject: [PATCH 1/4] feat: Simplifying network interfaces, enumerating all adapter types # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 3 + ICD.Common.Utils/IcdEnvironment.SimplSharp.cs | 123 +++++++----------- 2 files changed, 48 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1365e4..c7d31a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + - Network/MAC/DNS address utils are now enumerating all adapter types + ## [10.2.0] - 2019-12-04 ### Added - Added shim methods for finding closest DateTimes from a sequence diff --git a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs index 3b7aad2..70a1caa 100644 --- a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs +++ b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs @@ -9,6 +9,8 @@ namespace ICD.Common.Utils { public static partial class IcdEnvironment { + #region Properties + public static string NewLine { get { return CrestronEnvironment.NewLine; } } public static eRuntimeEnvironment RuntimeEnvironment @@ -31,36 +33,24 @@ namespace ICD.Common.Utils { const CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET param = CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS; - const EthernetAdapterType primaryType = EthernetAdapterType.EthernetLANAdapter; - const EthernetAdapterType secondaryType = EthernetAdapterType.EthernetLAN2Adapter; - string address1 = null; - - try + foreach (EthernetAdapterType type in EnumUtils.GetValuesExceptNone()) { - short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(primaryType); - address1 = CrestronEthernetHelper.GetEthernetParameter(param, id); - } - catch (ArgumentException) - { - } - - if (!string.IsNullOrEmpty(address1)) - yield return address1; + string address; - string address2 = null; + try + { + short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type); + address = CrestronEthernetHelper.GetEthernetParameter(param, id); + } + catch (ArgumentException) + { + continue; + } - try - { - short adapter2Type = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(secondaryType); - address2 = CrestronEthernetHelper.GetEthernetParameter(param, adapter2Type); + if (!string.IsNullOrEmpty(address)) + yield return address; } - catch (ArgumentException) - { - } - - if (!string.IsNullOrEmpty(address2)) - yield return address2; } } @@ -74,36 +64,24 @@ 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 + foreach (EthernetAdapterType type in EnumUtils.GetValuesExceptNone()) { - short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(primaryType); - macAddress1 = CrestronEthernetHelper.GetEthernetParameter(param, id); - } - catch (ArgumentException) - { - } + string macAddress; - if (!string.IsNullOrEmpty(macAddress1)) - yield return macAddress1; + try + { + short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type); + macAddress = CrestronEthernetHelper.GetEthernetParameter(param, id); + } + catch (ArgumentException) + { + continue; + } - string macAddress2 = null; - - try - { - short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(secondaryType); - macAddress2 = CrestronEthernetHelper.GetEthernetParameter(param, id); + if (!string.IsNullOrEmpty(macAddress)) + yield return macAddress; } - catch (ArgumentException) - { - } - - if (!string.IsNullOrEmpty(macAddress2)) - yield return macAddress2; } } @@ -141,40 +119,29 @@ namespace ICD.Common.Utils { 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 + foreach (EthernetAdapterType type in EnumUtils.GetValuesExceptNone()) { - short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(primaryType); - address1 = CrestronEthernetHelper.GetEthernetParameter(param, id); + string hostname; + + try + { + short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type); + hostname = CrestronEthernetHelper.GetEthernetParameter(param, id); + } + catch (ArgumentException) + { + continue; + } + + if (!string.IsNullOrEmpty(hostname)) + yield return hostname; } - 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; } } + #endregion + /// /// Static constructor. /// From 89f0214ccef0faeb8254abbb22b23e085a8b2755 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 16 Jan 2020 15:51:05 -0500 Subject: [PATCH 2/4] fix: Ignoring Crestron ethernet parameters that say "Invalid Value" --- CHANGELOG.md | 1 + ICD.Common.Utils/IcdEnvironment.SimplSharp.cs | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7d31a1..8f8b2ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Network/MAC/DNS address utils are now enumerating all adapter types + - Ignoring Crestron ethernet parameters that say "Invalid Value" ## [10.2.0] - 2019-12-04 ### Added diff --git a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs index 70a1caa..3d156f8 100644 --- a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs +++ b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs @@ -1,14 +1,19 @@ -using ICD.Common.Utils.Extensions; -#if SIMPLSHARP +#if SIMPLSHARP using System; using System.Collections.Generic; using Crestron.SimplSharp; using ICD.Common.Properties; +using ICD.Common.Utils.Extensions; namespace ICD.Common.Utils { public static partial class IcdEnvironment { + /// + /// For some reason crestron returns "Invalid Value" for ethernet parameters sometimes :/ + /// + private const string INVALID_VALUE = "Invalid Value"; + #region Properties public static string NewLine { get { return CrestronEnvironment.NewLine; } } @@ -48,7 +53,7 @@ namespace ICD.Common.Utils continue; } - if (!string.IsNullOrEmpty(address)) + if (!string.IsNullOrEmpty(address) && !address.Equals(INVALID_VALUE)) yield return address; } } @@ -79,7 +84,7 @@ namespace ICD.Common.Utils continue; } - if (!string.IsNullOrEmpty(macAddress)) + if (!string.IsNullOrEmpty(macAddress) && !macAddress.Equals(INVALID_VALUE)) yield return macAddress; } } @@ -100,7 +105,12 @@ namespace ICD.Common.Utils try { short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type); - return CrestronEthernetHelper.GetEthernetParameter(param, id); + string status = CrestronEthernetHelper.GetEthernetParameter(param, id); + + if (!string.IsNullOrEmpty(status) && !status.Equals(INVALID_VALUE)) + return status; + + return null; } catch (ArgumentException) { @@ -134,7 +144,7 @@ namespace ICD.Common.Utils continue; } - if (!string.IsNullOrEmpty(hostname)) + if (!string.IsNullOrEmpty(hostname) && !hostname.Equals(INVALID_VALUE)) yield return hostname; } } From 201639b30bde3a7fc73996acf3aec0b6b1363c86 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Fri, 17 Jan 2020 11:06:02 -0500 Subject: [PATCH 3/4] fix: Skip over invalid adapter ids when getting network information --- CHANGELOG.md | 1 + ICD.Common.Utils/IcdEnvironment.SimplSharp.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f8b2ab..61652bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Network/MAC/DNS address utils are now enumerating all adapter types - Ignoring Crestron ethernet parameters that say "Invalid Value" + - Skipping network interfaces with an invalid adapter id ## [10.2.0] - 2019-12-04 ### Added diff --git a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs index 3d156f8..e43e2fa 100644 --- a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs +++ b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs @@ -46,6 +46,9 @@ namespace ICD.Common.Utils try { short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type); + if (id >= InitialParametersClass.NumberOfEthernetInterfaces) + continue; + address = CrestronEthernetHelper.GetEthernetParameter(param, id); } catch (ArgumentException) @@ -77,6 +80,9 @@ namespace ICD.Common.Utils try { short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type); + if (id >= InitialParametersClass.NumberOfEthernetInterfaces) + continue; + macAddress = CrestronEthernetHelper.GetEthernetParameter(param, id); } catch (ArgumentException) @@ -105,6 +111,9 @@ namespace ICD.Common.Utils try { short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type); + if (id >= InitialParametersClass.NumberOfEthernetInterfaces) + return null; + string status = CrestronEthernetHelper.GetEthernetParameter(param, id); if (!string.IsNullOrEmpty(status) && !status.Equals(INVALID_VALUE)) @@ -137,6 +146,9 @@ namespace ICD.Common.Utils try { short id = CrestronEthernetHelper.GetAdapterdIdForSpecifiedAdapterType(type); + if (id >= InitialParametersClass.NumberOfEthernetInterfaces) + continue; + hostname = CrestronEthernetHelper.GetEthernetParameter(param, id); } catch (ArgumentException) From bf8061046bb9be18941f5a97239cd6509867b13c Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Mon, 20 Jan 2020 11:30:45 -0500 Subject: [PATCH 4/4] chore: Updating changelog, incrementing minor version --- CHANGELOG.md | 1 + ICD.Common.Utils/Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61652bf..1a54a88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [10.3.0] - 2020-01-20 ### Changed - Network/MAC/DNS address utils are now enumerating all adapter types - Ignoring Crestron ethernet parameters that say "Invalid Value" diff --git a/ICD.Common.Utils/Properties/AssemblyInfo.cs b/ICD.Common.Utils/Properties/AssemblyInfo.cs index fae3151..fa5d96e 100644 --- a/ICD.Common.Utils/Properties/AssemblyInfo.cs +++ b/ICD.Common.Utils/Properties/AssemblyInfo.cs @@ -3,5 +3,5 @@ using System.Reflection; [assembly: AssemblyTitle("ICD.Common.Utils")] [assembly: AssemblyCompany("ICD Systems")] [assembly: AssemblyProduct("ICD.Common.Utils")] -[assembly: AssemblyCopyright("Copyright © ICD Systems 2019")] -[assembly: AssemblyVersion("10.2.0.0")] +[assembly: AssemblyCopyright("Copyright © ICD Systems 2020")] +[assembly: AssemblyVersion("10.3.0.0")]