From b7ef3c860375baea7b5db95940519ce0746b6ecc Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Mon, 1 Oct 2018 22:20:36 +0200 Subject: added Command Response Handling --- FireBase/Http/HttpClientExtensions.cs | 40 +++++++++++++++++++++++++++++++++++ FireBase/Query/FirebaseQuery.cs | 16 ++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'FireBase') diff --git a/FireBase/Http/HttpClientExtensions.cs b/FireBase/Http/HttpClientExtensions.cs index 444145b..5d15c59 100644 --- a/FireBase/Http/HttpClientExtensions.cs +++ b/FireBase/Http/HttpClientExtensions.cs @@ -52,6 +52,46 @@ namespace Firebase.Database.Http } } + /*/// + /// The get object collection async. + /// + /// The client. + /// The request uri. + /// /// The Data Type. + /// The specific JSON Serializer Settings. + /// The type of entities the collection should contain. + /// The . + public static async Task>> GetObjectCollectionAsync(this HttpClient client, string requestUri, + JsonSerializerSettings jsonSerializerSettings, Type dataType) + { + var responseData = string.Empty; + var statusCode = HttpStatusCode.OK; + + try + { + var response = await client.GetAsync(requestUri).ConfigureAwait(false); + statusCode = response.StatusCode; + responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + + response.EnsureSuccessStatusCode(); + + Type dicType = typeof(Dictionary<,>).MakeGenericType(typeof(string), dataType); + + var dictionary = JsonConvert.DeserializeObject(responseData,dicType, jsonSerializerSettings) as Dictionary; + + if (dictionary == null) + { + return new FirebaseObject[0]; + } + + return dictionary.Select(item => new FirebaseObject(item.Key, item.Value)).ToList(); + } + catch (Exception ex) + { + throw new FirebaseException(requestUri, string.Empty, responseData, statusCode, ex); + } + }*/ + /// /// The get object collection async. /// diff --git a/FireBase/Query/FirebaseQuery.cs b/FireBase/Query/FirebaseQuery.cs index 0e1b84a..3513c85 100644 --- a/FireBase/Query/FirebaseQuery.cs +++ b/FireBase/Query/FirebaseQuery.cs @@ -66,6 +66,22 @@ namespace Firebase.Database.Query .ConfigureAwait(false); } + /*public async Task>> OnceAsync(Type dataType, TimeSpan? timeout = null) + { + var url = string.Empty; + + try + { + url = await this.BuildUrlAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + throw new FirebaseException("Couldn't build the url", string.Empty, string.Empty, HttpStatusCode.OK, ex); + } + + return await this.GetClient(timeout).GetObjectCollectionAsync(url, Client.Options.JsonSerializerSettings, dataType) + .ConfigureAwait(false); + }*/ /// /// Assumes given query is pointing to a single object of type and retrieves it. -- cgit v1.2.3-70-g09d2