diff --git a/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs b/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs index 6198076..d3993c4 100644 --- a/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs +++ b/src/ReactiveMarbles.CacheData.SystemTextJson/SystemJsonSerializer.cs @@ -1,11 +1,8 @@ -// 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.Text.Json; -using System.Text.Json.Serialization; - using ReactiveMarbles.CacheDatabase.Core; namespace ReactiveMarbles.CacheDatabase.SystemTextJson 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..68e6824 100644 --- a/src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs +++ b/src/ReactiveMarbles.CacheDatabase.Benchmarks/Utility.cs @@ -1,15 +1,11 @@ -// 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.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 0b9f8c1..2205070 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/CoreRegistrations.cs @@ -1,11 +1,8 @@ -// 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.Reactive.Concurrency; -using System.Text; namespace ReactiveMarbles.CacheDatabase.Core { 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..615ad8d 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. @@ -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/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..3c259b8 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/IHttpService.cs @@ -1,11 +1,10 @@ -// 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.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 fef8917..7641ba8 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/ISecureBlobCache.cs @@ -1,11 +1,7 @@ -// 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.Text; - namespace ReactiveMarbles.CacheDatabase.Core { /// diff --git a/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs b/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs index 02e4860..02b3811 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/ISerializer.cs @@ -1,11 +1,7 @@ -// 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.Text; - namespace ReactiveMarbles.CacheDatabase.Core { /// diff --git a/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs b/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs index b8e0e9d..e1730d7 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/LoginExtensions.cs @@ -1,12 +1,10 @@ -// 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.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 3e4e918..9d3f83d 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/LoginInfo.cs @@ -1,11 +1,7 @@ -// 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.Text; - namespace ReactiveMarbles.CacheDatabase.Core { /// diff --git a/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs b/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs index 181574d..7cb45f0 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/PreserveAttribute.cs @@ -1,10 +1,8 @@ -// 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.Text; namespace ReactiveMarbles.CacheDatabase.Core { 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..68dfa1d 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. @@ -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 6e50356..b370b17 100644 --- a/src/ReactiveMarbles.CacheDatabase.Core/SerializerExtensions.cs +++ b/src/ReactiveMarbles.CacheDatabase.Core/SerializerExtensions.cs @@ -1,17 +1,14 @@ -// 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 +18,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 +28,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 +47,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 +114,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 +143,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 +177,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 +191,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 +219,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 +242,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 +261,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 +309,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 +318,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 +350,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 +388,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..9ec3a25 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. @@ -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 088f2db..602472a 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. @@ -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/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..7aa3c44 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. @@ -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 352aaee..d6e622e 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/IntegrationTestHelper.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/IntegrationTestHelper.cs @@ -1,9 +1,8 @@ -// 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; 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 0b45df3..0934c07 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/Utility.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/Helpers/Utility.cs @@ -1,15 +1,11 @@ -// 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.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/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..7d615ce 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserObject.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/Mocks/UserObject.cs @@ -1,13 +1,7 @@ -// 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.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 0c6a737..ba3e5a4 100644 --- a/src/ReactiveMarbles.CacheDatabase.Tests/SqliteBlobCacheTests.cs +++ b/src/ReactiveMarbles.CacheDatabase.Tests/SqliteBlobCacheTests.cs @@ -1,14 +1,8 @@ -// 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.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")); } } 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"