-
-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Add maui and use HttpClient #788
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b0d4c9f
feature: Add maui and use HttpClient
glennawatson fff3650
Merge remote-tracking branch 'origin/main' into glennawatson/add/http…
glennawatson 272b71a
Remove redundant packages folder
glennawatson 39678cd
Update readme
glennawatson 02ba47e
Further fix to the readme
glennawatson da37f44
Update new stuff
glennawatson a2f2a6e
Merge branch 'main' into glennawatson/add/httpclient
glennawatson d08ea78
Fix nullable issues
glennawatson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
// Copyright (c) 2022 .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. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reactive.Threading.Tasks; | ||
|
||
using Newtonsoft.Json.Bson; | ||
|
||
using Splat; | ||
|
||
namespace Akavache; | ||
|
||
/// <summary> | ||
/// A class which represents a blobbed cache. | ||
/// </summary> | ||
public static class BlobCache | ||
{ | ||
private static string? _applicationName; | ||
private static IBlobCache? _localMachine; | ||
private static IBlobCache? _userAccount; | ||
private static ISecureBlobCache? _secure; | ||
private static bool _shutdownRequested; | ||
|
||
private static IScheduler? _taskPoolOverride; | ||
|
||
[ThreadStatic] | ||
private static IBlobCache? _unitTestLocalMachine; | ||
|
||
[ThreadStatic] | ||
private static IBlobCache? _unitTestUserAccount; | ||
|
||
[ThreadStatic] | ||
private static ISecureBlobCache? _unitTestSecure; | ||
|
||
static BlobCache() | ||
{ | ||
Locator.RegisterResolverCallbackChanged(() => | ||
{ | ||
if (Locator.CurrentMutable is null) | ||
{ | ||
return; | ||
} | ||
|
||
Locator.CurrentMutable.InitializeAkavache(Locator.Current); | ||
}); | ||
|
||
InMemory = new InMemoryBlobCache(Scheduler.Default); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets your application's name. Set this at startup, this defines where | ||
/// your data will be stored (usually at %AppData%\[ApplicationName]). | ||
/// </summary> | ||
[SuppressMessage("Design", "CA1065: Properties should not fire exceptions.", Justification = "Extreme non standard case.")] | ||
public static string ApplicationName | ||
{ | ||
<<<<<<< HEAD | ||
get | ||
{ | ||
if (_applicationName is null) | ||
{ | ||
throw new InvalidOperationException("Make sure to set BlobCache.ApplicationName on startup"); | ||
} | ||
|
||
return _applicationName; | ||
} | ||
======= | ||
get => _applicationName ?? throw new("Make sure to set BlobCache.ApplicationName on startup"); | ||
>>>>>>> main | ||
|
||
set => _applicationName = value; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the local machine cache. Store data here that is unrelated to the | ||
/// user account or shouldn't be uploaded to other machines (i.e. | ||
/// image cache data). | ||
/// </summary> | ||
public static IBlobCache LocalMachine | ||
{ | ||
get => _unitTestLocalMachine ?? _localMachine ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService<IBlobCache>("LocalMachine") ?? throw new InvalidOperationException("Unable to resolve LocalMachine cache. Make sure Akavache is initialized properly."); | ||
set | ||
{ | ||
if (ModeDetector.InUnitTestRunner()) | ||
{ | ||
_unitTestLocalMachine = value; | ||
_localMachine ??= value; | ||
} | ||
else | ||
{ | ||
_localMachine = value; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the user account cache. Store data here that is associated with | ||
/// the user; in large organizations, this data will be synced to all | ||
/// machines via NT Roaming Profiles. | ||
/// </summary> | ||
public static IBlobCache UserAccount | ||
{ | ||
get => _unitTestUserAccount ?? _userAccount ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService<IBlobCache>("UserAccount") ?? throw new InvalidOperationException("Unable to resolve UserAccount cache. Make sure Akavache is initialized properly."); | ||
set | ||
{ | ||
if (ModeDetector.InUnitTestRunner()) | ||
{ | ||
_unitTestUserAccount = value; | ||
_userAccount ??= value; | ||
} | ||
else | ||
{ | ||
_userAccount = value; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets an IBlobCache that is encrypted - store sensitive data in this | ||
/// cache such as login information. | ||
/// </summary> | ||
public static ISecureBlobCache Secure | ||
{ | ||
get => _unitTestSecure ?? _secure ?? (_shutdownRequested ? new ShutdownBlobCache() : null) ?? Locator.Current.GetService<ISecureBlobCache>() ?? throw new InvalidOperationException("Unable to resolve Secure cache. Make sure Akavache is initialized properly."); | ||
set | ||
{ | ||
if (ModeDetector.InUnitTestRunner()) | ||
{ | ||
_unitTestSecure = value; | ||
_secure ??= value; | ||
} | ||
else | ||
{ | ||
_secure = value; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets an IBlobCache that simply stores data in memory. Data stored in | ||
/// this cache will be lost when the application restarts. | ||
/// </summary> | ||
public static ISecureBlobCache InMemory { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the DateTimeKind handling for BSON readers to be forced. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// By default, <see cref="BsonReader"/> uses a <see cref="DateTimeKind"/> of <see cref="DateTimeKind.Local"/> and <see cref="BsonWriter"/> | ||
/// uses <see cref="DateTimeKind.Utc"/>. Thus, DateTimes are serialized as UTC but deserialized as local time. To force BSON readers to | ||
/// use some other <c>DateTimeKind</c>, you can set this value. | ||
/// </para> | ||
/// </remarks> | ||
public static DateTimeKind? ForcedDateTimeKind { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the Scheduler used for task pools. | ||
/// </summary> | ||
public static IScheduler TaskpoolScheduler | ||
{ | ||
get => _taskPoolOverride ?? Locator.Current.GetService<IScheduler>("Taskpool") ?? TaskPoolScheduler.Default; | ||
set => _taskPoolOverride = value; | ||
} | ||
|
||
/// <summary> | ||
/// Makes sure that the system has been initialized. | ||
/// </summary> | ||
public static void EnsureInitialized() => | ||
|
||
// NB: This method doesn't actually do anything, it just ensures | ||
// that the static constructor runs | ||
LogHost.Default.Debug("Initializing Akavache"); | ||
|
||
/// <summary> | ||
/// This method shuts down all of the blob caches. Make sure call it | ||
/// on app exit and await / Wait() on it. | ||
/// </summary> | ||
/// <returns>A Task representing when all caches have finished shutting | ||
/// down.</returns> | ||
public static Task Shutdown() | ||
{ | ||
_shutdownRequested = true; | ||
var toDispose = new[] { LocalMachine, UserAccount, Secure, InMemory, }; | ||
|
||
var ret = toDispose.Select(x => | ||
{ | ||
x.Dispose(); | ||
return x.Shutdown; | ||
}).Merge().ToList().Select(_ => Unit.Default); | ||
|
||
return ret.ToTask(); | ||
} | ||
|
||
private class ShutdownBlobCache : ISecureBlobCache | ||
{ | ||
IObservable<Unit> IBlobCache.Shutdown => Observable.Return(Unit.Default); | ||
|
||
public IScheduler Scheduler => System.Reactive.Concurrency.Scheduler.Immediate; | ||
|
||
/// <inheritdoc /> | ||
public DateTimeKind? ForcedDateTimeKind | ||
{ | ||
get => null; | ||
set { } | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
public IObservable<Unit> Insert(string key, byte[] data, DateTimeOffset? absoluteExpiration = null) => Observable.Empty<Unit>(); | ||
|
||
public IObservable<byte[]> Get(string key) => Observable.Empty<byte[]>(); | ||
|
||
public IObservable<IEnumerable<string>> GetAllKeys() => Observable.Empty<IEnumerable<string>>(); | ||
|
||
public IObservable<DateTimeOffset?> GetCreatedAt(string key) => Observable.Empty<DateTimeOffset?>(); | ||
|
||
public IObservable<Unit> Flush() => Observable.Empty<Unit>(); | ||
|
||
public IObservable<Unit> Invalidate(string key) => Observable.Empty<Unit>(); | ||
|
||
public IObservable<Unit> InvalidateAll() => Observable.Empty<Unit>(); | ||
|
||
public IObservable<Unit> Vacuum() => Observable.Empty<Unit>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these merge issues, or is GitHub UI bugged?