From 5d140b1f07c7ed42811ba528475217bc1f359e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bourgeois?= Date: Sun, 5 Jun 2016 12:48:49 +0200 Subject: [PATCH 1/4] Missing disposes --- FireSharp/FirebaseClient.cs | 42 ++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/FireSharp/FirebaseClient.cs b/FireSharp/FirebaseClient.cs index 9815c06..7dcfce6 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) { @@ -396,4 +404,4 @@ private void HandleIfErrorResponse(HttpStatusCode statusCode, string content, } } } -} \ No newline at end of file +} From cd220328755b2e893ccc4372e688bbba97ce3a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bourgeois?= Date: Sun, 5 Jun 2016 14:30:04 +0200 Subject: [PATCH 2/4] Added a ServerValues class --- FireSharp/FireSharp.csproj | 1 + FireSharp/ServerValues.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 FireSharp/ServerValues.cs 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/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" + }; + } +} From d02c88d45d897a230b99fe4f59bafc67da5877f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bourgeois?= Date: Sun, 5 Jun 2016 14:44:49 +0200 Subject: [PATCH 3/4] Starting to work on code documentation. --- FireSharp/Config/FirebaseConfig.cs | 34 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) 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; + } + } } } From fe1fa0b300bd9c8da7bf05f58c9d39cf6eec927f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bourgeois?= Date: Mon, 6 Jun 2016 18:38:38 +0200 Subject: [PATCH 4/4] Deprecated ListenAsync is now just a shortcut to OnAsync --- FireSharp/FirebaseClient.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/FireSharp/FirebaseClient.cs b/FireSharp/FirebaseClient.cs index 7dcfce6..66e9d9a 100644 --- a/FireSharp/FirebaseClient.cs +++ b/FireSharp/FirebaseClient.cs @@ -368,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,