кое что еще
This commit is contained in:
parent
8a61dd2832
commit
5eea91c76d
@ -0,0 +1,98 @@
|
|||||||
|
using IceCreamShopContracts.BindingModels;
|
||||||
|
using IceCreamShopContracts.BusinessLogicsContracts;
|
||||||
|
using IceCreamShopContracts.StoragesContracts;
|
||||||
|
using AbstractIceCreamShopDataModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.Serialization.Json;
|
||||||
|
|
||||||
|
namespace ConfectioneryBusinessLogic
|
||||||
|
{
|
||||||
|
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(BackUpSaveBinidngModel 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ using System.Windows.Forms;
|
|||||||
using IceCreamShop;
|
using IceCreamShop;
|
||||||
using IceCreamShopContracts.BindingModels;
|
using IceCreamShopContracts.BindingModels;
|
||||||
using IceCreamShopContracts.BusinessLogicsContracts;
|
using IceCreamShopContracts.BusinessLogicsContracts;
|
||||||
|
using IceCreamShopContracts.DI;
|
||||||
using IceCreamShopContracts.SearchModels;
|
using IceCreamShopContracts.SearchModels;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
@ -48,31 +49,25 @@ namespace IceCreamShopView
|
|||||||
|
|
||||||
private void buttonAdd_Click(object sender, EventArgs e)
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
var form = DependencyManager.Instance.Resolve<FormComponent>();
|
||||||
if (service is FormComponent form)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
LoadData();
|
||||||
{
|
}
|
||||||
LoadData();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonChange_Click(object sender, EventArgs e)
|
private void buttonChange_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
var service =
|
var form = DependencyManager.Instance.Resolve<FormComponent>();
|
||||||
Program.ServiceProvider?.GetService(typeof(FormComponent));
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
if (service is FormComponent form)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
form.Id =
|
LoadData();
|
||||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
}
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
}
|
||||||
LoadData();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonDelete_Click(object sender, EventArgs e)
|
private void buttonDelete_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,7 @@ using AbstractIceCreamShopDataModels.Models;
|
|||||||
using IceCreamShop;
|
using IceCreamShop;
|
||||||
using IceCreamShopContracts.BindingModels;
|
using IceCreamShopContracts.BindingModels;
|
||||||
using IceCreamShopContracts.BusinessLogicsContracts;
|
using IceCreamShopContracts.BusinessLogicsContracts;
|
||||||
|
using IceCreamShopContracts.DI;
|
||||||
using IceCreamShopContracts.SearchModels;
|
using IceCreamShopContracts.SearchModels;
|
||||||
using IceCreamShopContracts.ViewModels;
|
using IceCreamShopContracts.ViewModels;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@ -98,51 +99,49 @@ namespace IceCreamShopView
|
|||||||
|
|
||||||
private void buttonAdd_Click(object sender, EventArgs e)
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormIceCreamComponent));
|
var form = DependencyManager.Instance.Resolve<FormIceCreamComponent>();
|
||||||
if (service is FormIceCreamComponent form)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ComponentModel == null)
|
||||||
{
|
{
|
||||||
if (form.ComponentModel == null)
|
return;
|
||||||
{
|
}
|
||||||
return;
|
_logger.LogInformation("Добавление нового компонента: { ComponentName}- { Count}",
|
||||||
}
|
form.ComponentModel.ComponentName, form.Count);
|
||||||
_logger.LogInformation("Добавление нового компонента:{ ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count);
|
if (_iceCreamComponents.ContainsKey(form.Id))
|
||||||
if (_iceCreamComponents.ContainsKey(form.Id))
|
{
|
||||||
{
|
_iceCreamComponents[form.Id] = (form.ComponentModel,
|
||||||
_iceCreamComponents[form.Id] = (form.ComponentModel, form.Count);
|
form.Count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_iceCreamComponents.Add(form.Id, (form.ComponentModel, form.Count));
|
_iceCreamComponents.Add(form.Id, (form.ComponentModel,
|
||||||
}
|
form.Count));
|
||||||
LoadData();
|
}
|
||||||
}
|
LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonEdit_Click(object sender, EventArgs e)
|
private void buttonEdit_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormIceCreamComponent));
|
var form = DependencyManager.Instance.Resolve<FormIceCreamComponent>();
|
||||||
if (service is FormIceCreamComponent form)
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||||
{
|
form.Id = id;
|
||||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
form.Count = _iceCreamComponents[id].Item2;
|
||||||
form.Id = id;
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
form.Count = _iceCreamComponents[id].Item2;
|
{
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ComponentModel == null)
|
||||||
{
|
{
|
||||||
if (form.ComponentModel == null)
|
return;
|
||||||
{
|
}
|
||||||
return;
|
_logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ",
|
||||||
}
|
form.ComponentModel.ComponentName, form.Count);
|
||||||
_logger.LogInformation("Изменение компонента:{ ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count);
|
_iceCreamComponents[id] = (form.ComponentModel, form.Count);
|
||||||
_iceCreamComponents[form.Id] = (form.ComponentModel, form.Count);
|
LoadData();
|
||||||
LoadData();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonDelete_Click(object sender, EventArgs e)
|
private void buttonDelete_Click(object sender, EventArgs e)
|
||||||
|
@ -10,6 +10,7 @@ using System.Windows.Forms;
|
|||||||
using IceCreamShop;
|
using IceCreamShop;
|
||||||
using IceCreamShopContracts.BindingModels;
|
using IceCreamShopContracts.BindingModels;
|
||||||
using IceCreamShopContracts.BusinessLogicsContracts;
|
using IceCreamShopContracts.BusinessLogicsContracts;
|
||||||
|
using IceCreamShopContracts.DI;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
|
||||||
@ -48,30 +49,24 @@ namespace IceCreamShopView
|
|||||||
|
|
||||||
private void buttonAdd_Click(object sender, EventArgs e)
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormIceCream));
|
var form = DependencyManager.Instance.Resolve<FormIceCream>();
|
||||||
if (service is FormIceCream form)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
LoadData();
|
||||||
{
|
}
|
||||||
LoadData();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonEdit_Click(object sender, EventArgs e)
|
private void buttonEdit_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormIceCream));
|
var form = DependencyManager.Instance.Resolve<FormIceCream>();
|
||||||
if (service is FormIceCream form)
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
{
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
{
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
LoadData();
|
||||||
{
|
}
|
||||||
LoadData();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonDelete_Click(object sender, EventArgs e)
|
private void buttonDelete_Click(object sender, EventArgs e)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using IceCreamShop;
|
using IceCreamShop;
|
||||||
using IceCreamShopContracts.BindingModels;
|
using IceCreamShopContracts.BindingModels;
|
||||||
using IceCreamShopContracts.BusinessLogicsContracts;
|
using IceCreamShopContracts.BusinessLogicsContracts;
|
||||||
|
using IceCreamShopContracts.DI;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
|
||||||
@ -39,30 +40,24 @@ namespace IceCreamShopView
|
|||||||
|
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
|
var form = DependencyManager.Instance.Resolve<FormImplementer>();
|
||||||
if (service is FormImplementer form)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
LoadData();
|
||||||
{
|
}
|
||||||
LoadData();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
|
var form = DependencyManager.Instance.Resolve<FormImplementer>();
|
||||||
if (service is FormImplementer form)
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
{
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
{
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
LoadData();
|
||||||
{
|
}
|
||||||
LoadData();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonDel_Click(object sender, EventArgs e)
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
11
IceCreamShop/IceCreamShop/FormMain.Designer.cs
generated
11
IceCreamShop/IceCreamShop/FormMain.Designer.cs
generated
@ -44,6 +44,7 @@
|
|||||||
ordersToolStripMenuItem = new ToolStripMenuItem();
|
ordersToolStripMenuItem = new ToolStripMenuItem();
|
||||||
DoWorkToolStripMenuItem = new ToolStripMenuItem();
|
DoWorkToolStripMenuItem = new ToolStripMenuItem();
|
||||||
MailToolStripMenuItem = new ToolStripMenuItem();
|
MailToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
createBackupToolStripMenuItem = new ToolStripMenuItem();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
menuStrip.SuspendLayout();
|
menuStrip.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -95,7 +96,7 @@
|
|||||||
// menuStrip
|
// menuStrip
|
||||||
//
|
//
|
||||||
menuStrip.ImageScalingSize = new Size(20, 20);
|
menuStrip.ImageScalingSize = new Size(20, 20);
|
||||||
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, DoWorkToolStripMenuItem, MailToolStripMenuItem });
|
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, DoWorkToolStripMenuItem, MailToolStripMenuItem, createBackupToolStripMenuItem });
|
||||||
menuStrip.Location = new Point(0, 0);
|
menuStrip.Location = new Point(0, 0);
|
||||||
menuStrip.Name = "menuStrip";
|
menuStrip.Name = "menuStrip";
|
||||||
menuStrip.Padding = new Padding(5, 2, 0, 2);
|
menuStrip.Padding = new Padding(5, 2, 0, 2);
|
||||||
@ -180,6 +181,13 @@
|
|||||||
MailToolStripMenuItem.Text = "Письма";
|
MailToolStripMenuItem.Text = "Письма";
|
||||||
MailToolStripMenuItem.Click += MailToolStripMenuItem_Click;
|
MailToolStripMenuItem.Click += MailToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
|
// createBackupToolStripMenuItem
|
||||||
|
//
|
||||||
|
createBackupToolStripMenuItem.Name = "createBackupToolStripMenuItem";
|
||||||
|
createBackupToolStripMenuItem.Size = new Size(97, 20);
|
||||||
|
createBackupToolStripMenuItem.Text = "Создать бекап";
|
||||||
|
createBackupToolStripMenuItem.Click += createBackupToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
// FormMain
|
// FormMain
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
@ -218,5 +226,6 @@
|
|||||||
private ToolStripMenuItem ImplementersToolStripMenuItem;
|
private ToolStripMenuItem ImplementersToolStripMenuItem;
|
||||||
private ToolStripMenuItem DoWorkToolStripMenuItem;
|
private ToolStripMenuItem DoWorkToolStripMenuItem;
|
||||||
private ToolStripMenuItem MailToolStripMenuItem;
|
private ToolStripMenuItem MailToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem createBackupToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,10 @@
|
|||||||
using AbstractIceCreamShopDataModels.Enums;
|
using AbstractIceCreamShopDataModels.Enums;
|
||||||
|
using ConfectioneryBusinessLogic;
|
||||||
using IceCreamBusinessLogic.BusinessLogics;
|
using IceCreamBusinessLogic.BusinessLogics;
|
||||||
using IceCreamShop;
|
using IceCreamShop;
|
||||||
using IceCreamShopContracts.BindingModels;
|
using IceCreamShopContracts.BindingModels;
|
||||||
using IceCreamShopContracts.BusinessLogicsContracts;
|
using IceCreamShopContracts.BusinessLogicsContracts;
|
||||||
|
using IceCreamShopContracts.DI;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -22,13 +24,15 @@ namespace IceCreamShopView
|
|||||||
private readonly IOrderLogic _orderLogic;
|
private readonly IOrderLogic _orderLogic;
|
||||||
private readonly IReportLogic _reportLogic;
|
private readonly IReportLogic _reportLogic;
|
||||||
private readonly IWorkProcess _workProcess;
|
private readonly IWorkProcess _workProcess;
|
||||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
|
private readonly IBackUpLogic _backUpLogic;
|
||||||
|
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderLogic = orderLogic;
|
_orderLogic = orderLogic;
|
||||||
_reportLogic = reportLogic;
|
_reportLogic = reportLogic;
|
||||||
_workProcess = workProcess;
|
_workProcess = workProcess;
|
||||||
|
_backUpLogic = backUpLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormMain_Load(object sender, EventArgs e)
|
private void FormMain_Load(object sender, EventArgs e)
|
||||||
@ -53,30 +57,21 @@ namespace IceCreamShopView
|
|||||||
|
|
||||||
private void компонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
private void компонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
var form = DependencyManager.Instance.Resolve<FormComponents>();
|
||||||
if (service is FormComponents form)
|
form.ShowDialog();
|
||||||
{
|
|
||||||
form.ShowDialog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void мороженоеToolStripMenuItem_Click(object sender, EventArgs e)
|
private void мороженоеToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormIceCreams));
|
var form = DependencyManager.Instance.Resolve<FormIceCreams>();
|
||||||
if (service is FormIceCreams form)
|
form.ShowDialog();
|
||||||
{
|
|
||||||
form.ShowDialog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonCreateOrder_Click(object sender, EventArgs e)
|
private void buttonCreateOrder_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
var form = DependencyManager.Instance.Resolve<FormCreateOrder>();
|
||||||
if (service is FormCreateOrder form)
|
form.ShowDialog();
|
||||||
{
|
LoadData();
|
||||||
form.ShowDialog();
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonSetToWork_Click(object sender, EventArgs e)
|
private void buttonSetToWork_Click(object sender, EventArgs e)
|
||||||
@ -176,54 +171,65 @@ namespace IceCreamShopView
|
|||||||
|
|
||||||
private void IceCreamComponentsToolStripMenuItem_Click(object sender, EventArgs e)
|
private void IceCreamComponentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportProductComponents));
|
var form = DependencyManager.Instance.Resolve<FormReportProductComponents>();
|
||||||
if (service is FormReportProductComponents form)
|
form.ShowDialog();
|
||||||
{
|
|
||||||
form.ShowDialog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
|
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
|
var form = DependencyManager.Instance.Resolve<FormReportOrders>();
|
||||||
if (service is FormReportOrders form)
|
form.ShowDialog();
|
||||||
{
|
|
||||||
form.ShowDialog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
|
private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
|
var form = DependencyManager.Instance.Resolve<FormClients>();
|
||||||
if (service is FormClients form)
|
form.ShowDialog();
|
||||||
{
|
|
||||||
form.ShowDialog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
|
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
|
var form = DependencyManager.Instance.Resolve<FormImplementers>();
|
||||||
if (service is FormImplementers form)
|
form.ShowDialog();
|
||||||
{
|
|
||||||
form.ShowDialog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e)
|
private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_workProcess.DoWork((
|
_workProcess.DoWork(
|
||||||
Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
|
DependencyManager.Instance.Resolve<IImplementerLogic>(),
|
||||||
|
_orderLogic);
|
||||||
MessageBox.Show("Процесс обработки запущен", "Сообщение",
|
MessageBox.Show("Процесс обработки запущен", "Сообщение",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MailToolStripMenuItem_Click(object sender, EventArgs e)
|
private void MailToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormViewMail));
|
var form = DependencyManager.Instance.Resolve<FormViewMail>();
|
||||||
if (service is FormViewMail form)
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createBackupToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
if (_backUpLogic != null)
|
||||||
|
{
|
||||||
|
var fbd = new FolderBrowserDialog();
|
||||||
|
if (fbd.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
_backUpLogic.CreateBackUp(new BackUpSaveBinidngModel
|
||||||
|
{
|
||||||
|
FolderName = fbd.SelectedPath
|
||||||
|
});
|
||||||
|
MessageBox.Show("Бекап создан", "Сообщение",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
using IceCreamShopContracts.BusinessLogicsContracts;
|
using IceCreamShopContracts.BusinessLogicsContracts;
|
||||||
using IceCreamShopContracts.StoragesContracts;
|
|
||||||
using IceCreamBusinessLogic.BusinessLogics;
|
using IceCreamBusinessLogic.BusinessLogics;
|
||||||
using IceCreamShopView;
|
using IceCreamShopView;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
using IceCreamBusinessLogic.OfficePackage.Implements;
|
using IceCreamBusinessLogic.OfficePackage.Implements;
|
||||||
@ -11,13 +9,12 @@ using IceCreamShopDatabaseImplement.Implements;
|
|||||||
using IceCreamBusinessLogic.BusinessLogic;
|
using IceCreamBusinessLogic.BusinessLogic;
|
||||||
using IceCreamBusinessLogic.MailWorker;
|
using IceCreamBusinessLogic.MailWorker;
|
||||||
using IceCreamShopContracts.BindingModels;
|
using IceCreamShopContracts.BindingModels;
|
||||||
|
using IceCreamShopContracts.DI;
|
||||||
|
|
||||||
namespace IceCreamShop
|
namespace IceCreamShop
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
private static ServiceProvider? _serviceProvider;
|
|
||||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -27,14 +24,12 @@ namespace IceCreamShop
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
var services = new ServiceCollection();
|
InitDependency();
|
||||||
ConfigureServices(services);
|
|
||||||
_serviceProvider = services.BuildServiceProvider();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var mailSender = _serviceProvider.GetService<AbstractMailWorker>();
|
var mailSender = DependencyManager.Instance.Resolve<AbstractMailWorker>();
|
||||||
mailSender?.MailConfig(new MailConfigBindingModel
|
mailSender?.MailConfig(new MailConfigBindingModel
|
||||||
{
|
{
|
||||||
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
|
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
|
||||||
MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty,
|
MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty,
|
||||||
@ -47,58 +42,54 @@ namespace IceCreamShop
|
|||||||
// ñîçäàåì òàéìåð
|
// ñîçäàåì òàéìåð
|
||||||
var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000);
|
var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var logger = _serviceProvider.GetService<ILogger>();
|
var logger = DependencyManager.Instance.Resolve<ILogger>();
|
||||||
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
|
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
|
||||||
}
|
}
|
||||||
|
|
||||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
Application.Run(DependencyManager.Instance.Resolve<FormMain>());
|
||||||
}
|
|
||||||
|
|
||||||
private static void ConfigureServices(ServiceCollection services)
|
|
||||||
{
|
|
||||||
services.AddLogging(option =>
|
|
||||||
{
|
|
||||||
option.SetMinimumLevel(LogLevel.Information);
|
|
||||||
option.AddNLog("nlog.config");
|
|
||||||
});
|
|
||||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
|
||||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
|
||||||
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
|
||||||
services.AddTransient<IIceCreamStorage, IceCreamStorage>();
|
|
||||||
services.AddTransient<IClientStorage, ClientStorage>();
|
|
||||||
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
|
||||||
|
|
||||||
services.AddTransient<IClientLogic, ClientLogic>();
|
|
||||||
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
|
||||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
|
||||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
|
||||||
services.AddTransient<IIceCreamLogic, IceCreamLogic>();
|
|
||||||
services.AddTransient<IReportLogic, ReportLogic>();
|
|
||||||
services.AddTransient<IWorkProcess, WorkModeling>();
|
|
||||||
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
|
||||||
|
|
||||||
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
|
||||||
|
|
||||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
|
||||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
|
||||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
|
||||||
|
|
||||||
services.AddTransient<FormMain>();
|
|
||||||
services.AddTransient<FormImplementer>();
|
|
||||||
services.AddTransient<FormImplementers>();
|
|
||||||
services.AddTransient<FormClients>();
|
|
||||||
services.AddTransient<FormComponent>();
|
|
||||||
services.AddTransient<FormComponents>();
|
|
||||||
services.AddTransient<FormCreateOrder>();
|
|
||||||
services.AddTransient<FormIceCream>();
|
|
||||||
services.AddTransient<FormIceCreamComponent>();
|
|
||||||
services.AddTransient<FormIceCreams>();
|
|
||||||
services.AddTransient<FormReportProductComponents>();
|
|
||||||
services.AddTransient<FormReportOrders>();
|
|
||||||
services.AddTransient<FormViewMail>();
|
|
||||||
}
|
}
|
||||||
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
|
|
||||||
}
|
private static void InitDependency()
|
||||||
|
{
|
||||||
|
DependencyManager.InitDependency();
|
||||||
|
|
||||||
|
DependencyManager.Instance.AddLogging(option =>
|
||||||
|
{
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddNLog("nlog.config");
|
||||||
|
});
|
||||||
|
|
||||||
|
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IComponentLogic, ComponentLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IIceCreamLogic, IceCreamLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
||||||
|
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
||||||
|
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
||||||
|
|
||||||
|
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>();
|
||||||
|
|
||||||
|
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
||||||
|
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
||||||
|
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
||||||
|
|
||||||
|
DependencyManager.Instance.RegisterType<FormMain>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormImplementer>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormImplementers>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormClients>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormComponent>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormComponents>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormCreateOrder>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormIceCream>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormIceCreamComponent>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormIceCreams>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormReportProductComponents>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormReportOrders>();
|
||||||
|
DependencyManager.Instance.RegisterType<FormViewMail>();
|
||||||
|
}
|
||||||
|
private static void MailCheck(object obj) => DependencyManager.Instance.Resolve<AbstractMailWorker>()?.MailCheck();
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
namespace IceCreamShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class BackUpSaveBinidngModel
|
||||||
|
{
|
||||||
|
public string FolderName { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -15,5 +15,7 @@ namespace IceCreamShopContracts.BindingModels
|
|||||||
public string Body { get; set; } = string.Empty;
|
public string Body { get; set; } = string.Empty;
|
||||||
|
|
||||||
public DateTime DateDelivery { get; set; }
|
public DateTime DateDelivery { get; set; }
|
||||||
}
|
|
||||||
|
public int Id => throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using IceCreamShopContracts.BindingModels;
|
||||||
|
|
||||||
|
namespace IceCreamShopContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IBackUpLogic
|
||||||
|
{
|
||||||
|
void CreateBackUp(BackUpSaveBinidngModel model);
|
||||||
|
}
|
||||||
|
}
|
61
IceCreamShop/IceCreamShopContracts/DI/DependencyManager.cs
Normal file
61
IceCreamShop/IceCreamShopContracts/DI/DependencyManager.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace IceCreamShopContracts.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; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Иницализация библиотек, в которых идут установки зависомстей
|
||||||
|
/// </summary>
|
||||||
|
public static void InitDependency()
|
||||||
|
{
|
||||||
|
var ext = ServiceProviderLoader.GetImplementationExtensions();
|
||||||
|
if (ext == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
||||||
|
}
|
||||||
|
// регистрируем зависимости
|
||||||
|
ext.RegisterServices();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Регистрация логгера
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="configure"></param>
|
||||||
|
public void AddLogging(Action<ILoggingBuilder> configure) => _dependencyManager.AddLogging(configure);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление зависимости
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="U"></typeparam>
|
||||||
|
public void RegisterType<T, U>(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType<T, U>(isSingle);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление зависимости
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="U"></typeparam>
|
||||||
|
public void RegisterType<T>(bool isSingle = false) where T : class => _dependencyManager.RegisterType<T>(isSingle);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение класса со всеми зависмостями
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T Resolve<T>() => _dependencyManager.Resolve<T>();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace IceCreamShopContracts.DI
|
||||||
|
{
|
||||||
|
public interface IDependencyContainer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Регистрация логгера
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="configure"></param>
|
||||||
|
void AddLogging(Action<ILoggingBuilder> configure);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление зависимости
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="U"></typeparam>
|
||||||
|
/// <param name="isSingle"></param>
|
||||||
|
void RegisterType<T, U>(bool isSingle) where U : class, T where T : class;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление зависимости
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="isSingle"></param>
|
||||||
|
void RegisterType<T>(bool isSingle) where T : class;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение класса со всеми зависмостями
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
T Resolve<T>();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
namespace IceCreamShopContracts.DI
|
||||||
|
{
|
||||||
|
public interface IImplementationExtension
|
||||||
|
{
|
||||||
|
public int Priority { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Регистрация сервисов
|
||||||
|
/// </summary>
|
||||||
|
public void RegisterServices();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace IceCreamShopContracts.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>()!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace IceCreamShopContracts.DI
|
||||||
|
{
|
||||||
|
public class ServiceProviderLoader
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Загрузка всех классов-реализаций IImplementationExtension
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Unity;
|
||||||
|
using Unity.Microsoft.Logging;
|
||||||
|
|
||||||
|
namespace IceCreamShopContracts.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||||
|
<PackageReference Include="Unity" Version="5.11.10" />
|
||||||
|
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
namespace IceCreamShopContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IBackUpInfo
|
||||||
|
{
|
||||||
|
List<T>? GetList<T>() where T : class, new();
|
||||||
|
Type? GetTypeByModelInterface(string modelInterfaceName);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
using AbstractIceCreamShopDataModels.Models;
|
using AbstractIceCreamShopDataModels.Models;
|
||||||
using IceCreamShopContracts.Attributes;
|
using IceCreamShopContracts.Attributes;
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace IceCreamShopContracts.ViewModels
|
namespace IceCreamShopContracts.ViewModels
|
||||||
{
|
{
|
||||||
@ -25,5 +24,6 @@ namespace IceCreamShopContracts.ViewModels
|
|||||||
public string Body { get; set; } = string.Empty;
|
public string Body { get; set; } = string.Empty;
|
||||||
|
|
||||||
[Column(visible: false)]
|
[Column(visible: false)]
|
||||||
|
public int Id => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
namespace AbstractIceCreamShopDataModels.Models
|
namespace AbstractIceCreamShopDataModels.Models
|
||||||
{
|
{
|
||||||
public interface IMessageInfoModel
|
public interface IMessageInfoModel : IId
|
||||||
{
|
{
|
||||||
string MessageId { get; }
|
string MessageId { get; }
|
||||||
int? ClientId { get; }
|
int? ClientId { get; }
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
using IceCreamShopContracts.StoragesContracts;
|
||||||
|
|
||||||
|
namespace IceCreamShopDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class BackUpInfo : IBackUpInfo
|
||||||
|
{
|
||||||
|
public List<T>? GetList<T>() where T : class, new()
|
||||||
|
{
|
||||||
|
using var context = new IceCreamShopDatabase();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -48,5 +48,7 @@ namespace IceCreamShopDatabaseImplement.Models
|
|||||||
SenderName = SenderName,
|
SenderName = SenderName,
|
||||||
DateDelivery = DateDelivery,
|
DateDelivery = DateDelivery,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
public int Id => throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,5 +71,7 @@ namespace IceCreamShopFileImplement.Models
|
|||||||
new XAttribute("SenderName", SenderName),
|
new XAttribute("SenderName", SenderName),
|
||||||
new XAttribute("DateDelivery", DateDelivery)
|
new XAttribute("DateDelivery", DateDelivery)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
public int Id => throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,4 +15,8 @@
|
|||||||
<ProjectReference Include="..\IceCreamShopDataModels\IceCreamShopDataModels.csproj" />
|
<ProjectReference Include="..\IceCreamShopDataModels\IceCreamShopDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
using IceCreamShopContracts.StoragesContracts;
|
||||||
|
|
||||||
|
namespace IceCreamShopListImplement.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,13 @@
|
|||||||
using IceCreamShopContracts.BindingModels;
|
using IceCreamShopContracts.BindingModels;
|
||||||
using IceCreamShopContracts.SearchModels;
|
using IceCreamShopContracts.SearchModels;
|
||||||
using IceCreamShopContracts.ViewModels;
|
using IceCreamShopContracts.ViewModels;
|
||||||
|
using IceCreamShopContracts.StoragesContracts;
|
||||||
using IceCreamShopListImplement.Models;
|
using IceCreamShopListImplement.Models;
|
||||||
|
|
||||||
namespace IceCreamShopListImplement.Implements
|
namespace IceCreamShopListImplement.Implements
|
||||||
{
|
{
|
||||||
public class MessageInfoStorage
|
public class MessageInfoStorage : IMessageInfoStorage
|
||||||
{
|
{
|
||||||
private readonly DataListSingleton _source;
|
private readonly DataListSingleton _source;
|
||||||
public MessageInfoStorage()
|
public MessageInfoStorage()
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
using IceCreamShopContracts.DI;
|
||||||
|
using IceCreamShopContracts.StoragesContracts;
|
||||||
|
using IceCreamShopListImplement.Implements;
|
||||||
|
|
||||||
|
namespace IceCreamShopListImplement
|
||||||
|
{
|
||||||
|
public class ListImplementationExtension : IImplementationExtension
|
||||||
|
{
|
||||||
|
public int Priority => 0;
|
||||||
|
|
||||||
|
public void RegisterServices()
|
||||||
|
{
|
||||||
|
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IComponentStorage, ComponentStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IIceCreamStorage, IceCreamStorage>();
|
||||||
|
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -45,5 +45,6 @@ namespace IceCreamShopListImplement.Models
|
|||||||
DateDelivery = DateDelivery,
|
DateDelivery = DateDelivery,
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
public int Id => throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
IceCreamShop/ImplementationExtensions/IceCreamShopContracts.dll
Normal file
BIN
IceCreamShop/ImplementationExtensions/IceCreamShopContracts.dll
Normal file
Binary file not shown.
BIN
IceCreamShop/ImplementationExtensions/IceCreamShopDataModels.dll
Normal file
BIN
IceCreamShop/ImplementationExtensions/IceCreamShopDataModels.dll
Normal file
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user