summaryrefslogtreecommitdiff
path: root/FireBase/Query
diff options
context:
space:
mode:
Diffstat (limited to 'FireBase/Query')
-rw-r--r--FireBase/Query/AuthQuery.cs7
-rw-r--r--FireBase/Query/ChildQuery.cs16
-rw-r--r--FireBase/Query/FilterQuery.cs36
-rw-r--r--FireBase/Query/FirebaseQuery.cs82
-rw-r--r--FireBase/Query/IFirebaseQuery.cs13
-rw-r--r--FireBase/Query/OrderQuery.cs4
-rw-r--r--FireBase/Query/ParameterQuery.cs6
-rw-r--r--FireBase/Query/QueryExtensions.cs25
-rw-r--r--FireBase/Query/QueryFactoryExtensions.cs6
-rw-r--r--FireBase/Query/SilentQuery.cs4
10 files changed, 88 insertions, 111 deletions
diff --git a/FireBase/Query/AuthQuery.cs b/FireBase/Query/AuthQuery.cs
index 8a8d3e8..14beb7e 100644
--- a/FireBase/Query/AuthQuery.cs
+++ b/FireBase/Query/AuthQuery.cs
@@ -15,7 +15,8 @@ namespace Firebase.Database.Query
/// <param name="parent"> The parent. </param>
/// <param name="tokenFactory"> The authentication token factory. </param>
/// <param name="client"> The owner. </param>
- public AuthQuery(FirebaseQuery parent, Func<string> tokenFactory, FirebaseClient client) : base(parent, () => client.Options.AsAccessToken ? "access_token" : "auth", client)
+ public AuthQuery(FirebaseQuery parent, Func<string> tokenFactory, FirebaseClient client) : base(parent,
+ () => client.Options.AsAccessToken ? "access_token" : "auth", client)
{
this.tokenFactory = tokenFactory;
}
@@ -27,7 +28,7 @@ namespace Firebase.Database.Query
/// <returns> The <see cref="string"/>. </returns>
protected override string BuildUrlParameter(FirebaseQuery child)
{
- return this.tokenFactory();
+ return tokenFactory();
}
}
-}
+} \ No newline at end of file
diff --git a/FireBase/Query/ChildQuery.cs b/FireBase/Query/ChildQuery.cs
index 1696ea8..510ae75 100644
--- a/FireBase/Query/ChildQuery.cs
+++ b/FireBase/Query/ChildQuery.cs
@@ -1,7 +1,7 @@
namespace Firebase.Database.Query
{
using System;
-
+
/// <summary>
/// Firebase query which references the child of current node.
/// </summary>
@@ -38,19 +38,13 @@ namespace Firebase.Database.Query
/// <returns> The <see cref="string"/>. </returns>
protected override string BuildUrlSegment(FirebaseQuery child)
{
- var s = this.pathFactory();
+ var s = pathFactory();
- if (s != string.Empty && !s.EndsWith("/"))
- {
- s += '/';
- }
+ if (s != string.Empty && !s.EndsWith("/")) s += '/';
- if (!(child is ChildQuery))
- {
- return s + ".json";
- }
+ if (!(child is ChildQuery)) return s + ".json";
return s;
}
}
-}
+} \ No newline at end of file
diff --git a/FireBase/Query/FilterQuery.cs b/FireBase/Query/FilterQuery.cs
index f9f6271..be544c8 100644
--- a/FireBase/Query/FilterQuery.cs
+++ b/FireBase/Query/FilterQuery.cs
@@ -1,4 +1,4 @@
-namespace Firebase.Database.Query
+namespace Firebase.Database.Query
{
using System;
using System.Globalization;
@@ -6,7 +6,7 @@ namespace Firebase.Database.Query
/// <summary>
/// Represents a firebase filtering query, e.g. "?LimitToLast=10".
/// </summary>
- public class FilterQuery : ParameterQuery
+ public class FilterQuery : ParameterQuery
{
private readonly Func<string> valueFactory;
private readonly Func<double> doubleValueFactory;
@@ -19,7 +19,8 @@ namespace Firebase.Database.Query
/// <param name="filterFactory"> The filter. </param>
/// <param name="valueFactory"> The value for filter. </param>
/// <param name="client"> The owning client. </param>
- public FilterQuery(FirebaseQuery parent, Func<string> filterFactory, Func<string> valueFactory, FirebaseClient client)
+ public FilterQuery(FirebaseQuery parent, Func<string> filterFactory, Func<string> valueFactory,
+ FirebaseClient client)
: base(parent, filterFactory, client)
{
this.valueFactory = valueFactory;
@@ -32,10 +33,11 @@ namespace Firebase.Database.Query
/// <param name="filterFactory"> The filter. </param>
/// <param name="valueFactory"> The value for filter. </param>
/// <param name="client"> The owning client. </param>
- public FilterQuery(FirebaseQuery parent, Func<string> filterFactory, Func<double> valueFactory, FirebaseClient client)
+ public FilterQuery(FirebaseQuery parent, Func<string> filterFactory, Func<double> valueFactory,
+ FirebaseClient client)
: base(parent, filterFactory, client)
{
- this.doubleValueFactory = valueFactory;
+ doubleValueFactory = valueFactory;
}
/// <summary>
@@ -45,10 +47,11 @@ namespace Firebase.Database.Query
/// <param name="filterFactory"> The filter. </param>
/// <param name="valueFactory"> The value for filter. </param>
/// <param name="client"> The owning client. </param>
- public FilterQuery(FirebaseQuery parent, Func<string> filterFactory, Func<bool> valueFactory, FirebaseClient client)
+ public FilterQuery(FirebaseQuery parent, Func<string> filterFactory, Func<bool> valueFactory,
+ FirebaseClient client)
: base(parent, filterFactory, client)
{
- this.boolValueFactory = valueFactory;
+ boolValueFactory = valueFactory;
}
/// <summary>
@@ -58,24 +61,21 @@ namespace Firebase.Database.Query
/// <returns> Url parameter part of the resulting path. </returns>
protected override string BuildUrlParameter(FirebaseQuery child)
{
- if (this.valueFactory != null)
+ if (valueFactory != null)
{
- if(this.valueFactory() == null)
- {
- return $"null";
- }
- return $"\"{this.valueFactory()}\"";
+ if (valueFactory() == null) return $"null";
+ return $"\"{valueFactory()}\"";
}
- else if (this.doubleValueFactory != null)
+ else if (doubleValueFactory != null)
{
- return this.doubleValueFactory().ToString(CultureInfo.InvariantCulture);
+ return doubleValueFactory().ToString(CultureInfo.InvariantCulture);
}
- else if (this.boolValueFactory != null)
+ else if (boolValueFactory != null)
{
- return $"{this.boolValueFactory().ToString().ToLower()}";
+ return $"{boolValueFactory().ToString().ToLower()}";
}
return string.Empty;
}
}
-}
+} \ No newline at end of file
diff --git a/FireBase/Query/FirebaseQuery.cs b/FireBase/Query/FirebaseQuery.cs
index 3513c85..5e09795 100644
--- a/FireBase/Query/FirebaseQuery.cs
+++ b/FireBase/Query/FirebaseQuery.cs
@@ -5,11 +5,9 @@ namespace Firebase.Database.Query
using System.Net.Http;
using System.Reactive.Linq;
using System.Threading.Tasks;
-
- using Firebase.Database.Http;
- using Firebase.Database.Offline;
- using Firebase.Database.Streaming;
-
+ using Http;
+ using Offline;
+ using Streaming;
using Newtonsoft.Json;
using System.Net;
@@ -31,17 +29,14 @@ namespace Firebase.Database.Query
/// <param name="client"> The owning client. </param>
protected FirebaseQuery(FirebaseQuery parent, FirebaseClient client)
{
- this.Client = client;
- this.Parent = parent;
+ Client = client;
+ Parent = parent;
}
/// <summary>
/// Gets the client.
/// </summary>
- public FirebaseClient Client
- {
- get;
- }
+ public FirebaseClient Client { get; }
/// <summary>
/// Queries the firebase server once returning collection of items.
@@ -55,14 +50,15 @@ namespace Firebase.Database.Query
try
{
- url = await this.BuildUrlAsync().ConfigureAwait(false);
+ url = await BuildUrlAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
- throw new FirebaseException("Couldn't build the url", string.Empty, string.Empty, HttpStatusCode.OK, ex);
+ throw new FirebaseException("Couldn't build the url", string.Empty, string.Empty, HttpStatusCode.OK,
+ ex);
}
- return await this.GetClient(timeout).GetObjectCollectionAsync<T>(url, Client.Options.JsonSerializerSettings)
+ return await GetClient(timeout).GetObjectCollectionAsync<T>(url, Client.Options.JsonSerializerSettings)
.ConfigureAwait(false);
}
@@ -97,7 +93,7 @@ namespace Firebase.Database.Query
try
{
- url = await this.BuildUrlAsync().ConfigureAwait(false);
+ url = await BuildUrlAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -106,7 +102,7 @@ namespace Firebase.Database.Query
try
{
- var response = await this.GetClient(timeout).GetAsync(url).ConfigureAwait(false);
+ var response = await GetClient(timeout).GetAsync(url).ConfigureAwait(false);
statusCode = response.StatusCode;
responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
@@ -127,7 +123,8 @@ namespace Firebase.Database.Query
/// <typeparam name="T"> Type of elements. </typeparam>
/// <param name="elementRoot"> Optional custom root element of received json items. </param>
/// <returns> Observable stream of <see cref="FirebaseEvent{T}"/>. </returns>
- public IObservable<FirebaseEvent<T>> AsObservable<T>(EventHandler<ExceptionEventArgs<FirebaseException>> exceptionHandler = null, string elementRoot = "")
+ public IObservable<FirebaseEvent<T>> AsObservable<T>(
+ EventHandler<ExceptionEventArgs<FirebaseException>> exceptionHandler = null, string elementRoot = "")
{
return Observable.Create<FirebaseEvent<T>>(observer =>
{
@@ -144,13 +141,13 @@ namespace Firebase.Database.Query
public async Task<string> BuildUrlAsync()
{
// if token factory is present on the parent then use it to generate auth token
- if (this.Client.Options.AuthTokenAsyncFactory != null)
+ if (Client.Options.AuthTokenAsyncFactory != null)
{
- var token = await this.Client.Options.AuthTokenAsyncFactory().ConfigureAwait(false);
+ var token = await Client.Options.AuthTokenAsyncFactory().ConfigureAwait(false);
return this.WithAuth(token).BuildUrl(null);
}
- return this.BuildUrl(null);
+ return BuildUrl(null);
}
/// <summary>
@@ -161,20 +158,21 @@ namespace Firebase.Database.Query
/// <param name="timeout"> Optional timeout value. </param>
/// <typeparam name="T"> Type of <see cref="obj"/> </typeparam>
/// <returns> Resulting firebase object with populated key. </returns>
- public async Task<FirebaseObject<string>> PostAsync(string data, bool generateKeyOffline = true, TimeSpan? timeout = null)
+ public async Task<FirebaseObject<string>> PostAsync(string data, bool generateKeyOffline = true,
+ TimeSpan? timeout = null)
{
// post generates a new key server-side, while put can be used with an already generated local key
if (generateKeyOffline)
{
var key = FirebaseKeyGenerator.Next();
- await new ChildQuery(this, () => key, this.Client).PutAsync(data).ConfigureAwait(false);
+ await new ChildQuery(this, () => key, Client).PutAsync(data).ConfigureAwait(false);
return new FirebaseObject<string>(key, data);
}
else
{
- var c = this.GetClient(timeout);
- var sendData = await this.SendAsync(c, data, HttpMethod.Post).ConfigureAwait(false);
+ var c = GetClient(timeout);
+ var sendData = await SendAsync(c, data, HttpMethod.Post).ConfigureAwait(false);
var result = JsonConvert.DeserializeObject<PostResult>(sendData, Client.Options.JsonSerializerSettings);
return new FirebaseObject<string>(result.Name, data);
@@ -190,7 +188,7 @@ namespace Firebase.Database.Query
/// <returns> The <see cref="Task"/>. </returns>
public async Task PatchAsync(string data, TimeSpan? timeout = null)
{
- var c = this.GetClient(timeout);
+ var c = GetClient(timeout);
await this.Silent().SendAsync(c, data, new HttpMethod("PATCH")).ConfigureAwait(false);
}
@@ -204,7 +202,7 @@ namespace Firebase.Database.Query
/// <returns> The <see cref="Task"/>. </returns>
public async Task PutAsync(string data, TimeSpan? timeout = null)
{
- var c = this.GetClient(timeout);
+ var c = GetClient(timeout);
await this.Silent().SendAsync(c, data, HttpMethod.Put).ConfigureAwait(false);
}
@@ -216,14 +214,14 @@ namespace Firebase.Database.Query
/// <returns> The <see cref="Task"/>. </returns>
public async Task DeleteAsync(TimeSpan? timeout = null)
{
- var c = this.GetClient(timeout);
+ var c = GetClient(timeout);
var url = string.Empty;
var responseData = string.Empty;
var statusCode = HttpStatusCode.OK;
try
{
- url = await this.BuildUrlAsync().ConfigureAwait(false);
+ url = await BuildUrlAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -249,7 +247,7 @@ namespace Firebase.Database.Query
/// </summary>
public void Dispose()
{
- this.client?.Dispose();
+ client?.Dispose();
}
/// <summary>
@@ -261,33 +259,23 @@ namespace Firebase.Database.Query
private string BuildUrl(FirebaseQuery child)
{
- var url = this.BuildUrlSegment(child);
+ var url = BuildUrlSegment(child);
- if (this.Parent != null)
- {
- url = this.Parent.BuildUrl(this) + url;
- }
+ if (Parent != null) url = Parent.BuildUrl(this) + url;
return url;
}
private HttpClient GetClient(TimeSpan? timeout = null)
{
- if (this.client == null)
- {
- this.client = new HttpClient();
- }
+ if (client == null) client = new HttpClient();
if (!timeout.HasValue)
- {
- this.client.Timeout = DEFAULT_HTTP_CLIENT_TIMEOUT;
- }
+ client.Timeout = DEFAULT_HTTP_CLIENT_TIMEOUT;
else
- {
- this.client.Timeout = timeout.Value;
- }
+ client.Timeout = timeout.Value;
- return this.client;
+ return client;
}
private async Task<string> SendAsync(HttpClient client, string data, HttpMethod method)
@@ -299,7 +287,7 @@ namespace Firebase.Database.Query
try
{
- url = await this.BuildUrlAsync().ConfigureAwait(false);
+ url = await BuildUrlAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -327,4 +315,4 @@ namespace Firebase.Database.Query
}
}
}
-}
+} \ No newline at end of file
diff --git a/FireBase/Query/IFirebaseQuery.cs b/FireBase/Query/IFirebaseQuery.cs
index 2e8c671..9f6e36c 100644
--- a/FireBase/Query/IFirebaseQuery.cs
+++ b/FireBase/Query/IFirebaseQuery.cs
@@ -3,8 +3,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
-
- using Firebase.Database.Streaming;
+ using Streaming;
/// <summary>
/// The FirebaseQuery interface.
@@ -14,10 +13,7 @@
/// <summary>
/// Gets the owning client of this query.
/// </summary>
- FirebaseClient Client
- {
- get;
- }
+ FirebaseClient Client { get; }
/// <summary>
/// Retrieves items which exist on the location specified by this query instance.
@@ -32,7 +28,8 @@
/// </summary>
/// <typeparam name="T"> Type of the items. </typeparam>
/// <returns> Cold observable of <see cref="FirebaseEvent{T}"/>. </returns>
- IObservable<FirebaseEvent<T>> AsObservable<T>(EventHandler<ExceptionEventArgs<FirebaseException>> exceptionHandler, string elementRoot = "");
+ IObservable<FirebaseEvent<T>> AsObservable<T>(
+ EventHandler<ExceptionEventArgs<FirebaseException>> exceptionHandler, string elementRoot = "");
/// <summary>
/// Builds the actual url of this query.
@@ -40,4 +37,4 @@
/// <returns> The <see cref="string"/>. </returns>
Task<string> BuildUrlAsync();
}
-}
+} \ No newline at end of file
diff --git a/FireBase/Query/OrderQuery.cs b/FireBase/Query/OrderQuery.cs
index 46ebd2c..16adba7 100644
--- a/FireBase/Query/OrderQuery.cs
+++ b/FireBase/Query/OrderQuery.cs
@@ -28,7 +28,7 @@ namespace Firebase.Database.Query
/// <returns> The <see cref="string"/>. </returns>
protected override string BuildUrlParameter(FirebaseQuery child)
{
- return $"\"{this.propertyNameFactory()}\"";
+ return $"\"{propertyNameFactory()}\"";
}
}
-}
+} \ No newline at end of file
diff --git a/FireBase/Query/ParameterQuery.cs b/FireBase/Query/ParameterQuery.cs
index e3d9717..fb273a3 100644
--- a/FireBase/Query/ParameterQuery.cs
+++ b/FireBase/Query/ParameterQuery.cs
@@ -20,7 +20,7 @@ namespace Firebase.Database.Query
: base(parent, client)
{
this.parameterFactory = parameterFactory;
- this.separator = (this.Parent is ChildQuery) ? "?" : "&";
+ separator = Parent is ChildQuery ? "?" : "&";
}
/// <summary>
@@ -30,7 +30,7 @@ namespace Firebase.Database.Query
/// <returns> The <see cref="string"/>. </returns>
protected override string BuildUrlSegment(FirebaseQuery child)
{
- return $"{this.separator}{this.parameterFactory()}={this.BuildUrlParameter(child)}";
+ return $"{separator}{parameterFactory()}={BuildUrlParameter(child)}";
}
/// <summary>
@@ -40,4 +40,4 @@ namespace Firebase.Database.Query
/// <returns> The <see cref="string"/>. </returns>
protected abstract string BuildUrlParameter(FirebaseQuery child);
}
-}
+} \ No newline at end of file
diff --git a/FireBase/Query/QueryExtensions.cs b/FireBase/Query/QueryExtensions.cs
index 77db644..735fe0a 100644
--- a/FireBase/Query/QueryExtensions.cs
+++ b/FireBase/Query/QueryExtensions.cs
@@ -119,7 +119,7 @@ namespace Firebase.Database.Query
{
return child.EqualTo(() => value);
}
-
+
/// <summary>
/// Instructs firebase to send data equal to the <see cref="value"/>. This must be preceded by an OrderBy query.
/// </summary>
@@ -129,7 +129,7 @@ namespace Firebase.Database.Query
public static FilterQuery EqualTo(this ParameterQuery child, bool value)
{
return child.EqualTo(() => value);
- }
+ }
/// <summary>
/// Instructs firebase to send data equal to null. This must be preceded by an OrderBy query.
@@ -139,7 +139,7 @@ namespace Firebase.Database.Query
public static FilterQuery EqualTo(this ParameterQuery child)
{
return child.EqualTo(() => null);
- }
+ }
/// <summary>
/// Limits the result to first <see cref="count"/> items.
@@ -173,9 +173,12 @@ namespace Firebase.Database.Query
return query.PatchAsync(JsonConvert.SerializeObject(obj, query.Client.Options.JsonSerializerSettings));
}
- public static async Task<FirebaseObject<T>> PostAsync<T>(this FirebaseQuery query, T obj, bool generateKeyOffline = true)
+ public static async Task<FirebaseObject<T>> PostAsync<T>(this FirebaseQuery query, T obj,
+ bool generateKeyOffline = true)
{
- var result = await query.PostAsync(JsonConvert.SerializeObject(obj, query.Client.Options.JsonSerializerSettings), generateKeyOffline);
+ var result =
+ await query.PostAsync(JsonConvert.SerializeObject(obj, query.Client.Options.JsonSerializerSettings),
+ generateKeyOffline);
return new FirebaseObject<T>(result.Key, obj);
}
@@ -189,19 +192,13 @@ namespace Firebase.Database.Query
/// <param name="relativePaths"> Locations where to store the item. </param>
public static async Task FanOut<T>(this ChildQuery child, T item, params string[] relativePaths)
{
- if (relativePaths == null)
- {
- throw new ArgumentNullException(nameof(relativePaths));
- }
+ if (relativePaths == null) throw new ArgumentNullException(nameof(relativePaths));
var fanoutObject = new Dictionary<string, T>(relativePaths.Length);
- foreach (var path in relativePaths)
- {
- fanoutObject.Add(path, item);
- }
+ foreach (var path in relativePaths) fanoutObject.Add(path, item);
await child.PatchAsync(fanoutObject);
}
}
-}
+} \ No newline at end of file
diff --git a/FireBase/Query/QueryFactoryExtensions.cs b/FireBase/Query/QueryFactoryExtensions.cs
index b36e74a..b54c315 100644
--- a/FireBase/Query/QueryFactoryExtensions.cs
+++ b/FireBase/Query/QueryFactoryExtensions.cs
@@ -139,7 +139,7 @@ namespace Firebase.Database.Query
{
return new FilterQuery(child, () => "equalTo", valueFactory, child.Client);
}
-
+
/// <summary>
/// Instructs firebase to send data equal to the <see cref="valueFactory"/>. This must be preceded by an OrderBy query.
/// </summary>
@@ -149,7 +149,7 @@ namespace Firebase.Database.Query
public static FilterQuery EqualTo(this ParameterQuery child, Func<bool> valueFactory)
{
return new FilterQuery(child, () => "equalTo", valueFactory, child.Client);
- }
+ }
/// <summary>
/// Limits the result to first <see cref="countFactory"/> items.
@@ -173,4 +173,4 @@ namespace Firebase.Database.Query
return new FilterQuery(child, () => "limitToLast", () => countFactory(), child.Client);
}
}
-}
+} \ No newline at end of file
diff --git a/FireBase/Query/SilentQuery.cs b/FireBase/Query/SilentQuery.cs
index 15584f6..1960426 100644
--- a/FireBase/Query/SilentQuery.cs
+++ b/FireBase/Query/SilentQuery.cs
@@ -5,7 +5,7 @@
/// </summary>
public class SilentQuery : ParameterQuery
{
- public SilentQuery(FirebaseQuery parent, FirebaseClient client)
+ public SilentQuery(FirebaseQuery parent, FirebaseClient client)
: base(parent, () => "print", client)
{
}
@@ -15,4 +15,4 @@
return "silent";
}
}
-}
+} \ No newline at end of file