Skip to content

Commit 6f2e39f

Browse files
authored
Merge pull request step-up-labs#213 from cabauman/xml-docs-and-minor-optimizations
xml doc fixes and minor optimizations
2 parents 2b55d6f + 6c3c7c0 commit 6f2e39f

14 files changed

+73
-63
lines changed

src/Firebase/FirebaseClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class FirebaseClient : IDisposable
2525
/// Initializes a new instance of the <see cref="FirebaseClient"/> class.
2626
/// </summary>
2727
/// <param name="baseUrl"> The base url. </param>
28-
/// <param name="offlineDatabaseFactory"> Offline database. </param>
28+
/// <param name="options"> The Firebase options. </param>
2929
public FirebaseClient(string baseUrl, FirebaseOptions options = null)
3030
{
3131
this.Options = options ?? new FirebaseOptions();

src/Firebase/FirebaseKeyGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Firebase.Database
77
/// Offline key generator which mimics the official Firebase generators.
88
/// Credit: https://github.com/bubbafat/FirebaseSharp/blob/master/src/FirebaseSharp.Portable/FireBasePushIdGenerator.cs
99
/// </summary>
10-
public class FirebaseKeyGenerator
10+
public static class FirebaseKeyGenerator
1111
{
1212
// Modeled after base64 web-safe chars, but ordered by ASCII.
1313
private const string PushCharsString = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";

src/Firebase/FirebaseObject.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Firebase.Database
22
{
33
/// <summary>
4-
/// Holds the object of type <typeparam name="T" /> along with its key.
4+
/// Holds the object of type <typeparamref name="T" /> along with its key.
55
/// </summary>
66
/// <typeparam name="T"> Type of the underlying object. </typeparam>
77
public class FirebaseObject<T>

src/Firebase/Http/HttpClientExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static async Task<IReadOnlyCollection<FirebaseObject<T>>> GetObjectCollec
4141

4242
if (dictionary == null)
4343
{
44-
return new FirebaseObject<T>[0];
44+
return Array.Empty<FirebaseObject<T>>();
4545
}
4646

4747
return dictionary.Select(item => new FirebaseObject<T>(item.Key, item.Value)).ToList();

src/Firebase/Offline/DatabaseExtensions.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public static class DatabaseExtensions
1313
/// Create new instances of the <see cref="RealtimeDatabase{T}"/>.
1414
/// </summary>
1515
/// <typeparam name="T"> Type of elements. </typeparam>
16+
/// <param name="query"> The child query. </param>
1617
/// <param name="filenameModifier"> Custom string which will get appended to the file name. </param>
1718
/// <param name="elementRoot"> Optional custom root element of received json items. </param>
1819
/// <param name="streamingOptions"> Realtime streaming options. </param>
@@ -30,6 +31,7 @@ public static RealtimeDatabase<T> AsRealtimeDatabase<T>(this ChildQuery query, s
3031
/// </summary>
3132
/// <typeparam name="T"> Type of elements. </typeparam>
3233
/// <typeparam name="TSetHandler"> Type of the custom <see cref="ISetHandler{T}"/> to use. </typeparam>
34+
/// <param name="query"> The child query. </param>
3335
/// <param name="filenameModifier"> Custom string which will get appended to the file name. </param>
3436
/// <param name="elementRoot"> Optional custom root element of received json items. </param>
3537
/// <param name="streamingOptions"> Realtime streaming options. </param>
@@ -46,6 +48,7 @@ public static RealtimeDatabase<T> AsRealtimeDatabase<T, TSetHandler>(this ChildQ
4648
/// <summary>
4749
/// Overwrites existing object with given key leaving any missing properties intact in firebase.
4850
/// </summary>
51+
/// <param name="db"> Database instance. </param>
4952
/// <param name="key"> The key. </param>
5053
/// <param name="obj"> The object to set. </param>
5154
/// <param name="syncOnline"> Indicates whether the item should be synced online. </param>
@@ -59,6 +62,7 @@ public static void Patch<T>(this RealtimeDatabase<T> db, string key, T obj, bool
5962
/// <summary>
6063
/// Overwrites existing object with given key.
6164
/// </summary>
65+
/// <param name="db"> Database instance. </param>
6266
/// <param name="key"> The key. </param>
6367
/// <param name="obj"> The object to set. </param>
6468
/// <param name="syncOnline"> Indicates whether the item should be synced online. </param>
@@ -72,6 +76,7 @@ public static void Put<T>(this RealtimeDatabase<T> db, string key, T obj, bool s
7276
/// <summary>
7377
/// Adds a new entity to the Database.
7478
/// </summary>
79+
/// <param name="db"> Database instance. </param>
7580
/// <param name="obj"> The object to add. </param>
7681
/// <param name="syncOnline"> Indicates whether the item should be synced online. </param>
7782
/// <param name="priority"> The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. </param>
@@ -89,6 +94,7 @@ public static string Post<T>(this RealtimeDatabase<T> db, T obj, bool syncOnline
8994
/// <summary>
9095
/// Deletes the entity with the given key.
9196
/// </summary>
97+
/// <param name="db"> Database instance. </param>
9298
/// <param name="key"> The key. </param>
9399
/// <param name="syncOnline"> Indicates whether the item should be synced online. </param>
94100
/// <param name="priority"> The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. </param>
@@ -140,7 +146,6 @@ public static void Patch<T, TProperty>(this RealtimeDatabase<T> db, string key,
140146
/// <param name="db"> Database instance. </param>
141147
/// <param name="key"> Key of the root element to modify. </param>
142148
/// <param name="propertyExpression"> Expression on the root element leading to target value to modify. </param>
143-
/// <param name="value"> Value to put. </param>
144149
/// <param name="syncOnline"> Indicates whether the item should be synced online. </param>
145150
/// <param name="priority"> The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. </param>
146151
public static void Delete<T, TProperty>(this RealtimeDatabase<T> db, string key, Expression<Func<T, TProperty>> propertyExpression, bool syncOnline = true, int priority = 1)
@@ -177,7 +182,6 @@ public static void Post<T, TSelector, TProperty>(this RealtimeDatabase<T> db, st
177182
/// The key of the new entity is automatically generated.
178183
/// </summary>
179184
/// <typeparam name="T"> Type of the root elements. </typeparam>
180-
/// <typeparam name="TSelector"> Type of the dictionary being modified</typeparam>
181185
/// <typeparam name="TProperty"> Type of the value within the dictionary being modified</typeparam>
182186
/// <param name="db"> Database instance. </param>
183187
/// <param name="key"> Key of the root element to modify. </param>

src/Firebase/Offline/OfflineEntry.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ public class OfflineEntry
1616
/// </summary>
1717
/// <param name="key"> The key. </param>
1818
/// <param name="obj"> The object. </param>
19-
/// <param name="priority"> The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. </param>
19+
/// <param name="data"> The json data. </param>
20+
/// <param name="priority"> The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. </param>
2021
/// <param name="syncOptions"> The sync options. </param>
22+
/// <param name="isPartial"> A value indicating whether this is only a partial object. </param>
2123
public OfflineEntry(string key, object obj, string data, int priority, SyncOptions syncOptions, bool isPartial = false)
2224
{
2325
this.Key = key;
@@ -37,6 +39,7 @@ public OfflineEntry(string key, object obj, string data, int priority, SyncOptio
3739
/// <param name="obj"> The object. </param>
3840
/// <param name="priority"> The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. </param>
3941
/// <param name="syncOptions"> The sync options. </param>
42+
/// <param name="isPartial"> A value indicating whether this is only a partial object. </param>
4043
public OfflineEntry(string key, object obj, int priority, SyncOptions syncOptions, bool isPartial = false)
4144
: this(key, obj, JsonConvert.SerializeObject(obj), priority, syncOptions, isPartial)
4245
{

src/Firebase/Offline/RealtimeDatabase.cs

+13-12
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ public partial class RealtimeDatabase<T> : IDisposable where T : class
4343
/// <param name="elementRoot"> The element Root. </param>
4444
/// <param name="offlineDatabaseFactory"> The offline database factory. </param>
4545
/// <param name="filenameModifier"> Custom string which will get appended to the file name. </param>
46-
/// <param name="streamChanges"> Specifies whether changes should be streamed from the server. </param>
47-
/// <param name="pullEverythingOnStart"> Specifies if everything should be pull from the online storage on start. It only makes sense when <see cref="streamChanges"/> is set to true. </param>
46+
/// <param name="streamingOptions"> Specifies condition for which items get streamed. </param>
47+
/// <param name="initialPullStrategy"> Specifies the strategy for initial pull of server data. </param>
4848
/// <param name="pushChanges"> Specifies whether changed items should actually be pushed to the server. If this is false, then Put / Post / Delete will not affect server data. </param>
49+
/// <param name="setHandler"></param>
4950
public RealtimeDatabase(ChildQuery childQuery, string elementRoot, Func<Type, string, IDictionary<string, OfflineEntry>> offlineDatabaseFactory, string filenameModifier, StreamingOptions streamingOptions, InitialPullStrategy initialPullStrategy, bool pushChanges, ISetHandler<T> setHandler = null)
5051
{
5152
this.childQuery = childQuery;
@@ -93,7 +94,7 @@ public ISetHandler<T> PutHandler
9394
/// </summary>
9495
/// <param name="key"> The key. </param>
9596
/// <param name="obj"> The object to set. </param>
96-
/// <param name="syncOnline"> Indicates whether the item should be synced online. </param>
97+
/// <param name="syncOptions"> Specifies type of sync requested for given data. </param>
9798
/// <param name="priority"> The priority. Objects with higher priority will be synced first. Higher number indicates higher priority. </param>
9899
public void Set(string key, T obj, SyncOptions syncOptions, int priority = 1)
99100
{
@@ -293,7 +294,7 @@ private IObservable<IReadOnlyCollection<FirebaseObject<T>>> GetInitialPullObserv
293294
}
294295

295296
// there is an element root, which indicates the target location is not a collection but a single element
296-
return Observable.Defer(async () => Observable.Return(await query.OnceSingleAsync<T>()).Select(e => new[] { new FirebaseObject<T>(this.elementRoot, e) }));
297+
return Observable.Defer(async () => Observable.Return(await query.OnceSingleAsync<T>().ConfigureAwait(false)).Select(e => new[] { new FirebaseObject<T>(this.elementRoot, e) }));
297298
}
298299

299300
private IDisposable InitializeStreamingSubscription(IObserver<FirebaseEvent<T>> observer)
@@ -336,19 +337,19 @@ private async void SynchronizeThread()
336337
try
337338
{
338339
var validEntries = this.Database.Where(e => e.Value != null);
339-
await this.PullEntriesAsync(validEntries.Where(kvp => kvp.Value.SyncOptions == SyncOptions.Pull));
340+
await PullEntriesAsync(validEntries.Where(kvp => kvp.Value.SyncOptions == SyncOptions.Pull)).ConfigureAwait(false);
340341

341342
if (this.pushChanges)
342343
{
343-
await this.PushEntriesAsync(validEntries.Where(kvp => kvp.Value.SyncOptions == SyncOptions.Put || kvp.Value.SyncOptions == SyncOptions.Patch));
344+
await PushEntriesAsync(validEntries.Where(kvp => kvp.Value.SyncOptions == SyncOptions.Put || kvp.Value.SyncOptions == SyncOptions.Patch)).ConfigureAwait(false);
344345
}
345346
}
346347
catch (Exception ex)
347348
{
348349
this.SyncExceptionThrown?.Invoke(this, new ExceptionEventArgs(ex));
349350
}
350351

351-
await Task.Delay(this.childQuery.Client.Options.SyncPeriod);
352+
await Task.Delay(childQuery.Client.Options.SyncPeriod).ConfigureAwait(false);
352353
}
353354
}
354355

@@ -377,7 +378,7 @@ private async Task PushEntriesAsync(IEnumerable<KeyValuePair<string, OfflineEntr
377378

378379
try
379380
{
380-
await Task.WhenAll(tasks).WithAggregateException();
381+
await Task.WhenAll(tasks).WithAggregateException().ConfigureAwait(false);
381382
}
382383
catch (Exception ex)
383384
{
@@ -396,7 +397,7 @@ private async Task PullEntriesAsync(IEnumerable<KeyValuePair<string, OfflineEntr
396397

397398
try
398399
{
399-
await Task.WhenAll(tasks).WithAggregateException();
400+
await Task.WhenAll(tasks).WithAggregateException().ConfigureAwait(false);
400401
}
401402
catch (Exception ex)
402403
{
@@ -407,13 +408,13 @@ private async Task PullEntriesAsync(IEnumerable<KeyValuePair<string, OfflineEntr
407408

408409
private async Task ResetAfterPull(Task<T> task, string key, OfflineEntry entry)
409410
{
410-
await task;
411+
await task.ConfigureAwait(false);
411412
this.SetAndRaise(key, new OfflineEntry(key, task.Result, entry.Priority, SyncOptions.None), FirebaseEventSource.OnlinePull);
412413
}
413414

414415
private async Task ResetSyncAfterPush(Task task, string key, T obj)
415416
{
416-
await this.ResetSyncAfterPush(task, key);
417+
await ResetSyncAfterPush(task, key).ConfigureAwait(false);
417418

418419
if (this.streamingOptions == StreamingOptions.None)
419420
{
@@ -423,7 +424,7 @@ private async Task ResetSyncAfterPush(Task task, string key, T obj)
423424

424425
private async Task ResetSyncAfterPush(Task task, string key)
425426
{
426-
await task;
427+
await task.ConfigureAwait(false);
427428
this.ResetSyncOptions(key);
428429
}
429430

src/Firebase/Offline/SetHandler.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66

77
public class SetHandler<T> : ISetHandler<T>
88
{
9-
public virtual async Task SetAsync(ChildQuery query, string key, OfflineEntry entry)
9+
public virtual Task SetAsync(ChildQuery query, string key, OfflineEntry entry)
1010
{
1111
using (var child = query.Child(key))
1212
{
1313
if (entry.SyncOptions == SyncOptions.Put)
1414
{
15-
await child.PutAsync(entry.Data);
15+
return child.PutAsync(entry.Data);
1616
}
1717
else
1818
{
19-
await child.PatchAsync(entry.Data);
19+
20+
return child.PatchAsync(entry.Data);
2021
}
2122
}
2223
}

src/Firebase/Query/FirebaseQuery.cs

+8-10
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public async Task<T> OnceSingleAsync<T>(TimeSpan? timeout = null)
109109
/// Starts observing this query watching for changes real time sent by the server.
110110
/// </summary>
111111
/// <typeparam name="T"> Type of elements. </typeparam>
112+
/// <param name="exceptionHandler"> Optional exception handler for the stream subscription. </param>
112113
/// <param name="elementRoot"> Optional custom root element of received json items. </param>
113114
/// <returns> Observable stream of <see cref="FirebaseEvent{T}"/>. </returns>
114115
public IObservable<FirebaseEvent<T>> AsObservable<T>(EventHandler<ContinueExceptionEventArgs<FirebaseException>> exceptionHandler = null, string elementRoot = "")
@@ -140,10 +141,9 @@ public async Task<string> BuildUrlAsync()
140141
/// <summary>
141142
/// Posts given object to repository.
142143
/// </summary>
143-
/// <param name="obj"> The object. </param>
144+
/// <param name="data"> The json data. </param>
144145
/// <param name="generateKeyOffline"> Specifies whether the key should be generated offline instead of online. </param>
145146
/// <param name="timeout"> Optional timeout value. </param>
146-
/// <typeparam name="T"> Type of <see cref="obj"/> </typeparam>
147147
/// <returns> Resulting firebase object with populated key. </returns>
148148
public async Task<FirebaseObject<string>> PostAsync(string data, bool generateKeyOffline = true, TimeSpan? timeout = null)
149149
{
@@ -168,29 +168,27 @@ public async Task<FirebaseObject<string>> PostAsync(string data, bool generateKe
168168
/// <summary>
169169
/// Patches data at given location instead of overwriting them.
170170
/// </summary>
171-
/// <param name="obj"> The object. </param>
171+
/// <param name="data"> The json data. </param>
172172
/// <param name="timeout"> Optional timeout value. </param>
173-
/// <typeparam name="T"> Type of <see cref="obj"/> </typeparam>
174173
/// <returns> The <see cref="Task"/>. </returns>
175-
public async Task PatchAsync(string data, TimeSpan? timeout = null)
174+
public Task PatchAsync(string data, TimeSpan? timeout = null)
176175
{
177176
var c = this.GetClient(timeout);
178177

179-
await this.Silent().SendAsync(c, data, new HttpMethod("PATCH")).ConfigureAwait(false);
178+
return this.Silent().SendAsync(c, data, new HttpMethod("PATCH"));
180179
}
181180

182181
/// <summary>
183182
/// Sets or overwrites data at given location.
184183
/// </summary>
185-
/// <param name="obj"> The object. </param>
184+
/// <param name="data"> The json data. </param>
186185
/// <param name="timeout"> Optional timeout value. </param>
187-
/// <typeparam name="T"> Type of <see cref="obj"/> </typeparam>
188186
/// <returns> The <see cref="Task"/>. </returns>
189-
public async Task PutAsync(string data, TimeSpan? timeout = null)
187+
public Task PutAsync(string data, TimeSpan? timeout = null)
190188
{
191189
var c = this.GetClient(timeout);
192190

193-
await this.Silent().SendAsync(c, data, HttpMethod.Put).ConfigureAwait(false);
191+
return this.Silent().SendAsync(c, data, HttpMethod.Put);
194192
}
195193

196194
/// <summary>

0 commit comments

Comments
 (0)