36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace TeleWave.Application.Programming.Templates;
|
|
|
|
/// <summary>
|
|
/// Откуда слот-повтор берёт содержимое: точка в уже записанной ленте того же канала. «Вечерний фильм
|
|
/// утром в субботу» — это <c>daysAgo = 1, time = 20:00</c>.
|
|
/// </summary>
|
|
public sealed record RepeatSource(int DaysAgo, TimeOnly Time, int DurationMinutes)
|
|
{
|
|
private static readonly JsonSerializerOptions Options = new()
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
|
Converters = { new JsonStringEnumConverter() },
|
|
};
|
|
|
|
public string ToJson() => JsonSerializer.Serialize(this, Options);
|
|
|
|
public static RepeatSource? FromJson(string? json)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(json))
|
|
return null;
|
|
|
|
try
|
|
{
|
|
return JsonSerializer.Deserialize<RepeatSource>(json, Options);
|
|
}
|
|
catch (JsonException)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|