From c4d046858e0822b7c2c540ac2368b2c0e88e7a26 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sun, 19 May 2019 17:00:02 +0200 Subject: general refectoring added 42 as dummy Token --- FireBase/ExceptionEventArgs.cs | 10 +- FireBase/Extensions/ObservableExtensions.cs | 15 +- FireBase/Extensions/TaskExtensions.cs | 10 +- FireBase/FirebaseClient.cs | 34 ++--- FireBase/FirebaseException.cs | 16 +-- FireBase/FirebaseKeyGenerator.cs | 15 +- FireBase/FirebaseObject.cs | 10 +- FireBase/FirebaseOptions.cs | 30 ++-- FireBase/Http/HttpClientExtensions.cs | 32 ++--- FireBase/Http/PostResult.cs | 4 +- FireBase/ObservableExtensions.cs | 16 +-- FireBase/Offline/ConcurrentOfflineDatabase.cs | 128 +++++++++++------ FireBase/Offline/DatabaseExtensions.cs | 111 ++++++++++----- FireBase/Offline/ISetHandler.cs | 8 +- FireBase/Offline/InitialPullStrategy.cs | 10 +- FireBase/Offline/Internals/MemberAccessVisitor.cs | 16 +-- FireBase/Offline/OfflineCacheAdapter.cs | 64 ++++----- FireBase/Offline/OfflineDatabase.cs | 126 +++++++++++------ FireBase/Offline/OfflineEntry.cs | 43 +++--- FireBase/Offline/RealtimeDatabase.cs | 118 +++++++++------- FireBase/Offline/SetHandler.cs | 8 +- FireBase/Offline/StreamingOptions.cs | 10 +- FireBase/Offline/SyncOptions.cs | 10 +- FireBase/Query/AuthQuery.cs | 14 +- FireBase/Query/ChildQuery.cs | 14 +- FireBase/Query/FilterQuery.cs | 38 +++-- FireBase/Query/FirebaseQuery.cs | 162 +++++++++++----------- FireBase/Query/IFirebaseQuery.cs | 28 ++-- FireBase/Query/OrderQuery.cs | 12 +- FireBase/Query/ParameterQuery.cs | 18 +-- FireBase/Query/QueryExtensions.cs | 68 ++++----- FireBase/Query/QueryFactoryExtensions.cs | 85 +++++++----- FireBase/Query/SilentQuery.cs | 2 +- FireBase/Streaming/FirebaseCache.cs | 39 +++--- FireBase/Streaming/FirebaseEvent.cs | 8 +- FireBase/Streaming/FirebaseEventSource.cs | 14 +- FireBase/Streaming/FirebaseEventType.cs | 6 +- FireBase/Streaming/FirebaseSubscription.cs | 38 +++-- FireBase/Streaming/NonBlockingStreamReader.cs | 21 +-- 39 files changed, 774 insertions(+), 637 deletions(-) (limited to 'FireBase') diff --git a/FireBase/ExceptionEventArgs.cs b/FireBase/ExceptionEventArgs.cs index 185c952..09c205a 100644 --- a/FireBase/ExceptionEventArgs.cs +++ b/FireBase/ExceptionEventArgs.cs @@ -1,16 +1,16 @@ -namespace Firebase.Database -{ - using System; +using System; +namespace Firebase.Database +{ /// - /// Event args holding the object. + /// Event args holding the object. /// public class ExceptionEventArgs : EventArgs where T : Exception { public readonly T Exception; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The exception. public ExceptionEventArgs(T exception) diff --git a/FireBase/Extensions/ObservableExtensions.cs b/FireBase/Extensions/ObservableExtensions.cs index cb41bcc..0a672d7 100644 --- a/FireBase/Extensions/ObservableExtensions.cs +++ b/FireBase/Extensions/ObservableExtensions.cs @@ -1,19 +1,20 @@ -namespace Firebase.Database.Extensions -{ - using System; - using System.Reactive.Linq; +using System; +using System.Reactive.Linq; +namespace Firebase.Database.Extensions +{ public static class ObservableExtensions { /// - /// Returns a cold observable which retries (re-subscribes to) the source observable on error until it successfully terminates. + /// Returns a cold observable which retries (re-subscribes to) the source observable on error until it successfully + /// terminates. /// /// The source observable. /// How long to wait between attempts. /// A predicate determining for which exceptions to retry. Defaults to all /// - /// A cold observable which retries (re-subscribes to) the source observable on error up to the - /// specified number of times or until it successfully terminates. + /// A cold observable which retries (re-subscribes to) the source observable on error up to the + /// specified number of times or until it successfully terminates. /// public static IObservable RetryAfterDelay( this IObservable source, diff --git a/FireBase/Extensions/TaskExtensions.cs b/FireBase/Extensions/TaskExtensions.cs index 8e933b2..c955b3a 100644 --- a/FireBase/Extensions/TaskExtensions.cs +++ b/FireBase/Extensions/TaskExtensions.cs @@ -1,12 +1,12 @@ -namespace Firebase.Database.Extensions -{ - using System; - using System.Threading.Tasks; +using System; +using System.Threading.Tasks; +namespace Firebase.Database.Extensions +{ public static class TaskExtensions { /// - /// Instead of unwrapping it throws it as it is. + /// Instead of unwrapping it throws it as it is. /// public static async Task WithAggregateException(this Task source) { diff --git a/FireBase/FirebaseClient.cs b/FireBase/FirebaseClient.cs index 8795668..3079f3b 100644 --- a/FireBase/FirebaseClient.cs +++ b/FireBase/FirebaseClient.cs @@ -1,30 +1,26 @@ +using System; using System.Net.Http; +using System.Runtime.CompilerServices; +using Firebase.Database.Query; -[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Firebase.Database.Tests")] +[assembly: InternalsVisibleTo("Firebase.Database.Tests")] namespace Firebase.Database { - using System; - using System.Collections.Generic; - using System.Threading.Tasks; - using Offline; - using Query; - /// - /// Firebase client which acts as an entry point to the online database. + /// Firebase client which acts as an entry point to the online database. /// public class FirebaseClient : IDisposable { + private readonly string baseUrl; internal readonly HttpClient HttpClient; internal readonly FirebaseOptions Options; - private readonly string baseUrl; - /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The base url. - /// Offline database. + /// Offline database. public FirebaseClient(string baseUrl, FirebaseOptions options = null) { HttpClient = new HttpClient(); @@ -35,19 +31,19 @@ namespace Firebase.Database if (!this.baseUrl.EndsWith("/")) this.baseUrl += "/"; } + public void Dispose() + { + HttpClient?.Dispose(); + } + /// - /// Queries for a child of the data root. + /// Queries for a child of the data root. /// /// Name of the child. - /// . + /// . public ChildQuery Child(string resourceName) { return new ChildQuery(this, () => baseUrl + resourceName); } - - public void Dispose() - { - HttpClient?.Dispose(); - } } } \ No newline at end of file diff --git a/FireBase/FirebaseException.cs b/FireBase/FirebaseException.cs index 2f8269d..cfc09d3 100644 --- a/FireBase/FirebaseException.cs +++ b/FireBase/FirebaseException.cs @@ -1,8 +1,8 @@ -namespace Firebase.Database -{ - using System; - using System.Net; +using System; +using System.Net; +namespace Firebase.Database +{ public class FirebaseException : Exception { public FirebaseException(string requestUrl, string requestData, string responseData, HttpStatusCode statusCode) @@ -25,22 +25,22 @@ } /// - /// Post data passed to the authentication service. + /// Post data passed to the authentication service. /// public string RequestData { get; } /// - /// Original url of the request. + /// Original url of the request. /// public string RequestUrl { get; } /// - /// Response from the authentication service. + /// Response from the authentication service. /// public string ResponseData { get; } /// - /// Status code of the response. + /// Status code of the response. /// public HttpStatusCode StatusCode { get; } diff --git a/FireBase/FirebaseKeyGenerator.cs b/FireBase/FirebaseKeyGenerator.cs index 70a855d..37beed5 100644 --- a/FireBase/FirebaseKeyGenerator.cs +++ b/FireBase/FirebaseKeyGenerator.cs @@ -1,11 +1,11 @@ +using System; +using System.Text; + namespace Firebase.Database { - using System; - using System.Text; - /// - /// Offline key generator which mimics the official Firebase generators. - /// Credit: https://github.com/bubbafat/FirebaseSharp/blob/master/src/FirebaseSharp.Portable/FireBasePushIdGenerator.cs + /// Offline key generator which mimics the official Firebase generators. + /// Credit: https://github.com/bubbafat/FirebaseSharp/blob/master/src/FirebaseSharp.Portable/FireBasePushIdGenerator.cs /// public class FirebaseKeyGenerator { @@ -26,10 +26,11 @@ namespace Firebase.Database } /// - /// Returns next firebase key based on current time. + /// Returns next firebase key based on current time. /// /// - /// The . + /// The . + /// public static string Next() { // We generate 72-bits of randomness which get turned into 12 characters and diff --git a/FireBase/FirebaseObject.cs b/FireBase/FirebaseObject.cs index 653d508..2e0fd20 100644 --- a/FireBase/FirebaseObject.cs +++ b/FireBase/FirebaseObject.cs @@ -1,9 +1,11 @@ namespace Firebase.Database { /// - /// Holds the object of type along with its key. + /// Holds the object of type + /// + /// along with its key. /// - /// Type of the underlying object. + /// Type of the underlying object. public class FirebaseObject { internal FirebaseObject(string key, T obj) @@ -13,12 +15,12 @@ namespace Firebase.Database } /// - /// Gets the key of . + /// Gets the key of . /// public string Key { get; } /// - /// Gets the underlying object. + /// Gets the underlying object. /// public T Object { get; } } diff --git a/FireBase/FirebaseOptions.cs b/FireBase/FirebaseOptions.cs index f31a047..b4a5e51 100644 --- a/FireBase/FirebaseOptions.cs +++ b/FireBase/FirebaseOptions.cs @@ -1,12 +1,12 @@ -namespace Firebase.Database -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Threading.Tasks; - using Offline; - using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using Firebase.Database.Offline; +using Newtonsoft.Json; +namespace Firebase.Database +{ public class FirebaseOptions { public FirebaseOptions() @@ -18,32 +18,34 @@ } /// - /// Gets or sets the factory for Firebase offline database. Default is in-memory dictionary. + /// Gets or sets the factory for Firebase offline database. Default is in-memory dictionary. /// public Func> OfflineDatabaseFactory { get; set; } /// - /// Gets or sets the method for retrieving auth tokens. Default is null. + /// Gets or sets the method for retrieving auth tokens. Default is null. /// public Func> AuthTokenAsyncFactory { get; set; } /// - /// Gets or sets the factory for used for reading online streams. Default is . + /// Gets or sets the factory for used for reading online streams. Default is + /// . /// public Func SubscriptionStreamReaderFactory { get; set; } /// - /// Gets or sets the json serializer settings. + /// Gets or sets the json serializer settings. /// public JsonSerializerSettings JsonSerializerSettings { get; set; } /// - /// Gets or sets the time between synchronization attempts for pulling and pushing offline entities. Default is 10 seconds. + /// Gets or sets the time between synchronization attempts for pulling and pushing offline entities. Default is 10 + /// seconds. /// public TimeSpan SyncPeriod { get; set; } /// - /// Specify if token returned by factory will be used as "auth" url parameter or "access_token". + /// Specify if token returned by factory will be used as "auth" url parameter or "access_token". /// public bool AsAccessToken { get; set; } } diff --git a/FireBase/Http/HttpClientExtensions.cs b/FireBase/Http/HttpClientExtensions.cs index 7f8fffe..6582769 100644 --- a/FireBase/Http/HttpClientExtensions.cs +++ b/FireBase/Http/HttpClientExtensions.cs @@ -1,27 +1,27 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; +using Newtonsoft.Json; + namespace Firebase.Database.Http { - using System; - using System.Collections; - using System.Collections.Generic; - using System.Linq; - using System.Net.Http; - using System.Threading.Tasks; - using Newtonsoft.Json; - using System.Net; - /// - /// The http client extensions for object deserializations. + /// The http client extensions for object deserializations. /// internal static class HttpClientExtensions { /// - /// The get object collection async. + /// The get object collection async. /// /// The client. - /// The request uri. - /// The specific JSON Serializer Settings. + /// The request uri. + /// The specific JSON Serializer Settings. /// The type of entities the collection should contain. - /// The . + /// The . public static async Task>> GetObjectCollectionAsync( this HttpClient client, string requestUri, JsonSerializerSettings jsonSerializerSettings) @@ -91,11 +91,11 @@ namespace Firebase.Database.Http }*/ /// - /// The get object collection async. + /// The get object collection async. /// /// The json data. /// The type of entities the collection should contain. - /// The . + /// The . public static IEnumerable> GetObjectCollection(this string data, Type elementType) { var dictionaryType = typeof(Dictionary<,>).MakeGenericType(typeof(string), elementType); diff --git a/FireBase/Http/PostResult.cs b/FireBase/Http/PostResult.cs index 5a779ed..15a4894 100644 --- a/FireBase/Http/PostResult.cs +++ b/FireBase/Http/PostResult.cs @@ -1,12 +1,12 @@ namespace Firebase.Database.Http { /// - /// Represents data returned after a successful POST to firebase server. + /// Represents data returned after a successful POST to firebase server. /// public class PostResult { /// - /// Gets or sets the generated key after a successful post. + /// Gets or sets the generated key after a successful post. /// public string Name { get; set; } } diff --git a/FireBase/ObservableExtensions.cs b/FireBase/ObservableExtensions.cs index da78365..bc46261 100644 --- a/FireBase/ObservableExtensions.cs +++ b/FireBase/ObservableExtensions.cs @@ -1,20 +1,20 @@ -namespace Firebase.Database -{ - using System; - using System.Collections.ObjectModel; - using Streaming; +using System; +using System.Collections.ObjectModel; +using Firebase.Database.Streaming; +namespace Firebase.Database +{ /// - /// Extensions for . + /// Extensions for . /// public static class ObservableExtensions { /// - /// Starts observing on given firebase observable and propagates event into an . + /// Starts observing on given firebase observable and propagates event into an . /// /// The observable. /// Type of entity. - /// The . + /// The . public static ObservableCollection AsObservableCollection(this IObservable> observable) { var collection = new ObservableCollection(); diff --git a/FireBase/Offline/ConcurrentOfflineDatabase.cs b/FireBase/Offline/ConcurrentOfflineDatabase.cs index 5527168..1a9e607 100644 --- a/FireBase/Offline/ConcurrentOfflineDatabase.cs +++ b/FireBase/Offline/ConcurrentOfflineDatabase.cs @@ -1,23 +1,23 @@ -namespace Firebase.Database.Offline +using System; +using System.Collections; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using LiteDB; + +namespace Firebase.Database.Offline { - using System; - using System.Collections; - using System.Collections.Concurrent; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using LiteDB; - /// - /// The offline database. + /// The offline database. /// public class ConcurrentOfflineDatabase : IDictionary { - private readonly LiteRepository db; private readonly ConcurrentDictionary ccache; + private readonly LiteRepository db; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The item type which is used to determine the database file name. /// Custom string which will get appended to the file name. @@ -43,33 +43,41 @@ } /// - /// Gets the number of elements contained in the . + /// Gets the number of elements contained in the . /// - /// The number of elements contained in the . + /// The number of elements contained in the . public int Count => ccache.Count; /// - /// Gets a value indicating whether this is a read-only collection. + /// Gets a value indicating whether this is a read-only collection. /// public bool IsReadOnly => false; /// - /// Gets an containing the keys of the . + /// Gets an containing the keys of the + /// . /// - /// An containing the keys of the object that implements . + /// + /// An containing the keys of the object that + /// implements . + /// public ICollection Keys => ccache.Keys; /// - /// Gets an containing the values in the . + /// Gets an containing the values in the + /// . /// - /// An containing the values in the object that implements . + /// + /// An containing the values in the object that + /// implements . + /// public ICollection Values => ccache.Values; /// - /// Gets or sets the element with the specified key. + /// Gets or sets the element with the specified key. /// /// The key of the element to get or set. - /// The element with the specified key. + /// The element with the specified key. public OfflineEntry this[string key] { get => ccache[key]; @@ -82,7 +90,7 @@ } /// - /// Returns an enumerator that iterates through the collection. + /// Returns an enumerator that iterates through the collection. /// /// An enumerator that can be used to iterate through the collection. public IEnumerator> GetEnumerator() @@ -96,65 +104,82 @@ } /// - /// Adds an item to the . + /// Adds an item to the . /// - /// The object to add to the . + /// The object to add to the . public void Add(KeyValuePair item) { Add(item.Key, item.Value); } /// - /// Removes all items from the . - /// + /// Removes all items from the . + /// public void Clear() { ccache.Clear(); - db.Delete(Query.All()); + db.Delete(LiteDB.Query.All()); } /// - /// Determines whether the contains a specific value. + /// Determines whether the contains a specific value. /// - /// The object to locate in the . - /// True if is found in the ; otherwise, false. + /// The object to locate in the . + /// + /// True if is found in the ; + /// otherwise, false. + /// public bool Contains(KeyValuePair item) { return ContainsKey(item.Key); } /// - /// Copies the elements of the to an , starting at a particular index. + /// Copies the elements of the to an + /// , starting at a particular index. /// - /// The one-dimensional that is the destination of the elements copied from . The must have zero-based indexing. - /// The zero-based index in at which copying begins. + /// + /// The one-dimensional that is the destination of the elements copied + /// from . The must have + /// zero-based indexing. + /// + /// The zero-based index in at which copying begins. public void CopyTo(KeyValuePair[] array, int arrayIndex) { ccache.ToList().CopyTo(array, arrayIndex); } /// - /// Removes the first occurrence of a specific object from the . + /// Removes the first occurrence of a specific object from the + /// . /// - /// The object to remove from the . - /// True if was successfully removed from the ; otherwise, false. This method also returns false if is not found in the original . + /// The object to remove from the . + /// + /// True if was successfully removed from the + /// ; otherwise, false. This method also returns false if + /// is not found in the original . + /// public bool Remove(KeyValuePair item) { return Remove(item.Key); } /// - /// Determines whether the contains an element with the specified key. + /// Determines whether the contains an element with the + /// specified key. /// - /// The key to locate in the . - /// True if the contains an element with the key; otherwise, false. + /// The key to locate in the . + /// + /// True if the contains an element with the key; + /// otherwise, false. + /// public bool ContainsKey(string key) { return ccache.ContainsKey(key); } /// - /// Adds an element with the provided key and value to the . + /// Adds an element with the provided key and value to the . /// /// The object to use as the key of the element to add. /// The object to use as the value of the element to add. @@ -165,10 +190,13 @@ } /// - /// Removes the element with the specified key from the . + /// Removes the element with the specified key from the . /// /// The key of the element to remove. - /// True if the element is successfully removed; otherwise, false. This method also returns false if was not found in the original . + /// + /// True if the element is successfully removed; otherwise, false. This method also returns false if + /// was not found in the original . + /// public bool Remove(string key) { ccache.TryRemove(key, out _); @@ -176,10 +204,18 @@ } /// - /// Gets the value associated with the specified key. - /// - /// The key whose value to get.When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the parameter. This parameter is passed uninitialized. - /// True if the object that implements contains an element with the specified key; otherwise, false. + /// Gets the value associated with the specified key. + /// + /// The key whose value to get. + /// + /// When this method returns, the value associated with the specified key, if the key is found; + /// otherwise, the default value for the type of the parameter. This parameter is passed + /// uninitialized. + /// + /// + /// True if the object that implements contains an + /// element with the specified key; otherwise, false. + /// public bool TryGetValue(string key, out OfflineEntry value) { return ccache.TryGetValue(key, out value); diff --git a/FireBase/Offline/DatabaseExtensions.cs b/FireBase/Offline/DatabaseExtensions.cs index 56dcf46..e7c4074 100644 --- a/FireBase/Offline/DatabaseExtensions.cs +++ b/FireBase/Offline/DatabaseExtensions.cs @@ -1,24 +1,26 @@ -namespace Firebase.Database.Offline -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Linq.Expressions; - using System.Reflection; - using Query; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Reflection; +using Firebase.Database.Query; +namespace Firebase.Database.Offline +{ public static class DatabaseExtensions { /// - /// Create new instances of the . + /// Create new instances of the . /// /// Type of elements. /// Custom string which will get appended to the file name. /// Optional custom root element of received json items. - /// Realtime streaming options. + /// Realtime streaming options. /// 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 . + /// + /// 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) @@ -29,16 +31,19 @@ } /// - /// Create new instances of the . + /// Create new instances of the . /// /// Type of elements. - /// Type of the custom to use. + /// Type of the custom to use. /// Custom string which will get appended to the file name. /// Optional custom root element of received json items. - /// Realtime streaming options. + /// Realtime streaming options. /// 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 . + /// + /// 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, @@ -52,12 +57,15 @@ } /// - /// Overwrites existing object with given key leaving any missing properties intact in firebase. + /// Overwrites existing object with given key leaving any missing properties intact in firebase. /// /// The key. /// 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. + /// + /// 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 @@ -66,12 +74,15 @@ } /// - /// Overwrites existing object with given key. + /// Overwrites existing object with given key. /// /// The key. /// 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. + /// + /// 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 @@ -80,11 +91,14 @@ } /// - /// Adds a new entity to the Database. + /// Adds a new entity to the Database. /// /// The object to add. /// Indicates whether the item should be synced online. - /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. + /// + /// 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 @@ -97,11 +111,14 @@ } /// - /// Deletes the entity with the given key. + /// Deletes the entity with the given key. /// /// The key. /// Indicates whether the item should be synced online. - /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. + /// + /// 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 { @@ -109,7 +126,8 @@ } /// - /// Do a Put for a nested property specified by of an object with key . + /// Do a Put for a nested property specified by of an object with key + /// . /// /// Type of the root elements. /// Type of the property being modified @@ -118,7 +136,10 @@ /// Expression on the root element leading to target value to modify. /// 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. + /// + /// 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) @@ -128,7 +149,8 @@ } /// - /// Do a Patch for a nested property specified by of an object with key . + /// Do a Patch for a nested property specified by of an object with key + /// . /// /// Type of the root elements. /// Type of the property being modified @@ -137,7 +159,10 @@ /// Expression on the root element leading to target value to modify. /// 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. + /// + /// 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) @@ -147,7 +172,8 @@ } /// - /// Delete a nested property specified by of an object with key . This basically does a Put with null value. + /// Delete a nested property specified by of an object with key + /// . This basically does a Put with null value. /// /// Type of the root elements. /// Type of the property being modified @@ -156,7 +182,10 @@ /// Expression on the root element leading to target value to modify. /// 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. + /// + /// 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 @@ -166,8 +195,9 @@ } /// - /// Post a new entity into the nested dictionary specified by of an object with key . - /// The key of the new entity is automatically generated. + /// Post a new entity into the nested dictionary specified by of an object with + /// key . + /// The key of the new entity is automatically generated. /// /// Type of the root elements. /// Type of the dictionary being modified @@ -177,7 +207,10 @@ /// Expression on the root element leading to target value to modify. /// 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. + /// + /// 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) @@ -193,8 +226,9 @@ } /// - /// Delete an entity with key in the nested dictionary specified by of an object with key . - /// The key of the new entity is automatically generated. + /// Delete an entity with key in the nested dictionary specified by + /// of an object with key . + /// The key of the new entity is automatically generated. /// /// Type of the root elements. /// Type of the dictionary being modified @@ -204,7 +238,10 @@ /// Expression on the root element leading to target value to modify. /// 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. + /// + /// 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) diff --git a/FireBase/Offline/ISetHandler.cs b/FireBase/Offline/ISetHandler.cs index e3b49b5..c04bd41 100644 --- a/FireBase/Offline/ISetHandler.cs +++ b/FireBase/Offline/ISetHandler.cs @@ -1,8 +1,8 @@ -namespace Firebase.Database.Offline -{ - using Query; - using System.Threading.Tasks; +using System.Threading.Tasks; +using Firebase.Database.Query; +namespace Firebase.Database.Offline +{ public interface ISetHandler { Task SetAsync(ChildQuery query, string key, OfflineEntry entry); diff --git a/FireBase/Offline/InitialPullStrategy.cs b/FireBase/Offline/InitialPullStrategy.cs index a1ae3f7..ca2bebf 100644 --- a/FireBase/Offline/InitialPullStrategy.cs +++ b/FireBase/Offline/InitialPullStrategy.cs @@ -1,23 +1,23 @@ namespace Firebase.Database.Offline { /// - /// Specifies the strategy for initial pull of server data. + /// Specifies the strategy for initial pull of server data. /// public enum InitialPullStrategy { /// - /// Don't pull anything. + /// Don't pull anything. /// None, /// - /// Pull only what isn't already stored offline. + /// Pull only what isn't already stored offline. /// MissingOnly, /// - /// Pull everything that exists on the server. + /// Pull everything that exists on the server. /// - Everything, + Everything } } \ No newline at end of file diff --git a/FireBase/Offline/Internals/MemberAccessVisitor.cs b/FireBase/Offline/Internals/MemberAccessVisitor.cs index 2bc0fc3..89a77da 100644 --- a/FireBase/Offline/Internals/MemberAccessVisitor.cs +++ b/FireBase/Offline/Internals/MemberAccessVisitor.cs @@ -1,10 +1,10 @@ -namespace Firebase.Database.Offline.Internals -{ - using System.Collections.Generic; - using System.Linq.Expressions; - using System.Reflection; - using Newtonsoft.Json; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Reflection; +using Newtonsoft.Json; +namespace Firebase.Database.Offline.Internals +{ public class MemberAccessVisitor : ExpressionVisitor { private readonly IList propertyNames = new List(); @@ -13,10 +13,6 @@ public IEnumerable PropertyNames => propertyNames; - public MemberAccessVisitor() - { - } - public override Expression Visit(Expression expr) { if (expr?.NodeType == ExpressionType.MemberAccess) diff --git a/FireBase/Offline/OfflineCacheAdapter.cs b/FireBase/Offline/OfflineCacheAdapter.cs index 0918a8c..3153d1b 100644 --- a/FireBase/Offline/OfflineCacheAdapter.cs +++ b/FireBase/Offline/OfflineCacheAdapter.cs @@ -1,10 +1,10 @@ -namespace Firebase.Database.Offline -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Linq; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +namespace Firebase.Database.Offline +{ internal class OfflineCacheAdapter : IDictionary, IDictionary { private readonly IDictionary database; @@ -19,14 +19,10 @@ throw new NotImplementedException(); } - public int Count => database.Count; - public bool IsSynchronized { get; } public object SyncRoot { get; } - public bool IsReadOnly => database.IsReadOnly; - object IDictionary.this[object key] { get => database[key.ToString()].Deserialize(); @@ -42,27 +38,10 @@ } } - public ICollection Keys => database.Keys; - ICollection IDictionary.Values { get; } ICollection IDictionary.Keys { get; } - public ICollection Values => database.Values.Select(o => o.Deserialize()).ToList(); - - public T this[string key] - { - get => database[key].Deserialize(); - - set - { - if (database.ContainsKey(key)) - database[key] = new OfflineEntry(key, value, database[key].Priority, database[key].SyncOptions); - else - database[key] = new OfflineEntry(key, value, 1, SyncOptions.None); - } - } - public bool Contains(object key) { return ContainsKey(key.ToString()); @@ -80,6 +59,32 @@ public bool IsFixedSize => false; + public void Add(object key, object value) + { + Add(key.ToString(), (T) value); + } + + public int Count => database.Count; + + public bool IsReadOnly => database.IsReadOnly; + + public ICollection Keys => database.Keys; + + public ICollection Values => database.Values.Select(o => o.Deserialize()).ToList(); + + public T this[string key] + { + get => database[key].Deserialize(); + + set + { + if (database.ContainsKey(key)) + database[key] = new OfflineEntry(key, value, database[key].Priority, database[key].SyncOptions); + else + database[key] = new OfflineEntry(key, value, 1, SyncOptions.None); + } + } + public IEnumerator> GetEnumerator() { return database.Select(d => new KeyValuePair(d.Key, d.Value.Deserialize())).GetEnumerator(); @@ -95,11 +100,6 @@ Add(item.Key, item.Value); } - public void Add(object key, object value) - { - Add(key.ToString(), (T) value); - } - public void Clear() { database.Clear(); diff --git a/FireBase/Offline/OfflineDatabase.cs b/FireBase/Offline/OfflineDatabase.cs index 3e6e7d8..be0380b 100644 --- a/FireBase/Offline/OfflineDatabase.cs +++ b/FireBase/Offline/OfflineDatabase.cs @@ -1,22 +1,22 @@ -namespace Firebase.Database.Offline +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using LiteDB; + +namespace Firebase.Database.Offline { - using System; - using System.Collections; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using LiteDB; - /// - /// The offline database. + /// The offline database. /// public class OfflineDatabase : IDictionary { - private readonly LiteRepository db; private readonly IDictionary cache; + private readonly LiteRepository db; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The item type which is used to determine the database file name. /// Custom string which will get appended to the file name. @@ -38,33 +38,41 @@ } /// - /// Gets the number of elements contained in the . + /// Gets the number of elements contained in the . /// - /// The number of elements contained in the . + /// The number of elements contained in the . public int Count => cache.Count; /// - /// Gets a value indicating whether this is a read-only collection. + /// Gets a value indicating whether this is a read-only collection. /// public bool IsReadOnly => cache.IsReadOnly; /// - /// Gets an containing the keys of the . + /// Gets an containing the keys of the + /// . /// - /// An containing the keys of the object that implements . + /// + /// An containing the keys of the object that + /// implements . + /// public ICollection Keys => cache.Keys; /// - /// Gets an containing the values in the . + /// Gets an containing the values in the + /// . /// - /// An containing the values in the object that implements . + /// + /// An containing the values in the object that + /// implements . + /// public ICollection Values => cache.Values; /// - /// Gets or sets the element with the specified key. + /// Gets or sets the element with the specified key. /// /// The key of the element to get or set. - /// The element with the specified key. + /// The element with the specified key. public OfflineEntry this[string key] { get => cache[key]; @@ -77,7 +85,7 @@ } /// - /// Returns an enumerator that iterates through the collection. + /// Returns an enumerator that iterates through the collection. /// /// An enumerator that can be used to iterate through the collection. public IEnumerator> GetEnumerator() @@ -91,65 +99,82 @@ } /// - /// Adds an item to the . + /// Adds an item to the . /// - /// The object to add to the . + /// The object to add to the . public void Add(KeyValuePair item) { Add(item.Key, item.Value); } /// - /// Removes all items from the . - /// + /// Removes all items from the . + /// public void Clear() { cache.Clear(); - db.Delete(Query.All()); + db.Delete(LiteDB.Query.All()); } /// - /// Determines whether the contains a specific value. + /// Determines whether the contains a specific value. /// - /// The object to locate in the . - /// True if is found in the ; otherwise, false. + /// The object to locate in the . + /// + /// True if is found in the ; + /// otherwise, false. + /// public bool Contains(KeyValuePair item) { return ContainsKey(item.Key); } /// - /// Copies the elements of the to an , starting at a particular index. + /// Copies the elements of the to an + /// , starting at a particular index. /// - /// The one-dimensional that is the destination of the elements copied from . The must have zero-based indexing. - /// The zero-based index in at which copying begins. + /// + /// The one-dimensional that is the destination of the elements copied + /// from . The must have + /// zero-based indexing. + /// + /// The zero-based index in at which copying begins. public void CopyTo(KeyValuePair[] array, int arrayIndex) { cache.CopyTo(array, arrayIndex); } /// - /// Removes the first occurrence of a specific object from the . + /// Removes the first occurrence of a specific object from the + /// . /// - /// The object to remove from the . - /// True if was successfully removed from the ; otherwise, false. This method also returns false if is not found in the original . + /// The object to remove from the . + /// + /// True if was successfully removed from the + /// ; otherwise, false. This method also returns false if + /// is not found in the original . + /// public bool Remove(KeyValuePair item) { return Remove(item.Key); } /// - /// Determines whether the contains an element with the specified key. + /// Determines whether the contains an element with the + /// specified key. /// - /// The key to locate in the . - /// True if the contains an element with the key; otherwise, false. + /// The key to locate in the . + /// + /// True if the contains an element with the key; + /// otherwise, false. + /// public bool ContainsKey(string key) { return cache.ContainsKey(key); } /// - /// Adds an element with the provided key and value to the . + /// Adds an element with the provided key and value to the . /// /// The object to use as the key of the element to add. /// The object to use as the value of the element to add. @@ -160,10 +185,13 @@ } /// - /// Removes the element with the specified key from the . + /// Removes the element with the specified key from the . /// /// The key of the element to remove. - /// True if the element is successfully removed; otherwise, false. This method also returns false if was not found in the original . + /// + /// True if the element is successfully removed; otherwise, false. This method also returns false if + /// was not found in the original . + /// public bool Remove(string key) { cache.Remove(key); @@ -171,10 +199,18 @@ } /// - /// Gets the value associated with the specified key. - /// - /// The key whose value to get.When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the parameter. This parameter is passed uninitialized. - /// True if the object that implements contains an element with the specified key; otherwise, false. + /// Gets the value associated with the specified key. + /// + /// The key whose value to get. + /// + /// When this method returns, the value associated with the specified key, if the key is found; + /// otherwise, the default value for the type of the parameter. This parameter is passed + /// uninitialized. + /// + /// + /// True if the object that implements contains an + /// element with the specified key; otherwise, false. + /// public bool TryGetValue(string key, out OfflineEntry value) { return cache.TryGetValue(key, out value); diff --git a/FireBase/Offline/OfflineEntry.cs b/FireBase/Offline/OfflineEntry.cs index dfd5910..9feffa3 100644 --- a/FireBase/Offline/OfflineEntry.cs +++ b/FireBase/Offline/OfflineEntry.cs @@ -1,21 +1,24 @@ -namespace Firebase.Database.Offline -{ - using System; - using Newtonsoft.Json; +using System; +using Newtonsoft.Json; +namespace Firebase.Database.Offline +{ /// - /// Represents an object stored in offline storage. + /// Represents an object stored in offline storage. /// public class OfflineEntry { private object dataInstance; /// - /// Initializes a new instance of the class with an already serialized object. + /// Initializes a new instance of the class with an already serialized object. /// /// The key. /// The object. - /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. + /// + /// The priority. Objects with higher priority will be synced first. Higher number indicates higher + /// priority. + /// /// The sync options. public OfflineEntry(string key, object obj, string data, int priority, SyncOptions syncOptions, bool isPartial = false) @@ -31,11 +34,14 @@ } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The key. /// The object. - /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. + /// + /// The priority. Objects with higher priority will be synced first. Higher number indicates higher + /// priority. + /// /// The sync options. public OfflineEntry(string key, object obj, int priority, SyncOptions syncOptions, bool isPartial = false) : this(key, obj, JsonConvert.SerializeObject(obj), priority, syncOptions, isPartial) @@ -43,47 +49,48 @@ } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public OfflineEntry() { } /// - /// Gets or sets the key of this entry. + /// Gets or sets the key of this entry. /// public string Key { get; set; } /// - /// Gets or sets the priority. Objects with higher priority will be synced first. Higher number indicates higher priority. + /// Gets or sets the priority. Objects with higher priority will be synced first. Higher number indicates higher + /// priority. /// public int Priority { get; set; } /// - /// Gets or sets the timestamp when this entry was last touched. + /// Gets or sets the timestamp when this entry was last touched. /// public DateTime Timestamp { get; set; } /// - /// Gets or sets the which define what sync state this entry is in. + /// Gets or sets the which define what sync state this entry is in. /// public SyncOptions SyncOptions { get; set; } /// - /// Gets or sets serialized JSON data. + /// Gets or sets serialized JSON data. /// public string Data { get; set; } /// - /// Specifies whether this is only a partial object. + /// Specifies whether this is only a partial object. /// public bool IsPartial { get; set; } /// - /// Deserializes into . The result is cached. + /// Deserializes into . The result is cached. /// /// Type of object to deserialize into. - /// Instance of . + /// Instance of . public T Deserialize() { return (T) (dataInstance ?? (dataInstance = JsonConvert.DeserializeObject(Data))); diff --git a/FireBase/Offline/RealtimeDatabase.cs b/FireBase/Offline/RealtimeDatabase.cs index 4d61027..973db46 100644 --- a/FireBase/Offline/RealtimeDatabase.cs +++ b/FireBase/Offline/RealtimeDatabase.cs @@ -1,50 +1,57 @@ -namespace Firebase.Database.Offline +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Net; +using System.Reactive.Disposables; +using System.Reactive.Linq; +using System.Reactive.Subjects; +using System.Reactive.Threading.Tasks; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using Firebase.Database.Extensions; +using Firebase.Database.Offline.Internals; +using Firebase.Database.Query; +using Firebase.Database.Streaming; +using Newtonsoft.Json; + +namespace Firebase.Database.Offline { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Reactive.Linq; - using System.Reactive.Subjects; - using System.Threading; - using System.Threading.Tasks; - using Extensions; - using Query; - using Streaming; - using System.Reactive.Threading.Tasks; - using System.Linq.Expressions; - using Internals; - using Newtonsoft.Json; - using System.Reflection; - using System.Reactive.Disposables; - /// - /// The real-time Database which synchronizes online and offline data. + /// The real-time Database which synchronizes online and offline data. /// /// Type of entities. - public partial class RealtimeDatabase : IDisposable where T : class + public class RealtimeDatabase : IDisposable where T : class { private readonly ChildQuery childQuery; private readonly string elementRoot; - private readonly StreamingOptions streamingOptions; - private readonly Subject> subject; + private readonly FirebaseCache firebaseCache; private readonly InitialPullStrategy initialPullStrategy; private readonly bool pushChanges; - private readonly FirebaseCache firebaseCache; + private readonly StreamingOptions streamingOptions; + private readonly Subject> subject; + private FirebaseSubscription firebaseSubscription; private bool isSyncRunning; private IObservable> observable; - private FirebaseSubscription firebaseSubscription; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The child query. /// The element Root. /// The offline database factory. /// Custom string which will get appended to the file name. /// Specifies whether changes should be streamed from the server. - /// Specifies if everything should be pull from the online storage on start. It only makes sense when is set to true. - /// Specifies whether changed items should actually be pushed to the server. If this is false, then Put / Post / Delete will not affect server data. + /// + /// Specifies if everything should be pull from the online storage on start. It only + /// makes sense when is set to true. + /// + /// + /// Specifies whether changed items should actually be pushed to the server. If this is false, + /// then Put / Post / Delete will not affect server data. + /// public RealtimeDatabase(ChildQuery childQuery, string elementRoot, Func> offlineDatabaseFactory, string filenameModifier, StreamingOptions streamingOptions, InitialPullStrategy initialPullStrategy, bool pushChanges, @@ -67,24 +74,34 @@ } /// - /// Event raised whenever an exception is thrown in the synchronization thread. Exception thrown in there are swallowed, so this event is the only way to get to them. + /// Gets the backing Database. /// - public event EventHandler SyncExceptionThrown; + public IDictionary Database { get; } + + public ISetHandler PutHandler { private get; set; } + + public void Dispose() + { + subject.OnCompleted(); + firebaseSubscription?.Dispose(); + } /// - /// Gets the backing Database. + /// Event raised whenever an exception is thrown in the synchronization thread. Exception thrown in there are + /// swallowed, so this event is the only way to get to them. /// - public IDictionary Database { get; private set; } - - public ISetHandler PutHandler { private get; set; } + public event EventHandler SyncExceptionThrown; /// - /// Overwrites existing object with given key. + /// Overwrites existing object with given key. /// /// The key. /// 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. + /// + /// The priority. Objects with higher priority will be synced first. Higher number indicates higher + /// priority. + /// public void Set(string key, T obj, SyncOptions syncOptions, int priority = 1) { SetAndRaise(key, new OfflineEntry(key, obj, priority, syncOptions)); @@ -118,10 +135,13 @@ } /// - /// Fetches an object with the given key and adds it to the Database. + /// Fetches an object with the given key and adds it to the Database. /// /// The key. - /// The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. + /// + /// The priority. Objects with higher priority will be synced first. Higher number indicates higher + /// priority. + /// public void Pull(string key, int priority = 1) { if (!Database.ContainsKey(key)) @@ -132,7 +152,7 @@ } /// - /// Fetches everything from the remote database. + /// Fetches everything from the remote database. /// public async Task PullAsync() { @@ -142,7 +162,7 @@ .RetryAfterDelay>, FirebaseException>( childQuery.Client.Options.SyncPeriod, ex => ex.StatusCode == - System.Net.HttpStatusCode + HttpStatusCode .OK) // OK implies the request couldn't complete due to network error. .Select(e => ResetDatabaseFromInitial(e, false)) .SelectMany(e => e) @@ -164,7 +184,7 @@ } /// - /// Retrieves all offline items currently stored in local database. + /// Retrieves all offline items currently stored in local database. /// public IEnumerable> Once() { @@ -174,10 +194,10 @@ .ToList(); } - /// - /// Starts observing the real-time Database. Events will be fired both when change is done locally and remotely. - /// - /// Stream of . + /// + /// Starts observing the real-time Database. Events will be fired both when change is done locally and remotely. + /// + /// Stream of . public IObservable> AsObservable() { if (!isSyncRunning) @@ -212,7 +232,7 @@ .RetryAfterDelay>, FirebaseException>( childQuery.Client.Options.SyncPeriod, ex => ex.StatusCode == - System.Net.HttpStatusCode + HttpStatusCode .OK) // OK implies the request couldn't complete due to network error. .Select(e => ResetDatabaseFromInitial(e)) .SelectMany(e => e) @@ -230,12 +250,6 @@ return observable; } - public void Dispose() - { - subject.OnCompleted(); - firebaseSubscription?.Dispose(); - } - private IReadOnlyCollection> ResetDatabaseFromInitial( IReadOnlyCollection> collection, bool onlyWhenInitialEverything = true) { @@ -308,8 +322,6 @@ firebaseSubscription.ExceptionThrown += StreamingExceptionThrown; return new CompositeDisposable(firebaseSubscription.Run(), completeDisposable); - default: - break; } return completeDisposable; diff --git a/FireBase/Offline/SetHandler.cs b/FireBase/Offline/SetHandler.cs index 18a5131..6314c3c 100644 --- a/FireBase/Offline/SetHandler.cs +++ b/FireBase/Offline/SetHandler.cs @@ -1,8 +1,8 @@ -namespace Firebase.Database.Offline -{ - using Query; - using System.Threading.Tasks; +using System.Threading.Tasks; +using Firebase.Database.Query; +namespace Firebase.Database.Offline +{ public class SetHandler : ISetHandler { public virtual async Task SetAsync(ChildQuery query, string key, OfflineEntry entry) diff --git a/FireBase/Offline/StreamingOptions.cs b/FireBase/Offline/StreamingOptions.cs index 4a5f7b8..a420cbb 100644 --- a/FireBase/Offline/StreamingOptions.cs +++ b/FireBase/Offline/StreamingOptions.cs @@ -3,18 +3,20 @@ public enum StreamingOptions { /// - /// No realtime streaming. + /// No realtime streaming. /// None, /// - /// Streaming of only new items - not the existing ones. + /// Streaming of only new items - not the existing ones. /// LatestOnly, /// - /// Streaming of all items. This will also pull all existing items on start, so be mindful about the number of items in your DB. - /// When used, consider not setting the to because you would pointlessly pull everything twice. + /// Streaming of all items. This will also pull all existing items on start, so be mindful about the number of items in + /// your DB. + /// When used, consider not setting the to + /// because you would pointlessly pull everything twice. /// Everything } diff --git a/FireBase/Offline/SyncOptions.cs b/FireBase/Offline/SyncOptions.cs index aa3e21c..ca68d0a 100644 --- a/FireBase/Offline/SyncOptions.cs +++ b/FireBase/Offline/SyncOptions.cs @@ -1,27 +1,27 @@ namespace Firebase.Database.Offline { /// - /// Specifies type of sync requested for given data. + /// Specifies type of sync requested for given data. /// public enum SyncOptions { /// - /// No sync needed for given data. + /// No sync needed for given data. /// None, /// - /// Data should be pulled from firebase. + /// Data should be pulled from firebase. /// Pull, /// - /// Data should be put to firebase. + /// Data should be put to firebase. /// Put, /// - /// Data should be patched in firebase. + /// Data should be patched in firebase. /// Patch } diff --git a/FireBase/Query/AuthQuery.cs b/FireBase/Query/AuthQuery.cs index 14beb7e..2cfda3c 100644 --- a/FireBase/Query/AuthQuery.cs +++ b/FireBase/Query/AuthQuery.cs @@ -1,18 +1,18 @@ +using System; + namespace Firebase.Database.Query { - using System; - /// - /// Represents an auth parameter in firebase query, e.g. "?auth=xyz". + /// Represents an auth parameter in firebase query, e.g. "?auth=xyz". /// public class AuthQuery : ParameterQuery { private readonly Func tokenFactory; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// The parent. + /// The parent. /// The authentication token factory. /// The owner. public AuthQuery(FirebaseQuery parent, Func tokenFactory, FirebaseClient client) : base(parent, @@ -22,10 +22,10 @@ namespace Firebase.Database.Query } /// - /// Build the url parameter value of this child. + /// Build the url parameter value of this child. /// /// The child of this child. - /// The . + /// The . protected override string BuildUrlParameter(FirebaseQuery child) { return tokenFactory(); diff --git a/FireBase/Query/ChildQuery.cs b/FireBase/Query/ChildQuery.cs index 510ae75..014fe09 100644 --- a/FireBase/Query/ChildQuery.cs +++ b/FireBase/Query/ChildQuery.cs @@ -1,16 +1,16 @@ +using System; + namespace Firebase.Database.Query { - using System; - /// - /// Firebase query which references the child of current node. + /// Firebase query which references the child of current node. /// public class ChildQuery : FirebaseQuery { private readonly Func pathFactory; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The parent. /// The path to the child node. @@ -22,7 +22,7 @@ namespace Firebase.Database.Query } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The client. /// The path to the child node. @@ -32,10 +32,10 @@ namespace Firebase.Database.Query } /// - /// Build the url segment of this child. + /// Build the url segment of this child. /// /// The child of this child. - /// The . + /// The . protected override string BuildUrlSegment(FirebaseQuery child) { var s = pathFactory(); diff --git a/FireBase/Query/FilterQuery.cs b/FireBase/Query/FilterQuery.cs index be544c8..3434d1d 100644 --- a/FireBase/Query/FilterQuery.cs +++ b/FireBase/Query/FilterQuery.cs @@ -1,24 +1,24 @@ +using System; +using System.Globalization; + namespace Firebase.Database.Query { - using System; - using System.Globalization; - /// - /// Represents a firebase filtering query, e.g. "?LimitToLast=10". + /// Represents a firebase filtering query, e.g. "?LimitToLast=10". /// public class FilterQuery : ParameterQuery { - private readonly Func valueFactory; - private readonly Func doubleValueFactory; private readonly Func boolValueFactory; + private readonly Func doubleValueFactory; + private readonly Func valueFactory; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The parent. /// The filter. /// The value for filter. - /// The owning client. + /// The owning client. public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory, FirebaseClient client) : base(parent, filterFactory, client) @@ -27,7 +27,7 @@ namespace Firebase.Database.Query } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The parent. /// The filter. @@ -41,7 +41,7 @@ namespace Firebase.Database.Query } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The parent. /// The filter. @@ -55,25 +55,21 @@ namespace Firebase.Database.Query } /// - /// The build url parameter. + /// The build url parameter. /// - /// The child. - /// Url parameter part of the resulting path. + /// The child. + /// Url parameter part of the resulting path. protected override string BuildUrlParameter(FirebaseQuery child) { if (valueFactory != null) { - if (valueFactory() == null) return $"null"; + if (valueFactory() == null) return "null"; return $"\"{valueFactory()}\""; } - else if (doubleValueFactory != null) - { + + if (doubleValueFactory != null) return doubleValueFactory().ToString(CultureInfo.InvariantCulture); - } - else if (boolValueFactory != null) - { - return $"{boolValueFactory().ToString().ToLower()}"; - } + if (boolValueFactory != null) return $"{boolValueFactory().ToString().ToLower()}"; return string.Empty; } diff --git a/FireBase/Query/FirebaseQuery.cs b/FireBase/Query/FirebaseQuery.cs index 5e09795..60d0289 100644 --- a/FireBase/Query/FirebaseQuery.cs +++ b/FireBase/Query/FirebaseQuery.cs @@ -1,29 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Reactive.Linq; +using System.Threading.Tasks; +using Firebase.Database.Http; +using Firebase.Database.Streaming; +using Newtonsoft.Json; + namespace Firebase.Database.Query { - using System; - using System.Collections.Generic; - using System.Net.Http; - using System.Reactive.Linq; - using System.Threading.Tasks; - using Http; - using Offline; - using Streaming; - using Newtonsoft.Json; - using System.Net; - /// - /// Represents a firebase query. + /// Represents a firebase query. /// public abstract class FirebaseQuery : IFirebaseQuery, IDisposable { - protected TimeSpan DEFAULT_HTTP_CLIENT_TIMEOUT = new TimeSpan(0, 0, 180); - protected readonly FirebaseQuery Parent; private HttpClient client; + protected TimeSpan DEFAULT_HTTP_CLIENT_TIMEOUT = new TimeSpan(0, 0, 180); - /// - /// Initializes a new instance of the class. + /// + /// Initializes a new instance of the class. /// /// The parent of this query. /// The owning client. @@ -34,16 +32,24 @@ namespace Firebase.Database.Query } /// - /// Gets the client. + /// Disposes this instance. + /// + public void Dispose() + { + client?.Dispose(); + } + + /// + /// Gets the client. /// public FirebaseClient Client { get; } /// - /// Queries the firebase server once returning collection of items. + /// Queries the firebase server once returning collection of items. /// /// Optional timeout value. /// Type of elements. - /// Collection of holding the entities returned by server. + /// Collection of holding the entities returned by server. public async Task>> OnceAsync(TimeSpan? timeout = null) { var url = string.Empty; @@ -62,6 +68,39 @@ namespace Firebase.Database.Query .ConfigureAwait(false); } + /// + /// Starts observing this query watching for changes real time sent by the server. + /// + /// Type of elements. + /// Optional custom root element of received json items. + /// Observable stream of . + public IObservable> AsObservable( + EventHandler> exceptionHandler = null, string elementRoot = "") + { + return Observable.Create>(observer => + { + var sub = new FirebaseSubscription(observer, this, elementRoot, new FirebaseCache()); + sub.ExceptionThrown += exceptionHandler; + return sub.Run(); + }); + } + + /// + /// Builds the actual URL of this query. + /// + /// The . + public async Task BuildUrlAsync() + { + // if token factory is present on the parent then use it to generate auth token + if (Client.Options.AuthTokenAsyncFactory != null) + { + var token = await Client.Options.AuthTokenAsyncFactory().ConfigureAwait(false); + return this.WithAuth(token).BuildUrl(null); + } + + return BuildUrl(null); + } + /*public async Task>> OnceAsync(Type dataType, TimeSpan? timeout = null) { var url = string.Empty; @@ -80,11 +119,11 @@ namespace Firebase.Database.Query }*/ /// - /// Assumes given query is pointing to a single object of type and retrieves it. + /// Assumes given query is pointing to a single object of type and retrieves it. /// /// Optional timeout value. /// Type of elements. - /// Single object of type . + /// Single object of type . public async Task OnceSingleAsync(TimeSpan? timeout = null) { var responseData = string.Empty; @@ -118,45 +157,12 @@ namespace Firebase.Database.Query } /// - /// Starts observing this query watching for changes real time sent by the server. - /// - /// Type of elements. - /// Optional custom root element of received json items. - /// Observable stream of . - public IObservable> AsObservable( - EventHandler> exceptionHandler = null, string elementRoot = "") - { - return Observable.Create>(observer => - { - var sub = new FirebaseSubscription(observer, this, elementRoot, new FirebaseCache()); - sub.ExceptionThrown += exceptionHandler; - return sub.Run(); - }); - } - - /// - /// Builds the actual URL of this query. - /// - /// The . - public async Task BuildUrlAsync() - { - // if token factory is present on the parent then use it to generate auth token - if (Client.Options.AuthTokenAsyncFactory != null) - { - var token = await Client.Options.AuthTokenAsyncFactory().ConfigureAwait(false); - return this.WithAuth(token).BuildUrl(null); - } - - return BuildUrl(null); - } - - /// - /// Posts given object to repository. + /// Posts given object to repository. /// /// The object. /// Specifies whether the key should be generated offline instead of online. /// Optional timeout value. - /// Type of + /// Type of /// Resulting firebase object with populated key. public async Task> PostAsync(string data, bool generateKeyOffline = true, TimeSpan? timeout = null) @@ -169,23 +175,21 @@ namespace Firebase.Database.Query return new FirebaseObject(key, data); } - else - { - var c = GetClient(timeout); - var sendData = await SendAsync(c, data, HttpMethod.Post).ConfigureAwait(false); - var result = JsonConvert.DeserializeObject(sendData, Client.Options.JsonSerializerSettings); - return new FirebaseObject(result.Name, data); - } + var c = GetClient(timeout); + var sendData = await SendAsync(c, data, HttpMethod.Post).ConfigureAwait(false); + var result = JsonConvert.DeserializeObject(sendData, Client.Options.JsonSerializerSettings); + + return new FirebaseObject(result.Name, data); } /// - /// Patches data at given location instead of overwriting them. - /// + /// Patches data at given location instead of overwriting them. + /// /// The object. /// Optional timeout value. - /// Type of - /// The . + /// Type of + /// The . public async Task PatchAsync(string data, TimeSpan? timeout = null) { var c = GetClient(timeout); @@ -194,12 +198,12 @@ namespace Firebase.Database.Query } /// - /// Sets or overwrites data at given location. - /// + /// Sets or overwrites data at given location. + /// /// The object. /// Optional timeout value. - /// Type of - /// The . + /// Type of + /// The . public async Task PutAsync(string data, TimeSpan? timeout = null) { var c = GetClient(timeout); @@ -208,10 +212,10 @@ namespace Firebase.Database.Query } /// - /// Deletes data from given location. + /// Deletes data from given location. /// /// Optional timeout value. - /// The . + /// The . public async Task DeleteAsync(TimeSpan? timeout = null) { var c = GetClient(timeout); @@ -243,18 +247,10 @@ namespace Firebase.Database.Query } /// - /// Disposes this instance. - /// - public void Dispose() - { - client?.Dispose(); - } - - /// - /// Build the url segment of this child. + /// Build the url segment of this child. /// /// The child of this query. - /// The . + /// The . protected abstract string BuildUrlSegment(FirebaseQuery child); private string BuildUrl(FirebaseQuery child) diff --git a/FireBase/Query/IFirebaseQuery.cs b/FireBase/Query/IFirebaseQuery.cs index 9f6e36c..0da4b15 100644 --- a/FireBase/Query/IFirebaseQuery.cs +++ b/FireBase/Query/IFirebaseQuery.cs @@ -1,40 +1,40 @@ -namespace Firebase.Database.Query -{ - using System; - using System.Collections.Generic; - using System.Threading.Tasks; - using Streaming; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Firebase.Database.Streaming; +namespace Firebase.Database.Query +{ /// - /// The FirebaseQuery interface. + /// The FirebaseQuery interface. /// public interface IFirebaseQuery { /// - /// Gets the owning client of this query. + /// Gets the owning client of this query. /// FirebaseClient Client { get; } /// - /// Retrieves items which exist on the location specified by this query instance. + /// Retrieves items which exist on the location specified by this query instance. /// /// Optional timeout value. /// Type of the items. - /// Collection of . + /// Collection of . Task>> OnceAsync(TimeSpan? timeout = null); /// - /// Returns current location as an observable which allows to real-time listening to events from the firebase server. + /// Returns current location as an observable which allows to real-time listening to events from the firebase server. /// /// Type of the items. - /// Cold observable of . + /// Cold observable of . IObservable> AsObservable( EventHandler> exceptionHandler, string elementRoot = ""); /// - /// Builds the actual url of this query. + /// Builds the actual url of this query. /// - /// The . + /// The . Task BuildUrlAsync(); } } \ No newline at end of file diff --git a/FireBase/Query/OrderQuery.cs b/FireBase/Query/OrderQuery.cs index 16adba7..302d1a3 100644 --- a/FireBase/Query/OrderQuery.cs +++ b/FireBase/Query/OrderQuery.cs @@ -1,16 +1,16 @@ +using System; + namespace Firebase.Database.Query { - using System; - /// - /// Represents a firebase ordering query, e.g. "?OrderBy=Foo". + /// Represents a firebase ordering query, e.g. "?OrderBy=Foo". /// public class OrderQuery : ParameterQuery { private readonly Func propertyNameFactory; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The query parent. /// The property name. @@ -22,10 +22,10 @@ namespace Firebase.Database.Query } /// - /// The build url parameter. + /// The build url parameter. /// /// The child. - /// The . + /// The . protected override string BuildUrlParameter(FirebaseQuery child) { return $"\"{propertyNameFactory()}\""; diff --git a/FireBase/Query/ParameterQuery.cs b/FireBase/Query/ParameterQuery.cs index fb273a3..572224c 100644 --- a/FireBase/Query/ParameterQuery.cs +++ b/FireBase/Query/ParameterQuery.cs @@ -1,9 +1,9 @@ +using System; + namespace Firebase.Database.Query { - using System; - /// - /// Represents a parameter in firebase query, e.g. "?data=foo". + /// Represents a parameter in firebase query, e.g. "?data=foo". /// public abstract class ParameterQuery : FirebaseQuery { @@ -11,7 +11,7 @@ namespace Firebase.Database.Query private readonly string separator; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The parent of this query. /// The parameter. @@ -24,20 +24,20 @@ namespace Firebase.Database.Query } /// - /// Build the url segment represented by this query. - /// + /// Build the url segment represented by this query. + /// /// The child. - /// The . + /// The . protected override string BuildUrlSegment(FirebaseQuery child) { return $"{separator}{parameterFactory()}={BuildUrlParameter(child)}"; } /// - /// The build url parameter. + /// The build url parameter. /// /// The child. - /// The . + /// The . protected abstract string BuildUrlParameter(FirebaseQuery child); } } \ No newline at end of file diff --git a/FireBase/Query/QueryExtensions.cs b/FireBase/Query/QueryExtensions.cs index 735fe0a..df2edfc 100644 --- a/FireBase/Query/QueryExtensions.cs +++ b/FireBase/Query/QueryExtensions.cs @@ -6,158 +6,163 @@ using Newtonsoft.Json; namespace Firebase.Database.Query { /// - /// Query extensions providing linq like syntax for firebase server methods. + /// Query extensions providing linq like syntax for firebase server methods. /// public static class QueryExtensions { /// - /// Adds an auth parameter to the query. + /// Adds an auth parameter to the query. /// /// The child. /// The auth token. - /// The . + /// The . internal static AuthQuery WithAuth(this FirebaseQuery node, string token) { return node.WithAuth(() => token); } /// - /// Appends print=silent to save bandwidth. + /// Appends print=silent to save bandwidth. /// /// The child. - /// The . + /// The . internal static SilentQuery Silent(this FirebaseQuery node) { return new SilentQuery(node, node.Client); } /// - /// References a sub child of the existing node. + /// References a sub child of the existing node. /// /// The child. /// The path of sub child. - /// The . + /// The . public static ChildQuery Child(this ChildQuery node, string path) { return node.Child(() => path); } /// - /// Order data by given . Note that this is used mainly for following filtering queries and due to firebase implementation - /// the data may actually not be ordered. + /// Order data by given . Note that this is used mainly for following filtering queries and + /// due to firebase implementation + /// the data may actually not be ordered. /// /// The child. /// The property name. - /// The . + /// The . public static OrderQuery OrderBy(this ChildQuery child, string propertyName) { return child.OrderBy(() => propertyName); } /// - /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy + /// query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery StartAt(this ParameterQuery child, string value) { return child.StartAt(() => value); } /// - /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy + /// query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery EndAt(this ParameterQuery child, string value) { return child.EndAt(() => value); } /// - /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery EqualTo(this ParameterQuery child, string value) { return child.EqualTo(() => value); } /// - /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy + /// query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery StartAt(this ParameterQuery child, double value) { return child.StartAt(() => value); } /// - /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy + /// query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery EndAt(this ParameterQuery child, double value) { return child.EndAt(() => value); } /// - /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery EqualTo(this ParameterQuery child, double value) { return child.EqualTo(() => value); } /// - /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery EqualTo(this ParameterQuery child, bool value) { return child.EqualTo(() => value); } /// - /// Instructs firebase to send data equal to null. This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to null. This must be preceded by an OrderBy query. /// /// Current node. - /// The . + /// The . public static FilterQuery EqualTo(this ParameterQuery child) { return child.EqualTo(() => null); } /// - /// Limits the result to first items. + /// Limits the result to first items. /// /// Current node. /// Number of elements. - /// The . + /// The . public static FilterQuery LimitToFirst(this ParameterQuery child, int count) { return child.LimitToFirst(() => count); } /// - /// Limits the result to last items. + /// Limits the result to last items. /// /// Current node. /// Number of elements. - /// The . + /// The . public static FilterQuery LimitToLast(this ParameterQuery child, int count) { return child.LimitToLast(() => count); @@ -184,7 +189,8 @@ namespace Firebase.Database.Query } /// - /// Fan out given item to multiple locations at once. See https://firebase.googleblog.com/2015/10/client-side-fan-out-for-data-consistency_73.html for details. + /// Fan out given item to multiple locations at once. See + /// https://firebase.googleblog.com/2015/10/client-side-fan-out-for-data-consistency_73.html for details. /// /// Type of object to fan out. /// Current node. diff --git a/FireBase/Query/QueryFactoryExtensions.cs b/FireBase/Query/QueryFactoryExtensions.cs index b54c315..71dae5c 100644 --- a/FireBase/Query/QueryFactoryExtensions.cs +++ b/FireBase/Query/QueryFactoryExtensions.cs @@ -1,173 +1,184 @@ +using System; + namespace Firebase.Database.Query { - using System; - /// - /// Query extensions providing linq like syntax for firebase server methods. + /// Query extensions providing linq like syntax for firebase server methods. /// public static class QueryFactoryExtensions { /// - /// Adds an auth parameter to the query. + /// Adds an auth parameter to the query. /// /// The child. /// The auth token. - /// The . + /// The . internal static AuthQuery WithAuth(this FirebaseQuery node, Func tokenFactory) { return new AuthQuery(node, tokenFactory, node.Client); } /// - /// References a sub child of the existing node. + /// References a sub child of the existing node. /// /// The child. /// The path of sub child. - /// The . + /// The . public static ChildQuery Child(this ChildQuery node, Func pathFactory) { return new ChildQuery(node, pathFactory, node.Client); } /// - /// Order data by given . Note that this is used mainly for following filtering queries and due to firebase implementation - /// the data may actually not be ordered. + /// Order data by given . Note that this is used mainly for following filtering + /// queries and due to firebase implementation + /// the data may actually not be ordered. /// /// The child. /// The property name. - /// The . + /// The . public static OrderQuery OrderBy(this ChildQuery child, Func propertyNameFactory) { return new OrderQuery(child, propertyNameFactory, child.Client); } /// - /// Order data by $key. Note that this is used mainly for following filtering queries and due to firebase implementation - /// the data may actually not be ordered. + /// Order data by $key. Note that this is used mainly for following filtering queries and due to firebase + /// implementation + /// the data may actually not be ordered. /// /// The child. - /// The . + /// The . public static OrderQuery OrderByKey(this ChildQuery child) { return child.OrderBy("$key"); } /// - /// Order data by $value. Note that this is used mainly for following filtering queries and due to firebase implementation - /// the data may actually not be ordered. + /// Order data by $value. Note that this is used mainly for following filtering queries and due to firebase + /// implementation + /// the data may actually not be ordered. /// /// The child. - /// The . + /// The . public static OrderQuery OrderByValue(this ChildQuery child) { return child.OrderBy("$value"); } /// - /// Order data by $priority. Note that this is used mainly for following filtering queries and due to firebase implementation - /// the data may actually not be ordered. + /// Order data by $priority. Note that this is used mainly for following filtering queries and due to firebase + /// implementation + /// the data may actually not be ordered. /// /// The child. - /// The . + /// The . public static OrderQuery OrderByPriority(this ChildQuery child) { return child.OrderBy("$priority"); } /// - /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data greater or equal to the . This must be preceded by an + /// OrderBy query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery StartAt(this ParameterQuery child, Func valueFactory) { return new FilterQuery(child, () => "startAt", valueFactory, child.Client); } /// - /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data lower or equal to the . This must be preceded by an + /// OrderBy query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery EndAt(this ParameterQuery child, Func valueFactory) { return new FilterQuery(child, () => "endAt", valueFactory, child.Client); } /// - /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy + /// query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery EqualTo(this ParameterQuery child, Func valueFactory) { return new FilterQuery(child, () => "equalTo", valueFactory, child.Client); } /// - /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data greater or equal to the . This must be preceded by an + /// OrderBy query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery StartAt(this ParameterQuery child, Func valueFactory) { return new FilterQuery(child, () => "startAt", valueFactory, child.Client); } /// - /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data lower or equal to the . This must be preceded by an + /// OrderBy query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery EndAt(this ParameterQuery child, Func valueFactory) { return new FilterQuery(child, () => "endAt", valueFactory, child.Client); } /// - /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy + /// query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery EqualTo(this ParameterQuery child, Func valueFactory) { return new FilterQuery(child, () => "equalTo", valueFactory, child.Client); } /// - /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy + /// query. /// /// Current node. /// Value to start at. - /// The . + /// The . public static FilterQuery EqualTo(this ParameterQuery child, Func valueFactory) { return new FilterQuery(child, () => "equalTo", valueFactory, child.Client); } /// - /// Limits the result to first items. + /// Limits the result to first items. /// /// Current node. /// Number of elements. - /// The . + /// The . public static FilterQuery LimitToFirst(this ParameterQuery child, Func countFactory) { return new FilterQuery(child, () => "limitToFirst", () => countFactory(), child.Client); } /// - /// Limits the result to last items. + /// Limits the result to last items. /// /// Current node. /// Number of elements. - /// The . + /// The . public static FilterQuery LimitToLast(this ParameterQuery child, Func countFactory) { return new FilterQuery(child, () => "limitToLast", () => countFactory(), child.Client); diff --git a/FireBase/Query/SilentQuery.cs b/FireBase/Query/SilentQuery.cs index 1960426..d09d38b 100644 --- a/FireBase/Query/SilentQuery.cs +++ b/FireBase/Query/SilentQuery.cs @@ -1,7 +1,7 @@ namespace Firebase.Database.Query { /// - /// Appends print=silent to the url. + /// Appends print=silent to the url. /// public class SilentQuery : ParameterQuery { diff --git a/FireBase/Streaming/FirebaseCache.cs b/FireBase/Streaming/FirebaseCache.cs index 77fc622..66241e0 100644 --- a/FireBase/Streaming/FirebaseCache.cs +++ b/FireBase/Streaming/FirebaseCache.cs @@ -1,15 +1,15 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Firebase.Database.Http; +using Newtonsoft.Json; + namespace Firebase.Database.Streaming { - using System; - using System.Collections; - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - using Http; - using Newtonsoft.Json; - /// - /// The firebase cache. + /// The firebase cache. /// /// Type of top-level entities in the cache. public class FirebaseCache : IEnumerable> @@ -17,13 +17,13 @@ namespace Firebase.Database.Streaming private readonly IDictionary dictionary; private readonly bool isDictionaryType; - private readonly JsonSerializerSettings serializerSettings = new JsonSerializerSettings() + private readonly JsonSerializerSettings serializerSettings = new JsonSerializerSettings { ObjectCreationHandling = ObjectCreationHandling.Replace }; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public FirebaseCache() : this(new Dictionary()) @@ -31,7 +31,7 @@ namespace Firebase.Database.Streaming } /// - /// Initializes a new instance of the class and populates it with existing data. + /// Initializes a new instance of the class and populates it with existing data. /// /// The existing items. public FirebaseCache(IDictionary existingItems) @@ -41,10 +41,10 @@ namespace Firebase.Database.Streaming } /// - /// The push data. + /// The push data. /// - /// The path of incoming data, separated by slash. - /// The data in json format as returned by firebase. + /// The path of incoming data, separated by slash. + /// The data in json format as returned by firebase. /// Collection of top-level entities which were affected by the push. public IEnumerable> PushData(string path, string data, bool removeEmptyEntries = true) { @@ -63,7 +63,7 @@ namespace Firebase.Database.Streaming var dictionary = obj as IDictionary; var valueType = obj.GetType().GenericTypeArguments[1]; - primitiveObjSetter = (d) => dictionary[element] = d; + primitiveObjSetter = d => dictionary[element] = d; objDeleter = () => dictionary.Remove(element); if (dictionary.Contains(element)) @@ -87,7 +87,7 @@ namespace Firebase.Database.Streaming element == p.GetCustomAttribute()?.PropertyName); objDeleter = () => property.SetValue(objParent, null); - primitiveObjSetter = (d) => property.SetValue(objParent, d); + primitiveObjSetter = d => property.SetValue(objParent, d); obj = property.GetValue(obj); if (obj == null) { @@ -138,7 +138,7 @@ namespace Firebase.Database.Streaming // firebase sends strings without double quotes var targetObject = valueType == typeof(string) - ? data.ToString() + ? data : JsonConvert.DeserializeObject(data, valueType); if ((valueType.GetTypeInfo().IsPrimitive || valueType == typeof(string)) && primitiveObjSetter != null) @@ -161,8 +161,7 @@ namespace Firebase.Database.Streaming { if (type == typeof(string)) return string.Empty; - else - return Activator.CreateInstance(type); + return Activator.CreateInstance(type); } #region IEnumerable diff --git a/FireBase/Streaming/FirebaseEvent.cs b/FireBase/Streaming/FirebaseEvent.cs index e4fd238..1761a72 100644 --- a/FireBase/Streaming/FirebaseEvent.cs +++ b/FireBase/Streaming/FirebaseEvent.cs @@ -1,13 +1,13 @@ namespace Firebase.Database.Streaming { /// - /// Firebase event which hold and the object affected by the event. + /// Firebase event which hold and the object affected by the event. /// /// Type of object affected by the event. public class FirebaseEvent : FirebaseObject { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The key of the object. /// The object. @@ -20,12 +20,12 @@ namespace Firebase.Database.Streaming } /// - /// Gets the source of the event. + /// Gets the source of the event. /// public FirebaseEventSource EventSource { get; } /// - /// Gets the event type. + /// Gets the event type. /// public FirebaseEventType EventType { get; } diff --git a/FireBase/Streaming/FirebaseEventSource.cs b/FireBase/Streaming/FirebaseEventSource.cs index 0a397ad..b1385ca 100644 --- a/FireBase/Streaming/FirebaseEventSource.cs +++ b/FireBase/Streaming/FirebaseEventSource.cs @@ -1,37 +1,37 @@ namespace Firebase.Database.Streaming { /// - /// Specifies the origin of given + /// Specifies the origin of given /// public enum FirebaseEventSource { /// - /// Event comes from an offline source. + /// Event comes from an offline source. /// Offline, /// - /// Event comes from online source fetched during initial pull (valid only for RealtimeDatabase). + /// Event comes from online source fetched during initial pull (valid only for RealtimeDatabase). /// OnlineInitial, /// - /// Event comes from online source received thru active stream. + /// Event comes from online source received thru active stream. /// OnlineStream, /// - /// Event comes from online source being fetched manually. + /// Event comes from online source being fetched manually. /// OnlinePull, /// - /// Event raised after successful online push (valid only for RealtimeDatabase which isn't streaming). + /// Event raised after successful online push (valid only for RealtimeDatabase which isn't streaming). /// OnlinePush, /// - /// Event comes from an online source. + /// Event comes from an online source. /// Online = OnlineInitial | OnlinePull | OnlinePush | OnlineStream } diff --git a/FireBase/Streaming/FirebaseEventType.cs b/FireBase/Streaming/FirebaseEventType.cs index d8c65b3..7606331 100644 --- a/FireBase/Streaming/FirebaseEventType.cs +++ b/FireBase/Streaming/FirebaseEventType.cs @@ -1,17 +1,17 @@ namespace Firebase.Database.Streaming { /// - /// The type of event. + /// The type of event. /// public enum FirebaseEventType { /// - /// Item was inserted or updated. + /// Item was inserted or updated. /// InsertOrUpdate, /// - /// Item was deleted. + /// Item was deleted. /// Delete } diff --git a/FireBase/Streaming/FirebaseSubscription.cs b/FireBase/Streaming/FirebaseSubscription.cs index acdc76c..fb0f403 100644 --- a/FireBase/Streaming/FirebaseSubscription.cs +++ b/FireBase/Streaming/FirebaseSubscription.cs @@ -1,30 +1,28 @@ +using System; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading; +using System.Threading.Tasks; +using Firebase.Database.Query; +using Newtonsoft.Json.Linq; + namespace Firebase.Database.Streaming { - using System; - using System.Diagnostics; - using System.Linq; - using System.Net.Http; - using System.Net.Http.Headers; - using System.Threading; - using System.Threading.Tasks; - using Query; - using Newtonsoft.Json.Linq; - using System.Net; - /// - /// The firebase subscription. + /// The firebase subscription. /// /// Type of object to be streaming back to the called. internal class FirebaseSubscription : IDisposable { + private static readonly HttpClient http; + private readonly FirebaseCache cache; private readonly CancellationTokenSource cancel; + private readonly FirebaseClient client; + private readonly string elementRoot; private readonly IObserver> observer; private readonly IFirebaseQuery query; - private readonly FirebaseCache cache; - private readonly string elementRoot; - private readonly FirebaseClient client; - - private static HttpClient http; static FirebaseSubscription() { @@ -43,7 +41,7 @@ namespace Firebase.Database.Streaming } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The observer. /// The query. @@ -59,13 +57,13 @@ namespace Firebase.Database.Streaming client = query.Client; } - public event EventHandler> ExceptionThrown; - public void Dispose() { cancel.Cancel(); } + public event EventHandler> ExceptionThrown; + public IDisposable Run() { Task.Run(() => ReceiveThread()); diff --git a/FireBase/Streaming/NonBlockingStreamReader.cs b/FireBase/Streaming/NonBlockingStreamReader.cs index ab01510..8228e32 100644 --- a/FireBase/Streaming/NonBlockingStreamReader.cs +++ b/FireBase/Streaming/NonBlockingStreamReader.cs @@ -1,21 +1,24 @@ -namespace Firebase.Database.Streaming -{ - using System.IO; - using System.Text; +using System.IO; +using System.Text; +namespace Firebase.Database.Streaming +{ /// - /// When a regular is used in a UWP app its method tends to take a long - /// time for data larger then 2 KB. This extremly simple implementation of can be used instead to boost performance - /// in your UWP app. Use to inject an instance of this class into your . + /// When a regular is used in a UWP app its method + /// tends to take a long + /// time for data larger then 2 KB. This extremly simple implementation of can be used + /// instead to boost performance + /// in your UWP app. Use to inject an instance of this class into your + /// . /// public class NonBlockingStreamReader : TextReader { private const int DefaultBufferSize = 16000; - - private readonly Stream stream; private readonly byte[] buffer; private readonly int bufferSize; + private readonly Stream stream; + private string cachedData; public NonBlockingStreamReader(Stream stream, int bufferSize = DefaultBufferSize) -- cgit v1.2.3-54-g00ecf