mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-26 19:04:50 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f306801b3 | ||
|
|
51ec3dd8ff | ||
|
|
7cc8359284 | ||
|
|
62f54f1213 | ||
|
|
dd3c0f530b | ||
|
|
fc74865c5b | ||
|
|
d90c60126e | ||
|
|
49d12d454f | ||
|
|
69eb4b3d34 | ||
|
|
8e5486e1ef | ||
|
|
ecf7e626f3 | ||
|
|
d025946948 | ||
|
|
b74d2c9d60 | ||
|
|
ac4c0eccc9 | ||
|
|
55bf458a2b | ||
|
|
0a1f637b45 | ||
|
|
e0ace12ef9 | ||
|
|
9f1541f843 | ||
|
|
b9f5349055 |
24
CHANGELOG.md
24
CHANGELOG.md
@@ -6,6 +6,30 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [8.9.2] - 2020-07-28
|
||||
### Changed
|
||||
- StringExtensions - fixed an issue with IsNumeric where empty strings would return true
|
||||
|
||||
## [8.9.1] - 2020-05-27
|
||||
### Changed
|
||||
- Changed ProcessorUtils to use CrestronEnvironment to retrive serial number - this fixes issues with new serial numbers that aren't deciaml TSIDs
|
||||
|
||||
## [8.9.0] - 2020-04-30
|
||||
### Changed
|
||||
- ProgramUtils and ProcessorUtils return dates instead of strings for date properties
|
||||
|
||||
## [8.8.1] - 2020-02-18
|
||||
### Changed
|
||||
- IcdTimer - fixed issue that prevented OnElapsed event from firing when Length is less than (or close to) Heartbeat Interval
|
||||
|
||||
## [8.8.0] - 2020-01-23
|
||||
### Added
|
||||
- Added an overload to PriorityQueue for determing the de-duplication behaviour
|
||||
|
||||
## [8.7.2] - 2019-10-29
|
||||
### Changed
|
||||
- Fixed a bug with PriorityQueue de-duplication where a new command would be inserted in the wrong position
|
||||
|
||||
## [8.7.1] - 2019-08-22
|
||||
### Changed
|
||||
- Fixed a bug with the IcdOrderedDict index setter that was creating additional values
|
||||
|
||||
@@ -133,8 +133,8 @@ namespace ICD.Common.Utils.Tests.Collections
|
||||
};
|
||||
|
||||
Assert.AreEqual(1, dequeue[0]);
|
||||
Assert.AreEqual(4, dequeue[1]);
|
||||
Assert.AreEqual(3, dequeue[2]);
|
||||
Assert.AreEqual(3, dequeue[1]);
|
||||
Assert.AreEqual(4, dequeue[2]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -84,6 +84,20 @@ namespace ICD.Common.Utils.Collections
|
||||
m_Count++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the item to the queue with the given priority at the given index.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="priority"></param>
|
||||
/// <param name="position"></param>
|
||||
[PublicAPI]
|
||||
public void Enqueue([CanBeNull] T item, int priority, int position)
|
||||
{
|
||||
m_PriorityToQueue.GetOrAddNew(priority, ()=> new List<T>())
|
||||
.Insert(position, item);
|
||||
m_Count++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enqueues the item at the beginning of the queue.
|
||||
/// </summary>
|
||||
@@ -106,8 +120,8 @@ namespace ICD.Common.Utils.Collections
|
||||
|
||||
/// <summary>
|
||||
/// Removes any items in the queue matching the predicate.
|
||||
/// Inserts the given item in the position of the first removed item, or at the end of the queue.
|
||||
/// This is useful for reducing duplication, or replacing items with something more pertinant.
|
||||
/// Appends the given item at the end of the given priority level.
|
||||
/// This is useful for reducing duplication, or replacing items with something more pertinent.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="remove"></param>
|
||||
@@ -122,19 +136,38 @@ namespace ICD.Common.Utils.Collections
|
||||
|
||||
/// <summary>
|
||||
/// Removes any items in the queue matching the predicate.
|
||||
/// Inserts the given item in the position of the first removed item, or at the end of the queue.
|
||||
/// This is useful for reducing duplication, or replacing items with something more pertinant.
|
||||
/// Appends the given item at the end of the given priority level.
|
||||
/// This is useful for reducing duplication, or replacing items with something more pertinent.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="remove"></param>
|
||||
/// <param name="priority"></param>
|
||||
[PublicAPI]
|
||||
public void EnqueueRemove(T item, Func<T, bool> remove, int priority)
|
||||
public void EnqueueRemove([CanBeNull] T item, [NotNull] Func<T, bool> remove, int priority)
|
||||
{
|
||||
if (remove == null)
|
||||
throw new ArgumentNullException("remove");
|
||||
|
||||
bool inserted = false;
|
||||
EnqueueRemove(item, remove, priority, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes any items in the queue matching the predicate.
|
||||
/// Appends the given item at the end of the given priority level.
|
||||
/// This is useful for reducing duplication, or replacing items with something more pertinent.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="remove"></param>
|
||||
/// <param name="priority"></param>
|
||||
/// <param name="deDuplicateToEndOfQueue"></param>
|
||||
[PublicAPI]
|
||||
public void EnqueueRemove([CanBeNull] T item, [NotNull] Func<T, bool> remove, int priority, bool deDuplicateToEndOfQueue)
|
||||
{
|
||||
if (remove == null)
|
||||
throw new ArgumentNullException("remove");
|
||||
|
||||
int lowestMatchingPriority = int.MaxValue;
|
||||
int? firstMatchingIndex = null;
|
||||
|
||||
foreach (KeyValuePair<int, List<T>> kvp in m_PriorityToQueue.ToArray())
|
||||
{
|
||||
@@ -144,8 +177,11 @@ namespace ICD.Common.Utils.Collections
|
||||
.Reverse()
|
||||
.ToArray();
|
||||
|
||||
if (removeIndices.Length == 0)
|
||||
continue;
|
||||
if (removeIndices.Any() && kvp.Key < lowestMatchingPriority )
|
||||
{
|
||||
lowestMatchingPriority = kvp.Key;
|
||||
firstMatchingIndex = removeIndices.Last();
|
||||
}
|
||||
|
||||
foreach (int removeIndex in removeIndices)
|
||||
{
|
||||
@@ -153,26 +189,20 @@ namespace ICD.Common.Utils.Collections
|
||||
m_Count--;
|
||||
}
|
||||
|
||||
if (!inserted)
|
||||
{
|
||||
int insertIndex = removeIndices[0];
|
||||
|
||||
if (insertIndex >= kvp.Value.Count)
|
||||
kvp.Value.Add(item);
|
||||
else
|
||||
kvp.Value.Insert(insertIndex, item);
|
||||
|
||||
m_Count++;
|
||||
|
||||
inserted = true;
|
||||
}
|
||||
|
||||
if (kvp.Value.Count == 0)
|
||||
m_PriorityToQueue.Remove(kvp.Key);
|
||||
}
|
||||
|
||||
if (!inserted)
|
||||
|
||||
if(deDuplicateToEndOfQueue)
|
||||
Enqueue(item, priority);
|
||||
else
|
||||
{
|
||||
if(firstMatchingIndex == null)
|
||||
Enqueue(item, lowestMatchingPriority);
|
||||
else
|
||||
Enqueue(item, lowestMatchingPriority, firstMatchingIndex.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -130,6 +130,41 @@ namespace ICD.Common.Utils.Extensions
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the key is present in the dictionary return the value, otherwise add a new value to the dictionary and return it.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
/// <param name="extends"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="valueFunc"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static TValue GetOrAddNew<TKey, TValue>([NotNull] this IDictionary<TKey, TValue> extends,
|
||||
[NotNull] TKey key,
|
||||
[NotNull] Func<TValue> valueFunc)
|
||||
{
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
// ReSharper disable CompareNonConstrainedGenericWithNull
|
||||
if (key == null)
|
||||
// ReSharper restore CompareNonConstrainedGenericWithNull
|
||||
throw new ArgumentNullException("key");
|
||||
|
||||
if (valueFunc == null)
|
||||
throw new ArgumentNullException("valueFunc");
|
||||
|
||||
TValue value;
|
||||
if (!extends.TryGetValue(key, out value))
|
||||
{
|
||||
value = valueFunc();
|
||||
extends.Add(key, value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a key for the given value.
|
||||
/// </summary>
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace ICD.Common.Utils.Extensions
|
||||
if (extends == null)
|
||||
throw new ArgumentNullException("extends");
|
||||
|
||||
return extends.All(char.IsDigit);
|
||||
return extends.AnyAndAll(char.IsDigit);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using ICD.Common.Utils.Services;
|
||||
#if SIMPLSHARP
|
||||
using System.Globalization;
|
||||
using Crestron.SimplSharp;
|
||||
using ICD.Common.Utils.Services;
|
||||
using ICD.Common.Utils.Services.Logging;
|
||||
#if SIMPLSHARP
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using ICD.Common.Properties;
|
||||
@@ -91,7 +93,7 @@ namespace ICD.Common.Utils
|
||||
/// Gets the date that the firmware was updated.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public static string ModelVersionDate
|
||||
public static DateTime ModelVersionDate
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -99,12 +101,12 @@ namespace ICD.Common.Utils
|
||||
Match match = regex.Match(VersionResult);
|
||||
|
||||
if (match.Success)
|
||||
return match.Groups["date"].Value;
|
||||
return DateTime.ParseExact(match.Groups["date"].Value, "MMM dd yyyy", CultureInfo.InvariantCulture).ToUniversalTime();
|
||||
|
||||
ServiceProvider.TryGetService<ILoggerService>()
|
||||
.AddEntry(eSeverity.Warning, "Unable to get model version date from \"{0}\"", VersionResult);
|
||||
|
||||
return string.Empty;
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,19 +118,7 @@ namespace ICD.Common.Utils
|
||||
{
|
||||
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();
|
||||
return CrestronEnvironment.SystemInfo.SerialNumber;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,12 +31,12 @@ namespace ICD.Common.Utils
|
||||
/// Gets the date that the firmware was updated.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public static string ModelVersionDate
|
||||
public static DateTime ModelVersionDate
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO
|
||||
return null;
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using ICD.Common.Utils.Services;
|
||||
using ICD.Common.Utils.IO;
|
||||
using ICD.Common.Utils.Services;
|
||||
using ICD.Common.Utils.Services.Logging;
|
||||
#if SIMPLSHARP
|
||||
using Crestron.SimplSharp;
|
||||
@@ -40,7 +41,16 @@ namespace ICD.Common.Utils
|
||||
/// Gets the compile date of the program.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public static string CompiledDate { get { return ProgComments.GetDefault(COMPILED_ON_KEY, null); } }
|
||||
public static DateTime CompiledDate
|
||||
{
|
||||
get
|
||||
{
|
||||
string dateString;
|
||||
return ProgComments.TryGetValue(COMPILED_ON_KEY, out dateString)
|
||||
? DateTime.Parse(dateString).ToUniversalTime()
|
||||
: DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the compiler revision version.
|
||||
@@ -86,6 +96,16 @@ namespace ICD.Common.Utils
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the date and time the program was installed.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static DateTime ProgramInstallDate
|
||||
{
|
||||
get { return IcdFile.GetCreationTime(PathUtils.Join(PathUtils.ProgramPath, ProgramFile)).ToUniversalTime(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the prog comments and pulls program information.
|
||||
/// </summary>
|
||||
|
||||
@@ -18,11 +18,11 @@ namespace ICD.Common.Utils
|
||||
/// Gets the compile date of the program.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public static string CompiledDate
|
||||
public static DateTime CompiledDate
|
||||
{
|
||||
get
|
||||
{
|
||||
return IcdFile.GetLastWriteTime(Assembly.GetEntryAssembly().Location).ToString();
|
||||
return IcdFile.GetLastWriteTime(Assembly.GetEntryAssembly().Location);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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("8.7.1.0")]
|
||||
[assembly: AssemblyCopyright("Copyright © ICD Systems 2020")]
|
||||
[assembly: AssemblyVersion("8.9.2.0")]
|
||||
|
||||
@@ -118,6 +118,7 @@ namespace ICD.Common.Utils.Timers
|
||||
Length = length;
|
||||
|
||||
m_Stopwatch.Reset();
|
||||
m_LastHeartbeatMilliseconds = 0;
|
||||
m_Stopwatch.Start();
|
||||
|
||||
RaiseOnIsRunningChanged();
|
||||
|
||||
Reference in New Issue
Block a user