This commit is contained in:
@@ -42,7 +42,17 @@ public abstract class StatefullPage : Page
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected async Task SaveState(PageContext ctx, CancellationToken ct)
|
protected async Task SaveState(PageContext ctx, CancellationToken ct)
|
||||||
{
|
{
|
||||||
foreach (var prop in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
var t = GetType();
|
||||||
|
foreach (var prop in t.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
|
||||||
|
{
|
||||||
|
var attr = prop.GetCustomAttribute<StatefullAttribute>();
|
||||||
|
if (attr is null) continue;
|
||||||
|
|
||||||
|
var value = prop.GetValue(this);
|
||||||
|
await ctx.StateStorage.SetAsync(ctx.SessionKey, attr.Key, value, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var prop in t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
|
||||||
{
|
{
|
||||||
var attr = prop.GetCustomAttribute<StatefullAttribute>();
|
var attr = prop.GetCustomAttribute<StatefullAttribute>();
|
||||||
if (attr is null) continue;
|
if (attr is null) continue;
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ public sealed class InMemoryStateStorage : IStateStorage
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Task SetAsync<T>(CompositeSessionKey session, string key, T state, CancellationToken ct)
|
public Task SetAsync<T>(CompositeSessionKey session, string key, T state, CancellationToken ct)
|
||||||
{
|
{
|
||||||
|
if (!_store.ContainsKey(session))
|
||||||
|
{
|
||||||
|
_store[session] = new();
|
||||||
|
}
|
||||||
_store[session][key] = state!;
|
_store[session][key] = state!;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace Demo.Pages;
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Страница ввода деталей заявки.
|
/// Страница ввода деталей заявки.
|
||||||
/// Страница с параметрами и сохранением состояния.
|
/// Страница с параметрами и получением состояния.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class DetailsPage : StatefullPage<DetailsArgs>
|
public sealed class DetailsPage : StatefullPage<DetailsArgs>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public sealed class FilesPage : SingletonPage
|
|||||||
await ctx.SetStorageAsync("Request", request, ct);
|
await ctx.SetStorageAsync("Request", request, ct);
|
||||||
|
|
||||||
await new MessageBuilder(ctx)
|
await new MessageBuilder(ctx)
|
||||||
.Text($"Получено файлов: {files.Count}", MessageFormat.Plain)
|
.Text($"По заявке '{request.Title}' Получено файлов: {files.Count}", MessageFormat.Plain)
|
||||||
.Inline("Далее", "next")
|
.Inline("Далее", "next")
|
||||||
.SendAsync(ct);
|
.SendAsync(ct);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user