mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-11 18:54:55 +00:00
Merge remote-tracking branch 'origin/feat/seeded_guid' into Telemetry
# Conflicts: # ICD.Common.Utils/Attributes/RangeAttribute.cs
This commit is contained in:
16
CHANGELOG.md
16
CHANGELOG.md
@@ -5,8 +5,24 @@ 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
|
||||
- Added GetApplicationRootDirectory for all platforms
|
||||
|
||||
### Changed
|
||||
- Small fixes for better VC4 support
|
||||
|
||||
## [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
|
||||
|
||||
@@ -6,7 +6,17 @@
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
public BoolEventArgs(bool data) : base(data)
|
||||
public BoolEventArgs(bool data)
|
||||
: base(data)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
public BoolEventArgs(BoolEventArgs eventArgs)
|
||||
: this(eventArgs.Data)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,14 @@
|
||||
public StringEventArgs(string data) : base(data)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
public StringEventArgs(StringEventArgs eventArgs)
|
||||
: base(eventArgs.Data)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,5 +221,29 @@ namespace ICD.Common.Utils.Extensions
|
||||
|
||||
return extends.Contains(character.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a hashcode that is consistent between program executions.
|
||||
/// </summary>
|
||||
/// <param name="extends"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetStableHashCode(this string extends)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int hash1 = 5381;
|
||||
int hash2 = hash1;
|
||||
|
||||
for (int i = 0; i < extends.Length && extends[i] != '\0'; i += 2)
|
||||
{
|
||||
hash1 = ((hash1 << 5) + hash1) ^ extends[i];
|
||||
if (i == extends.Length - 1 || extends[i + 1] == '\0')
|
||||
break;
|
||||
hash2 = ((hash2 << 5) + hash2) ^ extends[i + 1];
|
||||
}
|
||||
|
||||
return hash1 + (hash2 * 1566083941);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,7 @@
|
||||
<Compile Include="Extensions\ParameterInfoExtensions.cs" />
|
||||
<Compile Include="Extensions\UriExtensions.cs" />
|
||||
<Compile Include="Extensions\UShortExtensions.cs" />
|
||||
<Compile Include="GuidUtils.cs" />
|
||||
<Compile Include="IcdUriBuilder.cs" />
|
||||
<Compile Include="IO\Compression\IcdZipEntry.cs" />
|
||||
<Compile Include="IO\IcdBinaryReader.cs" />
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#if SIMPLSHARP
|
||||
using Crestron.SimplSharp.CrestronIO;
|
||||
#else
|
||||
using ICD.Common.Utils.Extensions;
|
||||
using System.IO;
|
||||
using Microsoft.DotNet.PlatformAbstractions;
|
||||
#endif
|
||||
@@ -19,6 +20,19 @@ namespace ICD.Common.Utils.IO
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This gets the application root directory for Crestron systems
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetApplicationRootDirectory()
|
||||
{
|
||||
#if SIMPLSHARP
|
||||
return Directory.GetApplicationRootDirectory();
|
||||
#else
|
||||
return Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetPath());
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool Exists(string path)
|
||||
{
|
||||
if (path == null)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace ICD.Common.Utils
|
||||
{
|
||||
SimplSharp,
|
||||
SimplSharpPro,
|
||||
SimplSharpProMono,
|
||||
Standard
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,15 @@ namespace ICD.Common.Utils
|
||||
/// Gets the path to the root directory of the processor.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public static string RootPath { get { return IcdDirectory.GetDirectoryRoot("\\"); } }
|
||||
public static string RootPath {
|
||||
get
|
||||
{
|
||||
if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono)
|
||||
return IcdDirectory.GetApplicationRootDirectory();
|
||||
|
||||
return IcdDirectory.GetDirectoryRoot(IcdPath.DirectorySeparatorChar.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path to the program directory
|
||||
@@ -35,7 +43,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 +61,9 @@ namespace ICD.Common.Utils
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono)
|
||||
return Join(RootConfigPath, "ProgramConfig");
|
||||
|
||||
string directoryName = string.Format("Program{0:D2}Config", ProgramUtils.ProgramNumber);
|
||||
return Join(RootConfigPath, directoryName);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.3.0.0")]
|
||||
|
||||
@@ -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
|
||||
/// <param name="firstArgument"></param>
|
||||
/// <param name="method"></param>
|
||||
/// <returns></returns>
|
||||
[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.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[NotNull]
|
||||
public static T CreateInstance<T>(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
@@ -198,6 +198,7 @@ namespace ICD.Common.Utils
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
[NotNull]
|
||||
public static T CreateInstance<T>(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.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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<ILoggerService>();
|
||||
|
||||
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
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
[NotNull]
|
||||
public static Assembly LoadAssemblyFromPath(string path)
|
||||
{
|
||||
if (path == null)
|
||||
@@ -377,6 +359,7 @@ namespace ICD.Common.Utils
|
||||
/// <param name="handler">The instance with the callback MethodInfo. Null for static types.</param>
|
||||
/// <param name="callback">The MethodInfo for the callback method.</param>
|
||||
/// <returns></returns>
|
||||
[NotNull]
|
||||
public static Delegate SubscribeEvent(object instance, EventInfo eventInfo, object handler, MethodInfo callback)
|
||||
{
|
||||
if (eventInfo == null)
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user