From a6ad52d4920f94ef6091f5674520f2a6060369bb Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 10 Jan 2019 10:25:46 -0500 Subject: [PATCH 01/18] refactor: Removing log from ReflectionUtils.CreateInstance, doesn't make sense here --- ICD.Common.Utils/ReflectionUtils.cs | 31 +++++++---------------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/ICD.Common.Utils/ReflectionUtils.cs b/ICD.Common.Utils/ReflectionUtils.cs index a5b1ff6..e2a2ddf 100644 --- a/ICD.Common.Utils/ReflectionUtils.cs +++ b/ICD.Common.Utils/ReflectionUtils.cs @@ -4,8 +4,6 @@ using System.Linq; using ICD.Common.Properties; using ICD.Common.Utils.Extensions; using ICD.Common.Utils.IO; -using ICD.Common.Utils.Services; -using ICD.Common.Utils.Services.Logging; #if SIMPLSHARP using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.Reflection; @@ -170,6 +168,7 @@ namespace ICD.Common.Utils /// /// /// + [NotNull] public static Delegate CreateDelegate(Type type, object firstArgument, MethodInfo method) { return @@ -185,6 +184,7 @@ namespace ICD.Common.Utils /// Creates an instance of the given type, calling the default constructor. /// /// + [NotNull] public static T CreateInstance(Type type) { if (type == null) @@ -198,6 +198,7 @@ namespace ICD.Common.Utils /// /// /// + [NotNull] public static T CreateInstance(params object[] parameters) { if (parameters == null) @@ -210,6 +211,7 @@ namespace ICD.Common.Utils /// Creates an instance of the given type, calling the default constructor. /// /// + [NotNull] public static object CreateInstance(Type type, params object[] parameters) { if (type == null) @@ -218,28 +220,7 @@ namespace ICD.Common.Utils if (parameters == null) throw new ArgumentNullException("parameters"); - ConstructorInfo constructor = null; - - try - { - constructor = GetConstructor(type, parameters); - } - catch (ArgumentException e) - { - var logger = ServiceProvider.GetService(); - - logger.AddEntry(eSeverity.Error, "Could not find constructor while attempting to create instance."); - logger.AddEntry(eSeverity.Error, "Attempted to create an instance of type {0}", type.ToString()); - logger.AddEntry(eSeverity.Error, "With the following parameters:"); - foreach (var param in parameters) - { - logger.AddEntry(eSeverity.Error, "Type:{0}, Value:{1}", param.GetType().ToString(), param.ToString()); - } - logger.AddEntry(eSeverity.Error, "No valid constructor exists for this set of parameters."); - } - - if (constructor == null) - return null; + ConstructorInfo constructor = GetConstructor(type, parameters); try { @@ -289,6 +270,7 @@ namespace ICD.Common.Utils /// /// /// + [NotNull] public static Assembly LoadAssemblyFromPath(string path) { if (path == null) @@ -377,6 +359,7 @@ namespace ICD.Common.Utils /// The instance with the callback MethodInfo. Null for static types. /// The MethodInfo for the callback method. /// + [NotNull] public static Delegate SubscribeEvent(object instance, EventInfo eventInfo, object handler, MethodInfo callback) { if (eventInfo == null) From b9ec2f322285454b1245bab5ba0fdce1e6630501 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 10 Jan 2019 10:45:53 -0500 Subject: [PATCH 02/18] refactor: Tidying --- ICD.Common.Utils/Attributes/RangeAttribute.cs | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/ICD.Common.Utils/Attributes/RangeAttribute.cs b/ICD.Common.Utils/Attributes/RangeAttribute.cs index 31907e0..deb9813 100644 --- a/ICD.Common.Utils/Attributes/RangeAttribute.cs +++ b/ICD.Common.Utils/Attributes/RangeAttribute.cs @@ -1,4 +1,5 @@ using System; +using ICD.Common.Properties; namespace ICD.Common.Utils.Attributes { @@ -11,11 +12,23 @@ namespace ICD.Common.Utils.Attributes AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)] - public class RangeAttribute : AbstractIcdAttribute + public sealed class RangeAttribute : AbstractIcdAttribute { + #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 + public RangeAttribute(ushort min, ushort max) { Min = min; @@ -82,13 +95,25 @@ namespace ICD.Common.Utils.Attributes Max = max; } + #endregion + + #region Methods + + /// + /// Returns true if the given value is within the range of Min to Max. + /// + /// + /// 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 (!(Min is ushort)) - throw new ArgumentException("the type of value does not match the type of min / max"); - var castMin = (ushort)Min; var castMax = (ushort)Max; var castVal = (ushort)value; @@ -97,9 +122,6 @@ namespace ICD.Common.Utils.Attributes if (value is short) { - if (!(Min is short)) - throw new ArgumentException("the type of value does not match the type of min / max"); - var castMin = (short)Min; var castMax = (short)Max; var castVal = (short)value; @@ -108,9 +130,6 @@ namespace ICD.Common.Utils.Attributes if (value is uint) { - if (!(Min is uint)) - throw new ArgumentException("the type of value does not match the type of min / max"); - var castMin = (uint)Min; var castMax = (uint)Max; var castVal = (uint)value; @@ -119,9 +138,6 @@ namespace ICD.Common.Utils.Attributes if (value is int) { - if (!(Min is int)) - throw new ArgumentException("the type of value does not match the type of min / max"); - var castMin = (int)Min; var castMax = (int)Max; var castVal = (int)value; @@ -130,9 +146,6 @@ namespace ICD.Common.Utils.Attributes if (value is ulong) { - if (!(Min is ulong)) - throw new ArgumentException("the type of value does not match the type of min / max"); - var castMin = (ulong)Min; var castMax = (ulong)Max; var castVal = (ulong)value; @@ -141,9 +154,6 @@ namespace ICD.Common.Utils.Attributes if (value is long) { - if (!(Min is long)) - throw new ArgumentException("the type of value does not match the type of min / max"); - var castMin = (long)Min; var castMax = (long)Max; var castVal = (long)value; @@ -152,9 +162,6 @@ namespace ICD.Common.Utils.Attributes if (value is float) { - if (!(Min is float)) - throw new ArgumentException("the type of value does not match the type of min / max"); - var castMin = (float)Min; var castMax = (float)Max; var castVal = (float)value; @@ -163,9 +170,6 @@ namespace ICD.Common.Utils.Attributes if (value is double) { - if (!(Min is double)) - throw new ArgumentException("the type of value does not match the type of min / max"); - var castMin = (double)Min; var castMax = (double)Max; var castVal = (double)value; @@ -174,9 +178,6 @@ namespace ICD.Common.Utils.Attributes if (value is decimal) { - if (!(Min is decimal)) - throw new ArgumentException("the type of value does not match the type of min / max"); - var castMin = (decimal)Min; var castMax = (decimal)Max; var castVal = (decimal)value; @@ -185,9 +186,6 @@ namespace ICD.Common.Utils.Attributes if (value is byte) { - if (!(Min is byte)) - throw new ArgumentException("the type of value does not match the type of min / max"); - var castMin = (byte)Min; var castMax = (byte)Max; var castVal = (byte)value; @@ -196,9 +194,6 @@ namespace ICD.Common.Utils.Attributes if (value is sbyte) { - if (!(Min is sbyte)) - throw new ArgumentException("the type of value does not match the type of min / max"); - var castMin = (sbyte)Min; var castMax = (sbyte)Max; var castVal = (sbyte)value; @@ -208,24 +203,26 @@ namespace ICD.Common.Utils.Attributes throw new ArgumentException("the type of value is not a numeric type."); } - public ushort RemapRangeToUshort(double value) + public ushort RemapRangeToUShort(double value) { return (ushort)MathUtils.MapRange((double)Min, (double)Max, 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); } - public ushort RemapRangeToUshort(int value) + public ushort RemapRangeToUShort(int value) { return (ushort)MathUtils.MapRange((int)Min, (int)Max, 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); } + + #endregion } } \ No newline at end of file From 80a0ca26c5a78f76db2b4879f41f2e00334edac0 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 10 Jan 2019 16:11:00 -0500 Subject: [PATCH 03/18] chore: Updating changelog, incrementing minor version --- CHANGELOG.md | 7 +++++++ ICD.Common.Utils/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da1e65f..cd0afaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [8.2.0] - 2019-01-10 +### Added + - Added TryGetPortForScheme method to UriExtensions + - Added range attribute for clarifying numeric fields, properties and parameters + ### Changed - IcdHashSet preserves comparer when an operation creates a new IcdHashSet + - Fixed bug where XML fragments on Net Standard were being prepended with a document header ## [8.1.0] - 2019-01-02 ### Added diff --git a/ICD.Common.Utils/Properties/AssemblyInfo.cs b/ICD.Common.Utils/Properties/AssemblyInfo.cs index 4497a46..78de1a6 100644 --- a/ICD.Common.Utils/Properties/AssemblyInfo.cs +++ b/ICD.Common.Utils/Properties/AssemblyInfo.cs @@ -4,4 +4,4 @@ using System.Reflection; [assembly: AssemblyCompany("ICD Systems")] [assembly: AssemblyProduct("ICD.Common.Utils")] [assembly: AssemblyCopyright("Copyright © ICD Systems 2018")] -[assembly: AssemblyVersion("8.1.0.0")] +[assembly: AssemblyVersion("8.2.0.0")] From 27760f22828f227e5734ab1f7ccc094a1e6d6082 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Mon, 14 Jan 2019 16:42:32 -0500 Subject: [PATCH 04/18] fix: Resolving warning --- ICD.Common.Utils/Xml/AbstractGenericXmlConverter.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ICD.Common.Utils/Xml/AbstractGenericXmlConverter.cs b/ICD.Common.Utils/Xml/AbstractGenericXmlConverter.cs index e8fafcf..1673858 100644 --- a/ICD.Common.Utils/Xml/AbstractGenericXmlConverter.cs +++ b/ICD.Common.Utils/Xml/AbstractGenericXmlConverter.cs @@ -48,7 +48,9 @@ namespace ICD.Common.Utils.Xml if (writer == null) throw new ArgumentNullException("writer"); +// ReSharper disable CompareNonConstrainedGenericWithNull if (value == null) +// ReSharper restore CompareNonConstrainedGenericWithNull { writer.WriteElementString(elementName, null); return; From 8401ab1852e2b5a5faab41417e02d963ab88067f Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 17 Jan 2019 17:15:34 -0500 Subject: [PATCH 05/18] feat: Added SimplSharpProMono to eRuntimeEnvironment enum --- CHANGELOG.md | 5 +++++ ICD.Common.Utils/IcdConsole.cs | 4 ++++ ICD.Common.Utils/IcdEnvironment.SimplSharp.cs | 7 ++++++- ICD.Common.Utils/IcdEnvironment.cs | 1 + ICD.Common.Utils/ProgramUtils.cs | 4 ++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd0afaa..ecc2759 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + - Added SimplSharpProMono to eRuntimeEnvironment enum + +### Changed + - Small fixes for better VC4 support ## [8.2.0] - 2019-01-10 ### Added diff --git a/ICD.Common.Utils/IcdConsole.cs b/ICD.Common.Utils/IcdConsole.cs index 5ca1894..fe00a64 100644 --- a/ICD.Common.Utils/IcdConsole.cs +++ b/ICD.Common.Utils/IcdConsole.cs @@ -123,6 +123,10 @@ namespace ICD.Common.Utils public static bool SendControlSystemCommand(string command, ref string result) { #if SIMPLSHARP + // No console on VC4 + if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono) + return false; + return CrestronConsole.SendControlSystemCommand(command, ref result); #else return false; diff --git a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs index 68a8ef9..3452213 100644 --- a/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs +++ b/ICD.Common.Utils/IcdEnvironment.SimplSharp.cs @@ -12,7 +12,12 @@ namespace ICD.Common.Utils public static eRuntimeEnvironment RuntimeEnvironment { - get { return GetRuntimeEnvironment(CrestronEnvironment.RuntimeEnvironment); } + get + { + return CrestronEnvironment.DevicePlatform == eDevicePlatform.Server + ? eRuntimeEnvironment.SimplSharpProMono + : GetRuntimeEnvironment(CrestronEnvironment.RuntimeEnvironment); + } } /// diff --git a/ICD.Common.Utils/IcdEnvironment.cs b/ICD.Common.Utils/IcdEnvironment.cs index f947cab..f0d6a36 100644 --- a/ICD.Common.Utils/IcdEnvironment.cs +++ b/ICD.Common.Utils/IcdEnvironment.cs @@ -11,6 +11,7 @@ namespace ICD.Common.Utils { SimplSharp, SimplSharpPro, + SimplSharpProMono, Standard } diff --git a/ICD.Common.Utils/ProgramUtils.cs b/ICD.Common.Utils/ProgramUtils.cs index d291371..91fbdbf 100644 --- a/ICD.Common.Utils/ProgramUtils.cs +++ b/ICD.Common.Utils/ProgramUtils.cs @@ -33,6 +33,10 @@ namespace ICD.Common.Utils name = name.Substring(0, proLength).PadRight(26); break; + case IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono: + // No console + return; + case IcdEnvironment.eRuntimeEnvironment.Standard: name += ' '; break; From e708ef9603279e219b8bc137033bbc3897b0b21c Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Mon, 21 Jan 2019 11:49:21 -0500 Subject: [PATCH 06/18] fix: Fix for potential memory leak with timers --- ICD.Common.Utils/Timers/SafeTimer.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ICD.Common.Utils/Timers/SafeTimer.cs b/ICD.Common.Utils/Timers/SafeTimer.cs index 526c80e..1047f7d 100644 --- a/ICD.Common.Utils/Timers/SafeTimer.cs +++ b/ICD.Common.Utils/Timers/SafeTimer.cs @@ -20,7 +20,7 @@ namespace ICD.Common.Utils.Timers private readonly Timer m_Timer; private int m_RepeatPeriod; #endif - private readonly Action m_Callback; + private Action m_Callback; /// /// Returns true if this instance has been disposed. @@ -88,6 +88,8 @@ namespace ICD.Common.Utils.Timers Stop(); m_Timer.Dispose(); + m_Callback = null; + IsDisposed = true; } From a9d411dcfdab297ab947305672da0f88e582df48 Mon Sep 17 00:00:00 2001 From: Drew Tingen Date: Tue, 22 Jan 2019 09:11:48 -0800 Subject: [PATCH 07/18] feat: Path support for VC-4 --- ICD.Common.Utils/IO/IcdDirectory.cs | 12 ++++++++++++ ICD.Common.Utils/PathUtils.cs | 29 ++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/ICD.Common.Utils/IO/IcdDirectory.cs b/ICD.Common.Utils/IO/IcdDirectory.cs index 3ac77ad..4ae98bf 100644 --- a/ICD.Common.Utils/IO/IcdDirectory.cs +++ b/ICD.Common.Utils/IO/IcdDirectory.cs @@ -19,6 +19,18 @@ namespace ICD.Common.Utils.IO #endif } + +#if SIMPLSHARP + /// + /// This gets the application root directory for Crestron systems + /// + /// + public static string GetApplicationRootDirectory() + { + return Directory.GetApplicationRootDirectory(); + } +#endif + public static bool Exists(string path) { if (path == null) diff --git a/ICD.Common.Utils/PathUtils.cs b/ICD.Common.Utils/PathUtils.cs index 491fbae..7d56fe5 100644 --- a/ICD.Common.Utils/PathUtils.cs +++ b/ICD.Common.Utils/PathUtils.cs @@ -3,6 +3,9 @@ using System.Linq; using ICD.Common.Properties; using ICD.Common.Utils.Extensions; using ICD.Common.Utils.IO; +#if SIMPLSHARP +using Crestron.SimplSharp; +#endif namespace ICD.Common.Utils { @@ -17,7 +20,16 @@ namespace ICD.Common.Utils /// Gets the path to the root directory of the processor. /// [PublicAPI] - public static string RootPath { get { return IcdDirectory.GetDirectoryRoot("\\"); } } + public static string RootPath { + get + { +#if SIMPLSHARP + if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono) + return IcdDirectory.GetApplicationRootDirectory(); +#endif + return IcdDirectory.GetDirectoryRoot(IcdPath.DirectorySeparatorChar.ToString()); + } + } /// /// Gets the path to the program directory @@ -35,7 +47,7 @@ namespace ICD.Common.Utils get { #if SIMPLSHARP - return Join(RootPath, "USER"); + return Join(RootPath, "User"); #elif LINUX return Join(RootPath, "opt", "ICD.Connect"); #else @@ -53,6 +65,12 @@ namespace ICD.Common.Utils { get { +#if SIMPLSHARP + if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Server) + { + return Join(RootConfigPath, "ProgramConfig"); + } +#endif string directoryName = string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber); return Join(RootConfigPath, directoryName); } @@ -62,7 +80,12 @@ 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, "CommonConfig"); + } + } /// /// Returns the absolute path to the common config library directory. From 3cb29452a272daa299dc61fc9ecbecd0c39b7176 Mon Sep 17 00:00:00 2001 From: Drew Tingen Date: Tue, 22 Jan 2019 09:17:35 -0800 Subject: [PATCH 08/18] chore: tidying --- ICD.Common.Utils/PathUtils.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ICD.Common.Utils/PathUtils.cs b/ICD.Common.Utils/PathUtils.cs index 7d56fe5..3b5a20c 100644 --- a/ICD.Common.Utils/PathUtils.cs +++ b/ICD.Common.Utils/PathUtils.cs @@ -80,12 +80,7 @@ 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, "CommonConfig"); } } /// /// Returns the absolute path to the common config library directory. From 21ce86de0fad1786cc0f87bdb63492d9cef84fdf Mon Sep 17 00:00:00 2001 From: Drew Tingen Date: Tue, 22 Jan 2019 09:24:25 -0800 Subject: [PATCH 09/18] fix: Use IcdEnvironment instead of CrestronEnvironment --- ICD.Common.Utils/PathUtils.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ICD.Common.Utils/PathUtils.cs b/ICD.Common.Utils/PathUtils.cs index 3b5a20c..a4e49da 100644 --- a/ICD.Common.Utils/PathUtils.cs +++ b/ICD.Common.Utils/PathUtils.cs @@ -3,9 +3,6 @@ using System.Linq; using ICD.Common.Properties; using ICD.Common.Utils.Extensions; using ICD.Common.Utils.IO; -#if SIMPLSHARP -using Crestron.SimplSharp; -#endif namespace ICD.Common.Utils { @@ -65,12 +62,9 @@ namespace ICD.Common.Utils { get { -#if SIMPLSHARP - if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Server) - { + if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono) return Join(RootConfigPath, "ProgramConfig"); - } -#endif + string directoryName = string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber); return Join(RootConfigPath, directoryName); } From 3a4438ec1e4a4b35d013ca953f4512788d53444b Mon Sep 17 00:00:00 2001 From: Drew Tingen Date: Tue, 22 Jan 2019 09:24:37 -0800 Subject: [PATCH 10/18] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecc2759..2ddf899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added - Added SimplSharpProMono to eRuntimeEnvironment enum + - Added path support for SimplSharpProMono environment ### Changed - Small fixes for better VC4 support From 1d7ada87c5f35ebcce56b912aefd40e638df6ad4 Mon Sep 17 00:00:00 2001 From: Drew Tingen Date: Tue, 22 Jan 2019 09:47:20 -0800 Subject: [PATCH 11/18] refactor: Removing preprocessors and adding better multi-platform support --- ICD.Common.Utils/IO/IcdDirectory.cs | 7 ++++--- ICD.Common.Utils/PathUtils.cs | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ICD.Common.Utils/IO/IcdDirectory.cs b/ICD.Common.Utils/IO/IcdDirectory.cs index 4ae98bf..4b087c5 100644 --- a/ICD.Common.Utils/IO/IcdDirectory.cs +++ b/ICD.Common.Utils/IO/IcdDirectory.cs @@ -19,17 +19,18 @@ namespace ICD.Common.Utils.IO #endif } - -#if SIMPLSHARP /// /// This gets the application root directory for Crestron systems /// /// public static string GetApplicationRootDirectory() { +#if SIMPLSHARP return Directory.GetApplicationRootDirectory(); - } +#else + return Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase); #endif + } public static bool Exists(string path) { diff --git a/ICD.Common.Utils/PathUtils.cs b/ICD.Common.Utils/PathUtils.cs index a4e49da..64e21a6 100644 --- a/ICD.Common.Utils/PathUtils.cs +++ b/ICD.Common.Utils/PathUtils.cs @@ -20,10 +20,9 @@ namespace ICD.Common.Utils public static string RootPath { get { -#if SIMPLSHARP if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono) return IcdDirectory.GetApplicationRootDirectory(); -#endif + return IcdDirectory.GetDirectoryRoot(IcdPath.DirectorySeparatorChar.ToString()); } } From fffc8e4a6024d29f584eabd11155e203df48ec1e Mon Sep 17 00:00:00 2001 From: Drew Tingen Date: Tue, 22 Jan 2019 09:50:32 -0800 Subject: [PATCH 12/18] fix: Fixed GetApplicationRootDirectory for NetStandard --- ICD.Common.Utils/IO/IcdDirectory.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ICD.Common.Utils/IO/IcdDirectory.cs b/ICD.Common.Utils/IO/IcdDirectory.cs index 4b087c5..025d56a 100644 --- a/ICD.Common.Utils/IO/IcdDirectory.cs +++ b/ICD.Common.Utils/IO/IcdDirectory.cs @@ -1,4 +1,5 @@ using System; +using ICD.Common.Utils.Extensions; #if SIMPLSHARP using Crestron.SimplSharp.CrestronIO; #else @@ -28,7 +29,7 @@ namespace ICD.Common.Utils.IO #if SIMPLSHARP return Directory.GetApplicationRootDirectory(); #else - return Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase); + return Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetPath()); #endif } From fb7a6e27b84e7c0b744e2d761ef3e152c64314b8 Mon Sep 17 00:00:00 2001 From: Drew Tingen Date: Tue, 22 Jan 2019 09:50:42 -0800 Subject: [PATCH 13/18] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ddf899..29822c8 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. ### Added - Added SimplSharpProMono to eRuntimeEnvironment enum - Added path support for SimplSharpProMono environment + - Added GetApplicationRootDirectory for all platforms ### Changed - Small fixes for better VC4 support From 1d6e8d55cae00c95a5428fe94e5c036aaa7edaec Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Wed, 23 Jan 2019 11:10:35 -0500 Subject: [PATCH 14/18] refactor: Tidying --- ICD.Common.Utils/IO/IcdDirectory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICD.Common.Utils/IO/IcdDirectory.cs b/ICD.Common.Utils/IO/IcdDirectory.cs index 025d56a..27b3c31 100644 --- a/ICD.Common.Utils/IO/IcdDirectory.cs +++ b/ICD.Common.Utils/IO/IcdDirectory.cs @@ -1,8 +1,8 @@ using System; -using ICD.Common.Utils.Extensions; #if SIMPLSHARP using Crestron.SimplSharp.CrestronIO; #else +using ICD.Common.Utils.Extensions; using System.IO; using Microsoft.DotNet.PlatformAbstractions; #endif From 524cdc3e319aa72479aa48e4d97b613ede2cfcf8 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 24 Jan 2019 11:57:39 -0500 Subject: [PATCH 15/18] feat: EventArgs constructor overloads --- ICD.Common.Utils/EventArguments/BoolEventArgs.cs | 12 +++++++++++- ICD.Common.Utils/EventArguments/StringEventArgs.cs | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ICD.Common.Utils/EventArguments/BoolEventArgs.cs b/ICD.Common.Utils/EventArguments/BoolEventArgs.cs index 56d6c66..c73580c 100644 --- a/ICD.Common.Utils/EventArguments/BoolEventArgs.cs +++ b/ICD.Common.Utils/EventArguments/BoolEventArgs.cs @@ -6,7 +6,17 @@ /// Constructor. /// /// - public BoolEventArgs(bool data) : base(data) + public BoolEventArgs(bool data) + : base(data) + { + } + + /// + /// Constructor. + /// + /// + public BoolEventArgs(BoolEventArgs eventArgs) + : this(eventArgs.Data) { } } diff --git a/ICD.Common.Utils/EventArguments/StringEventArgs.cs b/ICD.Common.Utils/EventArguments/StringEventArgs.cs index 56acfa8..db25463 100644 --- a/ICD.Common.Utils/EventArguments/StringEventArgs.cs +++ b/ICD.Common.Utils/EventArguments/StringEventArgs.cs @@ -9,5 +9,14 @@ public StringEventArgs(string data) : base(data) { } + + /// + /// Constructor. + /// + /// + public StringEventArgs(StringEventArgs eventArgs) + : base(eventArgs.Data) + { + } } } From f60de4321bd602e8bce59072d16cf6a2194b013a Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Fri, 25 Jan 2019 17:07:05 -0500 Subject: [PATCH 16/18] chore: Updating changelog, incrementing minor version --- CHANGELOG.md | 2 ++ ICD.Common.Utils/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29822c8..5adbe94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [8.3.0] - 2019-01-25 ### Added - Added SimplSharpProMono to eRuntimeEnvironment enum - Added path support for SimplSharpProMono environment diff --git a/ICD.Common.Utils/Properties/AssemblyInfo.cs b/ICD.Common.Utils/Properties/AssemblyInfo.cs index 78de1a6..6df4043 100644 --- a/ICD.Common.Utils/Properties/AssemblyInfo.cs +++ b/ICD.Common.Utils/Properties/AssemblyInfo.cs @@ -4,4 +4,4 @@ using System.Reflection; [assembly: AssemblyCompany("ICD Systems")] [assembly: AssemblyProduct("ICD.Common.Utils")] [assembly: AssemblyCopyright("Copyright © ICD Systems 2018")] -[assembly: AssemblyVersion("8.2.0.0")] +[assembly: AssemblyVersion("8.3.0.0")] From 88a4801f8e25d70ea47b9edbf3f08372feffe1c0 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Tue, 26 Mar 2019 11:28:15 -0400 Subject: [PATCH 17/18] feat: Added extension method for generating stable string hashcodes --- .../Extensions/StringExtensions.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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); + } + } } } From 87d1f4da166c91088de560bad636a68239fa5fc7 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Tue, 26 Mar 2019 11:28:59 -0400 Subject: [PATCH 18/18] feat: Added util method for generating seeded guids --- ICD.Common.Utils/GuidUtils.cs | 17 +++++++++++++++++ .../ICD.Common.Utils_SimplSharp.csproj | 1 + 2 files changed, 18 insertions(+) create mode 100644 ICD.Common.Utils/GuidUtils.cs 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 103d153..297b013 100644 --- a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj +++ b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj @@ -112,6 +112,7 @@ +