diff --git a/MotorPlant/MotorPlantBusinessLogic/BackUpLogic.cs b/MotorPlant/MotorPlantBusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..ec4e73f --- /dev/null +++ b/MotorPlant/MotorPlantBusinessLogic/BackUpLogic.cs @@ -0,0 +1,98 @@ +using Microsoft.Extensions.Logging; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.StoragesContracts; +using MotorPlantDataModels; +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 MotorPlantBusinessLogic.BusinessLogic +{ + 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/MotorPlant/MotorPlantContracts/Attributes/ColumnAttribute.cs b/MotorPlant/MotorPlantContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..e9b2332 --- /dev/null +++ b/MotorPlant/MotorPlantContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.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/MotorPlant/MotorPlantContracts/Attributes/GridViewAutoSize.cs b/MotorPlant/MotorPlantContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..992e7eb --- /dev/null +++ b/MotorPlant/MotorPlantContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/MotorPlant/MotorPlantContracts/BindingModels/BackUpSaveBinidngModel.cs b/MotorPlant/MotorPlantContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..742f6c6 --- /dev/null +++ b/MotorPlant/MotorPlantContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/MotorPlant/MotorPlantContracts/BindingModels/MessageInfoBindingModel.cs b/MotorPlant/MotorPlantContracts/BindingModels/MessageInfoBindingModel.cs index a940c2a..c9a7897 100644 --- a/MotorPlant/MotorPlantContracts/BindingModels/MessageInfoBindingModel.cs +++ b/MotorPlant/MotorPlantContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,6 @@ namespace MotorPlantContracts.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/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IBackUpLogic.cs b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..1101056 --- /dev/null +++ b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using MotorPlantContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/MotorPlant/MotorPlantContracts/DI/DependencyManager.cs b/MotorPlant/MotorPlantContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..3ee20ed --- /dev/null +++ b/MotorPlant/MotorPlantContracts/DI/DependencyManager.cs @@ -0,0 +1,58 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.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/MotorPlant/MotorPlantContracts/DI/IDependencyContainer.cs b/MotorPlant/MotorPlantContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..1021b53 --- /dev/null +++ b/MotorPlant/MotorPlantContracts/DI/IDependencyContainer.cs @@ -0,0 +1,37 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.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/MotorPlant/MotorPlantContracts/DI/IImplementationExtension.cs b/MotorPlant/MotorPlantContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..24e7a7b --- /dev/null +++ b/MotorPlant/MotorPlantContracts/DI/IImplementationExtension.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + /// + /// Регистрация сервисов + /// + public void RegisterServices(); + } +} diff --git a/MotorPlant/MotorPlantContracts/DI/ServiceDependencyContainer.cs b/MotorPlant/MotorPlantContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..8a13157 --- /dev/null +++ b/MotorPlant/MotorPlantContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,56 @@ +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 MotorPlantContracts.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/MotorPlant/MotorPlantContracts/DI/ServiceProviderLoader.cs b/MotorPlant/MotorPlantContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..c045c9f --- /dev/null +++ b/MotorPlant/MotorPlantContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.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/MotorPlant/MotorPlantContracts/StoragesContracts/IBackUpInfo.cs b/MotorPlant/MotorPlantContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..1911d22 --- /dev/null +++ b/MotorPlant/MotorPlantContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/MotorPlant/MotorPlantContracts/ViewModels/ClientViewModel.cs b/MotorPlant/MotorPlantContracts/ViewModels/ClientViewModel.cs index 23522b8..256d063 100644 --- a/MotorPlant/MotorPlantContracts/ViewModels/ClientViewModel.cs +++ b/MotorPlant/MotorPlantContracts/ViewModels/ClientViewModel.cs @@ -1,16 +1,18 @@ using MotorPlantDataModels.Models; using System.ComponentModel; +using MotorPlantContracts.Attributes; namespace MotorPlantContracts.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/MotorPlant/MotorPlantContracts/ViewModels/ComponentViewModel.cs b/MotorPlant/MotorPlantContracts/ViewModels/ComponentViewModel.cs index acac773..06d4e46 100644 --- a/MotorPlant/MotorPlantContracts/ViewModels/ComponentViewModel.cs +++ b/MotorPlant/MotorPlantContracts/ViewModels/ComponentViewModel.cs @@ -1,14 +1,16 @@ using MotorPlantDataModels.Models; using System.ComponentModel; +using MotorPlantContracts.Attributes; namespace MotorPlantContracts.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/MotorPlant/MotorPlantContracts/ViewModels/EngineViewModel.cs b/MotorPlant/MotorPlantContracts/ViewModels/EngineViewModel.cs index 35c6a94..10c1e01 100644 --- a/MotorPlant/MotorPlantContracts/ViewModels/EngineViewModel.cs +++ b/MotorPlant/MotorPlantContracts/ViewModels/EngineViewModel.cs @@ -1,15 +1,18 @@ using MotorPlantDataModels.Models; using System.ComponentModel; +using MotorPlantContracts.Attributes; namespace MotorPlantContracts.ViewModels { public class EngineViewModel : IEngineModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("Название изделия")] + [Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string EngineName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column(title: "Цена", width: 70)] public double Price { get; set; } + [Column(visible: false)] public Dictionary EngineComponents { get; diff --git a/MotorPlant/MotorPlantContracts/ViewModels/ImplementerViewModel.cs b/MotorPlant/MotorPlantContracts/ViewModels/ImplementerViewModel.cs index ea49efc..4774970 100644 --- a/MotorPlant/MotorPlantContracts/ViewModels/ImplementerViewModel.cs +++ b/MotorPlant/MotorPlantContracts/ViewModels/ImplementerViewModel.cs @@ -5,19 +5,21 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using MotorPlantContracts.Attributes; namespace MotorPlantContracts.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: 60)] public int WorkExperience { get; set; } = 0; - [DisplayName("Квалификация")] + [Column(title: "Квалификация", width: 60)] public int Qualification { get; set; } = 0; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 100)] public string Password { get; set; } = string.Empty; } } diff --git a/MotorPlant/MotorPlantContracts/ViewModels/MessageInfoViewModel.cs b/MotorPlant/MotorPlantContracts/ViewModels/MessageInfoViewModel.cs index 8d81661..a66a392 100644 --- a/MotorPlant/MotorPlantContracts/ViewModels/MessageInfoViewModel.cs +++ b/MotorPlant/MotorPlantContracts/ViewModels/MessageInfoViewModel.cs @@ -5,20 +5,25 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using MotorPlantContracts.Attributes; namespace MotorPlantContracts.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: 120)] 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/MotorPlant/MotorPlantContracts/ViewModels/OrderViewModel.cs b/MotorPlant/MotorPlantContracts/ViewModels/OrderViewModel.cs index 0ff8575..e0988e8 100644 --- a/MotorPlant/MotorPlantContracts/ViewModels/OrderViewModel.cs +++ b/MotorPlant/MotorPlantContracts/ViewModels/OrderViewModel.cs @@ -1,31 +1,35 @@ using MotorPlantDataModels.Enums; using MotorPlantDataModels.Models; using System.ComponentModel; +using MotorPlantContracts.Attributes; namespace MotorPlantContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [Column(title: "Номер", width: 90)] public int Id { get; set; } + [Column(visible: false)] public int EngineId { get; set; } + [Column(visible: false)] public int ClientId { get; set; } + [Column(visible: false)] public int? ImplementerId { get; set; } = null; - [DisplayName("Клиент")] + [Column(title: "Клиент", width: 190)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Двигатель")] + [Column(title: "Двигатель", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string EngineName { get; set; } = string.Empty; - [DisplayName("Исполнитель")] + [Column(title: "Исполнитель", width: 150)] public string ImplementerFIO { 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; } } diff --git a/MotorPlant/MotorPlantDataModels/IImplementerModel.cs b/MotorPlant/MotorPlantDataModels/IImplementerModel.cs index 6e6064c..6963379 100644 --- a/MotorPlant/MotorPlantDataModels/IImplementerModel.cs +++ b/MotorPlant/MotorPlantDataModels/IImplementerModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace MotorPlantDataModels { - public interface IImplementerModel + public interface IImplementerModel : IId { string ImplementerFIO { get; } string Password { get; } diff --git a/MotorPlant/MotorPlantDataModels/IMessageInfoModel.cs b/MotorPlant/MotorPlantDataModels/IMessageInfoModel.cs index 464672c..84a5a77 100644 --- a/MotorPlant/MotorPlantDataModels/IMessageInfoModel.cs +++ b/MotorPlant/MotorPlantDataModels/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace MotorPlantDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; } diff --git a/MotorPlant/MotorPlantDatabaseImplement/BackUpInfo.cs b/MotorPlant/MotorPlantDatabaseImplement/BackUpInfo.cs new file mode 100644 index 0000000..424b9e9 --- /dev/null +++ b/MotorPlant/MotorPlantDatabaseImplement/BackUpInfo.cs @@ -0,0 +1,31 @@ +using MotorPlantContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantDatabaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new MotorPlantDataBase(); + 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/MotorPlant/MotorPlantDatabaseImplement/Client.cs b/MotorPlant/MotorPlantDatabaseImplement/Client.cs index 715dec8..5af4118 100644 --- a/MotorPlant/MotorPlantDatabaseImplement/Client.cs +++ b/MotorPlant/MotorPlantDatabaseImplement/Client.cs @@ -6,20 +6,26 @@ 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 MotorPlantDatabaseImplement.Models { - public class Client : IClientModel - { - public int Id { get; private set; } - [Required] - public string ClientFIO { get; set; } = string.Empty; - [Required] - public string Email { get; set; } = string.Empty; - [Required] - public string Password { get; set; } = string.Empty; + [DataContract] + public class Client : IClientModel + { + [DataMember] + public int Id { get; private set; } + [DataMember] + [Required] + public string ClientFIO { get; set; } = string.Empty; + [DataMember] + [Required] + public string Email { get; set; } = string.Empty; + [DataMember] + [Required] + public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); public static Client? Create(ClientBindingModel model) diff --git a/MotorPlant/MotorPlantDatabaseImplement/Component.cs b/MotorPlant/MotorPlantDatabaseImplement/Component.cs index 2382ad7..461284a 100644 --- a/MotorPlant/MotorPlantDatabaseImplement/Component.cs +++ b/MotorPlant/MotorPlantDatabaseImplement/Component.cs @@ -3,14 +3,19 @@ using MotorPlantContracts.ViewModels; using MotorPlantDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace MotorPlantDatabaseImplement.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")] diff --git a/MotorPlant/MotorPlantDatabaseImplement/Engine.cs b/MotorPlant/MotorPlantDatabaseImplement/Engine.cs index 8a51aae..9a7b9f7 100644 --- a/MotorPlant/MotorPlantDatabaseImplement/Engine.cs +++ b/MotorPlant/MotorPlantDatabaseImplement/Engine.cs @@ -3,18 +3,23 @@ using MotorPlantContracts.ViewModels; using MotorPlantDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace MotorPlantDatabaseImplement.Models { + [DataContract] public class Engine : IEngineModel { + [DataMember] public int Id { get; set; } + [DataMember] [Required] public string EngineName { get; set; } = string.Empty; + [DataMember] [Required] public double Price { get; set; } - private Dictionary? _EngineComponents = - null; + private Dictionary? _EngineComponents = null; + [DataMember] [NotMapped] public Dictionary EngineComponents { diff --git a/MotorPlant/MotorPlantDatabaseImplement/ImplementationExtension.cs b/MotorPlant/MotorPlantDatabaseImplement/ImplementationExtension.cs new file mode 100644 index 0000000..2e711fe --- /dev/null +++ b/MotorPlant/MotorPlantDatabaseImplement/ImplementationExtension.cs @@ -0,0 +1,21 @@ +using MotorPlantContracts.DI; +using MotorPlantContracts.StoragesContracts; +using MotorPlantDatabaseImplement.Implements; + +namespace MotorPlantDatabaseImplement +{ + 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/MotorPlant/MotorPlantDatabaseImplement/Implementer.cs b/MotorPlant/MotorPlantDatabaseImplement/Implementer.cs index cac72c1..fac030c 100644 --- a/MotorPlant/MotorPlantDatabaseImplement/Implementer.cs +++ b/MotorPlant/MotorPlantDatabaseImplement/Implementer.cs @@ -8,18 +8,25 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace MotorPlantDatabaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] [Required] public string Password { get; set; } = string.Empty; + [DataMember] [Required] public int Qualification { get; set; } = 0; + [DataMember] [Required] public int WorkExperience { get; set; } = 0; [ForeignKey("ImplementerId")] diff --git a/MotorPlant/MotorPlantDatabaseImplement/MessageInfo.cs b/MotorPlant/MotorPlantDatabaseImplement/MessageInfo.cs index 0a9bc4b..ae2e364 100644 --- a/MotorPlant/MotorPlantDatabaseImplement/MessageInfo.cs +++ b/MotorPlant/MotorPlantDatabaseImplement/MessageInfo.cs @@ -4,7 +4,9 @@ using MotorPlantDataModels.Models; 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; @@ -12,12 +14,25 @@ namespace MotorPlantDatabaseImplement.Models { public class MessageInfo : IMessageInfoModel { + [NotMapped] + public int Id { get; private set; } + [DataMember] [Key] + [DatabaseGenerated(DatabaseGeneratedOption.None)] public string MessageId { get; private set; } = string.Empty; + [DataMember] public int? ClientId { get; private set; } + [DataMember] + [Required] public string SenderName { get; private set; } = string.Empty; + [DataMember] + [Required] public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + [Required] public string Subject { get; private set; } = string.Empty; + [DataMember] + [Required] public string Body { get; private set; } = string.Empty; public Client? Client { get; private set; } public static MessageInfo? Create(MotorPlantDataBase context, MessageInfoBindingModel model) diff --git a/MotorPlant/MotorPlantDatabaseImplement/MotorPlantDatabaseImplement.csproj b/MotorPlant/MotorPlantDatabaseImplement/MotorPlantDatabaseImplement.csproj index 9416c52..c8f460d 100644 --- a/MotorPlant/MotorPlantDatabaseImplement/MotorPlantDatabaseImplement.csproj +++ b/MotorPlant/MotorPlantDatabaseImplement/MotorPlantDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/MotorPlant/MotorPlantDatabaseImplement/Order.cs b/MotorPlant/MotorPlantDatabaseImplement/Order.cs index d6416ea..93c61eb 100644 --- a/MotorPlant/MotorPlantDatabaseImplement/Order.cs +++ b/MotorPlant/MotorPlantDatabaseImplement/Order.cs @@ -3,27 +3,38 @@ using MotorPlantContracts.ViewModels; using MotorPlantDataModels.Enums; using MotorPlantDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace MotorPlantDatabaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] [Required] public int Count { get; private set; } + [DataMember] [Required] public double Sum { get; private set; } + [DataMember] [Required] public OrderStatus Status { get; private set; } + [DataMember] [Required] public DateTime DateCreate { get; private set; } + [DataMember] public DateTime? DateImplement { get; private set; } + [DataMember] [Required] public int EngineId { get; private set; } public virtual Engine Engine { get; private set; } + [DataMember] [Required] public int ClientId { get; private set; } public virtual Client Client { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } = null; public virtual Implementer? Implementer { get; private set; } public static Order? Create(MotorPlantDataBase context, OrderBindingModel model) diff --git a/MotorPlant/MotorPlantFileImplement/BackUpInfo.cs b/MotorPlant/MotorPlantFileImplement/BackUpInfo.cs new file mode 100644 index 0000000..53ecfd7 --- /dev/null +++ b/MotorPlant/MotorPlantFileImplement/BackUpInfo.cs @@ -0,0 +1,41 @@ +using MotorPlantContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantFileImplement.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/MotorPlant/MotorPlantFileImplement/Client.cs b/MotorPlant/MotorPlantFileImplement/Client.cs index 660f75d..bd61cb6 100644 --- a/MotorPlant/MotorPlantFileImplement/Client.cs +++ b/MotorPlant/MotorPlantFileImplement/Client.cs @@ -9,14 +9,20 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; +using System.Runtime.Serialization; namespace MotorPlantFileImplement.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; set; } = string.Empty; + [DataMember] public string Password { get; set; } = string.Empty; public static Client? Create(ClientBindingModel model) { diff --git a/MotorPlant/MotorPlantFileImplement/Component.cs b/MotorPlant/MotorPlantFileImplement/Component.cs index 5f29da5..0a39581 100644 --- a/MotorPlant/MotorPlantFileImplement/Component.cs +++ b/MotorPlant/MotorPlantFileImplement/Component.cs @@ -1,14 +1,19 @@ using MotorPlantContracts.BindingModels; using MotorPlantContracts.ViewModels; using MotorPlantDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace MotorPlantFileImplement.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/MotorPlant/MotorPlantFileImplement/Engine.cs b/MotorPlant/MotorPlantFileImplement/Engine.cs index 5f283a5..9088e6b 100644 --- a/MotorPlant/MotorPlantFileImplement/Engine.cs +++ b/MotorPlant/MotorPlantFileImplement/Engine.cs @@ -1,14 +1,19 @@ using MotorPlantContracts.BindingModels; using MotorPlantContracts.ViewModels; using MotorPlantDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace MotorPlantFileImplement.Models { + [DataContract] public class Engine : IEngineModel { + [DataMember] public int Id { get; private set; } + [DataMember] public string EngineName { get; private set; } = string.Empty; + [DataMember] public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); private Dictionary? _EngineComponents = null; diff --git a/MotorPlant/MotorPlantFileImplement/ImplementationExtension.cs b/MotorPlant/MotorPlantFileImplement/ImplementationExtension.cs new file mode 100644 index 0000000..a028733 --- /dev/null +++ b/MotorPlant/MotorPlantFileImplement/ImplementationExtension.cs @@ -0,0 +1,21 @@ +using MotorPlantContracts.DI; +using MotorPlantContracts.StoragesContracts; +using MotorPlantFileImplement.Implements; + +namespace MotorPlantFileImplement +{ + 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/MotorPlant/MotorPlantFileImplement/Implementer.cs b/MotorPlant/MotorPlantFileImplement/Implementer.cs index 86567e0..990694c 100644 --- a/MotorPlant/MotorPlantFileImplement/Implementer.cs +++ b/MotorPlant/MotorPlantFileImplement/Implementer.cs @@ -4,18 +4,25 @@ using MotorPlantDataModels; 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 MotorPlantFileImplement.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; set; } = string.Empty; + [DataMember] public int Qualification { get; set; } = 0; + [DataMember] public int WorkExperience { get; set; } = 0; public static Implementer? Create(ImplementerBindingModel model) { diff --git a/MotorPlant/MotorPlantFileImplement/MessageInfo.cs b/MotorPlant/MotorPlantFileImplement/MessageInfo.cs index fcb68a9..6bfd6bf 100644 --- a/MotorPlant/MotorPlantFileImplement/MessageInfo.cs +++ b/MotorPlant/MotorPlantFileImplement/MessageInfo.cs @@ -4,19 +4,29 @@ using MotorPlantDataModels.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 MotorPlantFileImplement.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/MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj b/MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj index 4da00b3..e955e36 100644 --- a/MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj +++ b/MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/MotorPlant/MotorPlantFileImplement/Order.cs b/MotorPlant/MotorPlantFileImplement/Order.cs index 961251f..23b1a3f 100644 --- a/MotorPlant/MotorPlantFileImplement/Order.cs +++ b/MotorPlant/MotorPlantFileImplement/Order.cs @@ -2,20 +2,31 @@ using MotorPlantContracts.ViewModels; using MotorPlantDataModels.Enums; using MotorPlantDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace MotorPlantFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int EngineId { get; private set; } + [DataMember] public int ClientId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } = null; + [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; } + [DataMember] public int Id { get; private set; } public static Order? Create(OrderBindingModel? model) { diff --git a/MotorPlant/MotorPlantListImplement/BackUpInfo.cs b/MotorPlant/MotorPlantListImplement/BackUpInfo.cs new file mode 100644 index 0000000..3a224b1 --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/BackUpInfo.cs @@ -0,0 +1,21 @@ +using MotorPlantContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantListImplement.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/MotorPlant/MotorPlantListImplement/ImplementationExtension.cs b/MotorPlant/MotorPlantListImplement/ImplementationExtension.cs new file mode 100644 index 0000000..670794e --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/ImplementationExtension.cs @@ -0,0 +1,21 @@ +using MotorPlantContracts.DI; +using MotorPlantContracts.StoragesContracts; +using MotorPlantListImplement.Implements; + +namespace MotorPlantListImplement +{ + 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/MotorPlant/MotorPlantListImplement/MessageInfo.cs b/MotorPlant/MotorPlantListImplement/MessageInfo.cs index 6e96b58..08d4e75 100644 --- a/MotorPlant/MotorPlantListImplement/MessageInfo.cs +++ b/MotorPlant/MotorPlantListImplement/MessageInfo.cs @@ -17,6 +17,7 @@ namespace MotorPlantListImplement.Models public DateTime DateDelivery { get; private set; } = DateTime.Now; public string Subject { get; private set; } = string.Empty; 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/MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj b/MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj index 4da00b3..e955e36 100644 --- a/MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj +++ b/MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/MotorPlant/MotorPlantView/DataGridViewExtension.cs b/MotorPlant/MotorPlantView/DataGridViewExtension.cs new file mode 100644 index 0000000..20a88f3 --- /dev/null +++ b/MotorPlant/MotorPlantView/DataGridViewExtension.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorPlantContracts.Attributes; + +namespace MotorPlantView.Forms +{ + 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/MotorPlant/MotorPlantView/FormClients.cs b/MotorPlant/MotorPlantView/FormClients.cs index 881caaa..83f44ce 100644 --- a/MotorPlant/MotorPlantView/FormClients.cs +++ b/MotorPlant/MotorPlantView/FormClients.cs @@ -27,19 +27,8 @@ namespace MotorPlantView.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ClientFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Email"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Password"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка клиентов"); + DataGridView.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) { diff --git a/MotorPlant/MotorPlantView/FormComponents.cs b/MotorPlant/MotorPlantView/FormComponents.cs index 6c22176..2f7469b 100644 --- a/MotorPlant/MotorPlantView/FormComponents.cs +++ b/MotorPlant/MotorPlantView/FormComponents.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using MotorPlantContracts.BindingModels; using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.DI; namespace MotorPlantView.Forms { @@ -42,13 +43,10 @@ namespace MotorPlantView.Forms 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(); } } @@ -56,14 +54,12 @@ namespace MotorPlantView.Forms { 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/MotorPlant/MotorPlantView/FormEngine.cs b/MotorPlant/MotorPlantView/FormEngine.cs index f58811c..291b40e 100644 --- a/MotorPlant/MotorPlantView/FormEngine.cs +++ b/MotorPlant/MotorPlantView/FormEngine.cs @@ -3,6 +3,8 @@ using MotorPlantDataModels.Models; using MotorPlantContracts.BusinessLogicsContracts; using MotorPlantContracts.SearchModels; using MotorPlantContracts.BindingModels; +using MotorPlantContracts.DI; +using MotorPlantDatabaseImplement.Models; namespace MotorPlantView.Forms { @@ -11,14 +13,14 @@ namespace MotorPlantView.Forms private readonly ILogger _logger; private readonly IEngineLogic _logic; private int? _id; - private Dictionary _productComponents; + private Dictionary _engineComponents; public int Id { set { _id = value; } } public FormEngine(ILogger logger, IEngineLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; - _productComponents = new Dictionary(); + _engineComponents = new Dictionary(); } private void FormEngine_Load(object sender, EventArgs e) { @@ -35,7 +37,7 @@ namespace MotorPlantView.Forms { textBoxName.Text = view.EngineName; textBoxPrice.Text = view.Price.ToString(); - _productComponents = view.EngineComponents ?? new Dictionary(); + _engineComponents = view.EngineComponents ?? new Dictionary(); LoadData(); } } @@ -50,10 +52,10 @@ namespace MotorPlantView.Forms _logger.LogInformation("Загрузка компонент изделия"); try { - if (_productComponents != null) + if (_engineComponents != null) { dataGridView.Rows.Clear(); - foreach (var pc in _productComponents) + foreach (var pc in _engineComponents) { dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); } @@ -67,51 +69,44 @@ namespace MotorPlantView.Forms } private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormEngineComponent)); - if (service is FormEngineComponent form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { + return; + } + _logger.LogInformation("Добавление нового ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + if (_engineComponents.ContainsKey(form.Id)) + { + _engineComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _engineComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _engineComponents[id].Item2; if (form.ShowDialog() == DialogResult.OK) { if (form.ComponentModel == null) { return; } - _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); - if (_productComponents.ContainsKey(form.Id)) - { - _productComponents[form.Id] = (form.ComponentModel, form.Count); - } - else - { - _productComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } + _logger.LogInformation("Изменение ингридиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); + _engineComponents[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(FormEngineComponent)); - if (service is FormEngineComponent form) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _productComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - _productComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); - } - } - } - } private void buttonDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -121,7 +116,7 @@ namespace MotorPlantView.Forms try { _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); - _productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + _engineComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); } catch (Exception ex) { @@ -147,7 +142,7 @@ namespace MotorPlantView.Forms MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (_productComponents == null || _productComponents.Count == 0) + if (_engineComponents == null || _engineComponents.Count == 0) { MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -160,7 +155,7 @@ namespace MotorPlantView.Forms Id = _id ?? 0, EngineName = textBoxName.Text, Price = Convert.ToDouble(textBoxPrice.Text), - EngineComponents = _productComponents + EngineComponents = _engineComponents }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) @@ -186,7 +181,7 @@ namespace MotorPlantView.Forms private double CalcPrice() { double price = 0; - foreach (var elem in _productComponents) + foreach (var elem in _engineComponents) { price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); } diff --git a/MotorPlant/MotorPlantView/FormEngines.cs b/MotorPlant/MotorPlantView/FormEngines.cs index 7e129dc..838152e 100644 --- a/MotorPlant/MotorPlantView/FormEngines.cs +++ b/MotorPlant/MotorPlantView/FormEngines.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using MotorPlantContracts.BindingModels; using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.DI; namespace MotorPlantView.Forms { @@ -24,14 +25,7 @@ namespace MotorPlantView.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["EngineComponents"].Visible = false; - dataGridView.Columns["EngineName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -42,13 +36,10 @@ namespace MotorPlantView.Forms private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormEngine)); - if (service is FormEngine form) + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -56,14 +47,11 @@ namespace MotorPlantView.Forms { if (dataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormEngine)); - if (service is FormEngine 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/MotorPlant/MotorPlantView/FormMain.Designer.cs b/MotorPlant/MotorPlantView/FormMain.Designer.cs index 2309e01..f525ec4 100644 --- a/MotorPlant/MotorPlantView/FormMain.Designer.cs +++ b/MotorPlant/MotorPlantView/FormMain.Designer.cs @@ -45,6 +45,7 @@ buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); + создатьБекапToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); toolStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); @@ -53,7 +54,7 @@ // toolStrip1 // toolStrip1.ImageScalingSize = new Size(20, 20); - toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, ReportsToolStripMenuItem, запускРаботToolStripMenuItem, почтаToolStripMenuItem }); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, ReportsToolStripMenuItem, запускРаботToolStripMenuItem, почтаToolStripMenuItem, создатьБекапToolStripMenuItem }); toolStrip1.Location = new Point(0, 0); toolStrip1.Name = "toolStrip1"; toolStrip1.Size = new Size(969, 25); @@ -72,14 +73,14 @@ // КомпонентыToolStripMenuItem // КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - КомпонентыToolStripMenuItem.Size = new Size(180, 22); + КомпонентыToolStripMenuItem.Size = new Size(174, 22); КомпонентыToolStripMenuItem.Text = "Компоненты"; КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; // // ДвигателиToolStripMenuItem // ДвигателиToolStripMenuItem.Name = "ДвигателиToolStripMenuItem"; - ДвигателиToolStripMenuItem.Size = new Size(180, 22); + ДвигателиToolStripMenuItem.Size = new Size(174, 22); ДвигателиToolStripMenuItem.Text = "Двигатели"; ДвигателиToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; // @@ -183,14 +184,14 @@ // клиентыToolStripMenuItem // клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(180, 22); + клиентыToolStripMenuItem.Size = new Size(174, 22); клиентыToolStripMenuItem.Text = "Клиенты"; клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; // // исполнителиToolStripMenuItem // исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(180, 22); + исполнителиToolStripMenuItem.Size = new Size(174, 22); исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; // @@ -201,6 +202,13 @@ почтаToolStripMenuItem.Text = "Почта"; почтаToolStripMenuItem.Click += почтаToolStripMenuItem_Click; // + // создатьБекапToolStripMenuItem + // + создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem"; + создатьБекапToolStripMenuItem.Size = new Size(97, 25); + создатьБекапToolStripMenuItem.Text = "Создать Бекап"; + создатьБекапToolStripMenuItem.Click += createBackUpToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); @@ -243,5 +251,6 @@ private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem почтаToolStripMenuItem; + private ToolStripMenuItem создатьБекапToolStripMenuItem; } } \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormMain.cs b/MotorPlant/MotorPlantView/FormMain.cs index 3eb4663..3834ad0 100644 --- a/MotorPlant/MotorPlantView/FormMain.cs +++ b/MotorPlant/MotorPlantView/FormMain.cs @@ -2,6 +2,8 @@ using MotorPlantContracts.BindingModels; using MotorPlantContracts.BusinessLogicsContracts; using MotorPlantBusinessLogic; +using MotorPlantContracts.DI; +using System.Windows.Forms; namespace MotorPlantView.Forms { @@ -11,13 +13,16 @@ namespace MotorPlantView.Forms private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + private readonly IBackUpLogic _backUpLogic; + + 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) { @@ -25,52 +30,32 @@ namespace MotorPlantView.Forms } private void LoadData() { - _logger.LogInformation("Загрузка заказов"); try { - var list = _orderLogic.ReadList(null); - - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["EngineId"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["EngineName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - + dataGridView.FillAndConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } 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(FormEngines)); - - if (service is FormEngines 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) { @@ -154,61 +139,62 @@ namespace MotorPlantView.Forms using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; if (dialog.ShowDialog() == DialogResult.OK) { - _reportLogic.SaveEnginesToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, - MessageBoxIcon.Information); + _reportLogic.SaveEnginesToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void компонентыПоДвигателямToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportEngineComponents)); - if (service is FormReportEngineComponents 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(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) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic -)) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); + _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(ImplementersForm)); - if (service is ImplementersForm form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void почтаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = -Program.ServiceProvider?.GetService(typeof(FormViewMail)); - if (service is FormViewMail form) + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + private void createBackUpToolStripMenuItem_Click(object sender, EventArgs e) + { + try { - form.ShowDialog(); + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка создания бэкапа", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } diff --git a/MotorPlant/MotorPlantView/FormViewMail.Designer.cs b/MotorPlant/MotorPlantView/FormViewMail.Designer.cs index 675c7cd..9bbb217 100644 --- a/MotorPlant/MotorPlantView/FormViewMail.Designer.cs +++ b/MotorPlant/MotorPlantView/FormViewMail.Designer.cs @@ -42,14 +42,14 @@ dataGridView.Size = new Size(776, 426); dataGridView.TabIndex = 0; // - // FormViewMail + // ViewMailForm // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); Controls.Add(dataGridView); - Name = "FormViewMail"; - Text = "Письма"; + Name = "ViewMailForm"; + Text = "ViewMailForm"; Load += ViewMailForm_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); diff --git a/MotorPlant/MotorPlantView/FormViewMail.cs b/MotorPlant/MotorPlantView/FormViewMail.cs index 2140a57..3361f4e 100644 --- a/MotorPlant/MotorPlantView/FormViewMail.cs +++ b/MotorPlant/MotorPlantView/FormViewMail.cs @@ -26,14 +26,7 @@ namespace MotorPlantView.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["MessageId"].Visible = false; - dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + dataGridView.FillAndConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка списка писем"); } catch (Exception ex) diff --git a/MotorPlant/MotorPlantView/ImplementersForm.cs b/MotorPlant/MotorPlantView/ImplementersForm.cs index 649c03a..6708e58 100644 --- a/MotorPlant/MotorPlantView/ImplementersForm.cs +++ b/MotorPlant/MotorPlantView/ImplementersForm.cs @@ -31,21 +31,8 @@ namespace MotorPlantView.Forms { try { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView1.DataSource = list; - dataGridView1.Columns["Id"].Visible = false; - dataGridView1.Columns["ImplementerFIO"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["Password"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["Qualification"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - dataGridView1.Columns["WorkExperience"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка компонентов"); + dataGridView1.FillAndConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) { diff --git a/MotorPlant/MotorPlantView/Program.cs b/MotorPlant/MotorPlantView/Program.cs index 048fb02..e93665d 100644 --- a/MotorPlant/MotorPlantView/Program.cs +++ b/MotorPlant/MotorPlantView/Program.cs @@ -11,6 +11,7 @@ using MotorPlantBusinessLogic; using MotorPlantBusinessLogic.BusinessLogic; using MotorPlantBusinessLogic.MailWorker; using MotorPlantContracts.BindingModels; +using MotorPlantContracts.DI; namespace MotorPlantView.Forms { @@ -27,84 +28,66 @@ namespace MotorPlantView.Forms // 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(); + 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(); - 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(); - 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.AddSingleton(); - 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