summaryrefslogtreecommitdiff
path: root/dsa/FireBase/Offline/ConcurrentOfflineDatabase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'dsa/FireBase/Offline/ConcurrentOfflineDatabase.cs')
-rw-r--r--dsa/FireBase/Offline/ConcurrentOfflineDatabase.cs51
1 files changed, 17 insertions, 34 deletions
diff --git a/dsa/FireBase/Offline/ConcurrentOfflineDatabase.cs b/dsa/FireBase/Offline/ConcurrentOfflineDatabase.cs
index 1a9e607..724115f 100644
--- a/dsa/FireBase/Offline/ConcurrentOfflineDatabase.cs
+++ b/dsa/FireBase/Offline/ConcurrentOfflineDatabase.cs
@@ -6,13 +6,11 @@ using System.IO;
using System.Linq;
using LiteDB;
-namespace Firebase.Database.Offline
-{
+namespace Firebase.Database.Offline {
/// <summary>
/// The offline database.
/// </summary>
- public class ConcurrentOfflineDatabase : IDictionary<string, OfflineEntry>
- {
+ public class ConcurrentOfflineDatabase : IDictionary<string, OfflineEntry> {
private readonly ConcurrentDictionary<string, OfflineEntry> ccache;
private readonly LiteRepository db;
@@ -21,8 +19,7 @@ namespace Firebase.Database.Offline
/// </summary>
/// <param name="itemType"> The item type which is used to determine the database file name. </param>
/// <param name="filenameModifier"> Custom string which will get appended to the file name. </param>
- public ConcurrentOfflineDatabase(Type itemType, string filenameModifier)
- {
+ public ConcurrentOfflineDatabase(Type itemType, string filenameModifier) {
var fullName = GetFileName(itemType.ToString());
if (fullName.Length > 100) fullName = fullName.Substring(0, 100);
@@ -78,12 +75,10 @@ namespace Firebase.Database.Offline
/// </summary>
/// <param name="key">The key of the element to get or set.</param>
/// <returns> The element with the specified key. </returns>
- public OfflineEntry this[string key]
- {
+ public OfflineEntry this[string key] {
get => ccache[key];
- set
- {
+ set {
ccache.AddOrUpdate(key, value, (k, existing) => value);
db.Upsert(value);
}
@@ -93,13 +88,11 @@ namespace Firebase.Database.Offline
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns> An enumerator that can be used to iterate through the collection. </returns>
- public IEnumerator<KeyValuePair<string, OfflineEntry>> GetEnumerator()
- {
+ public IEnumerator<KeyValuePair<string, OfflineEntry>> GetEnumerator() {
return ccache.GetEnumerator();
}
- IEnumerator IEnumerable.GetEnumerator()
- {
+ IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
@@ -107,16 +100,14 @@ namespace Firebase.Database.Offline
/// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1" />.
/// </summary>
/// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1" />.</param>
- public void Add(KeyValuePair<string, OfflineEntry> item)
- {
+ public void Add(KeyValuePair<string, OfflineEntry> item) {
Add(item.Key, item.Value);
}
/// <summary>
/// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1" />.
/// </summary>
- public void Clear()
- {
+ public void Clear() {
ccache.Clear();
db.Delete<OfflineEntry>(LiteDB.Query.All());
}
@@ -129,8 +120,7 @@ namespace Firebase.Database.Offline
/// True if <paramref name="item" /> is found in the <see cref="T:System.Collections.Generic.ICollection`1" />;
/// otherwise, false.
/// </returns>
- public bool Contains(KeyValuePair<string, OfflineEntry> item)
- {
+ public bool Contains(KeyValuePair<string, OfflineEntry> item) {
return ContainsKey(item.Key);
}
@@ -144,8 +134,7 @@ namespace Firebase.Database.Offline
/// zero-based indexing.
/// </param>
/// <param name="arrayIndex">The zero-based index in <paramref name="array" /> at which copying begins.</param>
- public void CopyTo(KeyValuePair<string, OfflineEntry>[] array, int arrayIndex)
- {
+ public void CopyTo(KeyValuePair<string, OfflineEntry>[] array, int arrayIndex) {
ccache.ToList().CopyTo(array, arrayIndex);
}
@@ -159,8 +148,7 @@ namespace Firebase.Database.Offline
/// <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false. This method also returns false if
/// <paramref name="item" /> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1" />.
/// </returns>
- public bool Remove(KeyValuePair<string, OfflineEntry> item)
- {
+ public bool Remove(KeyValuePair<string, OfflineEntry> item) {
return Remove(item.Key);
}
@@ -173,8 +161,7 @@ namespace Firebase.Database.Offline
/// True if the <see cref="T:System.Collections.Generic.IDictionary`2" /> contains an element with the key;
/// otherwise, false.
/// </returns>
- public bool ContainsKey(string key)
- {
+ public bool ContainsKey(string key) {
return ccache.ContainsKey(key);
}
@@ -183,8 +170,7 @@ namespace Firebase.Database.Offline
/// </summary>
/// <param name="key">The object to use as the key of the element to add.</param>
/// <param name="value">The object to use as the value of the element to add.</param>
- public void Add(string key, OfflineEntry value)
- {
+ public void Add(string key, OfflineEntry value) {
ccache.AddOrUpdate(key, value, (k, existing) => value);
db.Upsert(value);
}
@@ -197,8 +183,7 @@ namespace Firebase.Database.Offline
/// True if the element is successfully removed; otherwise, false. This method also returns false if
/// <paramref name="key" /> was not found in the original <see cref="T:System.Collections.Generic.IDictionary`2" />.
/// </returns>
- public bool Remove(string key)
- {
+ public bool Remove(string key) {
ccache.TryRemove(key, out _);
return db.Delete<OfflineEntry>(key);
}
@@ -216,13 +201,11 @@ namespace Firebase.Database.Offline
/// True if the object that implements <see cref="T:System.Collections.Generic.IDictionary`2" /> contains an
/// element with the specified key; otherwise, false.
/// </returns>
- public bool TryGetValue(string key, out OfflineEntry value)
- {
+ public bool TryGetValue(string key, out OfflineEntry value) {
return ccache.TryGetValue(key, out value);
}
- private string GetFileName(string fileName)
- {
+ private string GetFileName(string fileName) {
var invalidChars = new[] {'`', '[', ',', '='};
foreach (var c in invalidChars.Concat(Path.GetInvalidFileNameChars()).Distinct())
fileName = fileName.Replace(c, '_');