20240327-3
This commit is contained in:
parent
b13c15ea40
commit
84d94a2463
@ -35,9 +35,7 @@ public class ActionState<T>: ISerializable
|
||||
// ReSharper disable once MemberCanBeProtected.Global
|
||||
public ActionState ()
|
||||
{
|
||||
Info = [];
|
||||
Warnings = [];
|
||||
Errors = [];
|
||||
Messages = [];
|
||||
Value = default;
|
||||
}
|
||||
|
||||
@ -47,26 +45,14 @@ public class ActionState<T>: ISerializable
|
||||
/// <param name="defaultValue">Начальное значение <see cref="Value"/></param>
|
||||
public ActionState (T defaultValue)
|
||||
{
|
||||
Info = [];
|
||||
Warnings = [];
|
||||
Errors = [];
|
||||
Messages = [];
|
||||
Value = defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Список информации
|
||||
/// </summary>
|
||||
public List<ActionStateMessage> Info { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Список предупреждений
|
||||
/// </summary>
|
||||
public List<ActionStateMessage> Warnings { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Список ошибок
|
||||
/// </summary>
|
||||
public List<ActionStateMessage> Errors { get; }
|
||||
public List<ActionStateMessage> Messages { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Значение
|
||||
@ -114,21 +100,23 @@ public class ActionState<T>: ISerializable
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Добавление ошибки
|
||||
#region Добавление
|
||||
/// <summary>
|
||||
/// Добавление ошибки
|
||||
/// Добавление сообщения
|
||||
/// </summary>
|
||||
/// <param name="error">Ошибка</param>
|
||||
/// <param name="message">Сообщение</param>
|
||||
// ReSharper disable once MemberCanBeMadeStatic.Global
|
||||
// ReSharper disable once FunctionRecursiveOnAllPaths
|
||||
public void AddError (ActionStateMessage error) => Errors.Add(error);
|
||||
public void Add (ActionStateMessage message) => Messages.Add(message);
|
||||
|
||||
/// <summary>
|
||||
/// Добавляет ошибки в список
|
||||
/// Добавляет список
|
||||
/// </summary>
|
||||
/// <param name="errors">Список ошибок</param>
|
||||
public void AddErrors (IEnumerable<ActionStateMessage> errors) => Errors.AddRange(errors);
|
||||
/// <param name="messages">Список сообщений</param>
|
||||
public void AddRange (IEnumerable<ActionStateMessage> messages) => Messages.AddRange(messages);
|
||||
|
||||
#endregion
|
||||
#region Добавление ошибки
|
||||
/// <summary>
|
||||
/// Добавление ошибки
|
||||
/// </summary>
|
||||
@ -136,10 +124,13 @@ public class ActionState<T>: ISerializable
|
||||
public void AddError (bool critical = true)
|
||||
{
|
||||
//Создаю ошибку
|
||||
ActionStateMessage error = new("", critical);
|
||||
ActionStateMessage error = new("", critical)
|
||||
{
|
||||
MessageType = EActionStateMessageType.Error
|
||||
};
|
||||
|
||||
//Добавляю ошибку
|
||||
AddError(error);
|
||||
Add(error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -150,10 +141,13 @@ public class ActionState<T>: ISerializable
|
||||
public void AddError (string message, bool critical = true)
|
||||
{
|
||||
//Создаю ошибку
|
||||
ActionStateMessage error = new(message, critical);
|
||||
ActionStateMessage error = new(message, critical)
|
||||
{
|
||||
MessageType = EActionStateMessageType.Error
|
||||
};
|
||||
|
||||
//Добавляю ошибку
|
||||
AddError(error);
|
||||
Add(error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -165,10 +159,13 @@ public class ActionState<T>: ISerializable
|
||||
public void AddError (string errorObject, string message, bool critical = true)
|
||||
{
|
||||
//Создаю ошибку
|
||||
ActionStateMessage error = new(errorObject, message, critical);
|
||||
ActionStateMessage error = new(errorObject, message, critical)
|
||||
{
|
||||
MessageType = EActionStateMessageType.Error
|
||||
};
|
||||
|
||||
//Добавляю ошибку
|
||||
AddError(error);
|
||||
Add(error);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -389,6 +386,9 @@ public class ActionState<T>: ISerializable
|
||||
/// <inheritdoc />
|
||||
public void Deserialize (string json)
|
||||
{
|
||||
// Удаляю лишние символы
|
||||
json = json.Trim("\"".ToCharArray());
|
||||
|
||||
// Десериализую строку
|
||||
ActionStateSerializable itemSerializable =
|
||||
new NewtonsoftJsonSerializer().Deserialize<ActionStateSerializable>(json) ?? new();
|
||||
|
@ -1,5 +1,7 @@
|
||||
// ReSharper disable MemberCanBeInternal
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using anbs_cp.Enums;
|
||||
using anbs_cp.Interfaces;
|
||||
|
||||
namespace anbs_cp.Classes;
|
||||
@ -9,84 +11,141 @@ namespace anbs_cp.Classes;
|
||||
/// </summary>
|
||||
public sealed class ActionStateMessage: ISerializable
|
||||
{
|
||||
#region Свойства
|
||||
/// <summary>
|
||||
/// Критичность сообщения
|
||||
/// </summary>
|
||||
public bool IsCritical { get; set; }
|
||||
#region Свойства
|
||||
/// <summary>
|
||||
/// Тип сообщения
|
||||
/// </summary>
|
||||
public EActionStateMessageType MessageType { get; set; } = EActionStateMessageType.Information;
|
||||
|
||||
/// <summary>
|
||||
/// Объект сообщения
|
||||
/// </summary>
|
||||
public object Object { get; set; }
|
||||
/// <summary>
|
||||
/// Критичность сообщения
|
||||
/// </summary>
|
||||
public bool IsCritical { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Текст сообщения
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// Объект сообщения
|
||||
/// </summary>
|
||||
public string Object { get; set; }
|
||||
|
||||
#region Конструкторы
|
||||
/// <summary>
|
||||
/// Конструктор по умолчанию
|
||||
/// </summary>
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public ActionStateMessage ()
|
||||
/// <summary>
|
||||
/// Текст сообщения
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Конструкторы
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор по умолчанию
|
||||
/// </summary>
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public ActionStateMessage ()
|
||||
{
|
||||
IsCritical = true;
|
||||
Object = "Not Implemented";
|
||||
Message = "Not Implemented";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор с 2 параметрами
|
||||
/// </summary>
|
||||
/// <param name="message">Сообщение</param>
|
||||
/// <param name="isCritical">Критичность сообщения</param>
|
||||
public ActionStateMessage (string message, bool isCritical = true)
|
||||
{
|
||||
IsCritical = isCritical;
|
||||
Object = "";
|
||||
Message = message;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор с 3 параметрами
|
||||
/// </summary>
|
||||
/// <param name="eObject">Объект сообщения</param>
|
||||
/// <param name="message">Сообщение</param>
|
||||
/// <param name="isCritical">Критичность сообщения</param>
|
||||
public ActionStateMessage (string eObject, string message, bool isCritical = true)
|
||||
{
|
||||
IsCritical = isCritical;
|
||||
Object = eObject;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Методы
|
||||
|
||||
/// <summary>
|
||||
/// Вывод сообщения
|
||||
/// </summary>
|
||||
/// <param name="format">Строка-форматирование (например, «[{0}] - {1}»)</param>
|
||||
/// <returns>Отформатированную строка</returns>
|
||||
public string PrintMessage (string format) => string.Format(format, Object, Message);
|
||||
|
||||
/// <summary>
|
||||
/// Устанавливает объект
|
||||
/// </summary>
|
||||
/// <param name="obj">Объект</param>
|
||||
/// <typeparam name="T">Тип объекта</typeparam>
|
||||
public void SetObject<T> (T obj)
|
||||
{
|
||||
// Если объект реализует интерфейс ISerializable
|
||||
if (obj is ISerializable serializable)
|
||||
{
|
||||
IsCritical = true;
|
||||
Object = "Not Implemented";
|
||||
Message = "Not Implemented";
|
||||
// - то сериализуем его методами интерфейса
|
||||
Object = serializable.Serialize();
|
||||
// - и прерываем
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор с 2 параметрами
|
||||
/// </summary>
|
||||
/// <param name="message">Сообщение</param>
|
||||
/// <param name="isCritical">Критичность сообщения</param>
|
||||
public ActionStateMessage (string message, bool isCritical = true)
|
||||
{
|
||||
IsCritical = isCritical;
|
||||
Object = "";
|
||||
Message = message;
|
||||
}
|
||||
// Сериализуем объект с помощью NewtonsoftJson
|
||||
Object = new NewtonsoftJsonSerializer().Serialize(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор с 3 параметрами
|
||||
/// </summary>
|
||||
/// <param name="eObject">Объект сообщения</param>
|
||||
/// <param name="message">Сообщение</param>
|
||||
/// <param name="isCritical">Критичность сообщения</param>
|
||||
public ActionStateMessage (object eObject, string message, bool isCritical = true)
|
||||
{
|
||||
IsCritical = isCritical;
|
||||
Object = eObject;
|
||||
Message = message;
|
||||
}
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// Получает объект
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Класс объекта</typeparam>
|
||||
/// <returns>Объект или null</returns>
|
||||
public T? GetObject<T> () => new NewtonsoftJsonSerializer().Deserialize<T>(Object);
|
||||
|
||||
#region Методы
|
||||
/// <summary>
|
||||
/// Вывод сообщения
|
||||
/// </summary>
|
||||
/// <param name="format">Строка-форматирование (например, «[{0}] - {1}»)</param>
|
||||
/// <returns>Отформатированную строка</returns>
|
||||
public string PrintMessage (string format) => string.Format(format, Object, Message);
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// Получает объект
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Класс объекта, реализующий интерфейс ISerializable</typeparam>
|
||||
/// <returns>Объект</returns>
|
||||
public T GetSerializedObject<T> () where T : ISerializable, new()
|
||||
{
|
||||
// Создаём результирующую модель
|
||||
T model = new();
|
||||
|
||||
#region Реализация интерфейса ISerializable
|
||||
/// <inheritdoc />
|
||||
public string Serialize () => new NewtonsoftJsonSerializer().Serialize(this);
|
||||
// Десериализуем её методами интерфейса ISerializable
|
||||
model.Deserialize(Object);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Deserialize (string json)
|
||||
{
|
||||
// Десериализую строку
|
||||
ActionStateMessage item = new NewtonsoftJsonSerializer().Deserialize<ActionStateMessage>(json) ?? new();
|
||||
// Возвращаем модель
|
||||
return model;
|
||||
}
|
||||
|
||||
// Передаю параметры
|
||||
IsCritical = item.IsCritical;
|
||||
Object = item.Object;
|
||||
Message = item.Message;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Реализация интерфейса ISerializable
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Serialize () => new NewtonsoftJsonSerializer().Serialize(this);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Deserialize (string json)
|
||||
{
|
||||
// Десериализую строку
|
||||
ActionStateMessage item = new NewtonsoftJsonSerializer().Deserialize<ActionStateMessage>(json) ?? new();
|
||||
|
||||
// Передаю параметры
|
||||
MessageType = item.MessageType;
|
||||
IsCritical = item.IsCritical;
|
||||
Object = item.Object;
|
||||
Message = item.Message;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
21
anbs_cp/Enums/EActionStateMessageType.cs
Normal file
21
anbs_cp/Enums/EActionStateMessageType.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace anbs_cp.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Тип сообщения о состоянии
|
||||
/// </summary>
|
||||
public enum EActionStateMessageType
|
||||
{ /// <summary>
|
||||
/// Информация
|
||||
/// </summary>
|
||||
Information = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Предупреждение
|
||||
/// </summary>
|
||||
Warning = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Ошибка
|
||||
/// </summary>
|
||||
Error = 2
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Version>2024.3.26.2</Version>
|
||||
<Version>2024.3.27.2</Version>
|
||||
<Authors>Александр Бабаев</Authors>
|
||||
<Product>Набор компонентов ANB Software</Product>
|
||||
<Description>Библиотека полезных методов языка C#</Description>
|
||||
@ -38,7 +38,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MimeTypes" Version="2.4.1">
|
||||
<PackageReference Include="MimeTypes" Version="2.5.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
@ -8,7 +8,7 @@
|
||||
<RootNamespace>anbs_cp.Database</RootNamespace>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<PackageId>ANBSoftware.ComponentsPack.Database</PackageId>
|
||||
<Version>2024.3.25</Version>
|
||||
<Version>2024.3.27</Version>
|
||||
<Company>Александр Бабаев</Company>
|
||||
<Product>Набор компонентов ANB Software для работы с БД</Product>
|
||||
<Description>Библиотека полезных методов языка C# для работы с базами данных</Description>
|
||||
@ -21,7 +21,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.3.5" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.3.6" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<PackageId>ANBSoftware.ComponentsPackForNet</PackageId>
|
||||
<Version>2024.3.26</Version>
|
||||
<Version>2024.3.27</Version>
|
||||
<Authors>Александр Бабаев</Authors>
|
||||
<Product>Набор компонентов ANB Software для ASP.NET Core</Product>
|
||||
<Description>Библиотека полезных методов языка C# для ASP.NET Core</Description>
|
||||
@ -21,11 +21,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlSanitizer" Version="8.0.843" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Html.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -18,6 +18,7 @@
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0412_0435_0440_043D_0451_043C/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0412_0438_0434_0435_043E_043A_0430_0440_0442_0430/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0414_0435_0441_0435_0440_0438_0430_043B_0438_0437_043E_0432_0430_043D_043D_044B_0439/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0414_0435_0441_0435_0440_0438_0430_043B_0438_0437_0443_0435_043C/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0414_0435_0441_0435_0440_0438_0430_043B_0438_0437_0443_044E/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_041F_0430_0440_0441_0435_0440/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0421_0435_0440_0438_0430_043B_0438_0437_043E_0432_0430_043D_043D_0430_044F/@EntryIndexedValue">True</s:Boolean>
|
||||
@ -43,6 +44,7 @@
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0435_0440_0438_0430_043B_0438_0437_043E_0432_0430_043D_043D_043E_0433_043E/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0435_0440_0438_0430_043B_0438_0437_043E_0432_0430_043D_043D_043E_0435/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0435_0440_0438_0430_043B_0438_0437_043E_0432_0430_043D_043D_0443_044E/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0435_0440_0438_0430_043B_0438_0437_0443_0435_043C/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0435_0440_0438_0430_043B_0438_0437_0443_044E/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0447_0451_0442/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0441_0447_0451_0442_0447_0438_043A/@EntryIndexedValue">True</s:Boolean>
|
||||
|
Loading…
x
Reference in New Issue
Block a user