diff --git a/Confectionery/ConfectioneryBusinessLogic/BackUpLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..c51d47b --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BackUpLogic.cs @@ -0,0 +1,103 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BussinessLogicsContracts; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryDataModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.IO.Compression; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic +{ + 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(BackUpSaveBindingModel model) + { + if (_backUpInfo == null) + { + return; + } + try + { + _logger.LogDebug("Clear folder"); + // зачистка папки и удаление старого архива + var dirInfo = new DirectoryInfo(model.FolderName); + if (dirInfo.Exists) + { + foreach (var file in dirInfo.GetFiles()) + { + file.Delete(); + } + } + _logger.LogDebug("Delete archive"); + string fileName = $"{model.FolderName}.zip"; + if (File.Exists(fileName)) + { + File.Delete(fileName); + } + // берем метод для сохранения + _logger.LogDebug("Get assembly"); + var typeIId = typeof(IId); + var assembly = typeIId.Assembly; + if (assembly == null) + { + throw new ArgumentNullException("Сборка не найдена", nameof(assembly)); + } + var types = assembly.GetTypes(); + var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance); + _logger.LogDebug("Find {count} types", types.Length); + foreach (var type in types) + { + if (type.IsInterface && type.GetInterface(typeIId.Name) != null) + { + var modelType = _backUpInfo.GetTypeByModelInterface(type.Name); + if (modelType == null) + { + throw new InvalidOperationException($"Не найден класс-модель для {type.Name}"); + } + _logger.LogDebug("Call SaveToFile method for {name} type", type.Name); + // вызываем метод на выполнение + method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName }); + } + } + _logger.LogDebug("Create zip and remove folder"); + // архивируем + ZipFile.CreateFromDirectory(model.FolderName, fileName); + // удаляем папку + dirInfo.Delete(true); + } + catch (Exception) + { + throw; + } + } + + private void SaveToFile(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/Confectionery/ConfectioneryContracts/Attributes/ColumnAttribute.cs b/Confectionery/ConfectioneryContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..1b6bbc9 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/Attributes/GridViewAutoSize.cs b/Confectionery/ConfectioneryContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..a7d7365 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + + None = 1, + + ColumnHeader = 2, + + AllCellsExceptHeader = 4, + + AllCells = 6, + + DisplayedCellsExceptHeader = 8, + + DisplayedCells = 10, + + Fill = 16 + } +} diff --git a/Confectionery/ConfectioneryContracts/BindingModels/BackUpSaveBinidngModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..64d780b --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BindingModels +{ + public class BackUpSaveBindingModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/Confectionery/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs index 0ef8ce6..02c5f7f 100644 --- a/Confectionery/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs +++ b/Confectionery/ConfectioneryContracts/BindingModels/MessageInfoBindingModel.cs @@ -9,6 +9,7 @@ namespace ConfectioneryContracts.BindingModels { public class MessageInfoBindingModel : IMessageInfoModel { + public int Id => throw new NotImplementedException(); public string MessageId { get; set; } = string.Empty; public int? ClientId { get; set; } diff --git a/Confectionery/ConfectioneryContracts/BussinessLogicsContracts/IBackUpLogic.cs b/Confectionery/ConfectioneryContracts/BussinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..a2be961 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BussinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using ConfectioneryContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BussinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj index aca6a26..bfafc45 100644 --- a/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj +++ b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj @@ -9,6 +9,8 @@ + + diff --git a/Confectionery/ConfectioneryContracts/DI/DependencyManager.cs b/Confectionery/ConfectioneryContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..512362f --- /dev/null +++ b/Confectionery/ConfectioneryContracts/DI/DependencyManager.cs @@ -0,0 +1,66 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.DI +{ + public class DependencyManager + { + private readonly IDependencyContainer _dependencyManager; + + private static DependencyManager? _manager; + + private static readonly object _lockObject = new(); + + private DependencyManager() + { + _dependencyManager = new UnityDependencyContainer(); + } + + public static DependencyManager Instance { get { if (_manager == null) { lock (_lockObject) { _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/Confectionery/ConfectioneryContracts/DI/IDependencyContainer.cs b/Confectionery/ConfectioneryContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..2985420 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/DI/IDependencyContainer.cs @@ -0,0 +1,40 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/DI/IImplementationExtension.cs b/Confectionery/ConfectioneryContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..c434658 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/Confectionery/ConfectioneryContracts/DI/ServiceDependencyContainer.cs b/Confectionery/ConfectioneryContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..15fbb88 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/DI/ServiceProviderLoader.cs b/Confectionery/ConfectioneryContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..017dd9c --- /dev/null +++ b/Confectionery/ConfectioneryContracts/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 ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/DI/UnityDependencyContainer.cs b/Confectionery/ConfectioneryContracts/DI/UnityDependencyContainer.cs new file mode 100644 index 0000000..5cba1c7 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/DI/UnityDependencyContainer.cs @@ -0,0 +1,42 @@ +using Microsoft.Extensions.Logging; +using Unity.Microsoft.Logging; +using Unity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.DI +{ + public class UnityDependencyContainer : IDependencyContainer + { + private readonly IUnityContainer _container; + + public UnityDependencyContainer() + { + _container = new UnityContainer(); + } + + public void AddLogging(Action configure) + { + var factory = LoggerFactory.Create(configure); + _container.AddExtension(new LoggingExtension(factory)); + } + + public void RegisterType(bool isSingle) where U : class, T where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + + public void RegisterType(bool isSingle) where T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + + public T Resolve() + { + return _container.Resolve(); + } + } +} diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IBackUpInfo.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..d596fd6 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ClientViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ClientViewModel.cs index b380685..4ae515b 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/ClientViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,13 +11,16 @@ namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/ViewModels/ComponentViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ComponentViewModel.cs index 7ef4f36..7c16447 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/ComponentViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels.Models; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,10 +11,13 @@ namespace ConfectioneryContracts.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; } } } diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs index 3d038bb..728db26 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,18 +11,19 @@ namespace ConfectioneryContracts.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: 100)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column(title: "Квалификация", width: 100)] public int Qualification { get; set; } } } diff --git a/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs index bfee5a5..e8362a4 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/MessageInfoViewModel.cs @@ -6,25 +6,31 @@ using ConfectioneryDataModels.Models; using System.Linq; using System.Text; using System.Threading.Tasks; +using ConfectioneryContracts.Attributes; namespace ConfectioneryContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + [Column(visible: false)] + public int Id { get; set; } + + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] public int? ClientId { get; set; } - [DisplayName("Отправитель")] + [Column(title: "Отправитель", width: 150)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + [Column(title: "Дата письма", width: 120)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column(title: "Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; } } diff --git a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs index 5930a91..4bc1311 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels.Enums; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels.Enums; using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; @@ -11,26 +12,43 @@ namespace ConfectioneryContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", width: 100)] public int Id { get; set; } + + [Column(visible: false)] public int PastryId { get; set; } - [DisplayName("Кондитерское Изделие")] + + [Column(title: "Кондитерское изделие", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string PastryName { get; set; } = string.Empty; - [DisplayName("Количество")] + + [Column(visible: false)] public int ClientId { get; set; } - [DisplayName("ФИО клиента")] + + [Column(title: "ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] 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: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; + + [Column(title: "Количество", width: 100)] public int Count { get; set; } - [DisplayName("Сумма")] + + [Column(title: "Сумма", width: 120)] public double Sum { get; set; } - [DisplayName("Статус")] + + [Column(title: "Статус", width: 100)] 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; } } } diff --git a/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs index 3f6547e..eb56c9a 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs @@ -1,4 +1,5 @@ -using ConfectioneryDataModels.Models; +using ConfectioneryContracts.Attributes; +using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,11 +11,16 @@ namespace ConfectioneryContracts.ViewModels { public class PastryViewModel : IPastryModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название кондитерского изделия")] + + [Column(title: "Название кондитерского изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string PastryName { get; set; } = string.Empty; - [DisplayName("Цена")] + + [Column(title: "Цена", width: 150)] public double Price { get; set; } + + [Column(visible: false)] public Dictionary PastryComponents { get; diff --git a/Confectionery/ConfectioneryDataModels/IMessageInfoModel.cs b/Confectionery/ConfectioneryDataModels/IMessageInfoModel.cs index 5cf641c..95646d9 100644 --- a/Confectionery/ConfectioneryDataModels/IMessageInfoModel.cs +++ b/Confectionery/ConfectioneryDataModels/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ConfectioneryDataModels { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/Confectionery/ConfectioneryDatabaseImplement/DatabaseImplementationExtension.cs b/Confectionery/ConfectioneryDatabaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..185a638 --- /dev/null +++ b/Confectionery/ConfectioneryDatabaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.DI; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryDatabaseImplement.Implements; + +namespace ConfectioneryDatabaseImplement +{ + public class DatabaseImplementationExtension : IImplementationExtension + { + public int Priority => 2; + + 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/Confectionery/ConfectioneryDatabaseImplement/Implements/BackUpInfo.cs b/Confectionery/ConfectioneryDatabaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..3dcac96 --- /dev/null +++ b/Confectionery/ConfectioneryDatabaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using ConfectioneryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new ConfectioneryDatabase(); + 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/Confectionery/ConfectioneryDatabaseImplement/Implements/MessageInfoStorage.cs b/Confectionery/ConfectioneryDatabaseImplement/Implements/MessageInfoStorage.cs index de5b425..8069ad4 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Implements/MessageInfoStorage.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Implements/MessageInfoStorage.cs @@ -43,12 +43,12 @@ namespace ConfectioneryDatabaseImplement.Implements public MessageInfoViewModel? Insert(MessageInfoBindingModel model) { - using var context = new ConfectioneryDatabase(); - var newMessage = MessageInfo.Create(context, model); - if (newMessage == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId))) + var newMessage = MessageInfo.Create(model); + if (newMessage == null) { return null; } + using var context = new ConfectioneryDatabase(); context.Messages.Add(newMessage); context.SaveChanges(); return newMessage.GetViewModel; diff --git a/Confectionery/ConfectioneryDatabaseImplement/Models/Client.cs b/Confectionery/ConfectioneryDatabaseImplement/Models/Client.cs index 7e03e5a..dbc94e6 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Models/Client.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Models/Client.cs @@ -8,19 +8,25 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public string ClientFIO { get; private set; } = string.Empty; + [DataMember] [Required] public string Email { get; private set; } = string.Empty; + [DataMember] [Required] public string Password { get; private set; } = string.Empty; diff --git a/Confectionery/ConfectioneryDatabaseImplement/Models/Component.cs b/Confectionery/ConfectioneryDatabaseImplement/Models/Component.cs index e332294..09f86e5 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Models/Component.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Models/Component.cs @@ -8,16 +8,21 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.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; } diff --git a/Confectionery/ConfectioneryDatabaseImplement/Models/Implementer.cs b/Confectionery/ConfectioneryDatabaseImplement/Models/Implementer.cs index adafe95..3767281 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Models/Implementer.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Models/Implementer.cs @@ -8,22 +8,29 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.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/Confectionery/ConfectioneryDatabaseImplement/Models/MessageInfo.cs b/Confectionery/ConfectioneryDatabaseImplement/Models/MessageInfo.cs index 842ea89..e999f6b 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Models/MessageInfo.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Models/MessageInfo.cs @@ -4,30 +4,47 @@ using ConfectioneryDataModels; using System; 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 ConfectioneryDatabaseImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + [NotMapped] + public int Id { get; private set; } + + [DataMember] [Key] - public string MessageId { get; private set; } = string.Empty; + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public string MessageId { get; set; } = string.Empty; - public int? ClientId { get; private set; } + [DataMember] + public int? ClientId { get; set; } - public string SenderName { get; private set; } = string.Empty; + [DataMember] + [Required] + public string SenderName { get; set; } = string.Empty; - public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + [Required] + public DateTime DateDelivery { get; set; } - public string Subject { get; private set; } = string.Empty; + [DataMember] + [Required] + public string Subject { get; set; } = string.Empty; - public string Body { get; private set; } = string.Empty; + [DataMember] + [Required] + public string Body { get; set; } = string.Empty; - public Client? Client { get; private set; } + public virtual Client? Client { get; set; } - public static MessageInfo? Create(ConfectioneryDatabase context, MessageInfoBindingModel model) + public static MessageInfo? Create(MessageInfoBindingModel? model) { if (model == null) { @@ -35,24 +52,23 @@ namespace ConfectioneryDatabaseImplement.Models } return new() { - Body = model.Body, - Subject = model.Subject, - ClientId = context.Clients.FirstOrDefault(x => x.Email == model.SenderName).Id, - Client = context.Clients.FirstOrDefault(x => x.Email == model.SenderName), MessageId = model.MessageId, + ClientId = model.ClientId, SenderName = model.SenderName, DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body }; } public MessageInfoViewModel GetViewModel => new() { - Body = Body, - Subject = Subject, - ClientId = ClientId, MessageId = MessageId, + ClientId = ClientId, SenderName = SenderName, DateDelivery = DateDelivery, + Subject = Subject, + Body = Body }; } } diff --git a/Confectionery/ConfectioneryDatabaseImplement/Models/Order.cs b/Confectionery/ConfectioneryDatabaseImplement/Models/Order.cs index 78dbecb..d0d67ab 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Models/Order.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Models/Order.cs @@ -6,35 +6,46 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; set; } + [DataMember] [Required] public int PastryId { get; set; } + [DataMember] [Required] public int ClientId { get; set; } + [DataMember] public int? ImplementerId { get; private set; } + [DataMember] [Required] public int Count { get; set; } + [DataMember] [Required] public double Sum { get; set; } + [DataMember] [Required] public OrderStatus Status { get; set; } + [DataMember] [Required] public DateTime DateCreate { get; set; } + [DataMember] public DateTime? DateImplement { get; set; } public virtual Pastry Pastry { get; set; } diff --git a/Confectionery/ConfectioneryDatabaseImplement/Models/Pastry.cs b/Confectionery/ConfectioneryDatabaseImplement/Models/Pastry.cs index d4fa8ff..80cae23 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Models/Pastry.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Models/Pastry.cs @@ -8,21 +8,27 @@ using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace ConfectioneryDatabaseImplement.Models { + [DataContract] public class Pastry : IPastryModel { + [DataMember] public int Id { get; set; } + [DataMember] [Required] public string PastryName { get; set; } = string.Empty; + [DataMember] [Required] public double Price { get; set; } private Dictionary? _pastryComponents = null; + [DataMember] [NotMapped] public Dictionary PastryComponents { diff --git a/Confectionery/ConfectioneryFileImplement/FileImplementationExtension.cs b/Confectionery/ConfectioneryFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..5cfc99d --- /dev/null +++ b/Confectionery/ConfectioneryFileImplement/FileImplementationExtension.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.DI; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryFileImplement.Implements; + +namespace ConfectioneryFileImplement +{ + public class FileImplementationExtension : 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/Confectionery/ConfectioneryFileImplement/Implements/BackUpInfo.cs b/Confectionery/ConfectioneryFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..16eff99 --- /dev/null +++ b/Confectionery/ConfectioneryFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,40 @@ +using ConfectioneryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + private readonly DataFileSingleton source; + + public BackUpInfo() + { + source = DataFileSingleton.GetInstance(); + } + + public List? GetList() where T : class, new() + { + return (List?)source.GetType().GetProperties() + .FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T)) + ?.GetValue(source); + } + + public Type? GetTypeByModelInterface(string modelInterfaceName) + { + var assembly = typeof(BackUpInfo).Assembly; + var types = assembly.GetTypes(); + foreach (var type in types) + { + if (type.IsClass && type.GetInterface(modelInterfaceName) != null) + { + return type; + } + } + return null; + } + } +} diff --git a/Confectionery/ConfectioneryFileImplement/Models/Client.cs b/Confectionery/ConfectioneryFileImplement/Models/Client.cs index e924c69..0cbd0bf 100644 --- a/Confectionery/ConfectioneryFileImplement/Models/Client.cs +++ b/Confectionery/ConfectioneryFileImplement/Models/Client.cs @@ -4,20 +4,26 @@ using ConfectioneryDataModels; 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 ConfectioneryFileImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string ClientFIO { get; private set; } = string.Empty; + [DataMember] public string Email { get; private set; } = string.Empty; + [DataMember] public string Password { get; private set; } = string.Empty; public static Client? Create(ClientBindingModel model) diff --git a/Confectionery/ConfectioneryFileImplement/Models/Component.cs b/Confectionery/ConfectioneryFileImplement/Models/Component.cs index 4276d4d..cfb6737 100644 --- a/Confectionery/ConfectioneryFileImplement/Models/Component.cs +++ b/Confectionery/ConfectioneryFileImplement/Models/Component.cs @@ -8,16 +8,21 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.ViewModels; using ConfectioneryDataModels.Models; using System.Xml.Linq; +using System.Runtime.Serialization; namespace ConfectioneryFileImplement.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/Confectionery/ConfectioneryFileImplement/Models/Implementer.cs b/Confectionery/ConfectioneryFileImplement/Models/Implementer.cs index 6c59d67..de07e2e 100644 --- a/Confectionery/ConfectioneryFileImplement/Models/Implementer.cs +++ b/Confectionery/ConfectioneryFileImplement/Models/Implementer.cs @@ -4,22 +4,29 @@ using ConfectioneryDataModels; 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 ConfectioneryFileImplement.Models { + [DataContract] internal class Implementer : IImplementerModel { + [DataMember] public int Id { get; set; } + [DataMember] public string ImplementerFIO { get; set; } = string.Empty; + [DataMember] public string Password { get; set; } = string.Empty; + [DataMember] public int WorkExperience { get; set; } + [DataMember] public int Qualification { get; set; } public static Implementer? Create(ImplementerBindingModel? model) diff --git a/Confectionery/ConfectioneryFileImplement/Models/MessageInfo.cs b/Confectionery/ConfectioneryFileImplement/Models/MessageInfo.cs index 9a0af9c..053c8a9 100644 --- a/Confectionery/ConfectioneryFileImplement/Models/MessageInfo.cs +++ b/Confectionery/ConfectioneryFileImplement/Models/MessageInfo.cs @@ -4,24 +4,29 @@ using ConfectioneryDataModels; 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 ConfectioneryFileImplement.Models { + [DataContract] public class MessageInfo : IMessageInfoModel { + 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/Confectionery/ConfectioneryFileImplement/Models/Order.cs b/Confectionery/ConfectioneryFileImplement/Models/Order.cs index 3e6f358..b7e3892 100644 --- a/Confectionery/ConfectioneryFileImplement/Models/Order.cs +++ b/Confectionery/ConfectioneryFileImplement/Models/Order.cs @@ -5,30 +5,33 @@ using ConfectioneryDataModels.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 ConfectioneryFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } - + [DataMember] public int PastryId { get; private set; } - + [DataMember] public int ClientId { get; private set; } - + [DataMember] public int? ImplementerId { get; private set; } - + [DataMember] public int Count { get; private set; } - + [DataMember] public double Sum { get; private set; } - + [DataMember] public OrderStatus Status { get; private set; } - + [DataMember] public DateTime DateCreate { get; private set; } - + [DataMember] public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) diff --git a/Confectionery/ConfectioneryFileImplement/Models/Pastry.cs b/Confectionery/ConfectioneryFileImplement/Models/Pastry.cs index c66f88e..cec4712 100644 --- a/Confectionery/ConfectioneryFileImplement/Models/Pastry.cs +++ b/Confectionery/ConfectioneryFileImplement/Models/Pastry.cs @@ -4,24 +4,30 @@ using ConfectioneryDataModels.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 ConfectioneryFileImplement.Models { + [DataContract] public class Pastry : IPastryModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string PastryName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _pastryComponents = null; + [DataMember] public Dictionary PastryComponents { get diff --git a/Confectionery/ConfectioneryListImplement/Implements/BackUpInfo.cs b/Confectionery/ConfectioneryListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..458b705 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.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/Confectionery/ConfectioneryListImplement/ListImplementationExtension.cs b/Confectionery/ConfectioneryListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..94a4f21 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/ListImplementationExtension.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryContracts.DI; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryListImplement.Implements; + +namespace ConfectioneryListImplement +{ + public class ListImplementationExtension : 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/Confectionery/ConfectioneryListImplement/Models/MessageInfo.cs b/Confectionery/ConfectioneryListImplement/Models/MessageInfo.cs index 36bb35a..b2cdfcc 100644 --- a/Confectionery/ConfectioneryListImplement/Models/MessageInfo.cs +++ b/Confectionery/ConfectioneryListImplement/Models/MessageInfo.cs @@ -11,6 +11,7 @@ namespace ConfectioneryListImplement.Models { public class MessageInfo : IMessageInfoModel { + public int Id => throw new NotImplementedException(); public string MessageId { get; private set; } = string.Empty; public int? ClientId { get; private set; } diff --git a/Confectionery/ConfectioneryView/DataGridViewExtension.cs b/Confectionery/ConfectioneryView/DataGridViewExtension.cs new file mode 100644 index 0000000..5f6a868 --- /dev/null +++ b/Confectionery/ConfectioneryView/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using ConfectioneryContracts.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryView +{ + public 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/Confectionery/ConfectioneryView/FormClients.cs b/Confectionery/ConfectioneryView/FormClients.cs index c032e96..7d6591d 100644 --- a/Confectionery/ConfectioneryView/FormClients.cs +++ b/Confectionery/ConfectioneryView/FormClients.cs @@ -35,13 +35,7 @@ namespace ConfectioneryView { 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("Clients loading"); } catch (Exception ex) diff --git a/Confectionery/ConfectioneryView/FormComponents.cs b/Confectionery/ConfectioneryView/FormComponents.cs index 1b856c6..b907a51 100644 --- a/Confectionery/ConfectioneryView/FormComponents.cs +++ b/Confectionery/ConfectioneryView/FormComponents.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BussinessLogicsContracts; +using ConfectioneryContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -33,14 +34,7 @@ namespace ConfectioneryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -53,29 +47,22 @@ namespace ConfectioneryView 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(); } - } private void buttonUpd_Click(object sender, EventArgs e) { 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/Confectionery/ConfectioneryView/FormImplementers.cs b/Confectionery/ConfectioneryView/FormImplementers.cs index 45941ab..a679261 100644 --- a/Confectionery/ConfectioneryView/FormImplementers.cs +++ b/Confectionery/ConfectioneryView/FormImplementers.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BussinessLogicsContracts; +using ConfectioneryContracts.DI; using Microsoft.Extensions.Logging; namespace ConfectioneryView @@ -26,16 +27,7 @@ namespace ConfectioneryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Implementers loading"); } catch (Exception ex) @@ -47,13 +39,10 @@ namespace ConfectioneryView private void ButtonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -61,14 +50,11 @@ namespace ConfectioneryView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer 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/Confectionery/ConfectioneryView/FormMail.cs b/Confectionery/ConfectioneryView/FormMail.cs index b5c72a4..794302d 100644 --- a/Confectionery/ConfectioneryView/FormMail.cs +++ b/Confectionery/ConfectioneryView/FormMail.cs @@ -27,15 +27,8 @@ namespace ConfectioneryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка списка писем"); + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка списка писем"); } catch (Exception ex) { diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index 89145bc..c2bc320 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -44,6 +44,7 @@ buttonCreateOrder = new Button(); buttonIssuedOrder = new Button(); buttonUpd = new Button(); + СоздатьБэкапToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -51,7 +52,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, ЗапускРаботToolStripMenuItem, ПочтаToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, ЗапускРаботToolStripMenuItem, ПочтаToolStripMenuItem, СоздатьБэкапToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Padding = new Padding(7, 3, 0, 3); @@ -181,6 +182,13 @@ buttonUpd.UseVisualStyleBackColor = true; buttonUpd.Click += buttonUpd_Click; // + // СоздатьБэкапToolStripMenuItem + // + СоздатьБэкапToolStripMenuItem.Name = "СоздатьБэкапToolStripMenuItem"; + СоздатьБэкапToolStripMenuItem.Size = new Size(122, 24); + СоздатьБэкапToolStripMenuItem.Text = "Создать Бэкап"; + СоздатьБэкапToolStripMenuItem.Click += СоздатьБэкапToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -221,5 +229,6 @@ private ToolStripMenuItem ИсполнителиToolStripMenuItem; private ToolStripMenuItem ЗапускРаботToolStripMenuItem; private ToolStripMenuItem ПочтаToolStripMenuItem; + private ToolStripMenuItem СоздатьБэкапToolStripMenuItem; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs index 7d36da8..0d1ff7a 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.BussinessLogicsContracts; +using ConfectioneryContracts.DI; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -18,14 +19,16 @@ namespace ConfectioneryView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; + private readonly IBackUpLogic _backUpLogic; private readonly IWorkProcess _workProcess; - 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) @@ -36,17 +39,7 @@ namespace ConfectioneryView { try { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["PastryId"].Visible = false; - dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -58,48 +51,33 @@ namespace ConfectioneryView 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 КомпонентыToolStripMenuItem_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 КондитерскиеИзделияToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastries)); - if (service is FormPastries form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void КлиентыToolStripMenuItem_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 СписокЗаказовToolStripMenuItem_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 СписокИзделийToolStripMenuItem_Click_1(object sender, EventArgs e) { @@ -113,11 +91,8 @@ namespace ConfectioneryView private void ИзделияПоКомпонентамToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportPastryComponents)); - if (service is FormReportPastryComponents form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void buttonIssuedOrder_Click(object sender, EventArgs e) @@ -151,25 +126,43 @@ namespace ConfectioneryView private void ИсполнителиToolStripMenuItem_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 ЗапускРаботToolStripMenuItem_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 ПочтаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMail)); - if (service is FormMail form) + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void СоздатьБэкапToolStripMenuItem_Click(object sender, EventArgs e) + { + try { - form.ShowDialog(); + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBindingModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бэкап создан", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка создания бэкапа", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } diff --git a/Confectionery/ConfectioneryView/FormPastries.cs b/Confectionery/ConfectioneryView/FormPastries.cs index 4c215d0..219eacb 100644 --- a/Confectionery/ConfectioneryView/FormPastries.cs +++ b/Confectionery/ConfectioneryView/FormPastries.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ConfectioneryContracts.DI; namespace ConfectioneryView { @@ -34,14 +35,7 @@ namespace ConfectioneryView { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["PastryComponents"].Visible = false; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка кондитерских изделий"); } catch (Exception ex) @@ -53,13 +47,10 @@ namespace ConfectioneryView private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastry)); - if (service is FormPastry form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -67,14 +58,11 @@ namespace ConfectioneryView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastry)); - if (service is FormPastry 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/Confectionery/ConfectioneryView/FormPastry.cs b/Confectionery/ConfectioneryView/FormPastry.cs index 45c388d..a73db01 100644 --- a/Confectionery/ConfectioneryView/FormPastry.cs +++ b/Confectionery/ConfectioneryView/FormPastry.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ConfectioneryContracts.DI; namespace ConfectioneryView { @@ -84,26 +85,23 @@ namespace ConfectioneryView private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); - if (service is FormPastryComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); - if (_pastryComponents.ContainsKey(form.Id)) - { - _pastryComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _pastryComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - LoadData(); + return; } + _logger.LogInformation("Adding new component: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_pastryComponents.ContainsKey(form.Id)) + { + _pastryComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _pastryComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); } } @@ -111,22 +109,19 @@ namespace ConfectioneryView { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPastryComponent)); - if (service is FormPastryComponent form) + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _pastryComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _pastryComponents[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); - _pastryComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); + return; } + _logger.LogInformation("Component editing: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _pastryComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); } } } diff --git a/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index bdd1d59..2db3910 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -9,13 +9,12 @@ using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using ConfectioneryBusinessLogic.MailWorker; using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.DI; namespace ConfectioneryView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -25,86 +24,70 @@ namespace ConfectioneryView // 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, - MailPassword = - System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? - string.Empty, - SmtpClientHost = - System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? - string.Empty, - SmtpClientPort = - Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), - PopHost = - System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, - PopPort = - Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) + MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, + MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, + SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, + SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), + PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) }); - // - 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) { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, " "); + 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(); - 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(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddSingleton(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(true); + 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(); + 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