From 590675025f32e508e6dcbcd5dd17ee3eff4fed9f Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Sun, 4 Apr 2021 13:15:50 +0300 Subject: [PATCH 01/18] fix: Nullability annotations in blob cache --- .../SqlLiteCache/SqlRawPersistentBlobCache.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs b/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs index 355edf9cb..1ac16ca67 100644 --- a/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs +++ b/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs @@ -147,9 +147,7 @@ public IObservable Get(string key) ? Observable.Return(cacheElements.First().Value) : ExceptionHelper.ObservableThrowKeyNotFoundException(key); }) -#pragma warning disable CS8604 // Possible null reference argument. .SelectMany(x => AfterReadFromDiskFilter(x, Scheduler)) -#pragma warning restore CS8604 // Possible null reference argument. .PublishLast().PermaRef(); } @@ -295,7 +293,7 @@ public IObservable InsertObject(string key, T value, DateTimeOffset? ab } /// - public IObservable GetObject(string key) + public IObservable GetObject(string key) { if (_disposed) { @@ -320,9 +318,7 @@ public IObservable InsertObject(string key, T value, DateTimeOffset? ab ? Observable.Return(cacheElements.First().Value) : ExceptionHelper.ObservableThrowKeyNotFoundException(key); }) -#pragma warning disable CS8604 // Possible null reference argument. .SelectMany(x => AfterReadFromDiskFilter(x, Scheduler)) -#pragma warning restore CS8604 // Possible null reference argument. .SelectMany(DeserializeObject) .PublishLast().PermaRef(); } @@ -808,7 +804,7 @@ private byte[] SerializeObject(T value) } } - private IObservable DeserializeObject(byte[] data) + private IObservable DeserializeObject(byte[] data) { var serializer = GetSerializer(); using (var reader = new BsonDataReader(new MemoryStream(data))) @@ -834,10 +830,8 @@ private byte[] SerializeObject(T value) this.Log().Warn(ex, "Failed to deserialize data as boxed, we may be migrating from an old Akavache"); } - var rawVal = serializer.Deserialize(reader); -#pragma warning disable CS8604 // Possible null reference argument. + var rawVal = serializer.Deserialize(reader)!; return Observable.Return(rawVal); -#pragma warning restore CS8604 // Possible null reference argument. } catch (Exception ex) { From dd42c9ab6d80f84a1504788ea1652f112c997772 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 2 Apr 2021 00:30:12 +0000 Subject: [PATCH 02/18] build(deps): bump Microsoft.NET.Test.Sdk from 16.9.1 to 16.9.4 in /src Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 16.9.1 to 16.9.4. - [Release notes](https://github.com/microsoft/vstest/releases) - [Commits](https://github.com/microsoft/vstest/compare/v16.9.1...v16.9.4) Signed-off-by: dependabot[bot] --- src/Akavache.Tests/Akavache.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Akavache.Tests/Akavache.Tests.csproj b/src/Akavache.Tests/Akavache.Tests.csproj index a07a72e8a..2589d706c 100644 --- a/src/Akavache.Tests/Akavache.Tests.csproj +++ b/src/Akavache.Tests/Akavache.Tests.csproj @@ -8,7 +8,7 @@ - + From 973f66e30f7a1ad67bbd297f1575ffe64bf717ef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 Mar 2021 00:07:55 +0000 Subject: [PATCH 03/18] build(deps): bump Newtonsoft.Json from 12.0.3 to 13.0.1 in /src Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 12.0.3 to 13.0.1. - [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases) - [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/12.0.3...13.0.1) Signed-off-by: dependabot[bot] --- src/Akavache.Core/Akavache.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Akavache.Core/Akavache.Core.csproj b/src/Akavache.Core/Akavache.Core.csproj index 5b5452321..4eaec73f3 100644 --- a/src/Akavache.Core/Akavache.Core.csproj +++ b/src/Akavache.Core/Akavache.Core.csproj @@ -11,7 +11,7 @@ - + From 4613c9ece551375b9fc76d76bd1d0d4afe7d925a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 Mar 2021 00:07:51 +0000 Subject: [PATCH 04/18] build(deps): bump DiffEngine from 6.5.7 to 6.6.1 in /src Bumps [DiffEngine](https://github.com/VerifyTests/DiffEngine) from 6.5.7 to 6.6.1. - [Release notes](https://github.com/VerifyTests/DiffEngine/releases) - [Commits](https://github.com/VerifyTests/DiffEngine/compare/6.5.7...6.6.1) Signed-off-by: dependabot[bot] --- src/Akavache.Tests/Akavache.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Akavache.Tests/Akavache.Tests.csproj b/src/Akavache.Tests/Akavache.Tests.csproj index 2589d706c..4726a1609 100644 --- a/src/Akavache.Tests/Akavache.Tests.csproj +++ b/src/Akavache.Tests/Akavache.Tests.csproj @@ -21,7 +21,7 @@ - + all From 4d13c78f5674a6e77efec9b3430cf29188643c41 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Apr 2021 00:28:09 +0000 Subject: [PATCH 05/18] build(deps): update Splat requirement from 10.* to 11.* in /src Updates the requirements on [Splat](https://github.com/reactiveui/splat) to permit the latest version. - [Release notes](https://github.com/reactiveui/splat/releases) - [Changelog](https://github.com/reactiveui/splat/blob/main/RELEASENOTES.md) - [Commits](https://github.com/reactiveui/splat/compare/10.0.1...11.0.1) Signed-off-by: dependabot[bot] --- src/Akavache.Core/Akavache.Core.csproj | 2 +- src/Akavache.Sqlite3/Akavache.Sqlite3.csproj | 2 +- src/Akavache.Tests/Akavache.Tests.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Akavache.Core/Akavache.Core.csproj b/src/Akavache.Core/Akavache.Core.csproj index 4eaec73f3..a48c76af4 100644 --- a/src/Akavache.Core/Akavache.Core.csproj +++ b/src/Akavache.Core/Akavache.Core.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/Akavache.Sqlite3/Akavache.Sqlite3.csproj b/src/Akavache.Sqlite3/Akavache.Sqlite3.csproj index 1a57d5239..b91e846fb 100644 --- a/src/Akavache.Sqlite3/Akavache.Sqlite3.csproj +++ b/src/Akavache.Sqlite3/Akavache.Sqlite3.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/Akavache.Tests/Akavache.Tests.csproj b/src/Akavache.Tests/Akavache.Tests.csproj index 4726a1609..12af52051 100644 --- a/src/Akavache.Tests/Akavache.Tests.csproj +++ b/src/Akavache.Tests/Akavache.Tests.csproj @@ -16,7 +16,7 @@ - + From 9323a534787e0c523f4455ae059a0f2a6f697734 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Apr 2021 00:28:15 +0000 Subject: [PATCH 06/18] build(deps): update Splat.Drawing requirement from 10.* to 11.* in /src Updates the requirements on [Splat.Drawing](https://github.com/reactiveui/splat) to permit the latest version. - [Release notes](https://github.com/reactiveui/splat/releases) - [Changelog](https://github.com/reactiveui/splat/blob/main/RELEASENOTES.md) - [Commits](https://github.com/reactiveui/splat/compare/10.0.1...11.0.1) Signed-off-by: dependabot[bot] --- src/Akavache.Drawing/Akavache.Drawing.csproj | 2 +- src/Akavache.Tests/Akavache.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Akavache.Drawing/Akavache.Drawing.csproj b/src/Akavache.Drawing/Akavache.Drawing.csproj index b84008574..ebaa88328 100644 --- a/src/Akavache.Drawing/Akavache.Drawing.csproj +++ b/src/Akavache.Drawing/Akavache.Drawing.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Akavache.Tests/Akavache.Tests.csproj b/src/Akavache.Tests/Akavache.Tests.csproj index 12af52051..1a7d21b84 100644 --- a/src/Akavache.Tests/Akavache.Tests.csproj +++ b/src/Akavache.Tests/Akavache.Tests.csproj @@ -17,7 +17,7 @@ - + From 4e66b826ea03278ba6ffc16bd0b420a91ed660c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Apr 2021 00:04:30 +0000 Subject: [PATCH 07/18] build(deps): bump Nerdbank.GitVersioning from 3.3.37 to 3.4.194 in /src Bumps [Nerdbank.GitVersioning](https://github.com/dotnet/Nerdbank.GitVersioning) from 3.3.37 to 3.4.194. - [Release notes](https://github.com/dotnet/Nerdbank.GitVersioning/releases) - [Commits](https://github.com/dotnet/Nerdbank.GitVersioning/compare/v3.3.37...v3.4.194) Signed-off-by: dependabot[bot] --- src/Directory.build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.build.props b/src/Directory.build.props index 99ef9ae14..610fec98d 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -29,7 +29,7 @@ - + From 133291a2e338e45ee2213924e1d6f2a2ab1fa609 Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Mon, 12 Apr 2021 00:00:05 +0300 Subject: [PATCH 08/18] Update nullability annotations --- src/Akavache.Core/BlobCache/BlobCache.cs | 6 +++--- src/Akavache.Core/BlobCache/IObjectBlobCache.cs | 2 +- src/Akavache.Core/HttpMixinExtensions.cs | 14 ++++++-------- src/Akavache.Mobile/Registrations.cs | 4 ++-- .../SqlLiteCache/SqlRawPersistentBlobCache.cs | 6 ++---- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Akavache.Core/BlobCache/BlobCache.cs b/src/Akavache.Core/BlobCache/BlobCache.cs index 92371bda4..cf13a81f0 100644 --- a/src/Akavache.Core/BlobCache/BlobCache.cs +++ b/src/Akavache.Core/BlobCache/BlobCache.cs @@ -81,7 +81,7 @@ public static string ApplicationName /// public static IBlobCache LocalMachine { - get => _unitTestLocalMachine ?? _localMachine ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService("LocalMachine"); + get => _unitTestLocalMachine ?? _localMachine ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService("LocalMachine") ?? throw new InvalidOperationException("Unable to resolve LocalMachine cache. Make sure Akavache is initialized properly."); set { if (ModeDetector.InUnitTestRunner()) @@ -103,7 +103,7 @@ public static IBlobCache LocalMachine /// public static IBlobCache UserAccount { - get => _unitTestUserAccount ?? _userAccount ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService("UserAccount"); + get => _unitTestUserAccount ?? _userAccount ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService("UserAccount") ?? throw new InvalidOperationException("Unable to resolve UserAccount cache. Make sure Akavache is initialized properly."); set { if (ModeDetector.InUnitTestRunner()) @@ -124,7 +124,7 @@ public static IBlobCache UserAccount /// public static ISecureBlobCache Secure { - get => _unitTestSecure ?? _secure ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService(); + get => _unitTestSecure ?? _secure ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService() ?? throw new InvalidOperationException("Unable to resolve Secure cache. Make sure Akavache is initialized properly."); set { if (ModeDetector.InUnitTestRunner()) diff --git a/src/Akavache.Core/BlobCache/IObjectBlobCache.cs b/src/Akavache.Core/BlobCache/IObjectBlobCache.cs index 73f00cd5f..c947cd00b 100644 --- a/src/Akavache.Core/BlobCache/IObjectBlobCache.cs +++ b/src/Akavache.Core/BlobCache/IObjectBlobCache.cs @@ -31,7 +31,7 @@ public interface IObjectBlobCache : IBlobCache /// The type of object associated with the blob. /// The key to look up in the cache. /// A Future result representing the object in the cache. - IObservable GetObject(string key); + IObservable GetObject(string key); /// /// Return all objects of a specific Type in the cache. diff --git a/src/Akavache.Core/HttpMixinExtensions.cs b/src/Akavache.Core/HttpMixinExtensions.cs index bc3f49930..aac27e896 100644 --- a/src/Akavache.Core/HttpMixinExtensions.cs +++ b/src/Akavache.Core/HttpMixinExtensions.cs @@ -14,6 +14,8 @@ namespace Akavache /// public static class HttpMixinExtensions { + private static IAkavacheHttpMixin HttpMixin => Locator.Current.GetService() ?? throw new InvalidOperationException("Unable to resolve IAkavacheHttpMixin, probably Akavache is not initialized."); + /// /// Download data from an HTTP URL and insert the result into the /// cache. If the data is already in the cache, this returns @@ -28,8 +30,7 @@ public static class HttpMixinExtensions /// The data downloaded from the URL. public static IObservable DownloadUrl(this IBlobCache blobCache, string url, IDictionary? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null) { - var mixin = Locator.Current.GetService(); - return mixin.DownloadUrl(blobCache, new Uri(url), headers, fetchAlways, absoluteExpiration); + return HttpMixin.DownloadUrl(blobCache, new Uri(url), headers, fetchAlways, absoluteExpiration); } /// @@ -46,8 +47,7 @@ public static IObservable DownloadUrl(this IBlobCache blobCache, string /// The data downloaded from the URL. public static IObservable DownloadUrl(this IBlobCache blobCache, Uri url, IDictionary? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null) { - var mixin = Locator.Current.GetService(); - return mixin.DownloadUrl(blobCache, url, headers, fetchAlways, absoluteExpiration); + return HttpMixin.DownloadUrl(blobCache, url, headers, fetchAlways, absoluteExpiration); } /// @@ -65,8 +65,7 @@ public static IObservable DownloadUrl(this IBlobCache blobCache, Uri url /// The data downloaded from the URL. public static IObservable DownloadUrl(this IBlobCache blobCache, string key, string url, IDictionary? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null) { - var mixin = Locator.Current.GetService(); - return mixin.DownloadUrl(blobCache, key, new Uri(url), headers, fetchAlways, absoluteExpiration); + return HttpMixin.DownloadUrl(blobCache, key, new Uri(url), headers, fetchAlways, absoluteExpiration); } /// @@ -84,8 +83,7 @@ public static IObservable DownloadUrl(this IBlobCache blobCache, string /// The data downloaded from the URL. public static IObservable DownloadUrl(this IBlobCache blobCache, string key, Uri url, IDictionary? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null) { - var mixin = Locator.Current.GetService(); - return mixin.DownloadUrl(blobCache, key, url, headers, fetchAlways, absoluteExpiration); + return HttpMixin.DownloadUrl(blobCache, key, url, headers, fetchAlways, absoluteExpiration); } } } diff --git a/src/Akavache.Mobile/Registrations.cs b/src/Akavache.Mobile/Registrations.cs index d9416c779..cb95061ee 100644 --- a/src/Akavache.Mobile/Registrations.cs +++ b/src/Akavache.Mobile/Registrations.cs @@ -42,12 +42,12 @@ public void Register(IMutableDependencyResolver resolver, IReadonlyDependencyRes // NB: These correspond to the hacks in Akavache.Http's registrations resolver.Register( - () => readonlyDependencyResolver.GetService().ShouldPersistState, + () => readonlyDependencyResolver.GetService()?.ShouldPersistState ?? throw new InvalidOperationException("Unable to resolve ISuspensionHost, probably ReactiveUI is not initialized."), typeof(IObservable), "ShouldPersistState"); resolver.Register( - () => readonlyDependencyResolver.GetService().IsUnpausing, + () => readonlyDependencyResolver.GetService()?.IsUnpausing ?? throw new InvalidOperationException("Unable to resolve ISuspensionHost, probably ReactiveUI is not initialized."), typeof(IObservable), "IsUnpausing"); diff --git a/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs b/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs index 1ac16ca67..020f8818a 100644 --- a/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs +++ b/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs @@ -345,9 +345,7 @@ public IObservable> GetAllObjects() return _initializer.SelectMany(_ => _opQueue.SelectTypes(new[] { typeFullName }) .SelectMany(x => x.ToObservable() -#pragma warning disable CS8604 // Possible null reference argument. .SelectMany(y => AfterReadFromDiskFilter(y.Value, Scheduler)) -#pragma warning restore CS8604 // Possible null reference argument. .SelectMany(DeserializeObject) .Where(y => y is not null) .Select(y => y!) @@ -804,7 +802,7 @@ private byte[] SerializeObject(T value) } } - private IObservable DeserializeObject(byte[] data) + private IObservable DeserializeObject(byte[] data) { var serializer = GetSerializer(); using (var reader = new BsonDataReader(new MemoryStream(data))) @@ -830,7 +828,7 @@ private IObservable DeserializeObject(byte[] data) this.Log().Warn(ex, "Failed to deserialize data as boxed, we may be migrating from an old Akavache"); } - var rawVal = serializer.Deserialize(reader)!; + var rawVal = serializer.Deserialize(reader); return Observable.Return(rawVal); } catch (Exception ex) From 7fd457ce5cb4a3d077deb9d11aec18dbcf95b885 Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Mon, 12 Apr 2021 00:01:39 +0300 Subject: [PATCH 09/18] Add a nuget.config --- nuget.config | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 nuget.config diff --git a/nuget.config b/nuget.config new file mode 100644 index 000000000..13f008d0c --- /dev/null +++ b/nuget.config @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file From 8c992be317885d96e80375608ea784d9daa1f0cc Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Mon, 12 Apr 2021 00:06:21 +0300 Subject: [PATCH 10/18] Fix one more nullability error --- .../SqlLiteCache/SQLiteEncryptedBlobCache.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Akavache.Sqlite3/SqlLiteCache/SQLiteEncryptedBlobCache.cs b/src/Akavache.Sqlite3/SqlLiteCache/SQLiteEncryptedBlobCache.cs index eaff5eead..698399035 100644 --- a/src/Akavache.Sqlite3/SqlLiteCache/SQLiteEncryptedBlobCache.cs +++ b/src/Akavache.Sqlite3/SqlLiteCache/SQLiteEncryptedBlobCache.cs @@ -27,12 +27,13 @@ public class SQLiteEncryptedBlobCache : SqlRawPersistentBlobCache, ISecureBlobCa public SQLiteEncryptedBlobCache(string databaseFile, IEncryptionProvider? encryptionProvider = null, IScheduler? scheduler = null) : base(databaseFile, scheduler) { - _encryption = encryptionProvider ?? Locator.Current.GetService(); - - if (_encryption is null) + var encryption = encryptionProvider ?? Locator.Current.GetService(); + if (encryption is null) { throw new Exception("No IEncryptionProvider available. This should never happen, your DependencyResolver is broken"); } + + _encryption = encryption; } /// From 59e4dd2ae3b802bbbd581dbdff3266a329d3677a Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Mon, 12 Apr 2021 00:13:46 +0300 Subject: [PATCH 11/18] Match the nullability --- src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs b/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs index 020f8818a..8855c592b 100644 --- a/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs +++ b/src/Akavache.Sqlite3/SqlLiteCache/SqlRawPersistentBlobCache.cs @@ -293,7 +293,7 @@ public IObservable InsertObject(string key, T value, DateTimeOffset? ab } /// - public IObservable GetObject(string key) + public IObservable GetObject(string key) { if (_disposed) { From e42acacc0c5ec58ba96550d219e6879ab457f158 Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Mon, 12 Apr 2021 00:21:01 +0300 Subject: [PATCH 12/18] Fix bitmap loader nullability --- src/Akavache.Drawing/BitmapImageMixin.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Akavache.Drawing/BitmapImageMixin.cs b/src/Akavache.Drawing/BitmapImageMixin.cs index 602867bee..bb2b23820 100644 --- a/src/Akavache.Drawing/BitmapImageMixin.cs +++ b/src/Akavache.Drawing/BitmapImageMixin.cs @@ -7,6 +7,7 @@ using System.IO; using System.Reactive.Linq; using System.Reactive.Threading.Tasks; +using System.Threading.Tasks; using Splat; namespace Akavache @@ -152,12 +153,16 @@ public static IObservable ThrowOnBadImageBuffer(byte[] compressedImage) Observable.Return(compressedImage); } - private static IObservable BytesToImage(byte[] compressedImage, float? desiredWidth, float? desiredHeight) + private static async Task BytesToImage(byte[] compressedImage, float? desiredWidth, float? desiredHeight) { - using (var ms = new MemoryStream(compressedImage)) + using var ms = new MemoryStream(compressedImage); + var bitmap = await BitmapLoader.Current.Load(ms, desiredWidth, desiredHeight).ConfigureAwait(false); + if (bitmap is null) { - return BitmapLoader.Current.Load(ms, desiredWidth, desiredHeight).ToObservable(); + throw new IOException("Failed to load the bitmap!"); } + + return bitmap; } } } From 266450ea44dbb39c6e515f40c9e7001cdb149a06 Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Mon, 12 Apr 2021 00:23:19 +0300 Subject: [PATCH 13/18] Simplify encrypted blob cache ctor --- .../SqlLiteCache/SQLiteEncryptedBlobCache.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Akavache.Sqlite3/SqlLiteCache/SQLiteEncryptedBlobCache.cs b/src/Akavache.Sqlite3/SqlLiteCache/SQLiteEncryptedBlobCache.cs index 698399035..a169ac877 100644 --- a/src/Akavache.Sqlite3/SqlLiteCache/SQLiteEncryptedBlobCache.cs +++ b/src/Akavache.Sqlite3/SqlLiteCache/SQLiteEncryptedBlobCache.cs @@ -27,13 +27,7 @@ public class SQLiteEncryptedBlobCache : SqlRawPersistentBlobCache, ISecureBlobCa public SQLiteEncryptedBlobCache(string databaseFile, IEncryptionProvider? encryptionProvider = null, IScheduler? scheduler = null) : base(databaseFile, scheduler) { - var encryption = encryptionProvider ?? Locator.Current.GetService(); - if (encryption is null) - { - throw new Exception("No IEncryptionProvider available. This should never happen, your DependencyResolver is broken"); - } - - _encryption = encryption; + _encryption = encryptionProvider ?? Locator.Current.GetService() ?? throw new Exception("No IEncryptionProvider available. This should never happen, your DependencyResolver is broken"); } /// From 4c14772e95903c850de9cc60d23df8f1999ecbec Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Mon, 12 Apr 2021 00:32:57 +0300 Subject: [PATCH 14/18] Update API approvals --- .../API/ApiApprovalTests.AkavacheCore.net461.approved.txt | 2 +- .../API/ApiApprovalTests.AkavacheCore.net5.0.approved.txt | 2 +- .../ApiApprovalTests.AkavacheCore.netcoreapp3.1.approved.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.net461.approved.txt b/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.net461.approved.txt index 5893b9bf9..91077663a 100644 --- a/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.net461.approved.txt +++ b/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.net461.approved.txt @@ -119,7 +119,7 @@ namespace Akavache public interface IObjectBlobCache : Akavache.IBlobCache, System.IDisposable { System.IObservable> GetAllObjects(); - System.IObservable GetObject(string key); + System.IObservable GetObject(string key); System.IObservable GetObjectCreatedAt(string key); System.IObservable InsertObject(string key, T value, System.DateTimeOffset? absoluteExpiration = default); System.IObservable InvalidateAllObjects(); diff --git a/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.net5.0.approved.txt b/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.net5.0.approved.txt index 92c303645..9433aa13a 100644 --- a/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.net5.0.approved.txt +++ b/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.net5.0.approved.txt @@ -121,7 +121,7 @@ namespace Akavache public interface IObjectBlobCache : Akavache.IBlobCache, System.IDisposable { System.IObservable> GetAllObjects(); - System.IObservable GetObject(string key); + System.IObservable GetObject(string key); System.IObservable GetObjectCreatedAt(string key); System.IObservable InsertObject(string key, T value, System.DateTimeOffset? absoluteExpiration = default); System.IObservable InvalidateAllObjects(); diff --git a/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.netcoreapp3.1.approved.txt b/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.netcoreapp3.1.approved.txt index d58633d64..adb911472 100644 --- a/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.netcoreapp3.1.approved.txt +++ b/src/Akavache.Tests/API/ApiApprovalTests.AkavacheCore.netcoreapp3.1.approved.txt @@ -119,7 +119,7 @@ namespace Akavache public interface IObjectBlobCache : Akavache.IBlobCache, System.IDisposable { System.IObservable> GetAllObjects(); - System.IObservable GetObject(string key); + System.IObservable GetObject(string key); System.IObservable GetObjectCreatedAt(string key); System.IObservable InsertObject(string key, T value, System.DateTimeOffset? absoluteExpiration = default); System.IObservable InvalidateAllObjects(); From cfd90ef3f9d9c48f90f4374a5561b1d488291c69 Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Mon, 12 Apr 2021 00:59:33 +0300 Subject: [PATCH 15/18] Code simplifications, verify static fields aren't broken --- src/Akavache.Drawing/BitmapImageMixin.cs | 16 ++++++++-------- src/Akavache.Tests/UtilityTests.cs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Akavache.Drawing/BitmapImageMixin.cs b/src/Akavache.Drawing/BitmapImageMixin.cs index bb2b23820..06adcd954 100644 --- a/src/Akavache.Drawing/BitmapImageMixin.cs +++ b/src/Akavache.Drawing/BitmapImageMixin.cs @@ -7,7 +7,6 @@ using System.IO; using System.Reactive.Linq; using System.Reactive.Threading.Tasks; -using System.Threading.Tasks; using Splat; namespace Akavache @@ -153,16 +152,17 @@ public static IObservable ThrowOnBadImageBuffer(byte[] compressedImage) Observable.Return(compressedImage); } - private static async Task BytesToImage(byte[] compressedImage, float? desiredWidth, float? desiredHeight) + private static IObservable BytesToImage(byte[] compressedImage, float? desiredWidth, float? desiredHeight) { - using var ms = new MemoryStream(compressedImage); - var bitmap = await BitmapLoader.Current.Load(ms, desiredWidth, desiredHeight).ConfigureAwait(false); - if (bitmap is null) + using (var ms = new MemoryStream(compressedImage)) { - throw new IOException("Failed to load the bitmap!"); + return BitmapLoader.Current + .Load(ms, desiredWidth, desiredHeight) + .ToObservable() + .SelectMany(bitmap => bitmap is not null ? + Observable.Return(bitmap) : + Observable.Throw(new IOException("Failed to load the bitmap!"))); } - - return bitmap; } } } diff --git a/src/Akavache.Tests/UtilityTests.cs b/src/Akavache.Tests/UtilityTests.cs index f757755be..e85342d4c 100644 --- a/src/Akavache.Tests/UtilityTests.cs +++ b/src/Akavache.Tests/UtilityTests.cs @@ -142,5 +142,17 @@ public void KeyedOperationQueueCorrectlyShutsDown() op3.OnCompleted(); Assert.Equal(0, op3Result); } + + /// + /// Test to make sure the static caches are initialized. + /// + [Fact] + public void ShouldInitializeDefaultCaches() + { + Assert.NotNull(BlobCache.LocalMachine); + Assert.NotNull(BlobCache.UserAccount); + Assert.NotNull(BlobCache.InMemory); + Assert.NotNull(BlobCache.Secure); + } } } From ad2acdc04d030406ef4c894bd3af0fc2859b2322 Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Mon, 12 Apr 2021 01:12:11 +0300 Subject: [PATCH 16/18] Add a test for one more overload --- .../TestBases/BlobCacheExtensionsTestBase.cs | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs b/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs index 95d5b57e4..b4788603d 100644 --- a/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs +++ b/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs @@ -34,15 +34,27 @@ public abstract class BlobCacheExtensionsTestBase public async Task DownloadUrlTest() { string path; + using (Utility.WithEmptyDirectory(out path)) + using (var fixture = CreateBlobCache(path)) + { + var bytes = await fixture.DownloadUrl(@"http://httpbin.org/html").FirstAsync(); + Assert.True(bytes.Length > 0); + } + } + /// + /// Tests to make sure the download Uri extension method overload performs correctly. + /// + /// A task to monitor the progress. + [Fact] + public async Task DownloadUriTest() + { + string path; using (Utility.WithEmptyDirectory(out path)) + using (var fixture = CreateBlobCache(path)) { - var fixture = CreateBlobCache(path); - using (fixture) - { - var bytes = await fixture.DownloadUrl(@"http://httpbin.org/html").FirstAsync(); - Assert.True(bytes.Length > 0); - } + var bytes = await fixture.DownloadUrl(new Uri("http://httpbin.org/html")).FirstAsync(); + Assert.True(bytes.Length > 0); } } From e89312dd49663666754f57b6f8d87e2fe677e379 Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Mon, 12 Apr 2021 01:17:23 +0300 Subject: [PATCH 17/18] Check that we are storing the downloaded value with the given eky --- .../TestBases/BlobCacheExtensionsTestBase.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs b/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs index b4788603d..be39e881c 100644 --- a/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs +++ b/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs @@ -58,6 +58,24 @@ public async Task DownloadUriTest() } } + /// + /// Tests to make sure the download Uri with key extension method overload performs correctly. + /// + /// A task to monitor the progress. + [Fact] + public async Task DownloadUriWithKeyTest() + { + string path; + using (Utility.WithEmptyDirectory(out path)) + using (var fixture = CreateBlobCache(path)) + { + var key = Guid.NewGuid().ToString(); + await fixture.DownloadUrl(key, new Uri("http://httpbin.org/html")).FirstAsync(); + var bytes = await fixture.Get(key); + Assert.True(bytes.Length > 0); + } + } + /// /// Tests to make sure that getting non-existent keys throws an exception. /// From b45b66bf81216a68585b7486ea7091b971bee9fd Mon Sep 17 00:00:00 2001 From: Artjom Graf Date: Mon, 12 Apr 2021 01:28:16 +0300 Subject: [PATCH 18/18] Try prevent codecov from complaining --- src/Akavache.Drawing/BitmapImageMixin.cs | 4 +--- .../TestBases/BlobCacheExtensionsTestBase.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Akavache.Drawing/BitmapImageMixin.cs b/src/Akavache.Drawing/BitmapImageMixin.cs index 06adcd954..9effb381f 100644 --- a/src/Akavache.Drawing/BitmapImageMixin.cs +++ b/src/Akavache.Drawing/BitmapImageMixin.cs @@ -156,9 +156,7 @@ private static IObservable BytesToImage(byte[] compressedImage, float? { using (var ms = new MemoryStream(compressedImage)) { - return BitmapLoader.Current - .Load(ms, desiredWidth, desiredHeight) - .ToObservable() + return BitmapLoader.Current.Load(ms, desiredWidth, desiredHeight).ToObservable() .SelectMany(bitmap => bitmap is not null ? Observable.Return(bitmap) : Observable.Throw(new IOException("Failed to load the bitmap!"))); diff --git a/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs b/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs index be39e881c..e6e1d560d 100644 --- a/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs +++ b/src/Akavache.Tests/TestBases/BlobCacheExtensionsTestBase.cs @@ -58,6 +58,24 @@ public async Task DownloadUriTest() } } + /// + /// Tests to make sure the download with key extension method overload performs correctly. + /// + /// A task to monitor the progress. + [Fact] + public async Task DownloadUrlWithKeyTest() + { + string path; + using (Utility.WithEmptyDirectory(out path)) + using (var fixture = CreateBlobCache(path)) + { + var key = Guid.NewGuid().ToString(); + await fixture.DownloadUrl(key, "http://httpbin.org/html").FirstAsync(); + var bytes = await fixture.Get(key); + Assert.True(bytes.Length > 0); + } + } + /// /// Tests to make sure the download Uri with key extension method overload performs correctly. ///