3using System.Threading.Tasks;
17 private static readonly
object synchObject =
new object();
19 private class CounterRec
21 public TaskCompletionSource<bool> Stored =
new TaskCompletionSource<bool>();
30 counters.Removed += Counters_Removed;
41 e.
Value.Stored.TrySetResult(
true);
46 if (e.
Value.Counter.Counter == 0)
48 if (!
string.IsNullOrEmpty(e.
Value.Counter.ObjectId))
53 if (
string.IsNullOrEmpty(e.
Value.Counter.ObjectId))
59 e.
Value.Stored.TrySetResult(
true);
63 e.
Value.Stored.TrySetResult(
false);
73 CounterRec[] Records = counters.GetValues();
76 foreach (CounterRec Rec
in Records)
77 await Rec.Stored.Task;
79 return Records.Length;
102 if (counters.TryGetValue(Key, out CounterRec Rec))
104 Rec.Counter.Counter += Delta;
107 return Rec.Counter.Counter;
115 if (counters.TryGetValue(Key, out CounterRec Rec))
117 Rec.Counter.Counter += Delta;
132 counters[Key] =
new CounterRec()
140 Counter.Counter += Delta;
141 counters[Key] =
new CounterRec()
185 if (counters.TryGetValue(Key, out CounterRec Rec))
186 return Rec.Counter.Counter;
193 if (counters.TryGetValue(Key, out CounterRec Rec))
205 counters[Key] =
new CounterRec()
213 counters[Key] =
new CounterRec()
243 return ConvertToDictionary(Counters);
264 return ConvertToDictionary(Counters);
267 private static Dictionary<string, long> ConvertToDictionary(IEnumerable<RuntimeCounter> Counters)
269 Dictionary<string, long> Result =
new Dictionary<string, long>();
275 if (counters.TryGetValue(Counter.
Key, out CounterRec Rec))
276 Result[Counter.
Key] = Rec.Counter.Counter;
Represents a case-insensitive string.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static string WildcardToRegex(string s, string Wildcard)
Converts a wildcard string to a regular expression string.
static async Task Update(object Object)
Updates an object in the database.
static async Task Delete(object Object)
Deletes an object in the database.
static Task< IEnumerable< object > > Find(string Collection, params string[] SortOrder)
Finds objects in a given collection.
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
This filter selects objects that have a named field equal to a given value.
This filter selects objects that have a named field matching a given regular expression.
Base class for all filter classes.
Implements an in-memory cache.
Event arguments for cache item removal events.
ValueType Value
Value of item that was removed.
Contains a runtime counter.
CaseInsensitiveString Key
Counter Key
Static class managing persistent counters.
static Task< long > DecrementCounter(CaseInsensitiveString Key, long Delta)
Decrements a counter.
static async Task< int > FlushAsync()
Flushes all cached counters to the database.
static Dictionary< string, long > GetWhere(Filter Filter)
Gets available counters, matching a search filter.
static Dictionary< string, long > GetWhere()
Gets available counters.
static Task< Dictionary< string, long > > GetWhereKeyLikeAsync(string Key, string Wildcard)
Gets available counters, matching a search filter.
static async Task< Dictionary< string, long > > GetWhereAsync()
Gets available counters.
static Task< long > IncrementCounter(CaseInsensitiveString Key)
Increments a counter.
static async Task< long > IncrementCounter(CaseInsensitiveString Key, long Delta)
Increments a counter.
static Task< long > DecrementCounter(CaseInsensitiveString Key)
Decrements a counter.
static async Task< long > GetCount(CaseInsensitiveString Key)
Gets the current count of a counter.
static Dictionary< string, long > GetWhereKeyLike(string Key, string Wildcard)
Gets available counters, matching a search filter.
static async Task< Dictionary< string, long > > GetWhereAsync(Filter Filter)
Gets available counters, matching a search filter.
static Dictionary< string, long > GetWhereKeyLikeRegEx(string KeyPattern)
Gets available counters, matching a search filter.
static Task< Dictionary< string, long > > GetWhereKeyLikeRegExAsync(string KeyPattern)
Gets available counters, matching a search filter.