ISEbd-21.Fedotov.I.A.LabWork08 #8
25
Diner/DinerContracts/Attributes/ColumnAttribute.cs
Normal file
25
Diner/DinerContracts/Attributes/ColumnAttribute.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.Attributes {
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ColumnAttribute : Attribute {
|
||||
public string Title { get; private set; }
|
||||
public bool Visible { get; private set; }
|
||||
public int Width { get; private set; }
|
||||
public GridViewAutoSize _GridViewAutoSize { get; private set; }
|
||||
public bool IsUseAutoSize { get; private set; }
|
||||
|
||||
public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None,
|
||||
bool isUseAutoSize = false) {
|
||||
Title = title;
|
||||
Visible = visible;
|
||||
Width = width;
|
||||
_GridViewAutoSize = gridViewAutoSize;
|
||||
IsUseAutoSize = isUseAutoSize;
|
||||
}
|
||||
}
|
||||
}
|
18
Diner/DinerContracts/Attributes/GridViewAutoSize.cs
Normal file
18
Diner/DinerContracts/Attributes/GridViewAutoSize.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.Attributes {
|
||||
public enum GridViewAutoSize {
|
||||
NotSet = 0,
|
||||
None = 1,
|
||||
ColumnHeader = 2,
|
||||
AllCellsExceptHeader = 4,
|
||||
AllCells = 6,
|
||||
DisplayedCellsExceptHeader = 8,
|
||||
DisplayedCells = 10,
|
||||
Fill = 16
|
||||
}
|
||||
}
|
11
Diner/DinerContracts/BindingModels/BackUpSaveBindingModel.cs
Normal file
11
Diner/DinerContracts/BindingModels/BackUpSaveBindingModel.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.BindingModels {
|
||||
public class BackUpSaveBindingModel {
|
||||
public string FolderName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
12
Diner/DinerContracts/BusinessLogicsContracts/IBackUpLogic.cs
Normal file
12
Diner/DinerContracts/BusinessLogicsContracts/IBackUpLogic.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.BusinessLogicsContracts {
|
||||
public interface IBackUpLogic {
|
||||
void CreateBackUp(BackUpSaveBindingModel model);
|
||||
}
|
||||
}
|
13
Diner/DinerContracts/StoragesContracts/IBackUpInfo.cs
Normal file
13
Diner/DinerContracts/StoragesContracts/IBackUpInfo.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.StoragesContracts {
|
||||
public interface IBackUpInfo {
|
||||
List<T> GetList<T>() where T: class, new();
|
||||
|
||||
Type? GetTypeModelInterface(string modelInterfaceName);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using DinerDataModels.Models;
|
||||
using DinerContracts.Attributes;
|
||||
using DinerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,15 +11,16 @@ using System.Threading.Tasks;
|
||||
namespace DinerContracts.ViewModels {
|
||||
public class ClientViewModel : IClientModel {
|
||||
|
||||
[DisplayName("ФИО клиента")]
|
||||
[Column(title: "ФИО клиента", width:150)]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Логин (эл.почта)")]
|
||||
[Column(title: "Логин (эл.почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[Column(title: "Пароль", width: 150)]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[Column(visible: false)]
|
||||
public int ID { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using DinerDataModels.Models;
|
||||
using DinerContracts.Attributes;
|
||||
using DinerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -11,12 +12,13 @@ namespace DinerContracts.ViewModels
|
||||
{
|
||||
public class FoodViewModel : IFoodModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int ID { get; set; }
|
||||
|
||||
[DisplayName("Название еды для изготовления")]
|
||||
[Column(title: "Название еды для изготовления", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
[Column(title: "Цена", width: 150)]
|
||||
public double Price { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using DinerDataModels.Models;
|
||||
using DinerContracts.Attributes;
|
||||
using DinerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -9,18 +10,19 @@ using System.Threading.Tasks;
|
||||
namespace DinerContracts.ViewModels {
|
||||
public class ImplementerViewModel : IImplementerModel {
|
||||
|
||||
[DisplayName("ФИО исполнителя")]
|
||||
[Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль")]
|
||||
[Column(title: "Пароль", width: 150)]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Стаж работы")]
|
||||
[Column(title: "Стаж работы", width: 150)]
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
[DisplayName("Квалификация")]
|
||||
[Column(title: "Квалификация", width: 150)]
|
||||
public int Qualification { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public int ID { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using DinerDataModels.Models;
|
||||
using DinerContracts.Attributes;
|
||||
using DinerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -8,20 +9,23 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace DinerContracts.ViewModels {
|
||||
public class MessageInfoViewModel : IMessageInfoModel {
|
||||
|
||||
[Column(visible: false)]
|
||||
public string MessageID { get; set; } = string.Empty;
|
||||
|
||||
[Column(visible: false)]
|
||||
public int? ClientID { get; set; }
|
||||
|
||||
[DisplayName("Отправитель")]
|
||||
[Column(title: "Отправитель", width: 150)]
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата письма")]
|
||||
[Column(title: "Дата письма", width: 150)]
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
[DisplayName("Заголовоск")]
|
||||
[Column(title: "Заголовоск", width: 170)]
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Текст")]
|
||||
[Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using DinerDataModels.Enums;
|
||||
using DinerContracts.Attributes;
|
||||
using DinerDataModels.Enums;
|
||||
using DinerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -11,36 +12,41 @@ namespace DinerContracts.ViewModels
|
||||
{
|
||||
public class OrderViewModel : IOrderModel {
|
||||
|
||||
[Column(visible: false)]
|
||||
public int ClientID { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public int SnackID { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public int? ImplementerID { get; set; }
|
||||
|
||||
[DisplayName("Количество")]
|
||||
[Column(title: "Количество", width: 150)]
|
||||
public int Count { get; set; }
|
||||
|
||||
[DisplayName("Сумма")]
|
||||
[Column(title: "Сумма", width: 150)]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[DisplayName("Статус")]
|
||||
[Column(title: "Статус", width: 150)]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
||||
[DisplayName("Дата создания")]
|
||||
[Column(title: "Дата создания", width: 150)]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
[DisplayName("Дата выполнения")]
|
||||
[Column(title: "Дата выполнения", width: 150)]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
[DisplayName("Номер")]
|
||||
[Column(title: "Номер", width: 150)]
|
||||
public int ID { get; set; }
|
||||
|
||||
// какой снэк изготавливается в рамках заказа
|
||||
[DisplayName("Снэк")]
|
||||
[Column(title: "Снэк", width: 150)]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Клиент")]
|
||||
[Column(title: "Клиент", width: 150)]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Исполнитель")]
|
||||
[Column(title: "Исполнитель", width: 150)]
|
||||
public string? ImplementerFIO { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using DinerDataModels.Models;
|
||||
using DinerContracts.Attributes;
|
||||
using DinerDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,14 +11,16 @@ namespace DinerContracts.ViewModels
|
||||
{
|
||||
public class SnackViewModel : ISnackModel
|
||||
{
|
||||
[DisplayName("Название снэка")]
|
||||
[Column(title: "Название снэка", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
[Column(title: "Цена", width: 150)]
|
||||
public double Price { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public Dictionary<int, (IFoodModel, int)> ProductComponents { get; set; } = new();
|
||||
|
||||
public int ID { get; set; }
|
||||
[Column(visible: false)]
|
||||
public int ID { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
26
Diner/DinerDataBaseImplement/Implements/BackUpInfo.cs
Normal file
26
Diner/DinerDataBaseImplement/Implements/BackUpInfo.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using DinerContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerDataBaseImplement.Implements {
|
||||
public class BackUpInfo : IBackUpInfo {
|
||||
public List<T> GetList<T>() where T : class, new() {
|
||||
using var context = new DinerDatabaseBy7Work();
|
||||
return context.Set<T>().ToList();
|
||||
}
|
||||
|
||||
public Type? GetTypeModelInterface(string modelInterfaceName) {
|
||||
var assembly = typeof(BackUpInfo).Assembly;
|
||||
var types = assembly.GetTypes();
|
||||
foreach (var type in types) {
|
||||
if (type.IsClass && type.GetInterface(modelInterfaceName) != null) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.SearchModels;
|
||||
using DinerContracts.StoragesContracts;
|
||||
using DinerContracts.ViewModels;
|
||||
|
@ -12,6 +12,9 @@ using System.Threading.Tasks;
|
||||
namespace DinerDataBaseImplement.Models {
|
||||
public class MessageInfo : IMessageInfoModel {
|
||||
|
||||
[NotMapped]
|
||||
public int ID { get; private set; }
|
||||
|
||||
[Key]
|
||||
public string MessageID { get; set; } = string.Empty;
|
||||
|
||||
|
@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerDataModels.Models {
|
||||
public interface IMessageInfoModel {
|
||||
public interface IMessageInfoModel : IID{
|
||||
string MessageID { get; }
|
||||
int? ClientID { get; }
|
||||
string SenderName { get; }
|
||||
|
43
Diner/DinerView/DataGridViewExtension.cs
Normal file
43
Diner/DinerView/DataGridViewExtension.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using DinerContracts.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DinerView {
|
||||
internal static class DataGridViewExtension {
|
||||
public static void FillAndConfigGrid<T>(this DataGridView grid, List<T>? data) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
grid.DataSource = data;
|
||||
|
||||
var type = typeof(T);
|
||||
var properties = type.GetProperties();
|
||||
foreach (DataGridViewColumn column in grid.Columns) {
|
||||
var property = properties.FirstOrDefault(x => x.Name == column.Name);
|
||||
if (property == null) {
|
||||
throw new InvalidOperationException($"В типе {type.Name} не найдено свойств с именем {column.Name}");
|
||||
}
|
||||
var attribute = property.GetCustomAttributes(typeof(ColumnAttribute), true)?.SingleOrDefault();
|
||||
if (attribute == null) {
|
||||
throw new InvalidOperationException($"Не найден атрибут типа ColumnAttribute для свойства {property.Name}");
|
||||
}
|
||||
|
||||
// ищем нужный атрибут
|
||||
if (attribute is ColumnAttribute columnAttr) {
|
||||
column.HeaderText = columnAttr.Title;
|
||||
column.Visible = columnAttr.Visible;
|
||||
if (columnAttr.IsUseAutoSize) {
|
||||
column.AutoSizeMode = (DataGridViewAutoSizeColumnMode)Enum.Parse(typeof(DataGridViewAutoSizeColumnMode),
|
||||
columnAttr._GridViewAutoSize.ToString());
|
||||
}
|
||||
else {
|
||||
column.Width = columnAttr.Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,12 +25,7 @@ namespace DinerView {
|
||||
|
||||
private void LoadData() {
|
||||
try {
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null) {
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["ID"].Visible = false;
|
||||
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка клиентов");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
@ -29,13 +29,7 @@ namespace DinerView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["ID"].Visible = false;
|
||||
dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка продуктов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -30,12 +30,7 @@ namespace DinerView {
|
||||
|
||||
private void LoadData() {
|
||||
try {
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null) {
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["ID"].Visible = false;
|
||||
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка клиентов");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
@ -24,13 +24,7 @@ namespace DinerView {
|
||||
|
||||
private void FormMail_Load(object sender, EventArgs e) {
|
||||
try {
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null) {
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["ClientID"].Visible = false;
|
||||
dataGridView.Columns["MessageID"].Visible = false;
|
||||
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка списка писем");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
@ -36,16 +36,7 @@ namespace DinerView
|
||||
private void LoadData() {
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
try {
|
||||
var list = _orderLogic.ReadList(null);
|
||||
if (list != null) {
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["SnackID"].Visible = false;
|
||||
dataGridView.Columns["ClientID"].Visible = false;
|
||||
dataGridView.Columns["ImplementerID"].Visible = false;
|
||||
dataGridView.Columns["ID"].AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
|
||||
dataGridView.Columns["Sum"].AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
|
||||
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
@ -27,14 +27,7 @@ namespace DinerView
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["ID"].Visible = false;
|
||||
dataGridView.Columns["ProductComponents"].Visible = false;
|
||||
dataGridView.Columns["ProductName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
||||
_logger.LogInformation("Загрузка снэков");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
89
Diner/DineryBusinessLogic/BusinessLogic/BackUpLogic.cs
Normal file
89
Diner/DineryBusinessLogic/BusinessLogic/BackUpLogic.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using DinerContracts.BindingModels;
|
||||
using DinerContracts.BusinessLogicsContracts;
|
||||
using DinerContracts.StoragesContracts;
|
||||
using DinerDataModels;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net.WebSockets;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DineryBusinessLogic.BusinessLogic {
|
||||
public class BackUpLogic : IBackUpLogic {
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IBackUpInfo _backUpInfo;
|
||||
|
||||
public BackUpLogic(ILogger<BackUpLogic> logger, IBackUpInfo backUpInfo) {
|
||||
_logger = logger;
|
||||
_backUpInfo = backUpInfo;
|
||||
}
|
||||
|
||||
public void CreateBackUp(BackUpSaveBindingModel model) {
|
||||
if (_backUpInfo == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
_logger.LogDebug("Clera folder");
|
||||
// зачистка папки и удаление старого архива
|
||||
var dirInfo = new DirectoryInfo(model.FolderName);
|
||||
if (dirInfo.Exists) {
|
||||
foreach (var file in dirInfo.GetFiles()) {
|
||||
file.Delete();
|
||||
}
|
||||
}
|
||||
_logger.LogDebug("Delete archive");
|
||||
string fileName = $"{model.FolderName}.zip";
|
||||
if (File.Exists(fileName)) {
|
||||
File.Delete(fileName);
|
||||
}
|
||||
_logger.LogDebug("Get assembly");
|
||||
var typeIID = typeof(IID);
|
||||
var assembly = typeIID.Assembly;
|
||||
if (assembly == null) {
|
||||
throw new ArgumentNullException("Сборка не найдена", nameof(assembly));
|
||||
}
|
||||
var types = assembly.GetTypes();
|
||||
var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
_logger.LogDebug($"Find {types.Length} types");
|
||||
foreach (var type in types) {
|
||||
if (type.IsInterface && type.GetInterface(typeIID.Name) != null) {
|
||||
var modelType = _backUpInfo.GetTypeModelInterface(type.Name);
|
||||
if (modelType == null) {
|
||||
throw new InvalidOperationException($"Не найден класс-модель для {type.Name}");
|
||||
}
|
||||
_logger.LogDebug($"Call SaveToFile method for {type.Name} type");
|
||||
// вызываем метод на выполнение
|
||||
method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName });
|
||||
}
|
||||
}
|
||||
_logger.LogDebug("Create zip and remove folder");
|
||||
// архивируем
|
||||
ZipFile.CreateFromDirectory(model.FolderName, fileName);
|
||||
// удаляем папку
|
||||
dirInfo.Delete(true);
|
||||
}
|
||||
catch (Exception) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToFile<T>(string folderName) where T : class, new() {
|
||||
var records = _backUpInfo.GetList<T>();
|
||||
if (records == null) {
|
||||
_logger.LogWarning($"{typeof(T).Name} type get null list");
|
||||
}
|
||||
var jsonFormatter = new DataContractSerializer(typeof(List<T>));
|
||||
using var fs = new FileStream(string.Format($"{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate);
|
||||
jsonFormatter.WriteObject(fs, records);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user