From 2ad9adf86c24e7efbe8c37a7f46b3e89e6ac923a Mon Sep 17 00:00:00 2001 From: Drew Tingen Date: Thu, 7 May 2020 18:16:54 -0400 Subject: [PATCH 1/4] feat: ScrollQueue - added OnItemTrimmed event --- CHANGELOG.md | 3 ++ .../Collections/ScrollQueueTest.cs | 39 +++++++++++++++++++ ICD.Common.Utils/Collections/ScrollQueue.cs | 8 ++++ 3 files changed, 50 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 786413b..ded3585 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ 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 + - ScrollQueue - Added OnItemTrimmed event + - ScrollQueueTests - Added OnItemTrimmed event test ## [11.0.0] - 2020-03-20 ### Added diff --git a/ICD.Common.Utils.Tests/Collections/ScrollQueueTest.cs b/ICD.Common.Utils.Tests/Collections/ScrollQueueTest.cs index 2ede379..4613e1a 100644 --- a/ICD.Common.Utils.Tests/Collections/ScrollQueueTest.cs +++ b/ICD.Common.Utils.Tests/Collections/ScrollQueueTest.cs @@ -2,6 +2,7 @@ using ICD.Common.Properties; using NUnit.Framework; using ICD.Common.Utils.Collections; +using ICD.Common.Utils.EventArguments; namespace ICD.Common.Utils.Tests.Collections { @@ -76,5 +77,43 @@ namespace ICD.Common.Utils.Tests.Collections Assert.AreEqual(0, test.Peek()); } + + [Test, UsedImplicitly] + public void OnItemTrimmedTest() + { + ScrollQueue test = new ScrollQueue(3); + + int? removedItem = null; + + test.OnItemTrimmed += (sender, args) => removedItem = args.Data; + + test.Enqueue(1); + test.Enqueue(2); + test.Enqueue(3); + + Assert.IsNull(removedItem, "Raised Early"); + + test.Enqueue(4); + + Assert.True(removedItem.HasValue, "Not Raised"); + if (removedItem.HasValue) + Assert.AreEqual(1, removedItem.Value, "Incorrect Value"); + + removedItem = null; + + test.Enqueue(5); + + Assert.True(removedItem.HasValue, "Not Raised"); + if (removedItem.HasValue) + Assert.AreEqual(2, removedItem.Value, "Incorrect Value"); + + removedItem = null; + + test.MaxSize = 4; + + test.Enqueue(6); + + Assert.False(removedItem.HasValue, "Raised Early"); + } } } \ No newline at end of file diff --git a/ICD.Common.Utils/Collections/ScrollQueue.cs b/ICD.Common.Utils/Collections/ScrollQueue.cs index 087eda4..b7b5290 100644 --- a/ICD.Common.Utils/Collections/ScrollQueue.cs +++ b/ICD.Common.Utils/Collections/ScrollQueue.cs @@ -2,6 +2,8 @@ using System.Collections; using System.Collections.Generic; using ICD.Common.Properties; +using ICD.Common.Utils.EventArguments; +using ICD.Common.Utils.Extensions; namespace ICD.Common.Utils.Collections { @@ -15,6 +17,8 @@ namespace ICD.Common.Utils.Collections private readonly LinkedList m_Collection; private int m_MaxSize; + public event EventHandler> OnItemTrimmed; + #region Properties /// @@ -141,7 +145,11 @@ namespace ICD.Common.Utils.Collections private void Trim() { while (Count > MaxSize) + { + TContents removed = m_Collection.First.Value; m_Collection.RemoveFirst(); + OnItemTrimmed.Raise(this, new GenericEventArgs(removed)); + } } #endregion From 0431b5afe4770a873f8f23568f7f88d5bcc483d5 Mon Sep 17 00:00:00 2001 From: Drew Tingen Date: Mon, 18 May 2020 15:27:01 -0400 Subject: [PATCH 2/4] feat: DateTimeNullableEventArgs --- .../EventArguments/DateTimeNullableEventArgs.cs | 15 +++++++++++++++ .../ICD.Common.Utils_SimplSharp.csproj | 1 + 2 files changed, 16 insertions(+) create mode 100644 ICD.Common.Utils/EventArguments/DateTimeNullableEventArgs.cs diff --git a/ICD.Common.Utils/EventArguments/DateTimeNullableEventArgs.cs b/ICD.Common.Utils/EventArguments/DateTimeNullableEventArgs.cs new file mode 100644 index 0000000..a2519ac --- /dev/null +++ b/ICD.Common.Utils/EventArguments/DateTimeNullableEventArgs.cs @@ -0,0 +1,15 @@ +using System; + +namespace ICD.Common.Utils.EventArguments +{ + public sealed class DateTimeNullableEventArgs : GenericEventArgs + { + /// + /// Constructor. + /// + /// + public DateTimeNullableEventArgs(DateTime? data) : base(data) + { + } + } +} diff --git a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj index 7000084..4ffcc38 100644 --- a/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj +++ b/ICD.Common.Utils/ICD.Common.Utils_SimplSharp.csproj @@ -98,6 +98,7 @@ + From cad3cf60cf00b18c4684f7fee08686bed303a737 Mon Sep 17 00:00:00 2001 From: Drew Tingen Date: Mon, 18 May 2020 15:27:51 -0400 Subject: [PATCH 3/4] chore: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ded3585..eeb6379 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 - ScrollQueue - Added OnItemTrimmed event - ScrollQueueTests - Added OnItemTrimmed event test + - DateTimeNullableEventArgs ## [11.0.0] - 2020-03-20 ### Added From 9912097a33210e5ae1ade734947f4cb149c3f7d3 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Tue, 19 May 2020 10:45:05 -0400 Subject: [PATCH 4/4] chore: Updating changelog, incrementing minor version --- CHANGELOG.md | 5 +++-- ICD.Common.Utils/Collections/ScrollQueue.cs | 3 +++ ICD.Common.Utils/Properties/AssemblyInfo.cs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eeb6379..327e31d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +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] + +## [11.1.0] - 2020-05-19 ### Added - ScrollQueue - Added OnItemTrimmed event - - ScrollQueueTests - Added OnItemTrimmed event test - - DateTimeNullableEventArgs + - Added DateTimeNullableEventArgs ## [11.0.0] - 2020-03-20 ### Added diff --git a/ICD.Common.Utils/Collections/ScrollQueue.cs b/ICD.Common.Utils/Collections/ScrollQueue.cs index b7b5290..eb636c5 100644 --- a/ICD.Common.Utils/Collections/ScrollQueue.cs +++ b/ICD.Common.Utils/Collections/ScrollQueue.cs @@ -17,6 +17,9 @@ namespace ICD.Common.Utils.Collections private readonly LinkedList m_Collection; private int m_MaxSize; + /// + /// Raised when an item is trimmed from the end of the queue. + /// public event EventHandler> OnItemTrimmed; #region Properties diff --git a/ICD.Common.Utils/Properties/AssemblyInfo.cs b/ICD.Common.Utils/Properties/AssemblyInfo.cs index 92044d3..49b916b 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 2020")] -[assembly: AssemblyVersion("11.0.0.0")] +[assembly: AssemblyVersion("11.1.0.0")]