From f89f308c525e9deebc6d2cf6416e27dfe1a299dc Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sun, 19 May 2019 16:03:38 +0200 Subject: Cleanup DiscoBot Project --- FireBase/Offline/DatabaseExtensions.cs | 77 ++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 26 deletions(-) (limited to 'FireBase/Offline/DatabaseExtensions.cs') diff --git a/FireBase/Offline/DatabaseExtensions.cs b/FireBase/Offline/DatabaseExtensions.cs index 4b04314..56dcf46 100644 --- a/FireBase/Offline/DatabaseExtensions.cs +++ b/FireBase/Offline/DatabaseExtensions.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; - using Firebase.Database.Query; + using Query; public static class DatabaseExtensions { @@ -19,10 +19,13 @@ /// Specifies what strategy should be used for initial pulling of server data. /// Specifies whether changed items should actually be pushed to the server. It this is false, then Put / Post / Delete will not affect server data. /// The . - public static RealtimeDatabase AsRealtimeDatabase(this ChildQuery query, string filenameModifier = "", string elementRoot = "", StreamingOptions streamingOptions = StreamingOptions.LatestOnly, InitialPullStrategy initialPullStrategy = InitialPullStrategy.MissingOnly, bool pushChanges = true) + public static RealtimeDatabase AsRealtimeDatabase(this ChildQuery query, string filenameModifier = "", + string elementRoot = "", StreamingOptions streamingOptions = StreamingOptions.LatestOnly, + InitialPullStrategy initialPullStrategy = InitialPullStrategy.MissingOnly, bool pushChanges = true) where T : class { - return new RealtimeDatabase(query, elementRoot, query.Client.Options.OfflineDatabaseFactory, filenameModifier, streamingOptions, initialPullStrategy, pushChanges); + return new RealtimeDatabase(query, elementRoot, query.Client.Options.OfflineDatabaseFactory, + filenameModifier, streamingOptions, initialPullStrategy, pushChanges); } /// @@ -36,11 +39,16 @@ /// Specifies what strategy should be used for initial pulling of server data. /// Specifies whether changed items should actually be pushed to the server. It this is false, then Put / Post / Delete will not affect server data. /// The . - public static RealtimeDatabase AsRealtimeDatabase(this ChildQuery query, string filenameModifier = "", string elementRoot = "", StreamingOptions streamingOptions = StreamingOptions.LatestOnly, InitialPullStrategy initialPullStrategy = InitialPullStrategy.MissingOnly, bool pushChanges = true) + public static RealtimeDatabase AsRealtimeDatabase(this ChildQuery query, + string filenameModifier = "", string elementRoot = "", + StreamingOptions streamingOptions = StreamingOptions.LatestOnly, + InitialPullStrategy initialPullStrategy = InitialPullStrategy.MissingOnly, bool pushChanges = true) where T : class where TSetHandler : ISetHandler, new() { - return new RealtimeDatabase(query, elementRoot, query.Client.Options.OfflineDatabaseFactory, filenameModifier, streamingOptions, initialPullStrategy, pushChanges, Activator.CreateInstance()); + return new RealtimeDatabase(query, elementRoot, query.Client.Options.OfflineDatabaseFactory, + filenameModifier, streamingOptions, initialPullStrategy, pushChanges, + Activator.CreateInstance()); } /// @@ -50,8 +58,9 @@ /// The object to set. /// Indicates whether the item should be synced online. /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. - public static void Patch(this RealtimeDatabase db, string key, T obj, bool syncOnline = true, int priority = 1) - where T: class + public static void Patch(this RealtimeDatabase db, string key, T obj, bool syncOnline = true, + int priority = 1) + where T : class { db.Set(key, obj, syncOnline ? SyncOptions.Patch : SyncOptions.None, priority); } @@ -63,8 +72,9 @@ /// The object to set. /// Indicates whether the item should be synced online. /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. - public static void Put(this RealtimeDatabase db, string key, T obj, bool syncOnline = true, int priority = 1) - where T: class + public static void Put(this RealtimeDatabase db, string key, T obj, bool syncOnline = true, + int priority = 1) + where T : class { db.Set(key, obj, syncOnline ? SyncOptions.Put : SyncOptions.None, priority); } @@ -77,7 +87,7 @@ /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. /// The generated key for this object. public static string Post(this RealtimeDatabase db, T obj, bool syncOnline = true, int priority = 1) - where T: class + where T : class { var key = FirebaseKeyGenerator.Next(); @@ -93,7 +103,7 @@ /// Indicates whether the item should be synced online. /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. public static void Delete(this RealtimeDatabase db, string key, bool syncOnline = true, int priority = 1) - where T: class + where T : class { db.Set(key, null, syncOnline ? SyncOptions.Put : SyncOptions.None, priority); } @@ -109,8 +119,10 @@ /// Value to put. /// Indicates whether the item should be synced online. /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. - public static void Put(this RealtimeDatabase db, string key, Expression> propertyExpression, TProperty value, bool syncOnline = true, int priority = 1) - where T: class + public static void Put(this RealtimeDatabase db, string key, + Expression> propertyExpression, TProperty value, bool syncOnline = true, + int priority = 1) + where T : class { db.Set(key, propertyExpression, value, syncOnline ? SyncOptions.Put : SyncOptions.None, priority); } @@ -126,8 +138,10 @@ /// Value to patch. /// Indicates whether the item should be synced online. /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. - public static void Patch(this RealtimeDatabase db, string key, Expression> propertyExpression, TProperty value, bool syncOnline = true, int priority = 1) - where T: class + public static void Patch(this RealtimeDatabase db, string key, + Expression> propertyExpression, TProperty value, bool syncOnline = true, + int priority = 1) + where T : class { db.Set(key, propertyExpression, value, syncOnline ? SyncOptions.Patch : SyncOptions.None, priority); } @@ -143,9 +157,10 @@ /// Value to put. /// Indicates whether the item should be synced online. /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. - public static void Delete(this RealtimeDatabase db, string key, Expression> propertyExpression, bool syncOnline = true, int priority = 1) - where T: class - where TProperty: class + public static void Delete(this RealtimeDatabase db, string key, + Expression> propertyExpression, bool syncOnline = true, int priority = 1) + where T : class + where TProperty : class { db.Set(key, propertyExpression, null, syncOnline ? SyncOptions.Put : SyncOptions.None, priority); } @@ -163,12 +178,17 @@ /// Value to put. /// Indicates whether the item should be synced online. /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. - public static void Post(this RealtimeDatabase db, string key, Expression> propertyExpression, TProperty value, bool syncOnline = true, int priority = 1) - where T: class - where TSelector: IDictionary + public static void Post(this RealtimeDatabase db, string key, + Expression> propertyExpression, TProperty value, bool syncOnline = true, + int priority = 1) + where T : class + where TSelector : IDictionary { var nextKey = FirebaseKeyGenerator.Next(); - var expression = Expression.Lambda>(Expression.Call(propertyExpression.Body, typeof(TSelector).GetRuntimeMethod("get_Item", new[] { typeof(string) }), Expression.Constant(nextKey)), propertyExpression.Parameters); + var expression = Expression.Lambda>( + Expression.Call(propertyExpression.Body, + typeof(TSelector).GetRuntimeMethod("get_Item", new[] {typeof(string)}), + Expression.Constant(nextKey)), propertyExpression.Parameters); db.Set(key, expression, value, syncOnline ? SyncOptions.Put : SyncOptions.None, priority); } @@ -185,11 +205,16 @@ /// Key within the nested dictionary to delete. /// Indicates whether the item should be synced online. /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. - public static void Delete(this RealtimeDatabase db, string key, Expression>> propertyExpression, string dictionaryKey, bool syncOnline = true, int priority = 1) - where T: class + public static void Delete(this RealtimeDatabase db, string key, + Expression>> propertyExpression, string dictionaryKey, + bool syncOnline = true, int priority = 1) + where T : class { - var expression = Expression.Lambda>(Expression.Call(propertyExpression.Body, typeof(IDictionary).GetRuntimeMethod("get_Item", new[] { typeof(string) }), Expression.Constant(dictionaryKey)), propertyExpression.Parameters); + var expression = Expression.Lambda>( + Expression.Call(propertyExpression.Body, + typeof(IDictionary).GetRuntimeMethod("get_Item", new[] {typeof(string)}), + Expression.Constant(dictionaryKey)), propertyExpression.Parameters); db.Set(key, expression, null, syncOnline ? SyncOptions.Put : SyncOptions.None, priority); } } -} +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf