Compare commits

...

19 Commits

Author SHA1 Message Date
Drew Tingen
7f306801b3 chore: Updating changelog, incremeting patch version 2020-07-29 10:01:43 -04:00
Austin Noska
51ec3dd8ff docs: Update changelog 2020-07-28 18:09:00 -04:00
Austin Noska
7cc8359284 fix: Check if any & all characters in a string is a digit instead of just all 2020-07-28 17:31:41 -04:00
Chris Cameron
62f54f1213 chore: Updating changelog, incrementing patch version 2020-05-27 15:56:22 -04:00
Drew Tingen
dd3c0f530b chore: Changelog 2020-05-27 11:28:12 -04:00
Drew Tingen
fc74865c5b feat: Use CrestronEnvironment.SystemInfo.SerialNumber to retrieve the serial number, instead of trying to convert TSID from console. 2020-05-27 11:25:14 -04:00
Chris Cameron
d90c60126e chore: Updating changelog, incrementing minor version 2020-04-30 13:02:14 -04:00
Drew Tingen
49d12d454f fix: Program and Processor utils actually return DateTimes for date properties 2020-04-30 12:58:23 -04:00
Chris Cameron
69eb4b3d34 chore: Updating changelog, incrementing patch version 2020-02-18 12:13:00 -05:00
Drew Tingen
8e5486e1ef chore: Changelog 2020-02-14 23:56:56 -05:00
Drew Tingen
ecf7e626f3 fix: IcdTimer fix issue that prevents OnElapsed callback from firing when Length is less than (or close to) Heartbeat Interval 2020-02-14 23:55:32 -05:00
Chris Cameron
d025946948 chore: Updating changelog, incrementing minor version 2020-01-23 12:46:06 -05:00
Chris Cameron
b74d2c9d60 fix: Adding PriorityQueue EnqueueRemove overload for backwards compat 2020-01-23 12:44:08 -05:00
Jack Kanarish
ac4c0eccc9 feat: add ability to select when de-duplication should queue at the end of the queue, or at the first occurance
# Conflicts:
#	ICD.Common.Utils/Collections/PriorityQueue.cs
2020-01-23 11:44:31 -05:00
Chris Cameron
55bf458a2b test: Fixing PriorityQueue unit tests 2020-01-06 10:28:03 -05:00
Chris Cameron
0a1f637b45 chore: Updating changelog, incrementing patch version 2019-10-29 14:52:36 -04:00
Chris Cameron
e0ace12ef9 Merge pull request #43 from Utils fix/SerialQueueFix
Fix/SerialQueueFix
2019-10-29 14:33:28 -04:00
Jack Kanarish
9f1541f843 chore: update changelog 2019-10-29 14:19:58 -04:00
Jack Kanarish
b9f5349055 fix: fix an issue where commands would collapse to the point of the last deleted command instead of the position in queue where the new command was going 2019-10-29 14:18:45 -04:00
11 changed files with 152 additions and 52 deletions

View File

@@ -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

View File

@@ -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]

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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>

View File

@@ -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);
}
}

View File

@@ -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")]

View File

@@ -118,6 +118,7 @@ namespace ICD.Common.Utils.Timers
Length = length;
m_Stopwatch.Reset();
m_LastHeartbeatMilliseconds = 0;
m_Stopwatch.Start();
RaiseOnIsRunningChanged();