Skip to content

Commit

Permalink
Update code to fix code warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Nov 19, 2023
1 parent c2eeb87 commit b529d39
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 107 deletions.
2 changes: 0 additions & 2 deletions src/Akavache.Core/BlobCache/BlobCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

using System.Diagnostics.CodeAnalysis;
using System.Reactive.Threading.Tasks;

using Newtonsoft.Json.Bson;

using Splat;

namespace Akavache;
Expand Down
2 changes: 0 additions & 2 deletions src/Akavache.Core/BlobCache/InMemoryBlobCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

using System.Diagnostics.CodeAnalysis;
using System.Reactive.Disposables;

using Newtonsoft.Json;
using Newtonsoft.Json.Bson;

using Splat;

namespace Akavache;
Expand Down
5 changes: 1 addition & 4 deletions src/Akavache.Core/BlobCache/ObjectWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ public ObjectWrapper()
{
}

public ObjectWrapper(T value)
{
Value = value;
}
public ObjectWrapper(T value) => Value = value;

public T? Value { get; set; }
}
8 changes: 5 additions & 3 deletions src/Akavache.Core/Json/JsonSerializationMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
using System.Collections.Concurrent;
using System.Globalization;
using System.Reactive.Threading.Tasks;

using Newtonsoft.Json;

using Splat;

namespace Akavache;
Expand Down Expand Up @@ -125,7 +123,7 @@ public static IObservable<IEnumerable<T>> GetAllObjects<T>(this IBlobCache blobC
/// the cache.</returns>
public static IObservable<T?> GetOrFetchObject<T>(this IBlobCache blobCache, string key, Func<IObservable<T>> fetchFunc, DateTimeOffset? absoluteExpiration = null) => blobCache is null
? throw new ArgumentNullException(nameof(blobCache))
: blobCache.GetObject<T>(key).Catch<T?, Exception>(ex =>
: blobCache.GetObject<T>(key).Catch<T?, Exception>(__ =>
{
var prefixedKey = blobCache.GetHashCode().ToString(CultureInfo.InvariantCulture) + key;

Expand Down Expand Up @@ -245,10 +243,14 @@ public static IObservable<IEnumerable<T>> GetAllObjects<T>(this IBlobCache blobC
bool shouldInvalidateOnError = false,
Func<T, bool>? cacheValidationPredicate = null)
{
#if NETSTANDARD || XAMARINIOS || XAMARINMAC || XAMARINTVOS || TIZEN || MONOANDROID13_0
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}
#else
ArgumentNullException.ThrowIfNull(blobCache);
#endif

#pragma warning disable CS8604 // Possible null reference argument.
var fetch = Observable.Defer(() => blobCache.GetObjectCreatedAt<T>(key))
Expand Down
5 changes: 2 additions & 3 deletions src/Akavache.Core/KeyedOperations/KeyedOperationQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// See the LICENSE file in the project root for full license information.

using System.Globalization;

using Splat;

namespace Akavache;
Expand Down Expand Up @@ -137,7 +136,7 @@ private static IObservable<KeyedOperation> ProcessOperation(KeyedOperation opera
.Select(_ => operation)
.Catch(Observable.Return(operation));

private IObservable<T> SafeStart<T>(Func<T> calculationFunc)
private AsyncSubject<T> SafeStart<T>(Func<T> calculationFunc)
{
var ret = new AsyncSubject<T>();
Observable.Start(
Expand All @@ -159,4 +158,4 @@ private IObservable<T> SafeStart<T>(Func<T> calculationFunc)

return ret;
}
}
}
3 changes: 2 additions & 1 deletion src/Akavache.Core/LoginMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static class LoginMixin
/// <param name="blobCache">The blob cache where to get the data.</param>
/// <param name="host">The host associated with the data.</param>
/// <returns>A Future result representing the user/password Tuple.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1047:Non-asynchronous method name should not end with 'Async'.", Justification = "By Design")]
public static IObservable<LoginInfo> GetLoginAsync(this ISecureBlobCache blobCache, string host = "default") => blobCache.GetObject<(string, string)>("login:" + host).Select(x => new LoginInfo(x));

/// <summary>
Expand All @@ -40,4 +41,4 @@ public static class LoginMixin
/// <param name="host">The host associated with the data.</param>
/// <returns>A observable which signals when the erase is completed.</returns>
public static IObservable<Unit> EraseLogin(this ISecureBlobCache blobCache, string host = "default") => blobCache.InvalidateObject<(string, string)>("login:" + host);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

#if MONOANDROID13_0
using Android.App;
#endif

namespace Akavache;

Expand All @@ -15,9 +17,11 @@ public class AndroidFilesystemProvider : IFilesystemProvider
private readonly SimpleFilesystemProvider _inner = new();

/// <inheritdoc />
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1047:Non-asynchronous method name should not end with 'Async'.", Justification = "By Design")]
public IObservable<Stream> OpenFileForReadAsync(string path, IScheduler scheduler) => _inner.OpenFileForReadAsync(path, scheduler);

/// <inheritdoc />
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1047:Non-asynchronous method name should not end with 'Async'.", Justification = "By Design")]
public IObservable<Stream> OpenFileForWriteAsync(string path, IScheduler scheduler) => _inner.OpenFileForWriteAsync(path, scheduler);

/// <inheritdoc />
Expand Down Expand Up @@ -50,4 +54,4 @@ public class AndroidFilesystemProvider : IFilesystemProvider

return di.FullName;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 .NET Foundation and Contributors. All rights reserved.
// Copyright (c) 2023 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
Expand All @@ -15,9 +15,11 @@ public class MacFilesystemProvider : IFilesystemProvider
private readonly SimpleFilesystemProvider _inner = new();

/// <inheritdoc />
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1047:Non-asynchronous method name should not end with 'Async'.", Justification = "By Design")]
public IObservable<Stream> OpenFileForReadAsync(string path, IScheduler scheduler) => _inner.OpenFileForReadAsync(path, scheduler);

/// <inheritdoc />
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1047:Non-asynchronous method name should not end with 'Async'.", Justification = "By Design")]
public IObservable<Stream> OpenFileForWriteAsync(string path, IScheduler scheduler) => _inner.OpenFileForWriteAsync(path, scheduler);

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// See the LICENSE file in the project root for full license information.

using System.Reflection;

using Splat;

namespace Akavache;
Expand All @@ -15,9 +14,11 @@ namespace Akavache;
public class SimpleFilesystemProvider : IFilesystemProvider
{
/// <inheritdoc />
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1047:Non-asynchronous method name should not end with 'Async'.", Justification = "By Design")]
public IObservable<Stream> OpenFileForReadAsync(string path, IScheduler scheduler) => Utility.SafeOpenFileAsync(path, FileMode.Open, FileAccess.Read, FileShare.Read, scheduler);

/// <inheritdoc />
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1047:Non-asynchronous method name should not end with 'Async'.", Justification = "By Design")]
public IObservable<Stream> OpenFileForWriteAsync(string path, IScheduler scheduler) => Utility.SafeOpenFileAsync(path, FileMode.Create, FileAccess.Write, FileShare.None, scheduler);

/// <inheritdoc />
Expand Down Expand Up @@ -58,4 +59,4 @@ protected static string GetAssemblyDirectoryName()

return assemblyDirectoryName ?? throw new InvalidOperationException("The directory name of the assembly location is null");
}
}
}
34 changes: 34 additions & 0 deletions src/Akavache.Core/Platforms/shared/AkavacheHttpMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ public class AkavacheHttpMixin : IAkavacheHttpMixin
/// <inheritdoc/>
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, string url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
#if NETSTANDARD || XAMARINIOS || XAMARINMAC || XAMARINTVOS || TIZEN || MONOANDROID13_0
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}
#else
ArgumentNullException.ThrowIfNull(blobCache);
#endif

return blobCache.DownloadUrl(url, url, headers, fetchAlways, absoluteExpiration);
}

/// <inheritdoc/>
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, Uri url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
#if NETSTANDARD || XAMARINIOS || XAMARINMAC || XAMARINTVOS || TIZEN || MONOANDROID13_0
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
Expand All @@ -37,17 +42,25 @@ public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, Uri url, IDictionar
{
throw new ArgumentNullException(nameof(url));
}
#else
ArgumentNullException.ThrowIfNull(blobCache);
ArgumentNullException.ThrowIfNull(url);
#endif

return blobCache.DownloadUrl(url.ToString(), url, headers, fetchAlways, absoluteExpiration);
}

/// <inheritdoc/>
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, string key, string url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
#if NETSTANDARD || XAMARINIOS || XAMARINMAC || XAMARINTVOS || TIZEN || MONOANDROID13_0
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}
#else
ArgumentNullException.ThrowIfNull(blobCache);
#endif

var doFetch = MakeWebRequest(HttpMethod.Get, new Uri(url), headers).SelectMany(x => ProcessWebResponse(x, url, absoluteExpiration));
var fetchAndCache = doFetch.SelectMany(x => blobCache.Insert(key, x, absoluteExpiration).Select(_ => x));
Expand All @@ -70,10 +83,14 @@ public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, string key, string
/// <inheritdoc/>
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, string key, Uri url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
#if NETSTANDARD || XAMARINIOS || XAMARINMAC || XAMARINTVOS || TIZEN || MONOANDROID13_0
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}
#else
ArgumentNullException.ThrowIfNull(blobCache);
#endif

var doFetch = MakeWebRequest(HttpMethod.Get, url, headers).SelectMany(x => ProcessWebResponse(x, url, absoluteExpiration));
var fetchAndCache = doFetch.SelectMany(x => blobCache.Insert(key, x, absoluteExpiration).Select(_ => x));
Expand All @@ -96,17 +113,22 @@ public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, string key, Uri url
/// <inheritdoc/>
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, HttpMethod method, string url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
#if NETSTANDARD || XAMARINIOS || XAMARINMAC || XAMARINTVOS || TIZEN || MONOANDROID13_0
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}
#else
ArgumentNullException.ThrowIfNull(blobCache);
#endif

return blobCache.DownloadUrl(method, url, url, headers, fetchAlways, absoluteExpiration);
}

/// <inheritdoc/>
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, HttpMethod method, Uri url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
#if NETSTANDARD || XAMARINIOS || XAMARINMAC || XAMARINTVOS || TIZEN || MONOANDROID13_0
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
Expand All @@ -116,17 +138,25 @@ public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, HttpMethod method,
{
throw new ArgumentNullException(nameof(url));
}
#else
ArgumentNullException.ThrowIfNull(blobCache);
ArgumentNullException.ThrowIfNull(url);
#endif

return blobCache.DownloadUrl(method, url.ToString(), url, headers, fetchAlways, absoluteExpiration);
}

/// <inheritdoc/>
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, HttpMethod method, string key, string url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
#if NETSTANDARD || XAMARINIOS || XAMARINMAC || XAMARINTVOS || TIZEN || MONOANDROID13_0
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}
#else
ArgumentNullException.ThrowIfNull(blobCache);
#endif

var doFetch = MakeWebRequest(method, new Uri(url), headers).SelectMany(x => ProcessWebResponse(x, url, absoluteExpiration));
var fetchAndCache = doFetch.SelectMany(x => blobCache.Insert(key, x, absoluteExpiration).Select(_ => x));
Expand All @@ -149,10 +179,14 @@ public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, HttpMethod method,
/// <inheritdoc/>
public IObservable<byte[]> DownloadUrl(IBlobCache blobCache, HttpMethod method, string key, Uri url, IDictionary<string, string>? headers = null, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)
{
#if NETSTANDARD || XAMARINIOS || XAMARINMAC || XAMARINTVOS || TIZEN || MONOANDROID13_0
if (blobCache is null)
{
throw new ArgumentNullException(nameof(blobCache));
}
#else
ArgumentNullException.ThrowIfNull(blobCache);
#endif

var doFetch = MakeWebRequest(method, url, headers).SelectMany(x => ProcessWebResponse(x, url, absoluteExpiration));
var fetchAndCache = doFetch.SelectMany(x => blobCache.Insert(key, x, absoluteExpiration).Select(_ => x));
Expand Down
6 changes: 3 additions & 3 deletions src/Akavache.Core/Platforms/shared/EncryptionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class EncryptionProvider : IEncryptionProvider
{
/// <inheritdoc />
public IObservable<byte[]> EncryptBlock(byte[] block) =>
Observable.Return(
ProtectedData.Protect(block, null, DataProtectionScope.CurrentUser));
Observable.Return(ProtectedData.Protect(block, null, DataProtectionScope.CurrentUser));

/// <inheritdoc />
public IObservable<byte[]> DecryptBlock(byte[] block) => Observable.Return(ProtectedData.Unprotect(block, null, DataProtectionScope.CurrentUser));
public IObservable<byte[]> DecryptBlock(byte[] block) =>
Observable.Return(ProtectedData.Unprotect(block, null, DataProtectionScope.CurrentUser));
}
}
9 changes: 0 additions & 9 deletions src/Akavache.Core/Platforms/shared/MD5Managed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ internal class MD5Managed : MD5

public MD5Managed()
{
// TODO SHANE is this ok for UWP?
#if !WINDOWS_UWP
HashSizeValue = 0x80;
#endif
_data = new byte[64];
_abcd = default;
}
Expand Down Expand Up @@ -80,14 +76,9 @@ protected override void HashCore(byte[] array, int ibStart, int cbSize)
_totalLength += cbSize;
}

// TODO SHANE is this ok for UWP?
#if !WINDOWS_UWP
protected override byte[] HashFinal()
{
HashValue = MD5Core.GetHashFinalBlock(_data, 0, _dataSize, _abcd, _totalLength * 8);
return HashValue;
}
#else
protected override byte[] HashFinal() => MD5Core.GetHashFinalBlock(_data, 0, _dataSize, _abcd, _totalLength * 8);
#endif
}
10 changes: 4 additions & 6 deletions src/Akavache.Core/Platforms/shared/Registrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,23 @@ public class Registrations : IWantsToRegisterStuff
#endif
public void Register(IMutableDependencyResolver resolver, IReadonlyDependencyResolver readonlyDependencyResolver)
{
#if NETSTANDARD || XAMARINIOS || XAMARINMAC || XAMARINTVOS || TIZEN || MONOANDROID13_0
if (resolver is null)
{
throw new ArgumentNullException(nameof(resolver));
}
#else
ArgumentNullException.ThrowIfNull(resolver);
#endif

#if XAMARIN_MOBILE
var fs = new IsolatedStorageProvider();
#elif WINDOWS_UWP
var fs = new WinRTFilesystemProvider();
#else
var fs = new SimpleFilesystemProvider();
#endif
resolver.Register(() => fs, typeof(IFilesystemProvider), null);

#if WINDOWS_UWP
var enc = new WinRTEncryptionProvider();
#else
var enc = new EncryptionProvider();
#endif
resolver.Register(() => enc, typeof(IEncryptionProvider), null);

var localCache = new Lazy<IBlobCache>(() => new InMemoryBlobCache());
Expand Down
Loading

0 comments on commit b529d39

Please sign in to comment.