diff options
author | Dennis Kobert <d-kobert@web.de> | 2019-06-12 21:47:51 +0200 |
---|---|---|
committer | Dennis Kobert <d-kobert@web.de> | 2019-06-12 21:47:51 +0200 |
commit | 304437b834e8c87687f68333ae67a13ee1377a73 (patch) | |
tree | 51dd246568e8a159627d9cb92e99890adb5cbef8 /dsa/FireBase/Offline/ConcurrentOfflineDatabase.cs | |
parent | 2fa4a0e50ebfc97059c8b84dbd17e79f9afc8a8d (diff) |
Adjust Codestyle
Diffstat (limited to 'dsa/FireBase/Offline/ConcurrentOfflineDatabase.cs')
-rw-r--r-- | dsa/FireBase/Offline/ConcurrentOfflineDatabase.cs | 51 |
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, '_'); |