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/Offline/RealtimeDatabase.cs | 118 +++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 53 deletions(-) (limited to 'FireBase/Offline/RealtimeDatabase.cs') 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; -- cgit v1.2.3-54-g00ecf