From e6181c24124d97f2fbc932b8a68311e625463156 Mon Sep 17 00:00:00 2001 From: uzvkl Date: Tue, 11 Jun 2019 23:05:52 +0200 Subject: Move dsa related stuff to subfolder --- dsa/FireBase/Query/AuthQuery.cs | 34 +++ dsa/FireBase/Query/ChildQuery.cs | 50 +++++ dsa/FireBase/Query/FilterQuery.cs | 77 +++++++ dsa/FireBase/Query/FirebaseQuery.cs | 314 +++++++++++++++++++++++++++ dsa/FireBase/Query/IFirebaseQuery.cs | 40 ++++ dsa/FireBase/Query/OrderQuery.cs | 34 +++ dsa/FireBase/Query/ParameterQuery.cs | 43 ++++ dsa/FireBase/Query/QueryExtensions.cs | 210 ++++++++++++++++++ dsa/FireBase/Query/QueryFactoryExtensions.cs | 187 ++++++++++++++++ dsa/FireBase/Query/SilentQuery.cs | 18 ++ 10 files changed, 1007 insertions(+) create mode 100644 dsa/FireBase/Query/AuthQuery.cs create mode 100644 dsa/FireBase/Query/ChildQuery.cs create mode 100644 dsa/FireBase/Query/FilterQuery.cs create mode 100644 dsa/FireBase/Query/FirebaseQuery.cs create mode 100644 dsa/FireBase/Query/IFirebaseQuery.cs create mode 100644 dsa/FireBase/Query/OrderQuery.cs create mode 100644 dsa/FireBase/Query/ParameterQuery.cs create mode 100644 dsa/FireBase/Query/QueryExtensions.cs create mode 100644 dsa/FireBase/Query/QueryFactoryExtensions.cs create mode 100644 dsa/FireBase/Query/SilentQuery.cs (limited to 'dsa/FireBase/Query') diff --git a/dsa/FireBase/Query/AuthQuery.cs b/dsa/FireBase/Query/AuthQuery.cs new file mode 100644 index 0000000..2cfda3c --- /dev/null +++ b/dsa/FireBase/Query/AuthQuery.cs @@ -0,0 +1,34 @@ +using System; + +namespace Firebase.Database.Query +{ + /// + /// Represents an auth parameter in firebase query, e.g. "?auth=xyz". + /// + public class AuthQuery : ParameterQuery + { + private readonly Func tokenFactory; + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The authentication token factory. + /// The owner. + public AuthQuery(FirebaseQuery parent, Func tokenFactory, FirebaseClient client) : base(parent, + () => client.Options.AsAccessToken ? "access_token" : "auth", client) + { + this.tokenFactory = tokenFactory; + } + + /// + /// Build the url parameter value of this child. + /// + /// The child of this child. + /// The . + protected override string BuildUrlParameter(FirebaseQuery child) + { + return tokenFactory(); + } + } +} \ No newline at end of file diff --git a/dsa/FireBase/Query/ChildQuery.cs b/dsa/FireBase/Query/ChildQuery.cs new file mode 100644 index 0000000..014fe09 --- /dev/null +++ b/dsa/FireBase/Query/ChildQuery.cs @@ -0,0 +1,50 @@ +using System; + +namespace Firebase.Database.Query +{ + /// + /// Firebase query which references the child of current node. + /// + public class ChildQuery : FirebaseQuery + { + private readonly Func pathFactory; + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The path to the child node. + /// The owner. + public ChildQuery(FirebaseQuery parent, Func pathFactory, FirebaseClient client) + : base(parent, client) + { + this.pathFactory = pathFactory; + } + + /// + /// Initializes a new instance of the class. + /// + /// The client. + /// The path to the child node. + public ChildQuery(FirebaseClient client, Func pathFactory) + : this(null, pathFactory, client) + { + } + + /// + /// Build the url segment of this child. + /// + /// The child of this child. + /// The . + protected override string BuildUrlSegment(FirebaseQuery child) + { + var s = pathFactory(); + + if (s != string.Empty && !s.EndsWith("/")) s += '/'; + + if (!(child is ChildQuery)) return s + ".json"; + + return s; + } + } +} \ No newline at end of file diff --git a/dsa/FireBase/Query/FilterQuery.cs b/dsa/FireBase/Query/FilterQuery.cs new file mode 100644 index 0000000..3434d1d --- /dev/null +++ b/dsa/FireBase/Query/FilterQuery.cs @@ -0,0 +1,77 @@ +using System; +using System.Globalization; + +namespace Firebase.Database.Query +{ + /// + /// Represents a firebase filtering query, e.g. "?LimitToLast=10". + /// + public class FilterQuery : ParameterQuery + { + private readonly Func boolValueFactory; + private readonly Func doubleValueFactory; + private readonly Func valueFactory; + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The filter. + /// The value for filter. + /// The owning client. + public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory, + FirebaseClient client) + : base(parent, filterFactory, client) + { + this.valueFactory = valueFactory; + } + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The filter. + /// The value for filter. + /// The owning client. + public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory, + FirebaseClient client) + : base(parent, filterFactory, client) + { + doubleValueFactory = valueFactory; + } + + /// + /// Initializes a new instance of the class. + /// + /// The parent. + /// The filter. + /// The value for filter. + /// The owning client. + public FilterQuery(FirebaseQuery parent, Func filterFactory, Func valueFactory, + FirebaseClient client) + : base(parent, filterFactory, client) + { + boolValueFactory = valueFactory; + } + + /// + /// The build url parameter. + /// + /// The child. + /// Url parameter part of the resulting path. + protected override string BuildUrlParameter(FirebaseQuery child) + { + if (valueFactory != null) + { + 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/dsa/FireBase/Query/FirebaseQuery.cs b/dsa/FireBase/Query/FirebaseQuery.cs new file mode 100644 index 0000000..60d0289 --- /dev/null +++ b/dsa/FireBase/Query/FirebaseQuery.cs @@ -0,0 +1,314 @@ +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 +{ + /// + /// Represents a firebase query. + /// + public abstract class FirebaseQuery : IFirebaseQuery, IDisposable + { + protected readonly FirebaseQuery Parent; + + private HttpClient client; + protected TimeSpan DEFAULT_HTTP_CLIENT_TIMEOUT = new TimeSpan(0, 0, 180); + + /// + /// Initializes a new instance of the class. + /// + /// The parent of this query. + /// The owning client. + protected FirebaseQuery(FirebaseQuery parent, FirebaseClient client) + { + Client = client; + Parent = parent; + } + + /// + /// Disposes this instance. + /// + public void Dispose() + { + client?.Dispose(); + } + + /// + /// Gets the client. + /// + public FirebaseClient Client { get; } + + /// + /// Queries the firebase server once returning collection of items. + /// + /// Optional timeout value. + /// Type of elements. + /// Collection of holding the entities returned by server. + public async Task>> OnceAsync(TimeSpan? timeout = null) + { + var url = string.Empty; + + try + { + url = await BuildUrlAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + throw new FirebaseException("Couldn't build the url", string.Empty, string.Empty, HttpStatusCode.OK, + ex); + } + + return await GetClient(timeout).GetObjectCollectionAsync(url, Client.Options.JsonSerializerSettings) + .ConfigureAwait(false); + } + + /// + /// Starts observing this query watching for changes real time sent by the server. + /// + /// Type of elements. + /// Optional custom root element of received json items. + /// Observable stream of . + public IObservable> AsObservable( + EventHandler> exceptionHandler = null, string elementRoot = "") + { + return Observable.Create>(observer => + { + var sub = new FirebaseSubscription(observer, this, elementRoot, new FirebaseCache()); + sub.ExceptionThrown += exceptionHandler; + return sub.Run(); + }); + } + + /// + /// Builds the actual URL of this query. + /// + /// The . + public async Task 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>> 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. + /// + /// Optional timeout value. + /// Type of elements. + /// Single object of type . + public async Task OnceSingleAsync(TimeSpan? timeout = null) + { + var responseData = string.Empty; + var statusCode = HttpStatusCode.OK; + var url = string.Empty; + + try + { + url = await BuildUrlAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + throw new FirebaseException("Couldn't build the url", string.Empty, responseData, statusCode, ex); + } + + try + { + var response = await GetClient(timeout).GetAsync(url).ConfigureAwait(false); + statusCode = response.StatusCode; + responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + + response.EnsureSuccessStatusCode(); + response.Dispose(); + + return JsonConvert.DeserializeObject(responseData, Client.Options.JsonSerializerSettings); + } + catch (Exception ex) + { + throw new FirebaseException(url, string.Empty, responseData, statusCode, ex); + } + } + + /// + /// Posts given object to repository. + /// + /// The object. + /// Specifies whether the key should be generated offline instead of online. + /// Optional timeout value. + /// Type of + /// Resulting firebase object with populated key. + public async Task> 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, Client).PutAsync(data).ConfigureAwait(false); + + return new FirebaseObject(key, data); + } + + var c = GetClient(timeout); + var sendData = await SendAsync(c, data, HttpMethod.Post).ConfigureAwait(false); + var result = JsonConvert.DeserializeObject(sendData, Client.Options.JsonSerializerSettings); + + return new FirebaseObject(result.Name, data); + } + + /// + /// Patches data at given location instead of overwriting them. + /// + /// The object. + /// Optional timeout value. + /// Type of + /// The . + public async Task PatchAsync(string data, TimeSpan? timeout = null) + { + var c = GetClient(timeout); + + await this.Silent().SendAsync(c, data, new HttpMethod("PATCH")).ConfigureAwait(false); + } + + /// + /// Sets or overwrites data at given location. + /// + /// The object. + /// Optional timeout value. + /// Type of + /// The . + public async Task PutAsync(string data, TimeSpan? timeout = null) + { + var c = GetClient(timeout); + + await this.Silent().SendAsync(c, data, HttpMethod.Put).ConfigureAwait(false); + } + + /// + /// Deletes data from given location. + /// + /// Optional timeout value. + /// The . + public async Task DeleteAsync(TimeSpan? timeout = null) + { + var c = GetClient(timeout); + var url = string.Empty; + var responseData = string.Empty; + var statusCode = HttpStatusCode.OK; + + try + { + url = await BuildUrlAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + throw new FirebaseException("Couldn't build the url", string.Empty, responseData, statusCode, ex); + } + + try + { + var result = await c.DeleteAsync(url).ConfigureAwait(false); + statusCode = result.StatusCode; + responseData = await result.Content.ReadAsStringAsync().ConfigureAwait(false); + + result.EnsureSuccessStatusCode(); + } + catch (Exception ex) + { + throw new FirebaseException(url, string.Empty, responseData, statusCode, ex); + } + } + + /// + /// Build the url segment of this child. + /// + /// The child of this query. + /// The . + protected abstract string BuildUrlSegment(FirebaseQuery child); + + private string BuildUrl(FirebaseQuery child) + { + var url = BuildUrlSegment(child); + + if (Parent != null) url = Parent.BuildUrl(this) + url; + + return url; + } + + private HttpClient GetClient(TimeSpan? timeout = null) + { + if (client == null) client = new HttpClient(); + + if (!timeout.HasValue) + client.Timeout = DEFAULT_HTTP_CLIENT_TIMEOUT; + else + client.Timeout = timeout.Value; + + return client; + } + + private async Task SendAsync(HttpClient client, string data, HttpMethod method) + { + var responseData = string.Empty; + var statusCode = HttpStatusCode.OK; + var requestData = data; + var url = string.Empty; + + try + { + url = await BuildUrlAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + throw new FirebaseException("Couldn't build the url", requestData, responseData, statusCode, ex); + } + + var message = new HttpRequestMessage(method, url) + { + Content = new StringContent(requestData) + }; + + try + { + var result = await client.SendAsync(message).ConfigureAwait(false); + statusCode = result.StatusCode; + responseData = await result.Content.ReadAsStringAsync().ConfigureAwait(false); + + result.EnsureSuccessStatusCode(); + + return responseData; + } + catch (Exception ex) + { + throw new FirebaseException(url, requestData, responseData, statusCode, ex); + } + } + } +} \ No newline at end of file diff --git a/dsa/FireBase/Query/IFirebaseQuery.cs b/dsa/FireBase/Query/IFirebaseQuery.cs new file mode 100644 index 0000000..0da4b15 --- /dev/null +++ b/dsa/FireBase/Query/IFirebaseQuery.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Firebase.Database.Streaming; + +namespace Firebase.Database.Query +{ + /// + /// The FirebaseQuery interface. + /// + public interface IFirebaseQuery + { + /// + /// Gets the owning client of this query. + /// + FirebaseClient Client { get; } + + /// + /// Retrieves items which exist on the location specified by this query instance. + /// + /// Optional timeout value. + /// Type of the items. + /// Collection of . + Task>> OnceAsync(TimeSpan? timeout = null); + + /// + /// Returns current location as an observable which allows to real-time listening to events from the firebase server. + /// + /// Type of the items. + /// Cold observable of . + IObservable> AsObservable( + EventHandler> exceptionHandler, string elementRoot = ""); + + /// + /// Builds the actual url of this query. + /// + /// The . + Task BuildUrlAsync(); + } +} \ No newline at end of file diff --git a/dsa/FireBase/Query/OrderQuery.cs b/dsa/FireBase/Query/OrderQuery.cs new file mode 100644 index 0000000..302d1a3 --- /dev/null +++ b/dsa/FireBase/Query/OrderQuery.cs @@ -0,0 +1,34 @@ +using System; + +namespace Firebase.Database.Query +{ + /// + /// Represents a firebase ordering query, e.g. "?OrderBy=Foo". + /// + public class OrderQuery : ParameterQuery + { + private readonly Func propertyNameFactory; + + /// + /// Initializes a new instance of the class. + /// + /// The query parent. + /// The property name. + /// The owning client. + public OrderQuery(ChildQuery parent, Func propertyNameFactory, FirebaseClient client) + : base(parent, () => "orderBy", client) + { + this.propertyNameFactory = propertyNameFactory; + } + + /// + /// The build url parameter. + /// + /// The child. + /// The . + protected override string BuildUrlParameter(FirebaseQuery child) + { + return $"\"{propertyNameFactory()}\""; + } + } +} \ No newline at end of file diff --git a/dsa/FireBase/Query/ParameterQuery.cs b/dsa/FireBase/Query/ParameterQuery.cs new file mode 100644 index 0000000..572224c --- /dev/null +++ b/dsa/FireBase/Query/ParameterQuery.cs @@ -0,0 +1,43 @@ +using System; + +namespace Firebase.Database.Query +{ + /// + /// Represents a parameter in firebase query, e.g. "?data=foo". + /// + public abstract class ParameterQuery : FirebaseQuery + { + private readonly Func parameterFactory; + private readonly string separator; + + /// + /// Initializes a new instance of the class. + /// + /// The parent of this query. + /// The parameter. + /// The owning client. + protected ParameterQuery(FirebaseQuery parent, Func parameterFactory, FirebaseClient client) + : base(parent, client) + { + this.parameterFactory = parameterFactory; + separator = Parent is ChildQuery ? "?" : "&"; + } + + /// + /// Build the url segment represented by this query. + /// + /// The child. + /// The . + protected override string BuildUrlSegment(FirebaseQuery child) + { + return $"{separator}{parameterFactory()}={BuildUrlParameter(child)}"; + } + + /// + /// The build url parameter. + /// + /// The child. + /// The . + protected abstract string BuildUrlParameter(FirebaseQuery child); + } +} \ No newline at end of file diff --git a/dsa/FireBase/Query/QueryExtensions.cs b/dsa/FireBase/Query/QueryExtensions.cs new file mode 100644 index 0000000..df2edfc --- /dev/null +++ b/dsa/FireBase/Query/QueryExtensions.cs @@ -0,0 +1,210 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace Firebase.Database.Query +{ + /// + /// Query extensions providing linq like syntax for firebase server methods. + /// + public static class QueryExtensions + { + /// + /// Adds an auth parameter to the query. + /// + /// The child. + /// The auth token. + /// The . + internal static AuthQuery WithAuth(this FirebaseQuery node, string token) + { + return node.WithAuth(() => token); + } + + /// + /// Appends print=silent to save bandwidth. + /// + /// The child. + /// The . + internal static SilentQuery Silent(this FirebaseQuery node) + { + return new SilentQuery(node, node.Client); + } + + /// + /// References a sub child of the existing node. + /// + /// The child. + /// The path of sub child. + /// The . + public static ChildQuery Child(this ChildQuery node, string path) + { + return node.Child(() => path); + } + + /// + /// Order data by given . Note that this is used mainly for following filtering queries and + /// due to firebase implementation + /// the data may actually not be ordered. + /// + /// The child. + /// The property name. + /// The . + public static OrderQuery OrderBy(this ChildQuery child, string propertyName) + { + return child.OrderBy(() => propertyName); + } + + /// + /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy + /// query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery StartAt(this ParameterQuery child, string value) + { + return child.StartAt(() => value); + } + + /// + /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy + /// query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EndAt(this ParameterQuery child, string value) + { + return child.EndAt(() => value); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, string value) + { + return child.EqualTo(() => value); + } + + /// + /// Instructs firebase to send data greater or equal to the . This must be preceded by an OrderBy + /// query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery StartAt(this ParameterQuery child, double value) + { + return child.StartAt(() => value); + } + + /// + /// Instructs firebase to send data lower or equal to the . This must be preceded by an OrderBy + /// query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EndAt(this ParameterQuery child, double value) + { + return child.EndAt(() => value); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, double value) + { + return child.EqualTo(() => value); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, bool value) + { + return child.EqualTo(() => value); + } + + /// + /// Instructs firebase to send data equal to null. This must be preceded by an OrderBy query. + /// + /// Current node. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child) + { + return child.EqualTo(() => null); + } + + /// + /// Limits the result to first items. + /// + /// Current node. + /// Number of elements. + /// The . + public static FilterQuery LimitToFirst(this ParameterQuery child, int count) + { + return child.LimitToFirst(() => count); + } + + /// + /// Limits the result to last items. + /// + /// Current node. + /// Number of elements. + /// The . + public static FilterQuery LimitToLast(this ParameterQuery child, int count) + { + return child.LimitToLast(() => count); + } + + public static Task PutAsync(this FirebaseQuery query, T obj) + { + return query.PutAsync(JsonConvert.SerializeObject(obj, query.Client.Options.JsonSerializerSettings)); + } + + public static Task PatchAsync(this FirebaseQuery query, T obj) + { + return query.PatchAsync(JsonConvert.SerializeObject(obj, query.Client.Options.JsonSerializerSettings)); + } + + public static async Task> PostAsync(this FirebaseQuery query, T obj, + bool generateKeyOffline = true) + { + var result = + await query.PostAsync(JsonConvert.SerializeObject(obj, query.Client.Options.JsonSerializerSettings), + generateKeyOffline); + + return new FirebaseObject(result.Key, obj); + } + + /// + /// 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. + /// + /// Type of object to fan out. + /// Current node. + /// Object to fan out. + /// Locations where to store the item. + public static async Task FanOut(this ChildQuery child, T item, params string[] relativePaths) + { + if (relativePaths == null) throw new ArgumentNullException(nameof(relativePaths)); + + var fanoutObject = new Dictionary(relativePaths.Length); + + foreach (var path in relativePaths) fanoutObject.Add(path, item); + + await child.PatchAsync(fanoutObject); + } + } +} \ No newline at end of file diff --git a/dsa/FireBase/Query/QueryFactoryExtensions.cs b/dsa/FireBase/Query/QueryFactoryExtensions.cs new file mode 100644 index 0000000..71dae5c --- /dev/null +++ b/dsa/FireBase/Query/QueryFactoryExtensions.cs @@ -0,0 +1,187 @@ +using System; + +namespace Firebase.Database.Query +{ + /// + /// Query extensions providing linq like syntax for firebase server methods. + /// + public static class QueryFactoryExtensions + { + /// + /// Adds an auth parameter to the query. + /// + /// The child. + /// The auth token. + /// The . + internal static AuthQuery WithAuth(this FirebaseQuery node, Func tokenFactory) + { + return new AuthQuery(node, tokenFactory, node.Client); + } + + /// + /// References a sub child of the existing node. + /// + /// The child. + /// The path of sub child. + /// The . + public static ChildQuery Child(this ChildQuery node, Func pathFactory) + { + return new ChildQuery(node, pathFactory, node.Client); + } + + /// + /// Order data by given . Note that this is used mainly for following filtering + /// queries and due to firebase implementation + /// the data may actually not be ordered. + /// + /// The child. + /// The property name. + /// The . + public static OrderQuery OrderBy(this ChildQuery child, Func propertyNameFactory) + { + return new OrderQuery(child, propertyNameFactory, child.Client); + } + + /// + /// 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. + /// + /// The child. + /// The . + public static OrderQuery OrderByKey(this ChildQuery child) + { + return child.OrderBy("$key"); + } + + /// + /// 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. + /// + /// The child. + /// The . + public static OrderQuery OrderByValue(this ChildQuery child) + { + return child.OrderBy("$value"); + } + + /// + /// 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. + /// + /// The child. + /// The . + public static OrderQuery OrderByPriority(this ChildQuery child) + { + return child.OrderBy("$priority"); + } + + /// + /// Instructs firebase to send data greater or equal to the . This must be preceded by an + /// OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery StartAt(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "startAt", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data lower or equal to the . This must be preceded by an + /// OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EndAt(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "endAt", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy + /// query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "equalTo", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data greater or equal to the . This must be preceded by an + /// OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery StartAt(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "startAt", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data lower or equal to the . This must be preceded by an + /// OrderBy query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EndAt(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "endAt", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy + /// query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "equalTo", valueFactory, child.Client); + } + + /// + /// Instructs firebase to send data equal to the . This must be preceded by an OrderBy + /// query. + /// + /// Current node. + /// Value to start at. + /// The . + public static FilterQuery EqualTo(this ParameterQuery child, Func valueFactory) + { + return new FilterQuery(child, () => "equalTo", valueFactory, child.Client); + } + + /// + /// Limits the result to first items. + /// + /// Current node. + /// Number of elements. + /// The . + public static FilterQuery LimitToFirst(this ParameterQuery child, Func countFactory) + { + return new FilterQuery(child, () => "limitToFirst", () => countFactory(), child.Client); + } + + /// + /// Limits the result to last items. + /// + /// Current node. + /// Number of elements. + /// The . + public static FilterQuery LimitToLast(this ParameterQuery child, Func countFactory) + { + return new FilterQuery(child, () => "limitToLast", () => countFactory(), child.Client); + } + } +} \ No newline at end of file diff --git a/dsa/FireBase/Query/SilentQuery.cs b/dsa/FireBase/Query/SilentQuery.cs new file mode 100644 index 0000000..d09d38b --- /dev/null +++ b/dsa/FireBase/Query/SilentQuery.cs @@ -0,0 +1,18 @@ +namespace Firebase.Database.Query +{ + /// + /// Appends print=silent to the url. + /// + public class SilentQuery : ParameterQuery + { + public SilentQuery(FirebaseQuery parent, FirebaseClient client) + : base(parent, () => "print", client) + { + } + + protected override string BuildUrlParameter(FirebaseQuery child) + { + return "silent"; + } + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf