Всё заново и работает лучше прежнего

This commit is contained in:
Игорь Гордеев 2024-06-16 15:28:03 +04:00
parent 7745cfc783
commit e4070a6060
60 changed files with 940 additions and 171 deletions

2
.gitignore vendored
View File

@ -398,3 +398,5 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
#Labs8
SushiBar/ImplementationExtensions/*

View File

@ -0,0 +1,46 @@
using SushiBarContracts.Attributes;
namespace SushiBarView
{
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;
}
}
}
}
}
}

View File

@ -27,13 +27,7 @@ namespace SushiBarView
{
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)

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
namespace SushiBarView
{
@ -20,14 +21,7 @@ namespace SushiBarView
{
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)
@ -45,7 +39,7 @@ namespace SushiBarView
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
var service = DependencyManager.Instance.Resolve<FormImplementer>();
if (service is FormImplementer form)
{
if (form.ShowDialog() == DialogResult.OK)
@ -59,7 +53,7 @@ namespace SushiBarView
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
var service = DependencyManager.Instance.Resolve<FormImplementer>();
if (service is FormImplementer form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
namespace SushiBarView
{
@ -40,7 +41,7 @@ namespace SushiBarView
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormIngredient));
var service = DependencyManager.Instance.Resolve<FormIngredient>();
if (service is FormIngredient form)
{
if (form.ShowDialog() == DialogResult.OK)
@ -53,7 +54,7 @@ namespace SushiBarView
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormIngredient));
var service = DependencyManager.Instance.Resolve<FormIngredient>();
if (service is FormIngredient form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
namespace SushiBarView
{
@ -23,14 +24,7 @@ namespace SushiBarView
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["SushiIngredients"].Visible = false;
}
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка суши");
}
catch (Exception ex)
@ -42,7 +36,7 @@ namespace SushiBarView
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushi));
var service = DependencyManager.Instance.Resolve<FormSushi>();
if (service is FormSushi form)
{
if (form.ShowDialog() == DialogResult.OK)
@ -56,7 +50,7 @@ namespace SushiBarView
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushi));
var service = DependencyManager.Instance.Resolve<FormSushi>(); ;
if (service is FormSushi form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);

View File

@ -39,20 +39,21 @@
списокСушиToolStripMenuItem = new ToolStripMenuItem();
сушиСИнгредиентамиToolStripMenuItem = new ToolStripMenuItem();
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
письмаToolStripMenuItem = new ToolStripMenuItem();
buttonUpdate = new Button();
buttonSetToFinish = new Button();
buttonSetToDone = new Button();
buttonSetToWork = new Button();
buttonCreateOrder = new Button();
dataGridView = new DataGridView();
письмаToolStripMenuItem = new ToolStripMenuItem();
backUpToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip
//
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem });
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, backUpToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1112, 24);
@ -129,6 +130,13 @@
списокЗаказовToolStripMenuItem.Text = "Список заказов";
списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
//
// письмаToolStripMenuItem
//
письмаToolStripMenuItem.Name = "письмаToolStripMenuItem";
письмаToolStripMenuItem.Size = new Size(203, 22);
письмаToolStripMenuItem.Text = "Письма";
письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click;
//
// buttonUpdate
//
buttonUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Right;
@ -201,12 +209,12 @@
dataGridView.Size = new Size(919, 426);
dataGridView.TabIndex = 7;
//
// письмаToolStripMenuItem
// backUpToolStripMenuItem
//
письмаToolStripMenuItem.Name = "письмаToolStripMenuItem";
письмаToolStripMenuItem.Size = new Size(203, 22);
письмаToolStripMenuItem.Text = "Письма";
письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click;
backUpToolStripMenuItem.Name = "backUpToolStripMenuItem";
backUpToolStripMenuItem.Size = new Size(59, 20);
backUpToolStripMenuItem.Text = "BackUp";
backUpToolStripMenuItem.Click += toolStripMenuCreateBackUp_Click;
//
// FormMain
//
@ -251,5 +259,6 @@
private ToolStripMenuItem исполнителиToolStripMenuItem;
private ToolStripMenuItem начатьРаботуToolStripMenuItem;
private ToolStripMenuItem письмаToolStripMenuItem;
private ToolStripMenuItem backUpToolStripMenuItem;
}
}

View File

@ -1,6 +1,8 @@
using Microsoft.Extensions.Logging;
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
namespace SushiBarView
{
@ -9,9 +11,10 @@ namespace SushiBarView
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess;
private readonly IWorkProcess _workProcess;
private readonly IBackUpLogic _backUpLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic)
{
InitializeComponent();
_logger = logger;
@ -19,6 +22,7 @@ namespace SushiBarView
_reportLogic = reportLogic;
_workProcess = workProcess;
_workProcess = workProcess;
_backUpLogic = backUpLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
@ -29,14 +33,7 @@ namespace SushiBarView
_logger.LogInformation("Загрузка заказов");
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["SushiId"].Visible = false;
dataGridView.Columns["Implementerid"].Visible = false;
dataGridView.Columns["ClientEmail"].Visible = false;
}
dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null));
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
@ -47,7 +44,7 @@ namespace SushiBarView
}
private void IngredientsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormIngredients));
var service = DependencyManager.Instance.Resolve<FormIngredients>();
if (service is FormIngredients form)
{
form.ShowDialog();
@ -55,7 +52,7 @@ namespace SushiBarView
}
private void SushiToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormListSushi));
var service = DependencyManager.Instance.Resolve<FormListSushi>();
if (service is FormListSushi form)
{
form.ShowDialog();
@ -63,7 +60,7 @@ namespace SushiBarView
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
var service = DependencyManager.Instance.Resolve<FormCreateOrder>();
if (service is FormCreateOrder form)
{
form.ShowDialog();
@ -162,7 +159,7 @@ namespace SushiBarView
private void SushiIngredientToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportSushiIngredients));
var service = DependencyManager.Instance.Resolve<FormReportSushiIngredients>();
if (service is FormReportSushiIngredients form)
{
form.ShowDialog();
@ -171,7 +168,7 @@ namespace SushiBarView
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
var service = DependencyManager.Instance.Resolve<FormReportOrders>();
if (service is FormReportOrders form)
{
form.ShowDialog();
@ -180,7 +177,7 @@ namespace SushiBarView
private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
var service = DependencyManager.Instance.Resolve<FormClients>();
if (service is FormClients form)
{
form.ShowDialog();
@ -188,7 +185,7 @@ namespace SushiBarView
}
private void employersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
var service = DependencyManager.Instance.Resolve<FormImplementers>();
if (service is FormImplementers form)
{
form.ShowDialog();
@ -197,17 +194,33 @@ namespace SushiBarView
private void startWorkToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
_workProcess.DoWork((DependencyManager.Instance.Resolve<IImplementerLogic>() as IImplementerLogic)!, _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void письмаToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormViewMail));
var service = DependencyManager.Instance.Resolve<FormViewMail>();
if (service is FormViewMail form)
{
form.ShowDialog();
}
}
public void toolStripMenuCreateBackUp_Click(object sender, EventArgs e)
{
try
{
var fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
_backUpLogic.CreateBackUp(new BackUpSaveBindingModel { FolderName = fbd.SelectedPath });
}
MessageBox.Show("Бекап создан", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.DI;
using SushiBarContracts.SearchModels;
using SushiBarDataModels.Models;
@ -49,7 +50,7 @@ namespace SushiBarView
}
private void LoadData()
{
_logger.LogInformation("Загрузка ингредиентов суши");
_logger.LogInformation("Загрузка продукта");
try
{
if (_sushiIngredients != null)
@ -70,7 +71,7 @@ namespace SushiBarView
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients));
var service = DependencyManager.Instance.Resolve<FormSushiIngredients>();
if (service is FormSushiIngredients form)
{
if (form.ShowDialog() == DialogResult.OK)
@ -96,7 +97,7 @@ namespace SushiBarView
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients));
var service = DependencyManager.Instance.Resolve<FormSushiIngredients>();
if (service is FormSushiIngredients form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);

View File

@ -18,14 +18,7 @@ namespace SushiBarView
{
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)

View File

@ -10,13 +10,13 @@ using SushiBarDatabaseImplement.Implements;
using SushiBarBusinessLogic;
using SushiBarBusinessLogic.MailWorker;
using SushiBarContracts.BindingModels;
using SushiBarContracts.DI;
namespace SushiBarView
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -26,13 +26,11 @@ namespace SushiBarView
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
try
InitDependency();
try
{
var mailSender = _serviceProvider.GetService<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel
var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel
{
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty,
@ -46,56 +44,60 @@ namespace SushiBarView
}
catch (Exception ex)
{
var logger = _serviceProvider.GetService<ILogger>();
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
var logger = DependencyManager.Instance.Resolve<ILogger>();
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
}
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
Application.Run(DependencyManager.Instance.Resolve<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
private static void InitDependency()
{
services.AddLogging(option =>
DependencyManager.InitDependency();
DependencyManager.Instance.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IIngredientStorage, IngredientStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ISushiStorage, SushiStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IIngredientStorage, IngredientStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ISushiStorage, SushiStorage>();
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
services.AddTransient<IIngredientLogic, IngredientLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISushiLogic, SushiLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<IIngredientLogic, IngredientLogic>();
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
DependencyManager.Instance.RegisterType<ISushiLogic, SushiLogic>();
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormIngredient>();
services.AddTransient<FormIngredients>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormSushi>();
services.AddTransient<FormSushiIngredients>();
services.AddTransient<FormListSushi>();
services.AddTransient<FormClients>();
services.AddTransient<FormReportSushiIngredients>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormImplementers>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormViewMail>();
DependencyManager.Instance.RegisterType<FormMain>();
DependencyManager.Instance.RegisterType<FormIngredient>();
DependencyManager.Instance.RegisterType<FormIngredients>();
DependencyManager.Instance.RegisterType<FormCreateOrder>();
DependencyManager.Instance.RegisterType<FormSushi>();
DependencyManager.Instance.RegisterType<FormSushiIngredients>();
DependencyManager.Instance.RegisterType<FormListSushi>();
DependencyManager.Instance.RegisterType<FormClients>();
DependencyManager.Instance.RegisterType<FormReportSushiIngredients>();
DependencyManager.Instance.RegisterType<FormReportOrders>();
DependencyManager.Instance.RegisterType<FormImplementers>();
DependencyManager.Instance.RegisterType<FormImplementer>();
DependencyManager.Instance.RegisterType<FormViewMail>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>();
}
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
}
private static void MailCheck(object obj) => DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
}
}

View File

@ -0,0 +1,103 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarDataModels;
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarBusinessLogic.BusinessLogics
{
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("Clear 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 {count} types", types.Length);
foreach (var type in types)
{
if (type.IsInterface && type.GetInterface(typeIId.Name) != null)
{
var modelType = _backUpInfo.GetTypeByModelInterface(type.Name);
if (modelType == null)
{
throw new InvalidOperationException($"Не найден класс-модель для {type.Name}");
}
_logger.LogDebug("Call SaveToFile method for {name} type", type.Name);
// вызываем метод на выполнение
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("{type} type get null list", typeof(T).Name);
return;
}
var jsonFormatter = new DataContractJsonSerializer(typeof(List<T>));
using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate);
jsonFormatter.WriteObject(fs, records);
}
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarContracts.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;
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarContracts.Attributes
{
public enum GridViewAutoSize
{
NotSet = 0,
None = 1,
ColumnHeader = 2,
AllCellsExceptHeader = 4,
AllCells = 6,
DisplayedCellsExceptHeader = 8,
DisplayedCells = 10,
Fill = 16
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarContracts.BindingModels
{
public class BackUpSaveBindingModel
{
public string FolderName { get; set; } = string.Empty;
}
}

View File

@ -16,5 +16,6 @@ namespace SushiBarContracts.BindingModels
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public DateTime DateDelivery { get; set; }
}
public int Id { get; private set; }
}
}

View File

@ -0,0 +1,14 @@
using SushiBarContracts.BindingModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarContracts.BusinessLogicsContracts
{
public interface IBackUpLogic
{
void CreateBackUp(BackUpSaveBindingModel model);
}
}

View File

@ -0,0 +1,41 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarContracts.DI
{
public class DependencyManager
{
private readonly IDependencyContainer _dependencyManager;
private static DependencyManager? _manager;
private static readonly object _locjObject = new();
private DependencyManager()
{
_dependencyManager = new ServiceDependencyContainer();
}
public static DependencyManager Instance { get { if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } } return _manager; } }
public static void InitDependency()
{
var ext = ServiceProviderLoader.GetImplementationExtensions();
if (ext == null)
{
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
}
// регистрируем зависимости
ext.RegisterServices();
}
public void AddLogging(Action<ILoggingBuilder> configure) => _dependencyManager.AddLogging(configure);
public void RegisterType<T, U>(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType<T, U>(isSingle);
public void RegisterType<T>(bool isSingle = false) where T : class => _dependencyManager.RegisterType<T>(isSingle);
public T Resolve<T>() => _dependencyManager.Resolve<T>();
}
}

View File

@ -0,0 +1,20 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarContracts.DI
{
public interface IDependencyContainer
{
void AddLogging(Action<ILoggingBuilder> configure);
void RegisterType<T, U>(bool isSingle) where U : class, T where T : class;
void RegisterType<T>(bool isSingle) where T : class;
T Resolve<T>();
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarContracts.DI
{
public interface IImplementationExtension
{
public int Priority { get; }
public void RegisterServices();
}
}

View File

@ -0,0 +1,62 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarContracts.DI
{
public class ServiceDependencyContainer : IDependencyContainer
{
private ServiceProvider? _serviceProvider;
private readonly ServiceCollection _serviceCollection;
public ServiceDependencyContainer()
{
_serviceCollection = new ServiceCollection();
}
public void AddLogging(Action<ILoggingBuilder> configure)
{
_serviceCollection.AddLogging(configure);
}
public void RegisterType<T, U>(bool isSingle) where U : class, T where T : class
{
if (isSingle)
{
_serviceCollection.AddSingleton<T, U>();
}
else
{
_serviceCollection.AddTransient<T, U>();
}
_serviceProvider = null;
}
public void RegisterType<T>(bool isSingle) where T : class
{
if (isSingle)
{
_serviceCollection.AddSingleton<T>();
}
else
{
_serviceCollection.AddTransient<T>();
}
_serviceProvider = null;
}
public T Resolve<T>()
{
if (_serviceProvider == null)
{
_serviceProvider = _serviceCollection.BuildServiceProvider();
}
return _serviceProvider.GetService<T>()!;
}
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarContracts.DI
{
public class ServiceProviderLoader
{
public static IImplementationExtension? GetImplementationExtensions()
{
IImplementationExtension? source = null;
var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
foreach (var file in files.Distinct())
{
Assembly asm = Assembly.LoadFrom(file);
foreach (var t in asm.GetExportedTypes())
{
if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t))
{
if (source == null)
{
source = (IImplementationExtension)Activator.CreateInstance(t)!;
}
else
{
var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
if (newSource.Priority > source.Priority)
{
source = newSource;
}
}
}
}
}
return source;
}
private static string TryGetImplementationExtensionsFolder()
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions"))
{
directory = directory.Parent;
}
return $"{directory?.FullName}\\ImplementationExtensions";
}
}
}

View File

@ -0,0 +1,43 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
using Unity.Microsoft.Logging;
namespace SushiBarContracts.DI
{
public class UnityDependencyContainer : IDependencyContainer
{
private readonly IUnityContainer _container;
public UnityDependencyContainer()
{
_container = new UnityContainer();
}
public void AddLogging(Action<ILoggingBuilder> configure)
{
var factory = LoggerFactory.Create(configure);
_container.AddExtension(new LoggingExtension(factory));
}
public void RegisterType<T>(bool isSingle) where T : class
{
_container.RegisterType<T>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
public T Resolve<T>()
{
return _container.Resolve<T>();
}
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
{
_container.RegisterType<T, U>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
}
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarContracts.StoragesContracts
{
public interface IBackUpInfo
{
List<T>? GetList<T>() where T : class, new();
Type? GetTypeByModelInterface(string modelInterfaceName);
}
}

View File

@ -6,6 +6,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
</ItemGroup>

View File

@ -1,4 +1,5 @@
using SushiBarDataModels;
using SushiBarContracts.Attributes;
using SushiBarDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -10,15 +11,16 @@ namespace SushiBarContracts.ViewModels
{
public class ClientViewModel : IClientModel
{
[Column(visible: false)]
public int Id { get; set; }
[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("Пароль")]
[Column(title: "Пароль", width: 150)]
public string Password { get; set; } = string.Empty;

View File

@ -1,4 +1,5 @@
using SushiBarDataModels.Models;
using SushiBarContracts.Attributes;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -10,18 +11,19 @@ namespace SushiBarContracts.ViewModels
{
public class ImplementerViewModel : IImplementerModel
{
[Column(visible: false)]
public int Id { get; set; }
[DisplayName("ФИО исполнителя")]
[Column(title: "ФИО исполнителя", width: 150)]
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; }
}
}

View File

@ -1,14 +1,16 @@
using SushiBarDataModels.Models;
using SushiBarContracts.Attributes;
using SushiBarDataModels.Models;
using System.ComponentModel;
namespace SushiBarContracts.ViewModels
{
public class IngredientViewModel : IIngredientModel
{
[Column(visible: false)]
public int Id { get; set; }
[DisplayName("Название ингредиента")]
[Column(title: "Название еды для изготовления", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string IngredientName { get; set; } = string.Empty;
[DisplayName("Цена")]
[Column(title: "Цена", width: 150)]
public double Cost { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using PrecastConcretePlantDataModels.Models;
using SushiBarContracts.Attributes;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
@ -11,20 +12,24 @@ namespace SushiBarContracts.ViewModels
{
public class MessageInfoViewModel : IMessageInfoModel
{
public string MessageId { get; set; } = string.Empty;
[Column(visible: false)]
public string MessageId { get; set; } = string.Empty;
[Column(visible: false)]
public int? ClientId { get; set; }
public int? ClientId { get; set; }
[Column(visible: false)]
public int Id { get; private set; }
[DisplayName("Отправитель")]
public string SenderName { get; set; } = string.Empty;
[Column(title: "Отправитель", width: 150)]
public string SenderName { get; set; } = string.Empty;
[DisplayName("Дата письма")]
public DateTime DateDelivery { get; set; }
[Column(title: "Дата письма", width: 150)]
public DateTime DateDelivery { get; set; }
[DisplayName("Заголовок")]
public string Subject { get; set; } = string.Empty;
[Column(title: "Заголовоск", width: 170)]
public string Subject { get; set; } = string.Empty;
[DisplayName("Текст")]
public string Body { get; set; } = string.Empty;
[Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string Body { get; set; } = string.Empty;
}
}

View File

@ -1,4 +1,5 @@
using SushiBarDataModels.Enums;
using SushiBarContracts.Attributes;
using SushiBarDataModels.Enums;
using SushiBarDataModels.Models;
using System.ComponentModel;
@ -6,34 +7,38 @@ namespace SushiBarContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
[DisplayName("Номер")]
[Column(title: "Номер", width: 150)]
public int Id { get; set; }
[Column(visible: false)]
public int? ImplementerId { get; set; }
[DisplayName("Исполнитель")]
[Column(title: "Исполнитель", width: 150)]
public string? ImplementerFIO { get; set; } = null;
[Column(visible: false)]
public int SushiId { get; set; }
[Column(visible: false)]
public int ClientId { get; set; }
[Column(visible: false)]
public string ClientEmail { get; set; } = string.Empty;
[DisplayName("ФИО клиента")]
[Column(title: "Клиент", width: 150)]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Изделие")]
[Column(title: "Сушина", width: 150)]
public string SushiName { get; set; } = string.Empty;
[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; }
}
}

View File

@ -1,15 +1,18 @@
using SushiBarDataModels.Models;
using SushiBarContracts.Attributes;
using SushiBarDataModels.Models;
using System.ComponentModel;
namespace SushiBarContracts.ViewModels
{
public class SushiViewModel : ISushiModel
{
[Column(visible: false)]
public int Id { get; set; }
[DisplayName("Название изделия")]
[Column(title: "Название суши", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
public string SushiName { get; set; } = string.Empty;
[DisplayName("Цена")]
[Column(title: "Цена", width: 150)]
public double Price { get; set; }
[Column(visible: false)]
public Dictionary<int, (IIngredientModel, int)> SushiIngredients{ get; set; } = new();
}
}

View File

@ -1,4 +1,5 @@
using System;
using SushiBarDataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -6,8 +7,7 @@ using System.Threading.Tasks;
namespace PrecastConcretePlantDataModels.Models
{
public interface IMessageInfoModel
{
public interface IMessageInfoModel: IId {
string MessageId { get; }
int? ClientId { get; }

View File

@ -0,0 +1,29 @@
using SushiBarContracts.DI;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.StoragesContracts;
using SushiBarDatabaseImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement
{
public class DataBaseImplementationExtension : IImplementationExtension
{
public int Priority => 2;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IIngredientStorage, IngredientStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ISushiStorage, SushiStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,31 @@
using SushiBarContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarDatabaseImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
using var context = new SushiBarDatabase();
return context.Set<T>().ToList();
}
public Type? GetTypeByModelInterface(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;
}
}
}

View File

@ -12,8 +12,8 @@ using SushiBarDatabaseImplement;
namespace SushiBarDatabaseImplement.Migrations
{
[DbContext(typeof(SushiBarDatabase))]
[Migration("20240516141726_tested17")]
partial class tested17
[Migration("20240616102532_Init")]
partial class Init
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)

View File

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace SushiBarDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class tested17 : Migration
public partial class Init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)

View File

@ -3,20 +3,26 @@ using SushiBarContracts.ViewModels;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using SushiBarDataModels;
using System.Runtime.Serialization;
namespace SushiBarDatabaseImplement.Models
{
[DataContract]
public class Client : IClientModel
{
[DataMember]
public int Id { get; private set; }
[Required]
[DataMember]
public string ClientFIO { get; private set; } = string.Empty;
[Required]
[DataMember]
public string Email { get; private set; } = string.Empty;
[Required]
[DataMember]
public string Password { get; private set; } = string.Empty;
[ForeignKey("ClientId")]

View File

@ -8,23 +8,30 @@ using System.Threading.Tasks;
using SushiBarContracts.BindingModels;
using SushiBarDatabaseImplement.Models;
using SushiBarContracts.ViewModels;
using System.Runtime.Serialization;
namespace SushiBarDataModels.Models
{
[DataContract]
public class Implementer : IImplementerModel
{
[DataMember]
public int Id { get; set; }
[Required]
[DataMember]
public string ImplementerFIO { get; set; } = string.Empty;
[Required]
[DataMember]
public string Password { get; set; } = string.Empty;
[Required]
[DataMember]
public int WorkExperience { get; set; }
[Required]
[DataMember]
public int Qualification { get; set; }
[ForeignKey("ImplementerId")]

View File

@ -3,17 +3,22 @@ using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace SushiBarDatabaseImplement.Models
{
[DataContract]
public class Ingredient : IIngredientModel
{
[DataMember]
public int Id { get; private set; }
[Required]
[DataMember]
public string IngredientName { get; private set; } = string.Empty;
[Required]
[DataMember]
public double Cost { get; set; }
[ForeignKey("IngredientId")]

View File

@ -2,25 +2,30 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace SushiBarDatabaseImplement.Models
{
[DataContract]
public class MessageInfo : IMessageInfoModel
{
[Key]
[DataMember]
public string MessageId { get; private set; } = string.Empty;
[DataMember]
public int? ClientId { get; private set; }
[DataMember]
public string SenderName { get; private set; } = string.Empty;
[DataMember]
public DateTime DateDelivery { get; private set; } = DateTime.Now;
[DataMember]
public string Subject { get; private set; } = string.Empty;
[DataMember]
public string Body { get; private set; } = string.Empty;
[NotMapped]
public int Id { get; private set; }
public Client? Client { get; private set; }
public static MessageInfo? Create(MessageInfoBindingModel model)

View File

@ -3,24 +3,34 @@ using SushiBarContracts.ViewModels;
using SushiBarDataModels.Enums;
using SushiBarDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace SushiBarDatabaseImplement.Models
{
[DataContract]
public class Order : IOrderModel
{
[Required]
[DataMember]
public int SushiId { get; set; }
[Required]
[DataMember]
public int Count { get; set; }
[Required]
[DataMember]
public int ClientId { get; set; }
[Required]
[DataMember]
public double Sum { get; set; }
[Required]
[DataMember]
public OrderStatus Status { get; set; }
[Required]
[DataMember]
public DateTime DateCreate { get; set; }
[DataMember]
public DateTime? DateImplement { get; set; }
[DataMember]
public int Id { get; set; }
public virtual Client? Client { get; set; }
public Sushi? Sushi { get; set; }

View File

@ -3,22 +3,28 @@ using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
namespace SushiBarDatabaseImplement.Models
{
[DataContract]
public class Sushi : ISushiModel
{
[DataMember]
public int Id { get; set; }
[Required]
[DataMember]
public string SushiName { get; set; } = string.Empty;
[Required]
[DataMember]
public double Price { get; set; }
private Dictionary<int, (IIngredientModel, int)>? _sushiIngredients = null;
[NotMapped]
[DataMember]
public Dictionary<int, (IIngredientModel, int)> SushiIngredients
{
get

View File

@ -1,18 +1,24 @@
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
namespace SushiBarDatabaseImplement.Models
{
[DataContract]
public class SushiIngredient
{
[DataMember]
public int Id { get; set; }
[Required]
[DataMember]
public int SushiId { get; set; }
[Required]
[DataMember]
public int IngredientId { get; set; }
[Required]
[DataMember]
public int Count { get; set; }
public virtual Ingredient Ingredient { get; set; } = new();

View File

@ -10,7 +10,7 @@ namespace SushiBarDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=SushiBarDatabaseTest;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=SushiBarData;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
<Nullable>enable</Nullable>
</PropertyGroup>
@ -20,4 +21,7 @@
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(targetDir)*.dll&quot; &quot;$(solutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project>

View File

@ -0,0 +1,28 @@
using SushiBarContracts.DI;
using SushiBarContracts.StoragesContracts;
using SushiBarFileImplement.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarFileImplement
{
public class FileImplementationExtension : IImplementationExtension
{
public int Priority => 1;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IIngredientStorage, IngredientStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ISushiStorage, SushiStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -0,0 +1,34 @@
using SushiBarContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarFileImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
// Получаем значения из singleton-объекта универсального свойства содержащее тип T
var source = DataFileSingleton.GetInstance();
return (List<T>?)source.GetType().GetProperties()
.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))
?.GetValue(source);
}
public Type? GetTypeByModelInterface(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;
}
}
}

View File

@ -1,11 +1,12 @@
using SushiBarContracts.BindingModel;
using SushiBarContracts.SearchModel;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarFileImplement.Models;
namespace SushiBarFileImplement.Implements
{
public class ClientStorage
public class ClientStorage: IClientStorage
{
private readonly DataFileSingleton source;
public ClientStorage()

View File

@ -1,15 +1,21 @@
using SushiBarContracts.BindingModel;
using SushiBarContracts.ViewModels;
using SushiBarDataModels;
using System.Runtime.Serialization;
using System.Xml.Linq;
namespace SushiBarFileImplement.Models
{
[DataContract]
public class Client : IClientModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ClientFIO { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty;
[DataMember]
public string Email { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel model)
{

View File

@ -4,22 +4,25 @@ using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace SushiBarFileImplement.Models
{
[DataContract]
public class Implementer : IImplementerModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string ImplementerFIO { get; private set; } = string.Empty;
[DataMember]
public string Password { get; private set; } = string.Empty;
[DataMember]
public int WorkExperience { get; private set; }
[DataMember]
public int Qualification { get; private set; }
public static Implementer? Create(XElement element)

View File

@ -1,14 +1,19 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq;
namespace SushiBarFileImplement.Models
{
[DataContract]
public class Ingredient : IIngredientModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string IngredientName { get; private set; } = string.Empty;
[DataMember]
public double Cost { get; set; }
public static Ingredient? Create(IngredientBindingModel model)
{

View File

@ -14,6 +14,8 @@ namespace SushiBarFileImplement.Models
[DataContract]
public class MessageInfo : IMessageInfoModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string MessageId { get; private set; } = string.Empty;
[DataMember]

View File

@ -2,20 +2,31 @@
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Enums;
using SushiBarDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq;
namespace SushiBarFileImplement.Models
{
[DataContract]
public class Order : IOrderModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public int SushiId { get; private set; }
[DataMember]
public int ClientId { get; private set; }
[DataMember]
public int? ImplementerId { get; set; }
[DataMember]
public int Count { get; private set; }
[DataMember]
public double Sum { get; private set; }
[DataMember]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[DataMember]
public DateTime DateCreate { get; private set; } = DateTime.Now;
[DataMember]
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{

View File

@ -1,16 +1,22 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
using System.Runtime.Serialization;
using System.Xml.Linq;
namespace SushiBarFileImplement.Models
{
[DataContract]
public class Sushi : ISushiModel
{
[DataMember]
public int Id { get; private set; }
[DataMember]
public string SushiName { get; private set; } = string.Empty;
[DataMember]
public double Price { get; private set; }
public Dictionary<int, int> Ingredients { get; private set; } = new();
[DataMember]
private Dictionary<int, (IIngredientModel, int)>? _productIngredients = null;
public Dictionary<int, (IIngredientModel, int)> SushiIngredients
{

View File

@ -11,4 +11,7 @@
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(targetDir)*.dll&quot; &quot;$(solutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project>

View File

@ -0,0 +1,22 @@
using SushiBarContracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarListImplement.Implements
{
public class BackUpInfo : IBackUpInfo
{
public List<T>? GetList<T>() where T : class, new()
{
throw new NotImplementedException();
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,5 +1,6 @@
using SushiBarContracts.BindingModel;
using SushiBarContracts.SearchModel;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarListImplement;
using SushiBarListImplements.Models;
@ -11,7 +12,7 @@ using System.Threading.Tasks;
namespace SushiBarListImplements.Implements
{
public class ClientStorage
public class ClientStorage: IClientStorage
{
private readonly DataListSingleton _source;
public ClientStorage()

View File

@ -0,0 +1,26 @@

using SushiBarContracts.DI;
using SushiBarContracts.StoragesContracts;
using SushiBarListImplement.Implements;
using SushiBarListImplements.Implements;
namespace SushiBarListImplement
{
public class ListImplementationExtension : IImplementationExtension
{
public int Priority => 0;
public void RegisterServices()
{
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
DependencyManager.Instance.RegisterType<IIngredientStorage, IngredientStorage>();
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
DependencyManager.Instance.RegisterType<ISushiStorage, SushiStorage>();
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
}
}
}

View File

@ -11,6 +11,7 @@ namespace SushiBarListImplement.Models
{
public class MessageInfo : IMessageInfoModel
{
public int Id { get; private set; }
public string MessageId { get; private set; } = string.Empty;
public int? ClientId { get; private set; }

View File

@ -10,5 +10,8 @@
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy /Y &quot;$(targetDir)*.dll&quot; &quot;$(solutionDir)ImplementationExtensions\*.dll&quot;" />
</Target>
</Project>