summaryrefslogtreecommitdiff
path: root/FireBase/Streaming
diff options
context:
space:
mode:
Diffstat (limited to 'FireBase/Streaming')
-rw-r--r--FireBase/Streaming/FirebaseCache.cs39
-rw-r--r--FireBase/Streaming/FirebaseEvent.cs8
-rw-r--r--FireBase/Streaming/FirebaseEventSource.cs14
-rw-r--r--FireBase/Streaming/FirebaseEventType.cs6
-rw-r--r--FireBase/Streaming/FirebaseSubscription.cs38
-rw-r--r--FireBase/Streaming/NonBlockingStreamReader.cs21
6 files changed, 63 insertions, 63 deletions
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;
-
/// <summary>
- /// The firebase cache.
+ /// The firebase cache.
/// </summary>
/// <typeparam name="T"> Type of top-level entities in the cache. </typeparam>
public class FirebaseCache<T> : IEnumerable<FirebaseObject<T>>
@@ -17,13 +17,13 @@ namespace Firebase.Database.Streaming
private readonly IDictionary<string, T> dictionary;
private readonly bool isDictionaryType;
- private readonly JsonSerializerSettings serializerSettings = new JsonSerializerSettings()
+ private readonly JsonSerializerSettings serializerSettings = new JsonSerializerSettings
{
ObjectCreationHandling = ObjectCreationHandling.Replace
};
/// <summary>
- /// Initializes a new instance of the <see cref="FirebaseCache{T}"/> class.
+ /// Initializes a new instance of the <see cref="FirebaseCache{T}" /> class.
/// </summary>
public FirebaseCache()
: this(new Dictionary<string, T>())
@@ -31,7 +31,7 @@ namespace Firebase.Database.Streaming
}
/// <summary>
- /// Initializes a new instance of the <see cref="FirebaseCache{T}"/> class and populates it with existing data.
+ /// Initializes a new instance of the <see cref="FirebaseCache{T}" /> class and populates it with existing data.
/// </summary>
/// <param name="existingItems"> The existing items. </param>
public FirebaseCache(IDictionary<string, T> existingItems)
@@ -41,10 +41,10 @@ namespace Firebase.Database.Streaming
}
/// <summary>
- /// The push data.
+ /// The push data.
/// </summary>
- /// <param name="path"> The path of incoming data, separated by slash. </param>
- /// <param name="data"> The data in json format as returned by firebase. </param>
+ /// <param name="path"> The path of incoming data, separated by slash. </param>
+ /// <param name="data"> The data in json format as returned by firebase. </param>
/// <returns> Collection of top-level entities which were affected by the push. </returns>
public IEnumerable<FirebaseObject<T>> 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<JsonPropertyAttribute>()?.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
{
/// <summary>
- /// Firebase event which hold <see cref="EventType"/> and the object affected by the event.
+ /// Firebase event which hold <see cref="EventType" /> and the object affected by the event.
/// </summary>
/// <typeparam name="T"> Type of object affected by the event. </typeparam>
public class FirebaseEvent<T> : FirebaseObject<T>
{
/// <summary>
- /// Initializes a new instance of the <see cref="FirebaseEvent{T}"/> class.
+ /// Initializes a new instance of the <see cref="FirebaseEvent{T}" /> class.
/// </summary>
/// <param name="key"> The key of the object. </param>
/// <param name="obj"> The object. </param>
@@ -20,12 +20,12 @@ namespace Firebase.Database.Streaming
}
/// <summary>
- /// Gets the source of the event.
+ /// Gets the source of the event.
/// </summary>
public FirebaseEventSource EventSource { get; }
/// <summary>
- /// Gets the event type.
+ /// Gets the event type.
/// </summary>
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
{
/// <summary>
- /// Specifies the origin of given <see cref="FirebaseEvent{T}"/>
+ /// Specifies the origin of given <see cref="FirebaseEvent{T}" />
/// </summary>
public enum FirebaseEventSource
{
/// <summary>
- /// Event comes from an offline source.
+ /// Event comes from an offline source.
/// </summary>
Offline,
/// <summary>
- /// 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).
/// </summary>
OnlineInitial,
/// <summary>
- /// Event comes from online source received thru active stream.
+ /// Event comes from online source received thru active stream.
/// </summary>
OnlineStream,
/// <summary>
- /// Event comes from online source being fetched manually.
+ /// Event comes from online source being fetched manually.
/// </summary>
OnlinePull,
/// <summary>
- /// 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).
/// </summary>
OnlinePush,
/// <summary>
- /// Event comes from an online source.
+ /// Event comes from an online source.
/// </summary>
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
{
/// <summary>
- /// The type of event.
+ /// The type of event.
/// </summary>
public enum FirebaseEventType
{
/// <summary>
- /// Item was inserted or updated.
+ /// Item was inserted or updated.
/// </summary>
InsertOrUpdate,
/// <summary>
- /// Item was deleted.
+ /// Item was deleted.
/// </summary>
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;
-
/// <summary>
- /// The firebase subscription.
+ /// The firebase subscription.
/// </summary>
/// <typeparam name="T"> Type of object to be streaming back to the called. </typeparam>
internal class FirebaseSubscription<T> : IDisposable
{
+ private static readonly HttpClient http;
+ private readonly FirebaseCache<T> cache;
private readonly CancellationTokenSource cancel;
+ private readonly FirebaseClient client;
+ private readonly string elementRoot;
private readonly IObserver<FirebaseEvent<T>> observer;
private readonly IFirebaseQuery query;
- private readonly FirebaseCache<T> cache;
- private readonly string elementRoot;
- private readonly FirebaseClient client;
-
- private static HttpClient http;
static FirebaseSubscription()
{
@@ -43,7 +41,7 @@ namespace Firebase.Database.Streaming
}
/// <summary>
- /// Initializes a new instance of the <see cref="FirebaseSubscription{T}"/> class.
+ /// Initializes a new instance of the <see cref="FirebaseSubscription{T}" /> class.
/// </summary>
/// <param name="observer"> The observer. </param>
/// <param name="query"> The query. </param>
@@ -59,13 +57,13 @@ namespace Firebase.Database.Streaming
client = query.Client;
}
- public event EventHandler<ExceptionEventArgs<FirebaseException>> ExceptionThrown;
-
public void Dispose()
{
cancel.Cancel();
}
+ public event EventHandler<ExceptionEventArgs<FirebaseException>> 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
+{
/// <summary>
- /// When a regular <see cref="StreamReader"/> is used in a UWP app its <see cref="StreamReader.ReadLine"/> method tends to take a long
- /// time for data larger then 2 KB. This extremly simple implementation of <see cref="TextReader"/> can be used instead to boost performance
- /// in your UWP app. Use <see cref="FirebaseOptions"/> to inject an instance of this class into your <see cref="FirebaseClient"/>.
+ /// When a regular <see cref="StreamReader" /> is used in a UWP app its <see cref="StreamReader.ReadLine" /> method
+ /// tends to take a long
+ /// time for data larger then 2 KB. This extremly simple implementation of <see cref="TextReader" /> can be used
+ /// instead to boost performance
+ /// in your UWP app. Use <see cref="FirebaseOptions" /> to inject an instance of this class into your
+ /// <see cref="FirebaseClient" />.
/// </summary>
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)