From f88a86d631e186738991364ffac7304fcb14a388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Wed, 3 Apr 2024 17:52:29 +0400 Subject: [PATCH] done --- .gitignore | 5 + .../BusinessLogics/BackUpLogic.cs | 97 ++++++++++++++++ .../Attributes/ColumnAttribute.cs | 25 ++++ .../Attributes/GridViewAutoSize.cs | 21 ++++ .../BindingModels/BackUpSaveBinidngModel.cs | 7 ++ .../BindingModels/MessageInfoBindingModel.cs | 8 +- .../BusinessLogicsContracts/IBackUpLogic.cs | 9 ++ .../PizzeriaContracts/DI/DependencyManager.cs | 61 ++++++++++ .../DI/IDependencyContainer.cs | 35 ++++++ .../DI/IImplementationExtension.cs | 17 +++ .../DI/ServiceDependencyContainer.cs | 57 ++++++++++ .../DI/ServiceProviderLoader.cs | 55 +++++++++ .../PizzeriaContracts.csproj | 4 + .../StoragesContracts/IBackUpInfo.cs | 9 ++ .../ViewModels/ClientViewModel.cs | 10 +- .../ViewModels/ComponentViewModel.cs | 8 +- .../ViewModels/ImplementerViewModel.cs | 12 +- .../ViewModels/MessageInfoViewModel.cs | 34 +++--- .../ViewModels/OrderViewModel.cs | 26 +++-- .../ViewModels/PizzaViewModel.cs | 9 +- .../Models/IMessageInfoModel.cs | 4 +- .../ImplementationExtension.cs | 22 ++++ .../Implements/BackUpInfo.cs | 27 +++++ .../Models/Client.cs | 18 ++- .../Models/Component.cs | 8 ++ .../Models/Implementer.cs | 7 ++ .../Models/MessageInfo.cs | 22 +++- .../PizzeriaDatabaseImplement/Models/Order.cs | 11 ++ .../PizzeriaDatabaseImplement/Models/Pizza.cs | 9 ++ .../PizzeriaDatabaseImplement.csproj | 4 + .../ImplementationExtension.cs | 22 ++++ .../Implements/BackUpInfo.cs | 39 +++++++ .../PizzeriaFileImplement/Models/Client.cs | 16 ++- .../PizzeriaFileImplement/Models/Component.cs | 7 ++ .../Models/Implementer.cs | 7 ++ .../Models/MessageInfo.cs | 11 ++ .../PizzeriaFileImplement/Models/Order.cs | 19 ++++ .../PizzeriaFileImplement/Models/Pizza.cs | 9 ++ .../PizzeriaFileImplement.csproj | 4 + .../ImplementationExtension.cs | 27 +++++ .../Implements/BackUpInfo.cs | 22 ++++ .../Models/MessageInfo.cs | 2 + .../PizzeriaListImplement.csproj | 4 + .../PizzeriaView/DataGridViewExtension.cs | 46 ++++++++ Pizzeria/PizzeriaView/FormClients.cs | 8 +- Pizzeria/PizzeriaView/FormComponents.cs | 23 ++-- Pizzeria/PizzeriaView/FormImplementers.cs | 9 +- Pizzeria/PizzeriaView/FormMail.cs | 10 +- Pizzeria/PizzeriaView/FormMain.Designer.cs | 24 ++-- Pizzeria/PizzeriaView/FormMain.cs | 107 +++++++++--------- Pizzeria/PizzeriaView/FormPizza.cs | 60 +++++----- Pizzeria/PizzeriaView/FormPizzas.cs | 31 ++--- Pizzeria/PizzeriaView/Program.cs | 78 ++++++------- 53 files changed, 961 insertions(+), 265 deletions(-) create mode 100644 Pizzeria/PizzeriaBusinessLogic/BusinessLogics/BackUpLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/Attributes/ColumnAttribute.cs create mode 100644 Pizzeria/PizzeriaContracts/Attributes/GridViewAutoSize.cs create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/BackUpSaveBinidngModel.cs create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IBackUpLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/DI/DependencyManager.cs create mode 100644 Pizzeria/PizzeriaContracts/DI/IDependencyContainer.cs create mode 100644 Pizzeria/PizzeriaContracts/DI/IImplementationExtension.cs create mode 100644 Pizzeria/PizzeriaContracts/DI/ServiceDependencyContainer.cs create mode 100644 Pizzeria/PizzeriaContracts/DI/ServiceProviderLoader.cs create mode 100644 Pizzeria/PizzeriaContracts/StoragesContracts/IBackUpInfo.cs create mode 100644 Pizzeria/PizzeriaDatabaseImplement/ImplementationExtension.cs create mode 100644 Pizzeria/PizzeriaDatabaseImplement/Implements/BackUpInfo.cs create mode 100644 Pizzeria/PizzeriaFileImplement/ImplementationExtension.cs create mode 100644 Pizzeria/PizzeriaFileImplement/Implements/BackUpInfo.cs create mode 100644 Pizzeria/PizzeriaListImplement/ImplementationExtension.cs create mode 100644 Pizzeria/PizzeriaListImplement/Implements/BackUpInfo.cs create mode 100644 Pizzeria/PizzeriaView/DataGridViewExtension.cs diff --git a/.gitignore b/.gitignore index ca1c7a3..e8d9387 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,11 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +# dll файлы +*.dll + +/Pizzeria/ImplementationExtensions + # Mono auto generated files mono_crash.* diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/BackUpLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/BackUpLogic.cs new file mode 100644 index 0000000..e9d5b44 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/BackUpLogic.cs @@ -0,0 +1,97 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.StoragesContracts; +using PizzeriaDataModels; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + +namespace PizzeriaBusinessLogic.BusinessLogics +{ + public class BackUpLogic : IBackUpLogic + { + private readonly ILogger _logger; + + private readonly IBackUpInfo _backUpInfo; + + public BackUpLogic(ILogger 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(string folderName) where T : class, new() + { + var records = _backUpInfo.GetList(); + if (records == null) + { + _logger.LogWarning("{type} type get null list", typeof(T).Name); + return; + } + var jsonFormatter = new DataContractJsonSerializer(typeof(List)); + using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate); + jsonFormatter.WriteObject(fs, records); + } + } +} diff --git a/Pizzeria/PizzeriaContracts/Attributes/ColumnAttribute.cs b/Pizzeria/PizzeriaContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..3e1ba95 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,25 @@ +namespace PizzeriaContracts.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; + } + } +} diff --git a/Pizzeria/PizzeriaContracts/Attributes/GridViewAutoSize.cs b/Pizzeria/PizzeriaContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..3526aad --- /dev/null +++ b/Pizzeria/PizzeriaContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,21 @@ +namespace PizzeriaContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/BackUpSaveBinidngModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..6fac412 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,7 @@ +namespace PizzeriaContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/MessageInfoBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/MessageInfoBindingModel.cs index c941389..3ee6f19 100644 --- a/Pizzeria/PizzeriaContracts/BindingModels/MessageInfoBindingModel.cs +++ b/Pizzeria/PizzeriaContracts/BindingModels/MessageInfoBindingModel.cs @@ -1,9 +1,4 @@ using PizzeriaDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace PizzeriaContracts.BindingModels { @@ -15,5 +10,6 @@ namespace PizzeriaContracts.BindingModels public string Subject { get; set; } = string.Empty; public string Body { get; set; } = string.Empty; public DateTime DateDelivery { get; set; } - } + public int Id => throw new NotImplementedException(); + } } diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IBackUpLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..62337f0 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using PizzeriaContracts.BindingModels; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/DI/DependencyManager.cs b/Pizzeria/PizzeriaContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..46f8bb8 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/DI/DependencyManager.cs @@ -0,0 +1,61 @@ +using Microsoft.Extensions.Logging; + +namespace PizzeriaContracts.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 configure) => _dependencyManager.AddLogging(configure); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Добавление зависимости + /// + /// + /// + public void RegisterType(bool isSingle = false) where T : class => _dependencyManager.RegisterType(isSingle); + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + public T Resolve() => _dependencyManager.Resolve(); + } +} diff --git a/Pizzeria/PizzeriaContracts/DI/IDependencyContainer.cs b/Pizzeria/PizzeriaContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..0b1fc1e --- /dev/null +++ b/Pizzeria/PizzeriaContracts/DI/IDependencyContainer.cs @@ -0,0 +1,35 @@ +using Microsoft.Extensions.Logging; + +namespace PizzeriaContracts.DI +{ + public interface IDependencyContainer + { + /// + /// Регистрация логгера + /// + /// + void AddLogging(Action configure); + + /// + /// Добавление зависимости + /// + /// + /// + /// + void RegisterType(bool isSingle) where U : class, T where T : class; + + /// + /// Добавление зависимости + /// + /// + /// + void RegisterType(bool isSingle) where T : class; + + /// + /// Получение класса со всеми зависмостями + /// + /// + /// + T Resolve(); + } +} diff --git a/Pizzeria/PizzeriaContracts/DI/IImplementationExtension.cs b/Pizzeria/PizzeriaContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..ae8735e --- /dev/null +++ b/Pizzeria/PizzeriaContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/Pizzeria/PizzeriaContracts/DI/ServiceDependencyContainer.cs b/Pizzeria/PizzeriaContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..3730ffa --- /dev/null +++ b/Pizzeria/PizzeriaContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace PizzeriaContracts.DI +{ + public class ServiceDependencyContainer : IDependencyContainer + { + private ServiceProvider? _serviceProvider; + + private readonly ServiceCollection _serviceCollection; + + public ServiceDependencyContainer() + { + _serviceCollection = new ServiceCollection(); + } + + public void AddLogging(Action configure) + { + _serviceCollection.AddLogging(configure); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public T Resolve() + { + if (_serviceProvider == null) + { + _serviceProvider = _serviceCollection.BuildServiceProvider(); + } + return _serviceProvider.GetService()!; + } + } +} diff --git a/Pizzeria/PizzeriaContracts/DI/ServiceProviderLoader.cs b/Pizzeria/PizzeriaContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..80b8801 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.DI +{ + public class ServiceProviderLoader + { + /// + /// Загрузка всех классов-реализаций IImplementationExtension + /// + /// + 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"; + } + } +} diff --git a/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj index f8743a9..cf9fe6a 100644 --- a/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj +++ b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/Pizzeria/PizzeriaContracts/StoragesContracts/IBackUpInfo.cs b/Pizzeria/PizzeriaContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..33c9e64 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,9 @@ +namespace PizzeriaContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ClientViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ClientViewModel.cs index 5f24f4a..fa88bfa 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/ClientViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/ClientViewModel.cs @@ -1,16 +1,18 @@ -using PizzeriaDataModels.Models; +using PizzeriaContracts.Attributes; +using PizzeriaDataModels.Models; using System.ComponentModel; namespace PizzeriaContracts.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; } } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs index fa3377d..a7abcb1 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using PizzeriaDataModels.Models; +using PizzeriaContracts.Attributes; +using PizzeriaDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,13 @@ namespace PizzeriaContracts.ViewModels { public class ComponentViewModel : IComponentModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название ингредиента")] + [Column(title: "Название ингридиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 150)] public double Cost { get; set; } } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ImplementerViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ImplementerViewModel.cs index 8f5e29c..7436e02 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/ImplementerViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using PizzeriaDataModels.Models; +using PizzeriaContracts.Attributes; +using PizzeriaDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace PizzeriaContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 100)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column(title: "Стаж работы", width: 60)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title: "Квалификация", width: 60)] public int Qualification { get; set; } } } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/MessageInfoViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/MessageInfoViewModel.cs index b47a3de..8039a7e 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/MessageInfoViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/MessageInfoViewModel.cs @@ -1,29 +1,29 @@ -using PizzeriaDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using PizzeriaContracts.Attributes; +using PizzeriaDataModels.Models; namespace PizzeriaContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public int Id { get; set; } - public int? ClientId { get; set; } + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; - [DisplayName("Отправитель")] - public string SenderName { get; set; } = string.Empty; + [Column(visible: false)] + public int? ClientId { get; set; } - [DisplayName("Дата письма")] - public DateTime DateDelivery { get; set; } + [Column(title: "Отправитель", width: 150)] + public string SenderName { get; set; } = string.Empty; - [DisplayName("Заголовок")] - public string Subject { get; set; } = string.Empty; + [Column(title: "Дата письма", width: 120)] + public DateTime DateDelivery { get; set; } - [DisplayName("Текст")] - public string Body { get; set; } = string.Empty; + [Column(title: "Заголовок", width: 120)] + public string Subject { get; set; } = string.Empty; + + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Body { get; set; } = string.Empty; } } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs index 4ba8a4e..645fd87 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using PizzeriaDataModels.Enums; +using PizzeriaContracts.Attributes; +using PizzeriaDataModels.Enums; using PizzeriaDataModels.Models; using System; using System.Collections.Generic; @@ -11,38 +12,43 @@ namespace PizzeriaContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", width: 90)] public int Id { get; set; } + [Column(visible: false)] public int ClientId { get; set; } - [DisplayName("ФИО клиента")] + [Column(title: "Имя клиента", width: 190)] public string ClientFIO { get; set; } = string.Empty; + [Column(visible: false)] public string ClientEmail { get; set; } = string.Empty; + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] + + [Column(title: "Исполнитель", width: 150)] public string? ImplementerFIO { get; set; } = null; + [Column(visible: false)] public int PizzaId { get; set; } - [DisplayName("Пицца")] + [Column(title: "Пицца", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string PizzaName { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column(title: "Количество", width: 100)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column(title: "Сумма", width: 120)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column(title: "Статус", width: 70)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column(title: "Дата создания", width: 120)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column(title: "Дата выполнения", width: 120)] public DateTime? DateImplement { get; set; } } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs index bc37a36..57137e1 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs @@ -1,4 +1,5 @@ -using PizzeriaDataModels.Models; +using PizzeriaContracts.Attributes; +using PizzeriaDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,14 +11,16 @@ namespace PizzeriaContracts.ViewModels { public class PizzaViewModel : IPizzaModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название пиццы")] + [Column(title: "Название пиццы", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string PizzaName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 70)] public double Price { get; set; } + [Column(visible: false)] public Dictionary PizzaComponents { get; set; } = new(); } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaDataModels/Models/IMessageInfoModel.cs b/Pizzeria/PizzeriaDataModels/Models/IMessageInfoModel.cs index 139e615..9836643 100644 --- a/Pizzeria/PizzeriaDataModels/Models/IMessageInfoModel.cs +++ b/Pizzeria/PizzeriaDataModels/Models/IMessageInfoModel.cs @@ -6,8 +6,8 @@ using System.Threading.Tasks; namespace PizzeriaDataModels.Models { - public interface IMessageInfoModel - { + public interface IMessageInfoModel : IId + { string MessageId { get; } int? ClientId { get; } string SenderName { get; } diff --git a/Pizzeria/PizzeriaDatabaseImplement/ImplementationExtension.cs b/Pizzeria/PizzeriaDatabaseImplement/ImplementationExtension.cs new file mode 100644 index 0000000..f44bee3 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/ImplementationExtension.cs @@ -0,0 +1,22 @@ +using PizzeriaContracts.DI; +using PizzeriaContracts.StoragesContracts; +using PizzeriaDatabaseImplement.Implements; + +namespace PizzeriaDatabaseImplement +{ + public class ImplementationExtension : IImplementationExtension + { + public int Priority => 3; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Implements/BackUpInfo.cs b/Pizzeria/PizzeriaDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..485ef6d --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,27 @@ +using PizzeriaContracts.StoragesContracts; + +namespace PizzeriaDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new PizzeriaDatabase(); + return context.Set().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; + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs index 1ace96b..b4f1333 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs @@ -6,20 +6,28 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace PizzeriaDatabaseImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } - [Required] + [DataMember] + [Required] public string ClientFIO { get; set; } = string.Empty; - [Required] + + [DataMember] + [Required] public string Email { get; set; } = string.Empty; - [Required] + + [DataMember] + [Required] public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Component.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Component.cs index 79519b5..97dc7b9 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Component.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Component.cs @@ -3,16 +3,24 @@ using PizzeriaContracts.ViewModels; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; using PizzeriaDataModels.Models; +using System.Runtime.Serialization; namespace PizzeriaDatabaseImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } + + [DataMember] [Required] public string ComponentName { get; private set; } = string.Empty; + + [DataMember] [Required] public double Cost { get; set; } + [ForeignKey("ComponentId")] public virtual List PizzaComponents { get; set; } = new(); diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Implementer.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Implementer.cs index e8c82a4..eb97f9c 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Implementer.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Implementer.cs @@ -3,22 +3,29 @@ using PizzeriaContracts.ViewModels; using PizzeriaDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace PizzeriaDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; set; } + [DataMember] [Required] public string ImplementerFIO { get; set; } = string.Empty; + [DataMember] [Required] public string Password { get; set; } = string.Empty; + [DataMember] [Required] public int WorkExperience { get; set; } + [DataMember] [Required] public int Qualification { get; set; } diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/MessageInfo.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/MessageInfo.cs index eb52485..8a985ea 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/MessageInfo.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/MessageInfo.cs @@ -8,29 +8,39 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace PizzeriaDatabaseImplement.Models { public class MessageInfo : IMessageInfoModel { - [Key] + [NotMapped] + public int Id { get; private set; } + + [DataMember] + [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public string MessageId { get; set; } = string.Empty; - public int? ClientId { get; set; } + [DataMember] + public int? ClientId { get; set; } public virtual Client? Client { get; set; } - [Required] + [DataMember] + [Required] public string SenderName { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public DateTime DateDelivery { get; set; } - [Required] + [DataMember] + [Required] public string Subject { get; set; } = string.Empty; - [Required] + [DataMember] + [Required] public string Body { get; set; } = string.Empty; public static MessageInfo? Create(MessageInfoBindingModel? model) diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs index bad7435..4b391dd 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs @@ -3,39 +3,50 @@ using PizzeriaContracts.ViewModels; using PizzeriaDataModels.Enums; using PizzeriaDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace PizzeriaDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public int ClientId { get; private set; } public virtual Client Client { get; private set; } = new(); + [DataMember] [Required] public int PizzaId { get; private set; } public virtual Pizza Pizza { get; set; } = new(); + [DataMember] public int? ImplementerId { get; private set; } public virtual Implementer? Implementer { get; set; } = new(); + [DataMember] [Required] public int Count { get; private set; } + [DataMember] [Required] public double Sum { get; private set; } + [DataMember] [Required] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] [Required] public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] public DateTime? DateImplement { get; private set; } public static Order Create(PizzeriaDatabase context, OrderBindingModel model) diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs index a381511..f375d40 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs @@ -3,18 +3,27 @@ using PizzeriaContracts.ViewModels; using PizzeriaDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace PizzeriaDatabaseImplement.Models { + [DataContract] public class Pizza : IPizzaModel { + [DataMember] public int Id { get; set; } + + [DataMember] [Required] public string PizzaName { get; set; } = string.Empty; + + [DataMember] [Required] public double Price { get; set; } private Dictionary? _pizzaComponents = null; + + [DataMember] [NotMapped] public Dictionary PizzaComponents { diff --git a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabaseImplement.csproj b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabaseImplement.csproj index f2a4432..e3025c2 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabaseImplement.csproj +++ b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabaseImplement.csproj @@ -24,4 +24,8 @@ + + + + diff --git a/Pizzeria/PizzeriaFileImplement/ImplementationExtension.cs b/Pizzeria/PizzeriaFileImplement/ImplementationExtension.cs new file mode 100644 index 0000000..e879592 --- /dev/null +++ b/Pizzeria/PizzeriaFileImplement/ImplementationExtension.cs @@ -0,0 +1,22 @@ +using PizzeriaContracts.DI; +using PizzeriaContracts.StoragesContracts; +using PizzeriaFileImplement.Implements; + +namespace PizzeriaFileImplement +{ + public class ImplementationExtension : IImplementationExtension + { + public int Priority => 1; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/Pizzeria/PizzeriaFileImplement/Implements/BackUpInfo.cs b/Pizzeria/PizzeriaFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..860550b --- /dev/null +++ b/Pizzeria/PizzeriaFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,39 @@ +using PizzeriaContracts.StoragesContracts; +using System.Reflection; + +namespace PizzeriaFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + private readonly DataFileSingleton source; + private readonly PropertyInfo[] sourceProperties; + + public BackUpInfo() + { + source = DataFileSingleton.GetInstance(); + sourceProperties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); + } + + public List? GetList() where T : class, new() + { + var requredType = typeof(T); + return (List?)sourceProperties.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == requredType) + ?.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; + } + } +} diff --git a/Pizzeria/PizzeriaFileImplement/Models/Client.cs b/Pizzeria/PizzeriaFileImplement/Models/Client.cs index e6f1d82..409d2fd 100644 --- a/Pizzeria/PizzeriaFileImplement/Models/Client.cs +++ b/Pizzeria/PizzeriaFileImplement/Models/Client.cs @@ -1,16 +1,22 @@ using PizzeriaContracts.BindingModels; using PizzeriaContracts.ViewModels; using PizzeriaDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace PizzeriaFileImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; set; } - public string ClientFIO { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; + [DataMember] + public int Id { get; set; } + [DataMember] + public string ClientFIO { get; set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; + [DataMember] + public string Email { get; set; } = string.Empty; public static Client? Create(ClientBindingModel? model) { diff --git a/Pizzeria/PizzeriaFileImplement/Models/Component.cs b/Pizzeria/PizzeriaFileImplement/Models/Component.cs index bfba488..e5b0bc6 100644 --- a/Pizzeria/PizzeriaFileImplement/Models/Component.cs +++ b/Pizzeria/PizzeriaFileImplement/Models/Component.cs @@ -1,14 +1,21 @@ using PizzeriaContracts.BindingModels; using PizzeriaContracts.ViewModels; using PizzeriaDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace PizzeriaFileImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } + + [DataMember] public string ComponentName { get; private set; } = string.Empty; + + [DataMember] public double Cost { get; set; } public static Component? Create(ComponentBindingModel model) diff --git a/Pizzeria/PizzeriaFileImplement/Models/Implementer.cs b/Pizzeria/PizzeriaFileImplement/Models/Implementer.cs index a2f2384..39e823e 100644 --- a/Pizzeria/PizzeriaFileImplement/Models/Implementer.cs +++ b/Pizzeria/PizzeriaFileImplement/Models/Implementer.cs @@ -4,22 +4,29 @@ using PizzeriaDataModels.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 PizzeriaFileImplement.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) diff --git a/Pizzeria/PizzeriaFileImplement/Models/MessageInfo.cs b/Pizzeria/PizzeriaFileImplement/Models/MessageInfo.cs index db302eb..5cc65fc 100644 --- a/Pizzeria/PizzeriaFileImplement/Models/MessageInfo.cs +++ b/Pizzeria/PizzeriaFileImplement/Models/MessageInfo.cs @@ -4,24 +4,35 @@ using PizzeriaDataModels.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 PizzeriaFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [DataMember] + public int Id { get; private set; } + + [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; public static MessageInfo? Create(MessageInfoBindingModel model) diff --git a/Pizzeria/PizzeriaFileImplement/Models/Order.cs b/Pizzeria/PizzeriaFileImplement/Models/Order.cs index 6614c16..fc3ff00 100644 --- a/Pizzeria/PizzeriaFileImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaFileImplement/Models/Order.cs @@ -3,19 +3,38 @@ using PizzeriaDataModels.Models; using PizzeriaContracts.BindingModels; using PizzeriaContracts.ViewModels; using System.Xml.Linq; +using System.Runtime.Serialization; namespace PizzeriaFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + + [DataMember] public int ClientId { get; private set; } + + [DataMember] public int? ImplementerId { get; set; } + + [DataMember] public int PizzaId { get; private 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) diff --git a/Pizzeria/PizzeriaFileImplement/Models/Pizza.cs b/Pizzeria/PizzeriaFileImplement/Models/Pizza.cs index 7402c10..3513ae1 100644 --- a/Pizzeria/PizzeriaFileImplement/Models/Pizza.cs +++ b/Pizzeria/PizzeriaFileImplement/Models/Pizza.cs @@ -1,17 +1,26 @@ using PizzeriaContracts.BindingModels; using PizzeriaContracts.ViewModels; using PizzeriaDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace PizzeriaFileImplement.Models { + [DataContract] public class Pizza : IPizzaModel { + [DataMember] public int Id { get; private set; } + + [DataMember] public string PizzaName { get; private set; } = string.Empty; + + [DataMember] public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _pizzaComponents = null; + + [DataMember] public Dictionary PizzaComponents { get diff --git a/Pizzeria/PizzeriaFileImplement/PizzeriaFileImplement.csproj b/Pizzeria/PizzeriaFileImplement/PizzeriaFileImplement.csproj index 74101f5..6ebb144 100644 --- a/Pizzeria/PizzeriaFileImplement/PizzeriaFileImplement.csproj +++ b/Pizzeria/PizzeriaFileImplement/PizzeriaFileImplement.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/Pizzeria/PizzeriaListImplement/ImplementationExtension.cs b/Pizzeria/PizzeriaListImplement/ImplementationExtension.cs new file mode 100644 index 0000000..545baab --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/ImplementationExtension.cs @@ -0,0 +1,27 @@ +using PizzeriaContracts.DI; +using PizzeriaContracts.StoragesContracts; +using PizzeriaListImplement.Implements; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement +{ + internal class ImplementationExtension : IImplementationExtension + { + public int Priority => 0; + + public void RegisterServices() + { + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/BackUpInfo.cs b/Pizzeria/PizzeriaListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..4f65a66 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using PizzeriaContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + throw new NotImplementedException(); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + throw new NotImplementedException(); + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/MessageInfo.cs b/Pizzeria/PizzeriaListImplement/Models/MessageInfo.cs index b95d32e..02dce20 100644 --- a/Pizzeria/PizzeriaListImplement/Models/MessageInfo.cs +++ b/Pizzeria/PizzeriaListImplement/Models/MessageInfo.cs @@ -23,6 +23,8 @@ namespace PizzeriaListImplement.Models public string Body { get; private set; } = string.Empty; + public int Id => throw new NotImplementedException(); + public static MessageInfo? Create(MessageInfoBindingModel model) { if (model == null) diff --git a/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj b/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj index 74101f5..6ebb144 100644 --- a/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj +++ b/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/Pizzeria/PizzeriaView/DataGridViewExtension.cs b/Pizzeria/PizzeriaView/DataGridViewExtension.cs new file mode 100644 index 0000000..c82fdab --- /dev/null +++ b/Pizzeria/PizzeriaView/DataGridViewExtension.cs @@ -0,0 +1,46 @@ +using PizzeriaContracts.Attributes; + +namespace PizzeriaView +{ + internal static class DataGridViewExtension + { + public static void FillAndConfigGrid(this DataGridView grid, List? 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; + } + } + } + } + } +} diff --git a/Pizzeria/PizzeriaView/FormClients.cs b/Pizzeria/PizzeriaView/FormClients.cs index 6174f8d..6f53349 100644 --- a/Pizzeria/PizzeriaView/FormClients.cs +++ b/Pizzeria/PizzeriaView/FormClients.cs @@ -35,13 +35,7 @@ namespace PizzeriaView { 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) diff --git a/Pizzeria/PizzeriaView/FormComponents.cs b/Pizzeria/PizzeriaView/FormComponents.cs index 9da2885..7c7e014 100644 --- a/Pizzeria/PizzeriaView/FormComponents.cs +++ b/Pizzeria/PizzeriaView/FormComponents.cs @@ -2,6 +2,7 @@ using Pizzeria; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.DI; namespace PizzeriaView { @@ -46,13 +47,10 @@ namespace PizzeriaView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -60,15 +58,12 @@ namespace PizzeriaView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - if (service is FormComponent form) + var form = DependencyManager.Instance.Resolve(); + + 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(); } } } diff --git a/Pizzeria/PizzeriaView/FormImplementers.cs b/Pizzeria/PizzeriaView/FormImplementers.cs index b59f38a..339d97d 100644 --- a/Pizzeria/PizzeriaView/FormImplementers.cs +++ b/Pizzeria/PizzeriaView/FormImplementers.cs @@ -30,14 +30,7 @@ namespace PizzeriaView { 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) diff --git a/Pizzeria/PizzeriaView/FormMail.cs b/Pizzeria/PizzeriaView/FormMail.cs index f87d86c..d74ea6a 100644 --- a/Pizzeria/PizzeriaView/FormMail.cs +++ b/Pizzeria/PizzeriaView/FormMail.cs @@ -28,15 +28,7 @@ namespace PizzeriaView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка почтовых собщений"); } catch (Exception ex) diff --git a/Pizzeria/PizzeriaView/FormMain.Designer.cs b/Pizzeria/PizzeriaView/FormMain.Designer.cs index 520be00..c8851c9 100644 --- a/Pizzeria/PizzeriaView/FormMain.Designer.cs +++ b/Pizzeria/PizzeriaView/FormMain.Designer.cs @@ -39,13 +39,14 @@ this.componentPizzaToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.почтаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); - this.почтаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.создатьБекапToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -57,7 +58,8 @@ this.bookToolStripMenuItem, this.отчётыToolStripMenuItem, this.запускРаботToolStripMenuItem, - this.почтаToolStripMenuItem}); + this.почтаToolStripMenuItem, + this.создатьБекапToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); @@ -142,6 +144,13 @@ this.запускРаботToolStripMenuItem.Text = "Запуск работ"; this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.startWorkToolStripMenuItem_Click); // + // почтаToolStripMenuItem + // + this.почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; + this.почтаToolStripMenuItem.Size = new System.Drawing.Size(53, 20); + this.почтаToolStripMenuItem.Text = "Почта"; + this.почтаToolStripMenuItem.Click += new System.EventHandler(this.mailToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.AllowUserToAddRows = false; @@ -211,12 +220,12 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // - // почтаToolStripMenuItem + // создатьБекапToolStripMenuItem // - this.почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; - this.почтаToolStripMenuItem.Size = new System.Drawing.Size(53, 20); - this.почтаToolStripMenuItem.Text = "Почта"; - this.почтаToolStripMenuItem.Click += new System.EventHandler(this.mailToolStripMenuItem_Click); + this.создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem"; + this.создатьБекапToolStripMenuItem.Size = new System.Drawing.Size(97, 20); + this.создатьБекапToolStripMenuItem.Text = "Создать Бекап"; + this.создатьБекапToolStripMenuItem.Click += new System.EventHandler(this.createBackUpToolStripMenuItem_Click); // // FormMain // @@ -263,5 +272,6 @@ private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem почтаToolStripMenuItem; + private ToolStripMenuItem создатьБекапToolStripMenuItem; } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormMain.cs b/Pizzeria/PizzeriaView/FormMain.cs index 540092c..3e693f8 100644 --- a/Pizzeria/PizzeriaView/FormMain.cs +++ b/Pizzeria/PizzeriaView/FormMain.cs @@ -3,6 +3,8 @@ using Pizzeria; using PizzeriaBusinessLogic.BusinessLogics; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.DI; +using System.Windows.Forms; namespace PizzeriaView { @@ -12,14 +14,16 @@ namespace PizzeriaView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IBackUpLogic backUpLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; _workProcess = workProcess; + _backUpLogic = backUpLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -31,17 +35,7 @@ namespace PizzeriaView { try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["PizzaId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ClientEmail"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["PizzaName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -53,30 +47,21 @@ namespace PizzeriaView private void IngridentsToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void PizzasToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPizzas)); - if (service is FormPizzas form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + LoadData(); } private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) @@ -175,53 +160,63 @@ namespace PizzeriaView private void ComponentPizzaToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportPizzaComponents)); - if (service is FormReportPizzaComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void ClientToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void employersToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void startWorkToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void mailToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMail)); - if (service is FormMail form) - { - form.ShowDialog(); - } - } - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void createBackUpToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + 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); + } + } + } } diff --git a/Pizzeria/PizzeriaView/FormPizza.cs b/Pizzeria/PizzeriaView/FormPizza.cs index 1191b4d..d837022 100644 --- a/Pizzeria/PizzeriaView/FormPizza.cs +++ b/Pizzeria/PizzeriaView/FormPizza.cs @@ -2,6 +2,7 @@ using Pizzeria; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.DI; using PizzeriaContracts.SearchModels; using PizzeriaDataModels.Models; @@ -77,51 +78,42 @@ namespace PizzeriaView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPizzaComponent)); - if (service is FormPizzaComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); - if (_PizzaComponents.ContainsKey(form.Id)) - { - _PizzaComponents[form.Id] = (form.ComponentModel, - form.Count); - } - else - { - _PizzaComponents.Add(form.Id, (form.ComponentModel, - form.Count)); - } - LoadData(); - } + return; } + _logger.LogInformation("Добавление нового ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + if (_PizzaComponents.ContainsKey(form.Id)) + { + _PizzaComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _PizzaComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); } private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPizzaComponent)); - if (service is FormPizzaComponent form) + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _PizzaComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _PizzaComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); - _PizzaComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); + return; } + _logger.LogInformation("Изменение ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + _PizzaComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); } } } diff --git a/Pizzeria/PizzeriaView/FormPizzas.cs b/Pizzeria/PizzeriaView/FormPizzas.cs index 33acefb..74e48be 100644 --- a/Pizzeria/PizzeriaView/FormPizzas.cs +++ b/Pizzeria/PizzeriaView/FormPizzas.cs @@ -2,6 +2,7 @@ using Pizzeria; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.DI; namespace PizzeriaView { @@ -26,15 +27,7 @@ namespace PizzeriaView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["PizzaComponents"].Visible = false; - dataGridView.Columns["PizzaName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка пиццы"); } catch (Exception ex) @@ -46,13 +39,10 @@ namespace PizzeriaView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPizza)); - if (service is FormPizza form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -60,14 +50,11 @@ namespace PizzeriaView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPizza)); - if (service is FormPizza form) + var form = DependencyManager.Instance.Resolve(); + 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(); } } } diff --git a/Pizzeria/PizzeriaView/Program.cs b/Pizzeria/PizzeriaView/Program.cs index c58616a..d8723ee 100644 --- a/Pizzeria/PizzeriaView/Program.cs +++ b/Pizzeria/PizzeriaView/Program.cs @@ -11,6 +11,7 @@ using PizzeriaContracts.StoragesContracts; using PizzeriaDatabaseImplement.Implements; using PizzeriaView; using Microsoft.EntityFrameworkCore.Design; +using PizzeriaContracts.DI; namespace Pizzeria { @@ -27,12 +28,10 @@ namespace Pizzeria // 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(); + InitDependency(); try { - var mailSender = _serviceProvider.GetService(); + var mailSender = DependencyManager.Instance.Resolve(); mailSender?.MailConfig(new MailConfigBindingModel { MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, @@ -47,58 +46,53 @@ namespace Pizzeria } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, "Mails Problem"); } - Application.Run(_serviceProvider.GetRequiredService()); + Application.Run(DependencyManager.Instance.Resolve()); } - 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(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); + DependencyManager.Instance.RegisterType(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); } - private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + private static void MailCheck(object obj) => DependencyManager.Instance.Resolve()?.MailCheck(); } } \ No newline at end of file