Доработано сохранение состояния
All checks were successful
CI / build-test (push) Successful in 32s

This commit is contained in:
2025-12-05 13:45:38 +03:00
parent e6e5459280
commit 7f81ca85b8
4 changed files with 17 additions and 3 deletions

View File

@@ -42,7 +42,17 @@ public abstract class StatefullPage : Page
/// </summary>
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>();
if (attr is null) continue;

View File

@@ -19,6 +19,10 @@ public sealed class InMemoryStateStorage : IStateStorage
/// <inheritdoc />
public Task SetAsync<T>(CompositeSessionKey session, string key, T state, CancellationToken ct)
{
if (!_store.ContainsKey(session))
{
_store[session] = new();
}
_store[session][key] = state!;
return Task.CompletedTask;
}

View File

@@ -6,7 +6,7 @@ namespace Demo.Pages;
/// <summary>
/// Страница ввода деталей заявки.
/// Страница с параметрами и сохранением состояния.
/// Страница с параметрами и получением состояния.
/// </summary>
public sealed class DetailsPage : StatefullPage<DetailsArgs>
{

View File

@@ -30,7 +30,7 @@ public sealed class FilesPage : SingletonPage
await ctx.SetStorageAsync("Request", request, ct);
await new MessageBuilder(ctx)
.Text($"Получено файлов: {files.Count}", MessageFormat.Plain)
.Text($"По заявке '{request.Title}' Получено файлов: {files.Count}", MessageFormat.Plain)
.Inline("Далее", "next")
.SendAsync(ct);
}