Skip to content

Commit

Permalink
Sample updates
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Jun 26, 2024
1 parent 8576d64 commit 97b3fa2
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Sample/Contracts/OfflineRequest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Sample.Contracts;

public record OfflineRequest : IRequest<string>;
public record OfflineRequest : IRequest<string>;
8 changes: 4 additions & 4 deletions Sample/Handlers/CachedRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ namespace Sample.Handlers;


[RegisterHandler]
public class CachedRequestHandler : IRequestHandler<OfflineRequest, string>
public class CachedRequestHandler : IRequestHandler<CacheRequest, string>
{
[OfflineAvailable]
public Task<string> Handle(OfflineRequest request, CancellationToken cancellationToken)
[Cache]
public Task<string> Handle(CacheRequest request, CancellationToken cancellationToken)
{
var r = DateTimeOffset.UtcNow.ToLocalTime().ToString("h:mm:ss tt");
var r = DateTimeOffset.Now.ToString("h:mm:ss tt");
return Task.FromResult(r);
}
}
15 changes: 15 additions & 0 deletions Sample/Handlers/OfflineRequestHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Sample.Contracts;

namespace Sample.Handlers;


[RegisterHandler]
public class OfflineRequestHandler : IRequestHandler<OfflineRequest, string>
{
[OfflineAvailable(true)]
public Task<string> Handle(OfflineRequest request, CancellationToken cancellationToken)
{
var r = DateTimeOffset.Now.ToString("h:mm:ss tt");
return Task.FromResult(r);
}
}
2 changes: 1 addition & 1 deletion Sample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static MauiApp CreateMauiApp()
// )
.AddMemoryCaching(x =>
{

x.ExpirationScanFrequency = TimeSpan.FromSeconds(5);
})
);
builder.Services.AddDiscoveredMediatorHandlersFromSample();
Expand Down
8 changes: 8 additions & 0 deletions Sample/TriggerPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
Command="{Binding ErrorTrap}" />
</TableSection>

<TableSection Title="Offline">
<TextCell Text="Request"
Command="{Binding OfflineCommand}" />

<TextCell Text="Value"
Detail="{Binding OfflineValue}" />
</TableSection>

<TableSection Title="Cache">
<TextCell Text="Clear" Command="{Binding CacheClear}" />
<TextCell Text="Request" Command="{Binding CacheRequest}" />
Expand Down
22 changes: 16 additions & 6 deletions Sample/TriggerViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Extensions.Caching.Memory;
using Sample.Contracts;

namespace Sample;
Expand All @@ -11,6 +12,7 @@ public class TriggerViewModel : ViewModel, IEventHandler<MyMessageEvent>
public TriggerViewModel(
BaseServices services,
IMediator mediator,
IMemoryCache cache,
AppSqliteConnection data
)
: base(services)
Expand Down Expand Up @@ -72,11 +74,11 @@ await data.Log(
data.Log("TriggerViewModel-Subscribe", @event)
);

// this.CacheClear = ReactiveCommand.CreateFromTask(async () =>
// {
// await mediator.Send(new FlushAllCacheRequest());
// await this.Dialogs.Alert("Cache Cleared");
// });
this.CacheClear = ReactiveCommand.CreateFromTask(async () =>
{
cache.Clear();
await this.Dialogs.Alert("Cache Cleared");
});

this.CancelStream = ReactiveCommand.CreateFromTask(async () =>
{
Expand All @@ -85,14 +87,19 @@ await data.Log(
});
this.CacheRequest = ReactiveCommand.CreateFromTask(async () =>
{
this.CacheValue = await mediator.Request(new OfflineRequest());
this.CacheValue = await mediator.Request(new CacheRequest());
});

this.ResilientCommand = ReactiveCommand.CreateFromTask(async () =>
{
this.ResilientValue = await mediator.Request(new ResilientRequest());
});

this.OfflineCommand = ReactiveCommand.CreateFromTask(async () =>
{
this.OfflineValue = await mediator.Request(new OfflineRequest());
});

this.RefreshTimerStart = ReactiveCommand.CreateFromTask(async () =>
{
var en = mediator.Request(new AutoRefreshRequest(), this.DeactivateToken).GetAsyncEnumerator(this.DeactivateToken);
Expand All @@ -115,6 +122,9 @@ public Task Handle(MyMessageEvent @event, CancellationToken cancellationToken)
}


public ICommand OfflineCommand { get; }
[Reactive] public string OfflineValue { get; private set; }

public ICommand CancelStream { get; }
public ICommand ErrorTrap { get; }
public ICommand TriggerCommand { get; }
Expand Down

0 comments on commit 97b3fa2

Please sign in to comment.