Skip to content

Commit 126895a

Browse files
authored
Merge pull request #40 from I-RzR-I/feature/Multiple_1025
Feature/multiple 1025
2 parents 28687f3 + 5afaa21 commit 126895a

25 files changed

Lines changed: 2253 additions & 80 deletions

docs/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
### **v4.0.0.5323** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 14-10-2025
2+
* [c464d6d] (RzR) -> Add `TEA` extensions `TEAEncrypt`, `TEADecrypt`.
3+
* [ea248b6] (RzR) -> Implement `TEA` helper.
4+
* [21b0972] (RzR) -> Rename and relocate the `DisposablesCollectionHelper` to `DisposableStackCollection`
5+
* [5d30576] (RzR) -> Rename and relocate the `InsensitiveCaseHashtableHelper` to `InsensitiveCaseHashtable`.
6+
* [af81be2] (RzR) -> Add new enumerable extnesions: `ForEach`, `ForEachAsync`.
7+
* [eeba6d9] (RzR) -> Adjust location of the `JsonObjectSerializer` class.
8+
* [5e2128f] (RzR) -> Add `DirectoryInfo` extensions: `GetMatchingFiles`, `Empty`, `GetParentOf`, `Where`, `HasDirectories`, `HasFiles`, `IsEmpty`.
9+
* [8eb8728] (RzR) -> Add `ConcurrentDictionary` extensions: `Remove`, `RemoveWhere`, `TryRemove`, `RemoveAll`, `GetValueOrDefault`.
10+
* [9e39505] (RzR) -> Add `ConcurrentQueue` extensions: `Purge`, `Prune`, `DequeueAll`, `DequeueBatch`, `EnqueueRange`, `Enqueue`, `EnqueueRange`, `DequeueAndProcessBatches`.
11+
* [7fbff8d] (RzR) -> Add new DateTime extnesions: `ToEpoch`, `FromEpoch`, `IsDifferentDay`, `IsDifferentLocalDay`.
12+
* [d95d4fe] (RzR) -> Add new dictionary extnesions: `TryGetValue`, `GetValueOrDefault`, `ContainsAllKeys`, `ContainsAnyKeys`.
13+
* [6e7d3f9] (RzR) -> Add new enumerable extnesions: `ConvertToQuerystring`, `Convert`.
14+
* [08681a4] (RzR) -> Add new byte extnesion: `IsEntirelyNull`.
15+
116
### **v3.4.0.7452** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 07-10-2025
217
* [c160a83] (RzR) -> Auto commit uncommited files
318
* [b417765] (RzR) -> Add new enumeration extnesion: `AdddIfNotExist`.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// ***********************************************************************
2+
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions
3+
// Author : RzR
4+
// Created On : 2025-10-09 18:10
5+
//
6+
// Last Modified By : RzR
7+
// Last Modified On : 2025-10-09 18:05
8+
// ***********************************************************************
9+
// <copyright file="ConcurrentDictionaryExtensions.cs" company="RzR SOFT & TECH">
10+
// Copyright © RzR. All rights reserved.
11+
// </copyright>
12+
//
13+
// <summary>
14+
// </summary>
15+
// ***********************************************************************
16+
17+
#region U S A G E S
18+
19+
using System;
20+
using System.Collections.Concurrent;
21+
using System.Collections.Generic;
22+
using System.Linq;
23+
24+
#endregion
25+
26+
namespace DomainCommonExtensions.ArraysExtensions
27+
{
28+
/// -------------------------------------------------------------------------------------------------
29+
/// <summary>
30+
/// A concurrent dictionary extensions.
31+
/// </summary>
32+
/// =================================================================================================
33+
public static class ConcurrentDictionaryExtensions
34+
{
35+
/// -------------------------------------------------------------------------------------------------
36+
/// <summary>
37+
/// A ConcurrentDictionary&lt;TKey,TValue&gt; extension method that removes this object.
38+
/// </summary>
39+
/// <typeparam name="TKey">Type of the key.</typeparam>
40+
/// <typeparam name="TValue">Type of the value.</typeparam>
41+
/// <param name="dictionary">The dictionary to act on.</param>
42+
/// <param name="key">The key.</param>
43+
/// =================================================================================================
44+
public static void Remove<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary, TKey key)
45+
{
46+
dictionary.TryRemove(key, out _);
47+
}
48+
49+
/// -------------------------------------------------------------------------------------------------
50+
/// <summary>
51+
/// A ConcurrentDictionary&lt;TKey,TValue&gt; extension method that removes this object.
52+
/// </summary>
53+
/// <typeparam name="TKey">Type of the key.</typeparam>
54+
/// <typeparam name="TValue">Type of the value.</typeparam>
55+
/// <param name="dictionary">The dictionary to act on.</param>
56+
/// <param name="keys">The keys.</param>
57+
/// =================================================================================================
58+
public static void Remove<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary,
59+
IEnumerable<TKey> keys)
60+
{
61+
foreach (var key in keys)
62+
dictionary.Remove(key);
63+
}
64+
65+
/// -------------------------------------------------------------------------------------------------
66+
/// <summary>
67+
/// A ConcurrentDictionary&lt;TKey,TValue&gt; extension method that removes the where.
68+
/// </summary>
69+
/// <typeparam name="TKey">Type of the key.</typeparam>
70+
/// <typeparam name="TValue">Type of the value.</typeparam>
71+
/// <param name="dictionary">The dictionary to act on.</param>
72+
/// <param name="predicate">The predicate.</param>
73+
/// =================================================================================================
74+
public static void RemoveWhere<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary,
75+
Func<TValue, bool> predicate)
76+
{
77+
dictionary.Remove(dictionary.Where(kvp => predicate(kvp.Value)).Select(kvp => kvp.Key));
78+
}
79+
80+
/// -------------------------------------------------------------------------------------------------
81+
/// <summary>
82+
/// A ConcurrentDictionary&lt;TKey,TValue&gt; extension method that try remove.
83+
/// </summary>
84+
/// <typeparam name="TKey">Type of the key.</typeparam>
85+
/// <typeparam name="TValue">Type of the value.</typeparam>
86+
/// <param name="dictionary">The dictionary to act on.</param>
87+
/// <param name="key">The key.</param>
88+
/// =================================================================================================
89+
public static void TryRemove<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary, TKey key)
90+
{
91+
dictionary.TryRemove(key, out _);
92+
}
93+
94+
/// -------------------------------------------------------------------------------------------------
95+
/// <summary>
96+
/// A ConcurrentDictionary&lt;TKey,TValue&gt; extension method that removes all.
97+
/// </summary>
98+
/// <typeparam name="TKey">Type of the key.</typeparam>
99+
/// <typeparam name="TValue">Type of the value.</typeparam>
100+
/// <param name="dictionary">The dictionary to act on.</param>
101+
/// <param name="keys">The keys.</param>
102+
/// =================================================================================================
103+
public static void RemoveAll<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary,
104+
IEnumerable<TKey> keys)
105+
{
106+
foreach (var key in keys)
107+
dictionary.TryRemove(key, out _);
108+
}
109+
110+
/// -------------------------------------------------------------------------------------------------
111+
/// <summary>
112+
/// A ConcurrentDictionary&lt;TKey,TValue&gt; extension method that removes all.
113+
/// </summary>
114+
/// <typeparam name="TKey">Type of the key.</typeparam>
115+
/// <typeparam name="TValue">Type of the value.</typeparam>
116+
/// <param name="dictionary">The dictionary to act on.</param>
117+
/// <param name="predicate">The predicate.</param>
118+
/// =================================================================================================
119+
public static void RemoveAll<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary,
120+
Func<TValue, bool> predicate)
121+
{
122+
var keys = dictionary.Where(p => predicate(p.Value)).Select(p => p.Key).ToArray();
123+
124+
RemoveAll(dictionary, keys);
125+
}
126+
127+
/// -------------------------------------------------------------------------------------------------
128+
/// <summary>
129+
/// A ConcurrentDictionary&lt;TKey,TValue&gt; extension method that gets value or default.
130+
/// </summary>
131+
/// <typeparam name="TKey">Type of the key.</typeparam>
132+
/// <typeparam name="TValue">Type of the value.</typeparam>
133+
/// <param name="dictionary">The dictionary to act on.</param>
134+
/// <param name="key">The key.</param>
135+
/// <returns>
136+
/// The value or default.
137+
/// </returns>
138+
/// =================================================================================================
139+
public static TValue GetValueOrDefault<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> dictionary,
140+
TKey key)
141+
{
142+
if (dictionary.TryGetValue(key, out var value))
143+
return value;
144+
145+
return default(TValue);
146+
}
147+
}
148+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
// ***********************************************************************
2+
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions
3+
// Author : RzR
4+
// Created On : 2025-10-09 14:10
5+
//
6+
// Last Modified By : RzR
7+
// Last Modified On : 2025-10-09 14:27
8+
// ***********************************************************************
9+
// <copyright file="ConcurrentQueueExtensions.cs" company="RzR SOFT & TECH">
10+
// Copyright © RzR. All rights reserved.
11+
// </copyright>
12+
//
13+
// <summary>
14+
// </summary>
15+
// ***********************************************************************
16+
17+
#region U S A G E S
18+
19+
using System;
20+
using System.Collections.Concurrent;
21+
using System.Collections.Generic;
22+
using System.Linq;
23+
using DomainCommonExtensions.DataTypeExtensions;
24+
25+
#endregion
26+
27+
namespace DomainCommonExtensions.ArraysExtensions
28+
{
29+
/// -------------------------------------------------------------------------------------------------
30+
/// <summary>
31+
/// A concurrent queue extensions.
32+
/// </summary>
33+
/// =================================================================================================
34+
public static class ConcurrentQueueExtensions
35+
{
36+
/// -------------------------------------------------------------------------------------------------
37+
/// <summary>
38+
/// A ConcurrentQueue&lt;T&gt; extension method that purges the given queue.
39+
/// </summary>
40+
/// <typeparam name="T">Generic type parameter.</typeparam>
41+
/// <param name="queue">The queue to act on.</param>
42+
/// =================================================================================================
43+
public static void Purge<T>(this ConcurrentQueue<T> queue)
44+
{
45+
while (queue.IsEmpty.IsFalse())
46+
{
47+
queue.TryDequeue(out _);
48+
}
49+
}
50+
51+
/// -------------------------------------------------------------------------------------------------
52+
/// <summary>
53+
/// A ConcurrentQueue&lt;T&gt; extension method that prunes.
54+
/// </summary>
55+
/// <typeparam name="T">Generic type parameter.</typeparam>
56+
/// <param name="queue">The queue to act on.</param>
57+
/// <param name="maxSize">The maximum size of the array.</param>
58+
/// =================================================================================================
59+
public static void Prune<T>(this ConcurrentQueue<T> queue, int maxSize)
60+
{
61+
while (queue.Count > maxSize)
62+
{
63+
queue.TryDequeue(out _);
64+
}
65+
}
66+
67+
/// -------------------------------------------------------------------------------------------------
68+
/// <summary>
69+
/// A ConcurrentQueue&lt;T&gt; extension method that dequeue all.
70+
/// </summary>
71+
/// <typeparam name="T">Generic type parameter.</typeparam>
72+
/// <param name="queue">The queue to act on.</param>
73+
/// <returns>
74+
/// A T[].
75+
/// </returns>
76+
/// =================================================================================================
77+
public static T[] DequeueAll<T>(this ConcurrentQueue<T> queue)
78+
{
79+
var dequeued = new T[] { };
80+
while (queue.TryDequeue(out var value))
81+
dequeued.AppendItem(value);
82+
83+
return dequeued.ToArray();
84+
}
85+
86+
/// -------------------------------------------------------------------------------------------------
87+
/// <summary>
88+
/// A ConcurrentQueue&lt;T&gt; extension method that dequeue batch.
89+
/// </summary>
90+
/// <typeparam name="T">Generic type parameter.</typeparam>
91+
/// <param name="queue">The queue to act on.</param>
92+
/// <param name="batchSize">Size of the batch.</param>
93+
/// <returns>
94+
/// A T[].
95+
/// </returns>
96+
/// =================================================================================================
97+
public static T[] DequeueBatch<T>(this ConcurrentQueue<T> queue, int batchSize)
98+
{
99+
var dequeued = new T[] { };
100+
for (var i = 0; i < batchSize && queue.TryDequeue(out var value); i++)
101+
dequeued.AppendItem(value);
102+
103+
return dequeued.ToArray();
104+
}
105+
106+
/// -------------------------------------------------------------------------------------------------
107+
/// <summary>
108+
/// A ConcurrentQueue&lt;T&gt; extension method that enqueue range.
109+
/// </summary>
110+
/// <typeparam name="T">Generic type parameter.</typeparam>
111+
/// <param name="queue">The queue to act on.</param>
112+
/// <param name="items">The items.</param>
113+
/// =================================================================================================
114+
public static void EnqueueRange<T>(this ConcurrentQueue<T> queue, IEnumerable<T> items)
115+
{
116+
foreach (var item in items)
117+
queue.Enqueue(item);
118+
}
119+
120+
/// -------------------------------------------------------------------------------------------------
121+
/// <summary>
122+
/// A ConcurrentQueue&lt;T&gt; extension method that adds an object onto the end of this
123+
/// queue.
124+
/// </summary>
125+
/// <typeparam name="T">Generic type parameter.</typeparam>
126+
/// <param name="queue">The queue to act on.</param>
127+
/// <param name="item">The item.</param>
128+
/// <param name="limit">The limit.</param>
129+
/// <returns>
130+
/// An int.
131+
/// </returns>
132+
/// =================================================================================================
133+
public static int Enqueue<T>(this ConcurrentQueue<T> queue, T item, int limit)
134+
{
135+
var purgeCount = 0;
136+
while (queue.Count >= limit)
137+
{
138+
queue.TryDequeue(out _);
139+
purgeCount++;
140+
}
141+
142+
queue.Enqueue(item);
143+
144+
return purgeCount;
145+
}
146+
147+
/// -------------------------------------------------------------------------------------------------
148+
/// <summary>
149+
/// A ConcurrentQueue&lt;T&gt; extension method that enqueue range.
150+
/// </summary>
151+
/// <typeparam name="T">Generic type parameter.</typeparam>
152+
/// <param name="queue">The queue to act on.</param>
153+
/// <param name="items">The items.</param>
154+
/// <param name="limit">The limit.</param>
155+
/// <returns>
156+
/// An int.
157+
/// </returns>
158+
/// =================================================================================================
159+
public static int EnqueueRange<T>(this ConcurrentQueue<T> queue, IEnumerable<T> items, int limit)
160+
{
161+
var purgeCount = 0;
162+
foreach (var item in items)
163+
purgeCount += queue.Enqueue(item, limit);
164+
165+
return purgeCount;
166+
}
167+
168+
/// -------------------------------------------------------------------------------------------------
169+
/// <summary>
170+
/// A ConcurrentQueue&lt;T&gt; extension method that dequeue and process batches.
171+
/// </summary>
172+
/// <typeparam name="T">Generic type parameter.</typeparam>
173+
/// <param name="queue">The queue to act on.</param>
174+
/// <param name="maxBatchSize">The maximum size of the batch.</param>
175+
/// <param name="processBatch">The process batch.</param>
176+
/// =================================================================================================
177+
public static void DequeueAndProcessBatches<T>(this ConcurrentQueue<T> queue, int maxBatchSize,
178+
Action<T[]> processBatch)
179+
{
180+
for (var batch = queue.DequeueBatch(maxBatchSize); batch.Any(); batch = queue.DequeueBatch(maxBatchSize))
181+
processBatch(batch);
182+
}
183+
}
184+
}

0 commit comments

Comments
 (0)