diff --git a/FireSharp/Config/FirebaseConfig.cs b/FireSharp/Config/FirebaseConfig.cs
index 0321038..9a84d85 100644
--- a/FireSharp/Config/FirebaseConfig.cs
+++ b/FireSharp/Config/FirebaseConfig.cs
@@ -6,6 +6,7 @@ namespace FireSharp.Config
public class FirebaseConfig : IFirebaseConfig
{
private string _basePath;
+ private ISerializer _serializer;
public FirebaseConfig()
{
@@ -14,18 +15,41 @@ public FirebaseConfig()
public string BasePath
{
- get
- {
- return _basePath.EndsWith("/") ? _basePath : $"{_basePath}/";
- }
+ get { return _basePath.EndsWith("/") ? _basePath : $"{_basePath}/"; }
set { _basePath = value; }
}
public string Host { get; set; }
+
public string AuthSecret { get; set; }
+ ///
+ /// Gets or sets the request timeout.
+ ///
+ ///
+ /// The request timeout.
+ ///
public TimeSpan? RequestTimeout { get; set; }
- public ISerializer Serializer { get; set; }
+ ///
+ /// Gets or sets the serializer instance.
+ ///
+ ///
+ /// The currently used serializer.
+ ///
+ /// If an attempt to set a null instance is attempted
+ public ISerializer Serializer
+ {
+ get { return _serializer; }
+ set
+ {
+ if (value == null)
+ {
+ throw new ArgumentNullException(nameof(value));
+ }
+
+ _serializer = value;
+ }
+ }
}
}
diff --git a/FireSharp/FireSharp.csproj b/FireSharp/FireSharp.csproj
index 0e94be0..80038d1 100644
--- a/FireSharp/FireSharp.csproj
+++ b/FireSharp/FireSharp.csproj
@@ -95,6 +95,7 @@
+
diff --git a/FireSharp/FirebaseClient.cs b/FireSharp/FirebaseClient.cs
index 9815c06..66e9d9a 100644
--- a/FireSharp/FirebaseClient.cs
+++ b/FireSharp/FirebaseClient.cs
@@ -89,10 +89,12 @@ public SetResponse Set(string path, T data)
{
try
{
- var response = _requestManager.RequestAsync(HttpMethod.Put, path, data).Result;
- var content = response.Content.ReadAsStringAsync().Result;
- HandleIfErrorResponse(response.StatusCode, content);
- return new SetResponse(content, response.StatusCode);
+ using (var response = _requestManager.RequestAsync(HttpMethod.Put, path, data).Result)
+ {
+ var content = response.Content.ReadAsStringAsync().Result;
+ HandleIfErrorResponse(response.StatusCode, content);
+ return new SetResponse(content, response.StatusCode);
+ }
}
catch (HttpRequestException ex)
{
@@ -104,10 +106,12 @@ public PushResponse Push(string path, T data)
{
try
{
- var response = _requestManager.RequestAsync(HttpMethod.Post, path, data).Result;
- var content = response.Content.ReadAsStringAsync().Result;
- HandleIfErrorResponse(response.StatusCode, content);
- return new PushResponse(content, response.StatusCode);
+ using (var response = _requestManager.RequestAsync(HttpMethod.Post, path, data).Result)
+ {
+ var content = response.Content.ReadAsStringAsync().Result;
+ HandleIfErrorResponse(response.StatusCode, content);
+ return new PushResponse(content, response.StatusCode);
+ }
}
catch (HttpRequestException ex)
{
@@ -119,10 +123,12 @@ public FirebaseResponse Delete(string path)
{
try
{
- var response = _requestManager.RequestAsync(HttpMethod.Delete, path).Result;
- var content = response.Content.ReadAsStringAsync().Result;
- HandleIfErrorResponse(response.StatusCode, content);
- return new FirebaseResponse(content, response.StatusCode);
+ using (var response = _requestManager.RequestAsync(HttpMethod.Delete, path).Result)
+ {
+ var content = response.Content.ReadAsStringAsync().Result;
+ HandleIfErrorResponse(response.StatusCode, content);
+ return new FirebaseResponse(content, response.StatusCode);
+ }
}
catch (HttpRequestException ex)
{
@@ -185,10 +191,12 @@ public async Task SetAsync(string path, T data)
{
try
{
- var response = await _requestManager.RequestAsync(HttpMethod.Put, path, data).ConfigureAwait(false);
- var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
- HandleIfErrorResponse(response.StatusCode, content);
- return new SetResponse(content, response.StatusCode);
+ using (var response = await _requestManager.RequestAsync(HttpMethod.Put, path, data).ConfigureAwait(false))
+ {
+ var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
+ HandleIfErrorResponse(response.StatusCode, content);
+ return new SetResponse(content, response.StatusCode);
+ }
}
catch (HttpRequestException ex)
{
@@ -360,12 +368,11 @@ public async Task UpdateAsync(string path, T data)
}
[Obsolete("This method is obsolete use OnAsync instead.")]
- public async Task ListenAsync(string path, ValueAddedEventHandler added = null,
+ public Task ListenAsync(string path, ValueAddedEventHandler added = null,
ValueChangedEventHandler changed = null,
ValueRemovedEventHandler removed = null)
{
- return new EventStreamResponse(await _requestManager.ListenAsync(path).ConfigureAwait(false), added, changed,
- removed);
+ return OnAsync(path, added, changed, removed);
}
public async Task> OnChangeGetAsync(string path,
@@ -396,4 +403,4 @@ private void HandleIfErrorResponse(HttpStatusCode statusCode, string content,
}
}
}
-}
\ No newline at end of file
+}
diff --git a/FireSharp/ServerValues.cs b/FireSharp/ServerValues.cs
new file mode 100644
index 0000000..c04d5fe
--- /dev/null
+++ b/FireSharp/ServerValues.cs
@@ -0,0 +1,18 @@
+using System.Collections.Generic;
+
+namespace FireSharp
+{
+ ///
+ /// This class contains .NET representations of Firebase Server values.
+ ///
+ public static class ServerValues
+ {
+ ///
+ /// The time since UNIX epoch, in milliseconds.
+ ///
+ public static IDictionary Timestamp => new Dictionary
+ {
+ [".sv"] = "timestamp"
+ };
+ }
+}