From 3d0bd21ef90271d1bd8365667f7bc2a9915897e0 Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Fri, 13 May 2022 13:07:24 +0100 Subject: [PATCH 1/2] Fix GetOrCreateObject Update Copyright date range GetOrCreateObject did not add any data to the database Copyright updated form 2019 to 2021 to 2019 to 2022 Update formatting Use auto Null parameter check where possible i.e. key!! --- .../SystemJsonSerializer.cs | 2 +- .../Program.cs | 2 +- .../Utility.cs | 2 +- .../CoreRegistrations.cs | 2 +- .../HttpExtensions.cs | 2 +- .../HttpService.cs | 2 +- .../IBlobCache.cs | 2 +- .../IHttpService.cs | 2 +- .../ISecureBlobCache.cs | 2 +- .../ISerializer.cs | 2 +- .../LoginExtensions.cs | 2 +- .../LoginInfo.cs | 2 +- .../PreserveAttribute.cs | 2 +- .../Properties/AssemblyInfo.cs | 2 +- .../RelativeTimeExtensions.cs | 2 +- .../SerializerExtensions.cs | 168 ++++++------------ .../NewtonsoftSerializer.cs | 2 +- .../CacheEntry.cs | 2 +- .../SqliteBlobCache.cs | 2 +- .../BlobCacheTestsBase.cs | 2 +- .../EncryptedSqliteBlobCacheTests.cs | 2 +- .../Helpers/IntegrationTestHelper.cs | 2 +- .../Helpers/Utility.cs | 2 +- .../Mocks/UserModel.cs | 2 +- .../Mocks/UserObject.cs | 2 +- .../SqliteBlobCacheTests.cs | 2 +- src/stylecop.json | 2 +- 27 files changed, 84 insertions(+), 136 deletions(-) diff --git a/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs b/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs index 6198076..fd65950 100644 --- a/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs +++ b/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Benchmarks/Program.cs b/src/ReactiveMarbles.CacheDatabase.Benchmarks/Program.cs index 47434bf..f3f1717 100644 --- a/src/ReactiveMarbles.CacheDatabase.Benchmarks/Program.cs +++ b/src/ReactiveMarbles.CacheDatabase.Benchmarks/Program.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs b/src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs index 318cac7..8b6bd9d 100644 --- a/src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs +++ b/src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs b/src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs index 0b9f8c1..7d421c7 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/HttpExtensions.cs b/src/ReactiveMarbles.CacheDatabase.Core/HttpExtensions.cs index 13deddd..6d5bdad 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/HttpExtensions.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/HttpExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/HttpService.cs b/src/ReactiveMarbles.CacheDatabase.Core/HttpService.cs index c5de784..6d930d8 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/HttpService.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/HttpService.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/IBlobCache.cs b/src/ReactiveMarbles.CacheDatabase.Core/IBlobCache.cs index 60c07d8..13eae28 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/IBlobCache.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/IBlobCache.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs b/src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs index 4a18aea..1258b0a 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs b/src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs index fef8917..e111fe6 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs b/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs index 02e4860..5064939 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs b/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs index b8e0e9d..23ae626 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs b/src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs index 3e4e918..886316d 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs b/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs index 181574d..00fb32b 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/Properties/AssemblyInfo.cs b/src/ReactiveMarbles.CacheDatabase.Core/Properties/AssemblyInfo.cs index 13ff891..0125460 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/Properties/AssemblyInfo.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/RelativeTimeExtensions.cs b/src/ReactiveMarbles.CacheDatabase.Core/RelativeTimeExtensions.cs index d02736e..6b5fb30 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/RelativeTimeExtensions.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/RelativeTimeExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Core/SerializerExtensions.cs b/src/ReactiveMarbles.CacheDatabase.Core/SerializerExtensions.cs index 6e50356..8abebec 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/SerializerExtensions.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/SerializerExtensions.cs @@ -1,17 +1,15 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Globalization; using System.Linq; using System.Reactive; using System.Reactive.Linq; using System.Reactive.Subjects; using System.Reactive.Threading.Tasks; -using System.Text; using System.Threading.Tasks; namespace ReactiveMarbles.CacheDatabase.Core @@ -21,7 +19,7 @@ namespace ReactiveMarbles.CacheDatabase.Core /// public static class SerializerExtensions { - private static ISerializer Serializer => CoreRegistrations.Serializer ?? throw new InvalidOperationException("Unable to resolve ISerializer, make sure you are including the correct CacheDatabase NuGet packages."); + private static ISerializer Serializer => CoreRegistrations.Serializer ?? throw new InvalidOperationException("Unable to resolve ISerializer, make sure you are including a relevant CacheDatabase Serializer NuGet package, then initialise CoreRegistrations.Serializer with an instance."); /// /// Inserts the specified key/value pairs into the blob. @@ -31,18 +29,13 @@ public static class SerializerExtensions /// The key/value to insert. /// An optional expiration date. /// A observable which signals when complete. - public static IObservable InsertObjects(this IBlobCache blobCache, IEnumerable> keyValuePairs, DateTimeOffset? absoluteExpiration = null) + public static IObservable InsertObjects(this IBlobCache blobCache, IEnumerable> keyValuePairs!!, DateTimeOffset? absoluteExpiration = null) { if (blobCache is null) { throw new ArgumentNullException(nameof(blobCache)); } - if (keyValuePairs is null) - { - throw new ArgumentNullException(nameof(keyValuePairs)); - } - var items = keyValuePairs.Select(x => new KeyValuePair(x.Key, Serializer.Serialize(x.Value))); return blobCache.Insert(items, typeof(T), absoluteExpiration); @@ -55,18 +48,13 @@ public static IObservable InsertObjects(this IBlobCache blobCache, IEnu /// The blob cache. /// The keys to get the values for. /// A observable with the specified values. - public static IObservable> GetObjects(this IBlobCache blobCache, IEnumerable keys) + public static IObservable> GetObjects(this IBlobCache blobCache, IEnumerable keys!!) { if (blobCache is null) { throw new ArgumentNullException(nameof(blobCache)); } - if (keys is null) - { - throw new ArgumentNullException(nameof(keys)); - } - return blobCache .Get(keys, typeof(T)) .Select(x => (x.Key, Data: Serializer.Deserialize(x.Value))) @@ -127,19 +115,14 @@ public static IObservable InsertObject(this IBlobCache blobCache, strin /// The blob cache. /// A Future result representing all objects in the cache /// with the specified Type. - public static IObservable GetAllObjects(this IBlobCache blobCache) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache - .GetAll(typeof(T)) - .Select(x => Serializer.Deserialize(x.Value)) - .Where(x => x is not null) - .Select(x => x!); - } + public static IObservable GetAllObjects(this IBlobCache blobCache!!) => + blobCache is null + ? throw new ArgumentNullException(nameof(blobCache)) + : blobCache + .GetAll(typeof(T)) + .Select(x => Serializer.Deserialize(x.Value)) + .Where(x => x is not null) + .Select(x => x!); /// /// Returns the time that the object with the key was added to the cache, or returns @@ -161,8 +144,7 @@ public static IObservable GetAllObjects(this IBlobCache blobCache) throw new ArgumentException($"'{nameof(key)}' cannot be null or whitespace.", nameof(key)); } - return blobCache - .GetCreatedAt(key, typeof(T)); + return blobCache.GetCreatedAt(key, typeof(T)); } /// @@ -196,15 +178,10 @@ public static IObservable InvalidateObject(this IBlobCache blobCache, s /// The type of object associated with the blob. /// The blob cache. /// A Future result representing the completion of the invalidation. - public static IObservable InvalidateAllObjects(this IBlobCache blobCache) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.InvalidateAll(typeof(T)); - } + public static IObservable InvalidateAllObjects(this IBlobCache blobCache) => + blobCache is null + ? throw new ArgumentNullException(nameof(blobCache)) + : blobCache.InvalidateAll(typeof(T)); /// /// Insert several objects into the cache, via the JSON serializer. @@ -215,23 +192,21 @@ public static IObservable InvalidateAllObjects(this IBlobCache blobCach /// The data to insert into the cache. /// An optional expiration date. /// A Future result representing the completion of the insert. - public static IObservable InsertAllObjects(this IBlobCache blobCache, IEnumerable> keyValuePairs, DateTimeOffset? absoluteExpiration = null) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.Insert(keyValuePairs.Select(x => new KeyValuePair(x.Key, Serializer.Serialize(x.Value))), absoluteExpiration); - } + public static IObservable InsertAllObjects(this IBlobCache blobCache, IEnumerable> keyValuePairs, DateTimeOffset? absoluteExpiration = null) => + blobCache is null + ? throw new ArgumentNullException(nameof(blobCache)) + : blobCache.Insert(keyValuePairs.Select(x => new KeyValuePair(x.Key, Serializer.Serialize(x.Value))), absoluteExpiration); /// + /// /// Attempt to return an object from the cache. If the item doesn't /// exist or returns an error, call a Func to return the latest /// version of an object and insert the result in the cache. - /// + /// + /// /// For most Internet applications, this method is the best method to /// call to fetch static data (i.e. images) from the network. + /// /// /// The cache to get the item. /// The key to associate with the object. @@ -245,30 +220,19 @@ public static IObservable InsertAllObjects(this IBlobCache blobCache, I /// The type of item to get. /// A Future result representing the deserialized object from /// the cache. - public static IObservable GetOrFetchObject(this IBlobCache blobCache, string key, Func> fetchFunc, DateTimeOffset? absoluteExpiration = null) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.GetObject(key).Catch(ex => - { - var prefixedKey = blobCache.GetHashCode().ToString(CultureInfo.InvariantCulture) + key; - - var value = fetchFunc(); - - return value; - }); - } + public static IObservable GetOrFetchObject(this IBlobCache blobCache!!, string key, Func> fetchFunc, DateTimeOffset? absoluteExpiration = null) => + blobCache.GetObject(key).Catch(_ => fetchFunc()); /// + /// /// Attempt to return an object from the cache. If the item doesn't /// exist or returns an error, call a Func to return the latest /// version of an object and insert the result in the cache. - /// + /// + /// /// For most Internet applications, this method is the best method to /// call to fetch static data (i.e. images) from the network. + /// /// /// The type of item to get. /// The cache to get the item. @@ -279,22 +243,18 @@ public static IObservable InsertAllObjects(this IBlobCache blobCache, I /// An optional expiration date. /// A Future result representing the deserialized object from /// the cache. - public static IObservable GetOrFetchObject(this IBlobCache blobCache, string key, Func> fetchFunc, DateTimeOffset? absoluteExpiration = null) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.GetOrFetchObject(key, () => fetchFunc().ToObservable(), absoluteExpiration); - } + public static IObservable GetOrFetchObject(this IBlobCache blobCache!!, string key, Func> fetchFunc, DateTimeOffset? absoluteExpiration = null) => + blobCache.GetOrFetchObject(key, () => fetchFunc().ToObservable(), absoluteExpiration); /// + /// /// Attempt to return an object from the cache. If the item doesn't /// exist or returns an error, call a Func to create a new one. - /// + /// + /// /// For most Internet applications, this method is the best method to /// call to fetch static data (i.e. images) from the network. + /// /// /// The type of item to get. /// The cache to get the item. @@ -302,35 +262,39 @@ public static IObservable InsertAllObjects(this IBlobCache blobCache, I /// A Func which will return /// the latest value for the object should the cache not contain the /// key. - /// An optional expiration date. /// A Future result representing the deserialized object from /// the cache. - public static IObservable GetOrCreateObject(this IBlobCache blobCache, string key, Func fetchFunc, DateTimeOffset? absoluteExpiration = null) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.GetOrFetchObject(key, () => Observable.Return(fetchFunc()), absoluteExpiration); - } + public static IObservable GetOrCreateObject(this IBlobCache blobCache, string key, Func fetchFunc) => + blobCache is null + ? throw new ArgumentNullException(nameof(blobCache)) + : blobCache.GetObject(key).Catch(_ => + { + var value = fetchFunc(); + blobCache.InsertObject(key, value); + return Observable.Return(value); + }); /// + /// /// This method attempts to returned a cached value, while /// simultaneously calling a Func to return the latest value. When the /// latest data comes back, it replaces what was previously in the /// cache. - /// + /// + /// /// This method is best suited for loading dynamic data from the /// Internet, while still showing the user earlier data. - /// + /// + /// /// This method returns an IObservable that may return *two* results /// (first the cached data, then the latest data). Therefore, it's /// important for UI applications that in your Subscribe method, you /// write the code to merge the second result when it comes in. - /// + /// + /// /// This also means that await'ing this method is a Bad Idea(tm), always /// use Subscribe. + /// /// /// The type of item to get. /// The cache to get the item. @@ -346,9 +310,8 @@ public static IObservable InsertAllObjects(this IBlobCache blobCache, I /// if the fetched value should be cached. /// An Observable stream containing either one or two /// results (possibly a cached version, then the latest version). - [SuppressMessage("Design", "CA2000: call dispose", Justification = "Disposed by member")] public static IObservable GetAndFetchLatest( - this IBlobCache blobCache, + this IBlobCache blobCache!!, string key, Func> fetchFunc, Func? fetchPredicate = null, @@ -356,12 +319,6 @@ public static IObservable InsertAllObjects(this IBlobCache blobCache, I bool shouldInvalidateOnError = false, Func? cacheValidationPredicate = null) { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - -#pragma warning disable CS8604 // Possible null reference argument. var fetch = Observable.Defer(() => blobCache.GetObjectCreatedAt(key)) .Select(x => fetchPredicate is null || x is null || fetchPredicate(x.Value)) .Where(x => x) @@ -394,8 +351,6 @@ public static IObservable InsertAllObjects(this IBlobCache blobCache, I var result = blobCache.GetObject(key).Select(x => (x, true)) .Catch(Observable.Return((default(T), false))); -#pragma warning restore CS8604 // Possible null reference argument. - return result.SelectMany(x => x.Item2 ? Observable.Return(x.Item1) : Observable.Empty()) .Concat(fetch) .Multicast(new ReplaySubject()) @@ -434,21 +389,14 @@ public static IObservable InsertAllObjects(this IBlobCache blobCache, I /// An Observable stream containing either one or two /// results (possibly a cached version, then the latest version). public static IObservable GetAndFetchLatest( - this IBlobCache blobCache, + this IBlobCache blobCache!!, string key, Func> fetchFunc, Func? fetchPredicate = null, DateTimeOffset? absoluteExpiration = null, bool shouldInvalidateOnError = false, - Func? cacheValidationPredicate = null) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.GetAndFetchLatest(key, () => fetchFunc().ToObservable(), fetchPredicate, absoluteExpiration, shouldInvalidateOnError, cacheValidationPredicate); - } + Func? cacheValidationPredicate = null) => + blobCache.GetAndFetchLatest(key, () => fetchFunc().ToObservable(), fetchPredicate, absoluteExpiration, shouldInvalidateOnError, cacheValidationPredicate); internal static string GetTypePrefixedKey(string key, Type type) => type.FullName + "___" + key; } diff --git a/src/ReactiveMarbles.CacheDatabase.NewtonsoftJson/NewtonsoftSerializer.cs b/src/ReactiveMarbles.CacheDatabase.NewtonsoftJson/NewtonsoftSerializer.cs index b6dcec7..e4e9530 100644 --- a/src/ReactiveMarbles.CacheDatabase.NewtonsoftJson/NewtonsoftSerializer.cs +++ b/src/ReactiveMarbles.CacheDatabase.NewtonsoftJson/NewtonsoftSerializer.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Sqlite3/CacheEntry.cs b/src/ReactiveMarbles.CacheDatabase.Sqlite3/CacheEntry.cs index 6cff90c..940f1bf 100644 --- a/src/ReactiveMarbles.CacheDatabase.Sqlite3/CacheEntry.cs +++ b/src/ReactiveMarbles.CacheDatabase.Sqlite3/CacheEntry.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs b/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs index 088f2db..50955d8 100644 --- a/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs +++ b/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/BlobCacheTestsBase.cs b/src/ReactiveMarbles.CacheDatabase.Tests/BlobCacheTestsBase.cs index 26744f0..b4bc839 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/BlobCacheTestsBase.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/BlobCacheTestsBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/EncryptedSqliteBlobCacheTests.cs b/src/ReactiveMarbles.CacheDatabase.Tests/EncryptedSqliteBlobCacheTests.cs index 12f4d60..776ede3 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/EncryptedSqliteBlobCacheTests.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/EncryptedSqliteBlobCacheTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/IntegrationTestHelper.cs b/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/IntegrationTestHelper.cs index 352aaee..7eda20a 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/IntegrationTestHelper.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/IntegrationTestHelper.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/Utility.cs b/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/Utility.cs index 0b45df3..d79f098 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/Utility.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/Utility.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserModel.cs b/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserModel.cs index 8c39d0e..de63ec0 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserModel.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserModel.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserObject.cs b/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserObject.cs index 6e00a23..7fc4092 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserObject.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserObject.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/SqliteBlobCacheTests.cs b/src/ReactiveMarbles.CacheDatabase.Tests/SqliteBlobCacheTests.cs index 0c6a737..cfd7f29 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/SqliteBlobCacheTests.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/SqliteBlobCacheTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved. +// Copyright (c) 2019-2022 ReactiveUI Association Incorporated. All rights reserved. // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. diff --git a/src/stylecop.json b/src/stylecop.json index e1b328f..038eadf 100644 --- a/src/stylecop.json +++ b/src/stylecop.json @@ -13,7 +13,7 @@ "documentPrivateFields": false, "documentationCulture": "en-US", "companyName": "ReactiveUI Association Incorporated", - "copyrightText": "Copyright (c) 2019-2021 {companyName}. All rights reserved.\n{companyName} licenses this file to you under the {licenseName} license.\nSee the {licenseFile} file in the project root for full license information.", + "copyrightText": "Copyright (c) 2019-2022 {companyName}. All rights reserved.\n{companyName} licenses this file to you under the {licenseName} license.\nSee the {licenseFile} file in the project root for full license information.", "variables": { "licenseName": "MIT", "licenseFile": "LICENSE" From 3ce089bfef674fdca9aa2fea07d714fc19e54b1e Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Fri, 13 May 2022 15:04:33 +0100 Subject: [PATCH 2/2] Clean up code Use more expression bodies where possible --- .../SystemJsonSerializer.cs | 3 - .../Utility.cs | 4 -- .../CoreRegistrations.cs | 3 - .../HttpService.cs | 32 ++------- .../IHttpService.cs | 1 - .../ISecureBlobCache.cs | 4 -- .../ISerializer.cs | 4 -- .../LoginExtensions.cs | 20 ++---- .../LoginInfo.cs | 4 -- .../PreserveAttribute.cs | 2 - .../RelativeTimeExtensions.cs | 66 ++++++------------- .../SerializerExtensions.cs | 1 - .../CacheEntry.cs | 1 - .../SqliteBlobCache.cs | 1 - .../EncryptedSqliteBlobCacheTests.cs | 3 +- .../Helpers/IntegrationTestHelper.cs | 2 - .../Helpers/Utility.cs | 4 -- .../Mocks/UserObject.cs | 6 -- .../SqliteBlobCacheTests.cs | 9 +-- 19 files changed, 36 insertions(+), 134 deletions(-) diff --git a/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs b/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs index fd65950..d3993c4 100644 --- a/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs +++ b/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs @@ -2,10 +2,7 @@ // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; using System.Text.Json; -using System.Text.Json.Serialization; - using ReactiveMarbles.CacheDatabase.Core; namespace ReactiveMarbles.CacheDatabase.SystemTextJson diff --git a/src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs b/src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs index 8b6bd9d..68e6824 100644 --- a/src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs +++ b/src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs @@ -3,13 +3,9 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Reactive.Disposables; -using System.Text; using System.Threading; -using System.Threading.Tasks; namespace ReactiveMarbles.CacheDatabase.Benchmarks { diff --git a/src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs b/src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs index 7d421c7..2205070 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs @@ -2,10 +2,7 @@ // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; using System.Reactive.Concurrency; -using System.Text; namespace ReactiveMarbles.CacheDatabase.Core { diff --git a/src/ReactiveMarbles.CacheDatabase.Core/HttpService.cs b/src/ReactiveMarbles.CacheDatabase.Core/HttpService.cs index 6d930d8..615ad8d 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/HttpService.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/HttpService.cs @@ -48,15 +48,8 @@ public HttpService() /// Force a web request to always be issued, skipping the cache. /// An optional expiration date. /// The data downloaded from the URL. - public IObservable DownloadUrl(IBlobCache blobCache, string url, HttpMethod? method = default, IEnumerable>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.DownloadUrl(url, url, method, headers, fetchAlways, absoluteExpiration); - } + public IObservable DownloadUrl(IBlobCache blobCache!!, string url, HttpMethod? method = default, IEnumerable>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null) => + blobCache.DownloadUrl(url, url, method, headers, fetchAlways, absoluteExpiration); /// /// Download data from an HTTP URL and insert the result into the @@ -71,20 +64,9 @@ public IObservable DownloadUrl(IBlobCache blobCache, string url, HttpMet /// Force a web request to always be issued, skipping the cache. /// An optional expiration date. /// The data downloaded from the URL. - public IObservable DownloadUrl(IBlobCache blobCache, Uri url, HttpMethod? method = default, IEnumerable>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - if (url is null) - { - throw new ArgumentNullException(nameof(url)); - } - - return blobCache.DownloadUrl(url.ToString(), url, method, headers, fetchAlways, absoluteExpiration); - } + public IObservable DownloadUrl(IBlobCache blobCache!!, Uri url, HttpMethod? method = default, IEnumerable>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null) => url is null + ? throw new ArgumentNullException(nameof(url)) + : blobCache.DownloadUrl(url.ToString(), url, method, headers, fetchAlways, absoluteExpiration); /// /// Download data from an HTTP URL and insert the result into the @@ -186,9 +168,7 @@ protected virtual IObservable MakeWebRequest( int retries = 3, TimeSpan? timeout = null) { - IObservable request; - - request = Observable.Defer(() => + var request = Observable.Defer(() => { var httpRequest = CreateWebRequest(uri, method, headers); diff --git a/src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs b/src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs index 1258b0a..3c259b8 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Net.Http; -using System.Text; namespace ReactiveMarbles.CacheDatabase.Core { diff --git a/src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs b/src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs index e111fe6..7641ba8 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs @@ -2,10 +2,6 @@ // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Text; - namespace ReactiveMarbles.CacheDatabase.Core { /// diff --git a/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs b/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs index 5064939..02b3811 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs @@ -2,10 +2,6 @@ // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Text; - namespace ReactiveMarbles.CacheDatabase.Core { /// diff --git a/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs b/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs index 23ae626..e1730d7 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs @@ -3,10 +3,8 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.Reactive; using System.Reactive.Linq; -using System.Text; namespace ReactiveMarbles.CacheDatabase.Core { @@ -26,10 +24,8 @@ public static class LoginExtensions /// The host to associate with the data. /// An optional expiration date. /// A observable which signals when the insert is completed. - public static IObservable SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host = "default", DateTimeOffset? absoluteExpiration = null) - { - return blobCache.InsertObject("login:" + host, new Tuple(user, password), absoluteExpiration); - } + public static IObservable SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host = "default", DateTimeOffset? absoluteExpiration = null) => + blobCache.InsertObject("login:" + host, new Tuple(user, password), absoluteExpiration); /// /// Returns the currently cached user/password. If the cache does not @@ -39,10 +35,8 @@ public static IObservable SaveLogin(this ISecureBlobCache blobCache, strin /// The blob cache where to get the data. /// The host associated with the data. /// A Future result representing the user/password Tuple. - public static IObservable GetLoginAsync(this ISecureBlobCache blobCache, string host = "default") - { - return blobCache.GetObject<(string, string)>("login:" + host).Select(x => new LoginInfo(x)); - } + public static IObservable GetLoginAsync(this ISecureBlobCache blobCache, string host = "default") => + blobCache.GetObject<(string, string)>("login:" + host).Select(x => new LoginInfo(x)); /// /// Erases the login associated with the specified host. @@ -50,9 +44,7 @@ public static IObservable GetLoginAsync(this ISecureBlobCache blobCac /// The blob cache where to erase the data. /// The host associated with the data. /// A observable which signals when the erase is completed. - public static IObservable EraseLogin(this ISecureBlobCache blobCache, string host = "default") - { - return blobCache.InvalidateObject<(string, string)>("login:" + host); - } + public static IObservable EraseLogin(this ISecureBlobCache blobCache, string host = "default") => + blobCache.InvalidateObject<(string, string)>("login:" + host); } } diff --git a/src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs b/src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs index 886316d..9d3f83d 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs @@ -2,10 +2,6 @@ // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Text; - namespace ReactiveMarbles.CacheDatabase.Core { /// diff --git a/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs b/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs index 00fb32b..7cb45f0 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; -using System.Text; namespace ReactiveMarbles.CacheDatabase.Core { diff --git a/src/ReactiveMarbles.CacheDatabase.Core/RelativeTimeExtensions.cs b/src/ReactiveMarbles.CacheDatabase.Core/RelativeTimeExtensions.cs index 6b5fb30..68dfa1d 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/RelativeTimeExtensions.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/RelativeTimeExtensions.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Net.Http; using System.Reactive; -using System.Text; namespace ReactiveMarbles.CacheDatabase.Core { @@ -24,15 +23,10 @@ public static class RelativeTimeExtensions /// The data for the entry. /// A timespan that will be added to the current DateTime. /// A observable which will signal when the item is added. - public static IObservable Insert(this IBlobCache blobCache, string key, byte[] data, TimeSpan expiration) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.Insert(key, data, blobCache.Scheduler.Now + expiration); - } + public static IObservable Insert(this IBlobCache blobCache, string key, byte[] data, TimeSpan expiration) => + blobCache is null + ? throw new ArgumentNullException(nameof(blobCache)) + : blobCache.Insert(key, data, blobCache.Scheduler.Now + expiration); /// /// Inserts a item into the cache. @@ -43,15 +37,10 @@ public static IObservable Insert(this IBlobCache blobCache, string key, by /// A timespan that will be added to the current DateTime. /// The type of item to insert. /// A observable which will signal when the item is added. - public static IObservable InsertObject(this IBlobCache blobCache, string key, T value, TimeSpan expiration) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.InsertObject(key, value, blobCache.Scheduler.Now + expiration); - } + public static IObservable InsertObject(this IBlobCache blobCache, string key, T value, TimeSpan expiration) => + blobCache is null + ? throw new ArgumentNullException(nameof(blobCache)) + : blobCache.InsertObject(key, value, blobCache.Scheduler.Now + expiration); /// /// Downloads the specified url if there is not already a entry in the cache. @@ -63,15 +52,10 @@ public static IObservable InsertObject(this IBlobCache blobCache, strin /// The headers to specify when getting the entry. /// If we should fetch always and not return the cache entry if available. /// A observable which will signal when the data is available. - public static IObservable DownloadUrl(this IBlobCache blobCache, string url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable>? headers = null, bool fetchAlways = false) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration); - } + public static IObservable DownloadUrl(this IBlobCache blobCache, string url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable>? headers = null, bool fetchAlways = false) => + blobCache is null + ? throw new ArgumentNullException(nameof(blobCache)) + : blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration); /// /// Downloads the specified url if there is not already a entry in the cache. @@ -83,15 +67,10 @@ public static IObservable DownloadUrl(this IBlobCache blobCache, string /// The headers to specify when getting the entry. /// If we should fetch always and not return the cache entry if available. /// A observable which will signal when the data is available. - public static IObservable DownloadUrl(this IBlobCache blobCache, Uri url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable>? headers = null, bool fetchAlways = false) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration); - } + public static IObservable DownloadUrl(this IBlobCache blobCache, Uri url, HttpMethod httpMethod, TimeSpan expiration, IEnumerable>? headers = null, bool fetchAlways = false) => + blobCache is null + ? throw new ArgumentNullException(nameof(blobCache)) + : blobCache.DownloadUrl(url, httpMethod, headers, fetchAlways, blobCache.Scheduler.Now + expiration); /// /// Saves a username and password. @@ -102,14 +81,9 @@ public static IObservable DownloadUrl(this IBlobCache blobCache, Uri url /// The host to store against. /// A timespan that will be added to the current DateTime. /// A observable which will signal when the item is added. - public static IObservable SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host, TimeSpan expiration) - { - if (blobCache is null) - { - throw new ArgumentNullException(nameof(blobCache)); - } - - return blobCache.SaveLogin(user, password, host, blobCache.Scheduler.Now + expiration); - } + public static IObservable SaveLogin(this ISecureBlobCache blobCache, string user, string password, string host, TimeSpan expiration) => + blobCache is null + ? throw new ArgumentNullException(nameof(blobCache)) + : blobCache.SaveLogin(user, password, host, blobCache.Scheduler.Now + expiration); } } diff --git a/src/ReactiveMarbles.CacheDatabase.Core/SerializerExtensions.cs b/src/ReactiveMarbles.CacheDatabase.Core/SerializerExtensions.cs index 8abebec..b370b17 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/SerializerExtensions.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/SerializerExtensions.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reactive; using System.Reactive.Linq; diff --git a/src/ReactiveMarbles.CacheDatabase.Sqlite3/CacheEntry.cs b/src/ReactiveMarbles.CacheDatabase.Sqlite3/CacheEntry.cs index 940f1bf..9ec3a25 100644 --- a/src/ReactiveMarbles.CacheDatabase.Sqlite3/CacheEntry.cs +++ b/src/ReactiveMarbles.CacheDatabase.Sqlite3/CacheEntry.cs @@ -47,7 +47,6 @@ internal class CacheEntry /// /// Gets or sets the value of the entry. /// - [SuppressMessage("FxCop.Style", "CA1819: Properties should not return arrays", Justification = "Legacy reasons.")] public byte[]? Value { get; set; } = Array.Empty(); } } diff --git a/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs b/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs index 50955d8..602472a 100644 --- a/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs +++ b/src/ReactiveMarbles.CacheDatabase.Sqlite3/SqliteBlobCache.cs @@ -9,7 +9,6 @@ using System.Reactive; using System.Reactive.Concurrency; using System.Reactive.Linq; -using System.Reactive.Subjects; using System.Threading.Tasks; using ReactiveMarbles.CacheDatabase.Core; diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/EncryptedSqliteBlobCacheTests.cs b/src/ReactiveMarbles.CacheDatabase.Tests/EncryptedSqliteBlobCacheTests.cs index 776ede3..7aa3c44 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/EncryptedSqliteBlobCacheTests.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/EncryptedSqliteBlobCacheTests.cs @@ -15,6 +15,7 @@ namespace ReactiveMarbles.CacheDatabase.Tests public class EncryptedSqliteBlobCacheTests : BlobCacheTestsBase { /// - protected override IBlobCache CreateBlobCache(string path) => new EncryptedSqliteBlobCache(Path.Combine(path, "test.db"), "test1234"); + protected override IBlobCache CreateBlobCache(string path) => + new EncryptedSqliteBlobCache(Path.Combine(path, "test.db"), "test1234"); } } diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/IntegrationTestHelper.cs b/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/IntegrationTestHelper.cs index 7eda20a..d6e622e 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/IntegrationTestHelper.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/IntegrationTestHelper.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; @@ -11,7 +10,6 @@ using System.Net; using System.Net.Http; using System.Text; -using System.Threading.Tasks; namespace ReactiveMarbles.CacheDatabase.Tests.Helpers { diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/Utility.cs b/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/Utility.cs index d79f098..0934c07 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/Utility.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/Utility.cs @@ -3,13 +3,9 @@ // See the LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Reactive.Disposables; -using System.Text; using System.Threading; -using System.Threading.Tasks; namespace ReactiveMarbles.CacheDatabase.Tests.Helpers { diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserObject.cs b/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserObject.cs index 7fc4092..7d615ce 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserObject.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserObject.cs @@ -2,12 +2,6 @@ // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace ReactiveMarbles.CacheDatabase.Tests.Mocks { /// diff --git a/src/ReactiveMarbles.CacheDatabase.Tests/SqliteBlobCacheTests.cs b/src/ReactiveMarbles.CacheDatabase.Tests/SqliteBlobCacheTests.cs index cfd7f29..ba3e5a4 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/SqliteBlobCacheTests.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/SqliteBlobCacheTests.cs @@ -2,13 +2,7 @@ // ReactiveUI Association Incorporated licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - using ReactiveMarbles.CacheDatabase.Core; using ReactiveMarbles.CacheDatabase.Sqlite3; @@ -20,6 +14,7 @@ namespace ReactiveMarbles.CacheDatabase.Tests public class SqliteBlobCacheTests : BlobCacheTestsBase { /// - protected override IBlobCache CreateBlobCache(string path) => new SqliteBlobCache(Path.Combine(path, "test.db")); + protected override IBlobCache CreateBlobCache(string path) => + new SqliteBlobCache(Path.Combine(path, "test.db")); } }