2using System.Collections.Generic;
3using System.Reflection;
4using System.Threading.Tasks;
18 #region String-valued settings
26 public static string Get(
string Key,
string DefaultValue)
28 return GetAsync(Key, DefaultValue).Result;
37 public static async Task<string>
GetAsync(
string Key,
string DefaultValue)
40 return Setting?.Value ?? DefaultValue;
43 private static async Task<T> GetAsync<T>(
string Key)
59 public static bool Set(
string Key,
string Value)
70 public static async Task<bool>
SetAsync(
string Key,
string Value)
75 return await SetAsyncLocked(Key, Value,
Setting);
92 Setting.Value = Value;
104 #region Int64-valued settings
112 public static long Get(
string Key,
long DefaultValue)
114 return GetAsync(Key, DefaultValue).Result;
123 public static async Task<long>
GetAsync(
string Key,
long DefaultValue)
126 return Setting?.Value ?? DefaultValue;
135 public static bool Set(
string Key,
long Value)
146 public static async Task<bool>
SetAsync(
string Key,
long Value)
151 return await SetAsyncLocked(Key, Value,
Setting);
155 private static async Task<bool> SetAsyncLocked(
string Key,
long Value,
Int64Setting Setting)
168 Setting.Value = Value;
180 #region Boolean-valued settings
188 public static bool Get(
string Key,
bool DefaultValue)
190 return GetAsync(Key, DefaultValue).Result;
199 public static async Task<bool>
GetAsync(
string Key,
bool DefaultValue)
202 return Setting?.Value ?? DefaultValue;
211 public static bool Set(
string Key,
bool Value)
222 public static async Task<bool>
SetAsync(
string Key,
bool Value)
227 return await SetAsyncLocked(Key, Value,
Setting);
244 Setting.Value = Value;
256 #region DateTime-valued settings
264 public static DateTime
Get(
string Key, DateTime DefaultValue)
266 return GetAsync(Key, DefaultValue).Result;
275 public static async Task<DateTime>
GetAsync(
string Key, DateTime DefaultValue)
278 return Setting?.Value ?? DefaultValue;
287 public static bool Set(
string Key, DateTime Value)
298 public static async Task<bool>
SetAsync(
string Key, DateTime Value)
303 return await SetAsyncLocked(Key, Value,
Setting);
320 Setting.Value = Value;
332 #region TimeSpan-valued settings
340 public static TimeSpan
Get(
string Key, TimeSpan DefaultValue)
342 return GetAsync(Key, DefaultValue).Result;
351 public static async Task<TimeSpan>
GetAsync(
string Key, TimeSpan DefaultValue)
354 return Setting?.Value ?? DefaultValue;
363 public static bool Set(
string Key, TimeSpan Value)
374 public static async Task<bool>
SetAsync(
string Key, TimeSpan Value)
379 return await SetAsyncLocked(Key, Value,
Setting);
396 Setting.Value = Value;
408 #region Double-valued settings
416 public static double Get(
string Key,
double DefaultValue)
418 return GetAsync(Key, DefaultValue).Result;
427 public static async Task<double>
GetAsync(
string Key,
double DefaultValue)
430 return Setting?.Value ?? DefaultValue;
439 public static bool Set(
string Key,
double Value)
450 public static async Task<bool>
SetAsync(
string Key,
double Value)
455 return await SetAsyncLocked(Key, Value,
Setting);
472 Setting.Value = Value;
484 #region Enum-valued settings
492 public static Enum
Get(
string Key, Enum DefaultValue)
494 return GetAsync(Key, DefaultValue).Result;
503 public static async Task<Enum>
GetAsync(
string Key, Enum DefaultValue)
506 return Setting?.Value ?? DefaultValue;
515 public static bool Set(
string Key, Enum Value)
526 public static async Task<bool>
SetAsync(
string Key, Enum Value)
531 return await SetAsyncLocked(Key, Value,
Setting);
535 private static async Task<bool> SetAsyncLocked(
string Key, Enum Value,
EnumSetting Setting)
548 Setting.Value = Value;
560 #region Object-valued settings
568 public static object Get(
string Key,
object DefaultValue)
570 return GetAsync(Key, DefaultValue).Result;
579 public static async Task<object>
GetAsync(
string Key,
object DefaultValue)
591 public static bool Set(
string Key,
object Value)
602 public static async Task<bool>
SetAsync(
string Key,
object Value)
620 if (Value is
string s)
632 else if (Value is
long l)
644 else if (Value is
double d)
656 else if (Value is
bool b)
668 else if (Value is DateTime TP)
680 else if (Value is TimeSpan TS)
692 else if (Value is Enum E)
706 Type T = Value.GetType();
707 TypeInfo TI = T.GetTypeInfo();
710 throw new InvalidOperationException(
"Object setting values cannot be stored separate collections. (CollectionName attribute found.)");
714 throw new InvalidOperationException(
"Full Type names must be serialized when persisting object setting values. (TypeName attribute.). Exceptions for the types: Boolean, Int64, String, DateTime, TimeSpan, Double.");
722 ObjectSetting.Value = Value;
742 #region Delete Setting
781 Dictionary<string, object> Result =
new Dictionary<string, object>();
This attribute defines the name of the collection that will house objects of this type.
This attribute defines the name of the collection that will house objects of this type.
TypeNameSerialization TypeNameSerialization
How the type name should be serialized.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static Task< IEnumerable< object > > FindDelete(string Collection, params string[] SortOrder)
Finds objects in a given collection and deletes them in the same atomic operation.
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.
Static class managing persistent settings.
static double Get(string Key, double DefaultValue)
Gets a double-valued setting.
static async Task< bool > SetAsync(string Key, double Value)
Sets a double-valued setting.
static object Get(string Key, object DefaultValue)
Gets a object-valued setting.
static bool Set(string Key, object Value)
Sets a object-valued setting.
static Task< Dictionary< string, object > > GetWhereKeyLikeRegExAsync(string KeyPattern)
Gets available settings, matching a search filter.
static int DeleteWhereKeyLikeRegEx(string KeyPattern)
Deletes available settings, matching a search filter.
static int DeleteWhere(Filter Filter)
Deletes available settings, matching a search filter.
static TimeSpan Get(string Key, TimeSpan DefaultValue)
Gets a TimeSpan-valued setting.
static bool Set(string Key, DateTime Value)
Sets a DateTime-valued setting.
static Task< int > DeleteWhereKeyLikeAsync(string Key, string Wildcard)
Deletes available settings, matching a search filter.
static Task< int > DeleteWhereKeyLikeRegExAsync(string KeyPattern)
Deletes available settings, matching a search filter.
static bool Set(string Key, string Value)
Sets a string-valued setting.
static bool Set(string Key, long Value)
Sets a long-valued setting.
static Enum Get(string Key, Enum DefaultValue)
Gets a Enum-valued setting.
static async Task< Dictionary< string, object > > GetWhereAsync(Filter Filter)
Gets available settings, matching a search filter.
static async Task< int > DeleteWhereAsync(Filter Filter)
Deletes available settings, matching a search filter.
static async Task< long > GetAsync(string Key, long DefaultValue)
Gets a long-valued setting.
static bool Set(string Key, Enum Value)
Sets a Enum-valued setting.
static async Task< Enum > GetAsync(string Key, Enum DefaultValue)
Gets a Enum-valued setting.
static bool Set(string Key, TimeSpan Value)
Sets a TimeSpan-valued setting.
static async Task< DateTime > GetAsync(string Key, DateTime DefaultValue)
Gets a DateTime-valued setting.
static Task< Dictionary< string, object > > GetWhereKeyLikeAsync(string Key, string Wildcard)
Gets available settings, matching a search filter.
static async Task< bool > SetAsync(string Key, long Value)
Sets a long-valued setting.
static async Task< bool > SetAsync(string Key, TimeSpan Value)
Sets a TimeSpan-valued setting.
static string Get(string Key, string DefaultValue)
Gets a string-valued setting.
static bool Set(string Key, bool Value)
Sets a bool-valued setting.
static async Task< bool > SetAsync(string Key, Enum Value)
Sets a Enum-valued setting.
static async Task< bool > SetAsync(string Key, object Value)
Sets a object-valued setting.
static DateTime Get(string Key, DateTime DefaultValue)
Gets a DateTime-valued setting.
static Dictionary< string, object > GetWhereKeyLike(string Key, string Wildcard)
Gets available settings, matching a search filter.
static async Task< object > GetAsync(string Key, object DefaultValue)
Gets a object-valued setting.
static async Task< string > GetAsync(string Key, string DefaultValue)
Gets a string-valued setting.
static Dictionary< string, object > GetWhere(Filter Filter)
Gets available settings, matching a search filter.
static async Task< bool > DeleteAsync(string Key)
Deletes a runtime setting
static async Task< double > GetAsync(string Key, double DefaultValue)
Gets a double-valued setting.
static async Task< bool > SetAsync(string Key, string Value)
Sets a string-valued setting.
static int DeleteWhereKeyLike(string Key, string Wildcard)
Deletes available settings, matching a search filter.
static async Task< bool > SetAsync(string Key, bool Value)
Sets a bool-valued setting.
static bool Get(string Key, bool DefaultValue)
Gets a bool-valued setting.
static long Get(string Key, long DefaultValue)
Gets a long-valued setting.
static async Task< TimeSpan > GetAsync(string Key, TimeSpan DefaultValue)
Gets a TimeSpan-valued setting.
static async Task< bool > GetAsync(string Key, bool DefaultValue)
Gets a bool-valued setting.
static bool Set(string Key, double Value)
Sets a double-valued setting.
static Dictionary< string, object > GetWhereKeyLikeRegEx(string KeyPattern)
Gets available settings, matching a search filter.
static async Task< bool > SetAsync(string Key, DateTime Value)
Sets a DateTime-valued setting.
Enumeration setting object.
Base abstract class for settings.
abstract object GetValueObject()
Gets the value of the setting, as an object.
Represents a named semaphore, i.e. an object, identified by a name, that allows single concurrent wri...
Static class of application-wide semaphores that can be used to order access to editable objects.
static async Task< Semaphore > BeginRead(string Key)
Waits until the semaphore identified by Key is ready for reading. Each call to BeginRead must be fol...
static async Task< Semaphore > BeginWrite(string Key)
Waits until the semaphore identified by Key is ready for writing. Each call to BeginWrite must be fo...
TypeNameSerialization
How the type name should be serialized.