diff options
Diffstat (limited to 'FireBase/Query')
-rw-r--r-- | FireBase/Query/AuthQuery.cs | 21 | ||||
-rw-r--r-- | FireBase/Query/ChildQuery.cs | 28 | ||||
-rw-r--r-- | FireBase/Query/FilterQuery.cs | 66 | ||||
-rw-r--r-- | FireBase/Query/FirebaseQuery.cs | 218 | ||||
-rw-r--r-- | FireBase/Query/IFirebaseQuery.cs | 39 | ||||
-rw-r--r-- | FireBase/Query/OrderQuery.cs | 16 | ||||
-rw-r--r-- | FireBase/Query/ParameterQuery.cs | 24 | ||||
-rw-r--r-- | FireBase/Query/QueryExtensions.cs | 93 | ||||
-rw-r--r-- | FireBase/Query/QueryFactoryExtensions.cs | 91 | ||||
-rw-r--r-- | FireBase/Query/SilentQuery.cs | 6 |
10 files changed, 294 insertions, 308 deletions
diff --git a/FireBase/Query/AuthQuery.cs b/FireBase/Query/AuthQuery.cs index 8a8d3e8..2cfda3c 100644 --- a/FireBase/Query/AuthQuery.cs +++ b/FireBase/Query/AuthQuery.cs @@ -1,33 +1,34 @@ +using System; + namespace Firebase.Database.Query { - using System; - /// <summary> - /// Represents an auth parameter in firebase query, e.g. "?auth=xyz". + /// Represents an auth parameter in firebase query, e.g. "?auth=xyz". /// </summary> public class AuthQuery : ParameterQuery { private readonly Func<string> tokenFactory; /// <summary> - /// Initializes a new instance of the <see cref="AuthQuery"/> class. + /// Initializes a new instance of the <see cref="AuthQuery" /> class. /// </summary> - /// <param name="parent"> The parent. </param> + /// <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; } /// <summary> - /// Build the url parameter value of this child. + /// Build the url parameter value of this child. /// </summary> /// <param name="child"> The child of this child. </param> - /// <returns> The <see cref="string"/>. </returns> + /// <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..014fe09 100644 --- a/FireBase/Query/ChildQuery.cs +++ b/FireBase/Query/ChildQuery.cs @@ -1,16 +1,16 @@ +using System; + namespace Firebase.Database.Query { - using System; - /// <summary> - /// Firebase query which references the child of current node. + /// Firebase query which references the child of current node. /// </summary> public class ChildQuery : FirebaseQuery { private readonly Func<string> pathFactory; /// <summary> - /// Initializes a new instance of the <see cref="ChildQuery"/> class. + /// Initializes a new instance of the <see cref="ChildQuery" /> class. /// </summary> /// <param name="parent"> The parent. </param> /// <param name="pathFactory"> The path to the child node. </param> @@ -22,7 +22,7 @@ namespace Firebase.Database.Query } /// <summary> - /// Initializes a new instance of the <see cref="ChildQuery"/> class. + /// Initializes a new instance of the <see cref="ChildQuery" /> class. /// </summary> /// <param name="client"> The client. </param> /// <param name="pathFactory"> The path to the child node. </param> @@ -32,25 +32,19 @@ namespace Firebase.Database.Query } /// <summary> - /// Build the url segment of this child. + /// Build the url segment of this child. /// </summary> /// <param name="child"> The child of this child. </param> - /// <returns> The <see cref="string"/>. </returns> + /// <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..3434d1d 100644 --- a/FireBase/Query/FilterQuery.cs +++ b/FireBase/Query/FilterQuery.cs @@ -1,81 +1,77 @@ -namespace Firebase.Database.Query -{ - using System; - using System.Globalization; +using System; +using System.Globalization; +namespace Firebase.Database.Query +{ /// <summary> - /// Represents a firebase filtering query, e.g. "?LimitToLast=10". + /// 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; private readonly Func<bool> boolValueFactory; + private readonly Func<double> doubleValueFactory; + private readonly Func<string> valueFactory; /// <summary> - /// Initializes a new instance of the <see cref="FilterQuery"/> class. + /// Initializes a new instance of the <see cref="FilterQuery" /> class. /// </summary> /// <param name="parent"> The parent. </param> /// <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) + /// <param name="client"> The owning client. </param> + public FilterQuery(FirebaseQuery parent, Func<string> filterFactory, Func<string> valueFactory, + FirebaseClient client) : base(parent, filterFactory, client) { this.valueFactory = valueFactory; } /// <summary> - /// Initializes a new instance of the <see cref="FilterQuery"/> class. + /// Initializes a new instance of the <see cref="FilterQuery" /> class. /// </summary> /// <param name="parent"> The parent. </param> /// <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> - /// Initializes a new instance of the <see cref="FilterQuery"/> class. + /// Initializes a new instance of the <see cref="FilterQuery" /> class. /// </summary> /// <param name="parent"> The parent. </param> /// <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> - /// The build url parameter. + /// The build url parameter. /// </summary> - /// <param name="child"> The child. </param> - /// <returns> Url parameter part of the resulting path. </returns> + /// <param name="child"> The child. </param> + /// <returns> Url parameter part of the resulting path. </returns> protected override string BuildUrlParameter(FirebaseQuery child) { - if (this.valueFactory != null) - { - if(this.valueFactory() == null) - { - return $"null"; - } - return $"\"{this.valueFactory()}\""; - } - else if (this.doubleValueFactory != null) + if (valueFactory != null) { - return this.doubleValueFactory().ToString(CultureInfo.InvariantCulture); - } - else if (this.boolValueFactory != null) - { - return $"{this.boolValueFactory().ToString().ToLower()}"; + if (valueFactory() == null) return "null"; + return $"\"{valueFactory()}\""; } + if (doubleValueFactory != null) + return doubleValueFactory().ToString(CultureInfo.InvariantCulture); + if (boolValueFactory != null) 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..60d0289 100644 --- a/FireBase/Query/FirebaseQuery.cs +++ b/FireBase/Query/FirebaseQuery.cs @@ -1,71 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Reactive.Linq; +using System.Threading.Tasks; +using Firebase.Database.Http; +using Firebase.Database.Streaming; +using Newtonsoft.Json; + namespace Firebase.Database.Query { - using System; - using System.Collections.Generic; - 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 Newtonsoft.Json; - using System.Net; - /// <summary> - /// Represents a firebase query. + /// Represents a firebase query. /// </summary> public abstract class FirebaseQuery : IFirebaseQuery, IDisposable { - protected TimeSpan DEFAULT_HTTP_CLIENT_TIMEOUT = new TimeSpan(0, 0, 180); - protected readonly FirebaseQuery Parent; private HttpClient client; + protected TimeSpan DEFAULT_HTTP_CLIENT_TIMEOUT = new TimeSpan(0, 0, 180); - /// <summary> - /// Initializes a new instance of the <see cref="FirebaseQuery"/> class. + /// <summary> + /// Initializes a new instance of the <see cref="FirebaseQuery" /> class. /// </summary> /// <param name="parent"> The parent of this query. </param> /// <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. + /// Disposes this instance. /// </summary> - public FirebaseClient Client + public void Dispose() { - get; + client?.Dispose(); } /// <summary> - /// Queries the firebase server once returning collection of items. + /// Gets the client. + /// </summary> + public FirebaseClient Client { get; } + + /// <summary> + /// Queries the firebase server once returning collection of items. /// </summary> /// <param name="timeout"> Optional timeout value. </param> /// <typeparam name="T"> Type of elements. </typeparam> - /// <returns> Collection of <see cref="FirebaseObject{T}"/> holding the entities returned by server. </returns> + /// <returns> Collection of <see cref="FirebaseObject{T}" /> holding the entities returned by server. </returns> public async Task<IReadOnlyCollection<FirebaseObject<T>>> OnceAsync<T>(TimeSpan? timeout = null) { var url = string.Empty; 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); } + /// <summary> + /// Starts observing this query watching for changes real time sent by the server. + /// </summary> + /// <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 = "") + { + return Observable.Create<FirebaseEvent<T>>(observer => + { + var sub = new FirebaseSubscription<T>(observer, this, elementRoot, new FirebaseCache<T>()); + sub.ExceptionThrown += exceptionHandler; + return sub.Run(); + }); + } + + /// <summary> + /// Builds the actual URL of this query. + /// </summary> + /// <returns> The <see cref="string" />. </returns> + public async Task<string> BuildUrlAsync() + { + // if token factory is present on the parent then use it to generate auth token + if (Client.Options.AuthTokenAsyncFactory != null) + { + var token = await Client.Options.AuthTokenAsyncFactory().ConfigureAwait(false); + return this.WithAuth(token).BuildUrl(null); + } + + return BuildUrl(null); + } + /*public async Task<IReadOnlyCollection<FirebaseObject<Object>>> OnceAsync(Type dataType, TimeSpan? timeout = null) { var url = string.Empty; @@ -84,11 +119,11 @@ namespace Firebase.Database.Query }*/ /// <summary> - /// Assumes given query is pointing to a single object of type <typeparamref name="T"/> and retrieves it. + /// Assumes given query is pointing to a single object of type <typeparamref name="T" /> and retrieves it. /// </summary> /// <param name="timeout"> Optional timeout value. </param> /// <typeparam name="T"> Type of elements. </typeparam> - /// <returns> Single object of type <typeparamref name="T"/>. </returns> + /// <returns> Single object of type <typeparamref name="T" />. </returns> public async Task<T> OnceSingleAsync<T>(TimeSpan? timeout = null) { var responseData = string.Empty; @@ -97,7 +132,7 @@ namespace Firebase.Database.Query try { - url = await this.BuildUrlAsync().ConfigureAwait(false); + url = await BuildUrlAsync().ConfigureAwait(false); } catch (Exception ex) { @@ -106,7 +141,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); @@ -122,108 +157,75 @@ namespace Firebase.Database.Query } /// <summary> - /// Starts observing this query watching for changes real time sent by the server. - /// </summary> - /// <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 = "") - { - return Observable.Create<FirebaseEvent<T>>(observer => - { - var sub = new FirebaseSubscription<T>(observer, this, elementRoot, new FirebaseCache<T>()); - sub.ExceptionThrown += exceptionHandler; - return sub.Run(); - }); - } - - /// <summary> - /// Builds the actual URL of this query. - /// </summary> - /// <returns> The <see cref="string"/>. </returns> - 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) - { - var token = await this.Client.Options.AuthTokenAsyncFactory().ConfigureAwait(false); - return this.WithAuth(token).BuildUrl(null); - } - - return this.BuildUrl(null); - } - - /// <summary> - /// Posts given object to repository. + /// Posts given object to repository. /// </summary> /// <param name="obj"> The object. </param> /// <param name="generateKeyOffline"> Specifies whether the key should be generated offline instead of online. </param> /// <param name="timeout"> Optional timeout value. </param> - /// <typeparam name="T"> Type of <see cref="obj"/> </typeparam> + /// <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 result = JsonConvert.DeserializeObject<PostResult>(sendData, Client.Options.JsonSerializerSettings); - return new FirebaseObject<string>(result.Name, data); - } + 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); } /// <summary> - /// Patches data at given location instead of overwriting them. - /// </summary> + /// Patches data at given location instead of overwriting them. + /// </summary> /// <param name="obj"> The object. </param> /// <param name="timeout"> Optional timeout value. </param> - /// <typeparam name="T"> Type of <see cref="obj"/> </typeparam> - /// <returns> The <see cref="Task"/>. </returns> + /// <typeparam name="T"> Type of <see cref="obj" /> </typeparam> + /// <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); } /// <summary> - /// Sets or overwrites data at given location. - /// </summary> + /// Sets or overwrites data at given location. + /// </summary> /// <param name="obj"> The object. </param> /// <param name="timeout"> Optional timeout value. </param> - /// <typeparam name="T"> Type of <see cref="obj"/> </typeparam> - /// <returns> The <see cref="Task"/>. </returns> + /// <typeparam name="T"> Type of <see cref="obj" /> </typeparam> + /// <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); } /// <summary> - /// Deletes data from given location. + /// Deletes data from given location. /// </summary> /// <param name="timeout"> Optional timeout value. </param> - /// <returns> The <see cref="Task"/>. </returns> + /// <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) { @@ -245,49 +247,31 @@ namespace Firebase.Database.Query } /// <summary> - /// Disposes this instance. - /// </summary> - public void Dispose() - { - this.client?.Dispose(); - } - - /// <summary> - /// Build the url segment of this child. + /// Build the url segment of this child. /// </summary> /// <param name="child"> The child of this query. </param> - /// <returns> The <see cref="string"/>. </returns> + /// <returns> The <see cref="string" />. </returns> protected abstract string BuildUrlSegment(FirebaseQuery child); 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 +283,7 @@ namespace Firebase.Database.Query try { - url = await this.BuildUrlAsync().ConfigureAwait(false); + url = await BuildUrlAsync().ConfigureAwait(false); } catch (Exception ex) { @@ -327,4 +311,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..0da4b15 100644 --- a/FireBase/Query/IFirebaseQuery.cs +++ b/FireBase/Query/IFirebaseQuery.cs @@ -1,43 +1,40 @@ -namespace Firebase.Database.Query -{ - using System; - using System.Collections.Generic; - using System.Threading.Tasks; - - using Firebase.Database.Streaming; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Firebase.Database.Streaming; +namespace Firebase.Database.Query +{ /// <summary> - /// The FirebaseQuery interface. + /// The FirebaseQuery interface. /// </summary> public interface IFirebaseQuery { /// <summary> - /// Gets the owning client of this query. + /// 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. + /// Retrieves items which exist on the location specified by this query instance. /// </summary> /// <param name="timeout"> Optional timeout value. </param> /// <typeparam name="T"> Type of the items. </typeparam> - /// <returns> Collection of <see cref="FirebaseObject{T}"/>. </returns> + /// <returns> Collection of <see cref="FirebaseObject{T}" />. </returns> Task<IReadOnlyCollection<FirebaseObject<T>>> OnceAsync<T>(TimeSpan? timeout = null); /// <summary> - /// Returns current location as an observable which allows to real-time listening to events from the firebase server. + /// Returns current location as an observable which allows to real-time listening to events from the firebase server. /// </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 = ""); + /// <returns> Cold observable of <see cref="FirebaseEvent{T}" />. </returns> + IObservable<FirebaseEvent<T>> AsObservable<T>( + EventHandler<ExceptionEventArgs<FirebaseException>> exceptionHandler, string elementRoot = ""); /// <summary> - /// Builds the actual url of this query. + /// Builds the actual url of this query. /// </summary> - /// <returns> The <see cref="string"/>. </returns> + /// <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..302d1a3 100644 --- a/FireBase/Query/OrderQuery.cs +++ b/FireBase/Query/OrderQuery.cs @@ -1,16 +1,16 @@ +using System; + namespace Firebase.Database.Query { - using System; - /// <summary> - /// Represents a firebase ordering query, e.g. "?OrderBy=Foo". + /// Represents a firebase ordering query, e.g. "?OrderBy=Foo". /// </summary> public class OrderQuery : ParameterQuery { private readonly Func<string> propertyNameFactory; /// <summary> - /// Initializes a new instance of the <see cref="OrderQuery"/> class. + /// Initializes a new instance of the <see cref="OrderQuery" /> class. /// </summary> /// <param name="parent"> The query parent. </param> /// <param name="propertyNameFactory"> The property name. </param> @@ -22,13 +22,13 @@ namespace Firebase.Database.Query } /// <summary> - /// The build url parameter. + /// The build url parameter. /// </summary> /// <param name="child"> The child. </param> - /// <returns> The <see cref="string"/>. </returns> + /// <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..572224c 100644 --- a/FireBase/Query/ParameterQuery.cs +++ b/FireBase/Query/ParameterQuery.cs @@ -1,9 +1,9 @@ +using System; + namespace Firebase.Database.Query { - using System; - /// <summary> - /// Represents a parameter in firebase query, e.g. "?data=foo". + /// Represents a parameter in firebase query, e.g. "?data=foo". /// </summary> public abstract class ParameterQuery : FirebaseQuery { @@ -11,7 +11,7 @@ namespace Firebase.Database.Query private readonly string separator; /// <summary> - /// Initializes a new instance of the <see cref="ParameterQuery"/> class. + /// Initializes a new instance of the <see cref="ParameterQuery" /> class. /// </summary> /// <param name="parent"> The parent of this query. </param> /// <param name="parameterFactory"> The parameter. </param> @@ -20,24 +20,24 @@ namespace Firebase.Database.Query : base(parent, client) { this.parameterFactory = parameterFactory; - this.separator = (this.Parent is ChildQuery) ? "?" : "&"; + separator = Parent is ChildQuery ? "?" : "&"; } /// <summary> - /// Build the url segment represented by this query. - /// </summary> + /// Build the url segment represented by this query. + /// </summary> /// <param name="child"> The child. </param> - /// <returns> The <see cref="string"/>. </returns> + /// <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> - /// The build url parameter. + /// The build url parameter. /// </summary> /// <param name="child"> The child. </param> - /// <returns> The <see cref="string"/>. </returns> + /// <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..df2edfc 100644 --- a/FireBase/Query/QueryExtensions.cs +++ b/FireBase/Query/QueryExtensions.cs @@ -6,158 +6,163 @@ using Newtonsoft.Json; namespace Firebase.Database.Query { /// <summary> - /// Query extensions providing linq like syntax for firebase server methods. + /// Query extensions providing linq like syntax for firebase server methods. /// </summary> public static class QueryExtensions { /// <summary> - /// Adds an auth parameter to the query. + /// Adds an auth parameter to the query. /// </summary> /// <param name="node"> The child. </param> /// <param name="token"> The auth token. </param> - /// <returns> The <see cref="AuthQuery"/>. </returns> + /// <returns> The <see cref="AuthQuery" />. </returns> internal static AuthQuery WithAuth(this FirebaseQuery node, string token) { return node.WithAuth(() => token); } /// <summary> - /// Appends print=silent to save bandwidth. + /// Appends print=silent to save bandwidth. /// </summary> /// <param name="node"> The child. </param> - /// <returns> The <see cref="SilentQuery"/>. </returns> + /// <returns> The <see cref="SilentQuery" />. </returns> internal static SilentQuery Silent(this FirebaseQuery node) { return new SilentQuery(node, node.Client); } /// <summary> - /// References a sub child of the existing node. + /// References a sub child of the existing node. /// </summary> /// <param name="node"> The child. </param> /// <param name="path"> The path of sub child. </param> - /// <returns> The <see cref="ChildQuery"/>. </returns> + /// <returns> The <see cref="ChildQuery" />. </returns> public static ChildQuery Child(this ChildQuery node, string path) { return node.Child(() => path); } /// <summary> - /// Order data by given <see cref="propertyName"/>. Note that this is used mainly for following filtering queries and due to firebase implementation - /// the data may actually not be ordered. + /// Order data by given <see cref="propertyName" />. Note that this is used mainly for following filtering queries and + /// due to firebase implementation + /// the data may actually not be ordered. /// </summary> /// <param name="child"> The child. </param> /// <param name="propertyName"> The property name. </param> - /// <returns> The <see cref="OrderQuery"/>. </returns> + /// <returns> The <see cref="OrderQuery" />. </returns> public static OrderQuery OrderBy(this ChildQuery child, string propertyName) { return child.OrderBy(() => propertyName); } /// <summary> - /// Instructs firebase to send data greater or equal to the <see cref="value"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data greater or equal to the <see cref="value" />. This must be preceded by an OrderBy + /// query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="value"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery StartAt(this ParameterQuery child, string value) { return child.StartAt(() => value); } /// <summary> - /// Instructs firebase to send data lower or equal to the <see cref="value"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data lower or equal to the <see cref="value" />. This must be preceded by an OrderBy + /// query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="value"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery EndAt(this ParameterQuery child, string value) { return child.EndAt(() => value); } /// <summary> - /// Instructs firebase to send data equal to the <see cref="value"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to the <see cref="value" />. This must be preceded by an OrderBy query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="value"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery EqualTo(this ParameterQuery child, string value) { return child.EqualTo(() => value); } /// <summary> - /// Instructs firebase to send data greater or equal to the <see cref="value"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data greater or equal to the <see cref="value" />. This must be preceded by an OrderBy + /// query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="value"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery StartAt(this ParameterQuery child, double value) { return child.StartAt(() => value); } /// <summary> - /// Instructs firebase to send data lower or equal to the <see cref="value"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data lower or equal to the <see cref="value" />. This must be preceded by an OrderBy + /// query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="value"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery EndAt(this ParameterQuery child, double value) { return child.EndAt(() => value); } /// <summary> - /// Instructs firebase to send data equal to the <see cref="value"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to the <see cref="value" />. This must be preceded by an OrderBy query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="value"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery EqualTo(this ParameterQuery child, double value) { return child.EqualTo(() => value); } - + /// <summary> - /// Instructs firebase to send data equal to the <see cref="value"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to the <see cref="value" />. This must be preceded by an OrderBy query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="value"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> 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. + /// Instructs firebase to send data equal to null. This must be preceded by an OrderBy query. /// </summary> /// <param name="child"> Current node. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery EqualTo(this ParameterQuery child) { return child.EqualTo(() => null); - } + } /// <summary> - /// Limits the result to first <see cref="count"/> items. + /// Limits the result to first <see cref="count" /> items. /// </summary> /// <param name="child"> Current node. </param> /// <param name="count"> Number of elements. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery LimitToFirst(this ParameterQuery child, int count) { return child.LimitToFirst(() => count); } /// <summary> - /// Limits the result to last <see cref="count"/> items. + /// Limits the result to last <see cref="count" /> items. /// </summary> /// <param name="child"> Current node. </param> /// <param name="count"> Number of elements. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery LimitToLast(this ParameterQuery child, int count) { return child.LimitToLast(() => count); @@ -173,15 +178,19 @@ 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); } /// <summary> - /// Fan out given item to multiple locations at once. See https://firebase.googleblog.com/2015/10/client-side-fan-out-for-data-consistency_73.html for details. + /// Fan out given item to multiple locations at once. See + /// https://firebase.googleblog.com/2015/10/client-side-fan-out-for-data-consistency_73.html for details. /// </summary> /// <typeparam name="T"> Type of object to fan out. </typeparam> /// <param name="query"> Current node. </param> @@ -189,19 +198,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..71dae5c 100644 --- a/FireBase/Query/QueryFactoryExtensions.cs +++ b/FireBase/Query/QueryFactoryExtensions.cs @@ -1,176 +1,187 @@ +using System; + namespace Firebase.Database.Query { - using System; - /// <summary> - /// Query extensions providing linq like syntax for firebase server methods. + /// Query extensions providing linq like syntax for firebase server methods. /// </summary> public static class QueryFactoryExtensions { /// <summary> - /// Adds an auth parameter to the query. + /// Adds an auth parameter to the query. /// </summary> /// <param name="node"> The child. </param> /// <param name="tokenFactory"> The auth token. </param> - /// <returns> The <see cref="AuthQuery"/>. </returns> + /// <returns> The <see cref="AuthQuery" />. </returns> internal static AuthQuery WithAuth(this FirebaseQuery node, Func<string> tokenFactory) { return new AuthQuery(node, tokenFactory, node.Client); } /// <summary> - /// References a sub child of the existing node. + /// References a sub child of the existing node. /// </summary> /// <param name="node"> The child. </param> /// <param name="pathFactory"> The path of sub child. </param> - /// <returns> The <see cref="ChildQuery"/>. </returns> + /// <returns> The <see cref="ChildQuery" />. </returns> public static ChildQuery Child(this ChildQuery node, Func<string> pathFactory) { return new ChildQuery(node, pathFactory, node.Client); } /// <summary> - /// Order data by given <see cref="propertyNameFactory"/>. Note that this is used mainly for following filtering queries and due to firebase implementation - /// the data may actually not be ordered. + /// Order data by given <see cref="propertyNameFactory" />. Note that this is used mainly for following filtering + /// queries and due to firebase implementation + /// the data may actually not be ordered. /// </summary> /// <param name="child"> The child. </param> /// <param name="propertyNameFactory"> The property name. </param> - /// <returns> The <see cref="OrderQuery"/>. </returns> + /// <returns> The <see cref="OrderQuery" />. </returns> public static OrderQuery OrderBy(this ChildQuery child, Func<string> propertyNameFactory) { return new OrderQuery(child, propertyNameFactory, child.Client); } /// <summary> - /// Order data by $key. Note that this is used mainly for following filtering queries and due to firebase implementation - /// the data may actually not be ordered. + /// Order data by $key. Note that this is used mainly for following filtering queries and due to firebase + /// implementation + /// the data may actually not be ordered. /// </summary> /// <param name="child"> The child. </param> - /// <returns> The <see cref="OrderQuery"/>. </returns> + /// <returns> The <see cref="OrderQuery" />. </returns> public static OrderQuery OrderByKey(this ChildQuery child) { return child.OrderBy("$key"); } /// <summary> - /// Order data by $value. Note that this is used mainly for following filtering queries and due to firebase implementation - /// the data may actually not be ordered. + /// Order data by $value. Note that this is used mainly for following filtering queries and due to firebase + /// implementation + /// the data may actually not be ordered. /// </summary> /// <param name="child"> The child. </param> - /// <returns> The <see cref="OrderQuery"/>. </returns> + /// <returns> The <see cref="OrderQuery" />. </returns> public static OrderQuery OrderByValue(this ChildQuery child) { return child.OrderBy("$value"); } /// <summary> - /// Order data by $priority. Note that this is used mainly for following filtering queries and due to firebase implementation - /// the data may actually not be ordered. + /// Order data by $priority. Note that this is used mainly for following filtering queries and due to firebase + /// implementation + /// the data may actually not be ordered. /// </summary> /// <param name="child"> The child. </param> - /// <returns> The <see cref="OrderQuery"/>. </returns> + /// <returns> The <see cref="OrderQuery" />. </returns> public static OrderQuery OrderByPriority(this ChildQuery child) { return child.OrderBy("$priority"); } /// <summary> - /// Instructs firebase to send data greater or equal to the <see cref="valueFactory"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data greater or equal to the <see cref="valueFactory" />. This must be preceded by an + /// OrderBy query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="valueFactory"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery StartAt(this ParameterQuery child, Func<string> valueFactory) { return new FilterQuery(child, () => "startAt", valueFactory, child.Client); } /// <summary> - /// Instructs firebase to send data lower or equal to the <see cref="valueFactory"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data lower or equal to the <see cref="valueFactory" />. This must be preceded by an + /// OrderBy query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="valueFactory"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery EndAt(this ParameterQuery child, Func<string> valueFactory) { return new FilterQuery(child, () => "endAt", valueFactory, child.Client); } /// <summary> - /// Instructs firebase to send data equal to the <see cref="valueFactory"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to the <see cref="valueFactory" />. This must be preceded by an OrderBy + /// query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="valueFactory"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery EqualTo(this ParameterQuery child, Func<string> valueFactory) { return new FilterQuery(child, () => "equalTo", valueFactory, child.Client); } /// <summary> - /// Instructs firebase to send data greater or equal to the <see cref="valueFactory"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data greater or equal to the <see cref="valueFactory" />. This must be preceded by an + /// OrderBy query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="valueFactory"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery StartAt(this ParameterQuery child, Func<double> valueFactory) { return new FilterQuery(child, () => "startAt", valueFactory, child.Client); } /// <summary> - /// Instructs firebase to send data lower or equal to the <see cref="valueFactory"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data lower or equal to the <see cref="valueFactory" />. This must be preceded by an + /// OrderBy query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="valueFactory"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery EndAt(this ParameterQuery child, Func<double> valueFactory) { return new FilterQuery(child, () => "endAt", valueFactory, child.Client); } /// <summary> - /// Instructs firebase to send data equal to the <see cref="valueFactory"/>. This must be preceded by an OrderBy query. + /// Instructs firebase to send data equal to the <see cref="valueFactory" />. This must be preceded by an OrderBy + /// query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="valueFactory"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery EqualTo(this ParameterQuery child, Func<double> valueFactory) { 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. + /// Instructs firebase to send data equal to the <see cref="valueFactory" />. This must be preceded by an OrderBy + /// query. /// </summary> /// <param name="child"> Current node. </param> /// <param name="valueFactory"> Value to start at. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> 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. + /// Limits the result to first <see cref="countFactory" /> items. /// </summary> /// <param name="child"> Current node. </param> /// <param name="countFactory"> Number of elements. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery LimitToFirst(this ParameterQuery child, Func<int> countFactory) { return new FilterQuery(child, () => "limitToFirst", () => countFactory(), child.Client); } /// <summary> - /// Limits the result to last <see cref="countFactory"/> items. + /// Limits the result to last <see cref="countFactory" /> items. /// </summary> /// <param name="child"> Current node. </param> /// <param name="countFactory"> Number of elements. </param> - /// <returns> The <see cref="FilterQuery"/>. </returns> + /// <returns> The <see cref="FilterQuery" />. </returns> public static FilterQuery LimitToLast(this ParameterQuery child, Func<int> countFactory) { 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..d09d38b 100644 --- a/FireBase/Query/SilentQuery.cs +++ b/FireBase/Query/SilentQuery.cs @@ -1,11 +1,11 @@ namespace Firebase.Database.Query { /// <summary> - /// Appends print=silent to the url. + /// Appends print=silent to the url. /// </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 |