diff --git a/SoftwareInstallation/SofrwareInstallationContracts/Attributes/ColumnAttribute.cs b/SoftwareInstallation/SofrwareInstallationContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..ce3f82c --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,22 @@ +using System; + +namespace SofrwareInstallationContracts.Attributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class ColumnAttribute : Attribute + { + 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; + } + 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; } + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/Attributes/GridViewAutoSize.cs b/SoftwareInstallation/SofrwareInstallationContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..5b151b5 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,14 @@ +namespace SofrwareInstallationContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/BackUpSaveBinidngModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/BackUpSaveBinidngModel.cs new file mode 100644 index 0000000..9eadf79 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/BackUpSaveBinidngModel.cs @@ -0,0 +1,7 @@ +namespace SofrwareInstallationContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs index e4259c4..6e039e4 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,6 @@ namespace SofrwareInstallationContracts.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/SoftwareInstallation/SofrwareInstallationContracts/BusinessLogicsContracts/IBackUpLogic.cs b/SoftwareInstallation/SofrwareInstallationContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..cd4d69e --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,9 @@ +using SofrwareInstallationContracts.BindingModels; + +namespace SofrwareInstallationContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/DI/DependencyManager.cs b/SoftwareInstallation/SofrwareInstallationContracts/DI/DependencyManager.cs new file mode 100644 index 0000000..b81576e --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/DI/DependencyManager.cs @@ -0,0 +1,38 @@ +using Microsoft.Extensions.Logging; + +namespace SofrwareInstallationContracts.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/SoftwareInstallation/SofrwareInstallationContracts/DI/IDependencyContainer.cs b/SoftwareInstallation/SofrwareInstallationContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..505ebf2 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/DI/IDependencyContainer.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.Logging; + +namespace SofrwareInstallationContracts.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/SoftwareInstallation/SofrwareInstallationContracts/DI/IImplementationExtension.cs b/SoftwareInstallation/SofrwareInstallationContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..eaf62cf --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/DI/IImplementationExtension.cs @@ -0,0 +1,8 @@ +namespace SofrwareInstallationContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + public void RegisterServices(); + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/DI/ServiceDependencyContainer.cs b/SoftwareInstallation/SofrwareInstallationContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..2f169d0 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,59 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace SofrwareInstallationContracts.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/SoftwareInstallation/SofrwareInstallationContracts/DI/ServiceProviderLoader.cs b/SoftwareInstallation/SofrwareInstallationContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..15156bb --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,52 @@ +using System.Reflection; + +namespace SofrwareInstallationContracts.DI +{ + public class ServiceProviderLoader + { + public static IImplementationExtension? GetImplementationExtensions() + { + IImplementationExtension? source = null; + var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t)) + { + if (source == null) + { + source = (IImplementationExtension)Activator.CreateInstance(t)!; + } + else + { + var newSource = (IImplementationExtension)Activator.CreateInstance(t)!; + + if (newSource.Priority > source.Priority) + { + source = newSource; + } + } + } + } + } + + return source; + } + + private static string TryGetImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + + while (directory != null && !directory.GetDirectories("ImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions")) + { + directory = directory.Parent; + } + + return $"{directory?.FullName}\\ImplementationExtensions"; + } + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/DI/UnityDependencyContainer .cs b/SoftwareInstallation/SofrwareInstallationContracts/DI/UnityDependencyContainer .cs new file mode 100644 index 0000000..ae8e591 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/DI/UnityDependencyContainer .cs @@ -0,0 +1,40 @@ +using Microsoft.Extensions.Logging; +using System.ComponentModel; +using Unity; +using Unity.Lifetime; +using Unity.Microsoft.Logging; + +namespace SofrwareInstallationContracts.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 T : class + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + + } + + public T Resolve() + { + return _container.Resolve(); + } + + void IDependencyContainer.RegisterType(bool isSingle) + { + _container.RegisterType(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient); + } + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/SofrwareInstallationContracts.csproj b/SoftwareInstallation/SofrwareInstallationContracts/SofrwareInstallationContracts.csproj index 418382e..29e9d7c 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/SofrwareInstallationContracts.csproj +++ b/SoftwareInstallation/SofrwareInstallationContracts/SofrwareInstallationContracts.csproj @@ -38,6 +38,8 @@ + + diff --git a/SoftwareInstallation/SofrwareInstallationContracts/StoragesContracts/IBackUpInfo.cs b/SoftwareInstallation/SofrwareInstallationContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..2c85067 --- /dev/null +++ b/SoftwareInstallation/SofrwareInstallationContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,8 @@ +namespace SofrwareInstallationContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ClientViewModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ClientViewModel.cs index ea7c455..95617fe 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ClientViewModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ClientViewModel.cs @@ -1,16 +1,18 @@ using SoftwareInstallationDataModels.Models; using System.ComponentModel; +using SofrwareInstallationContracts.Attributes; namespace SofrwareInstallationContracts.ViewModels { public class ClientViewModel : IClientModel { - public int Id { get; set; } - [DisplayName("ФИО клиента")] + [Column(visible: false)] + public int Id { get; set; } + [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [Column("Логин (эл. почта)", width: 150)] public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column("Пароль", width: 150)] public string Password { get; set; } = string.Empty; } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ComponentViewModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ComponentViewModel.cs index ee989bc..fbb59b2 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ComponentViewModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ComponentViewModel.cs @@ -1,16 +1,18 @@ -using SoftwareInstallationDataModels.Models; +using SofrwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System.ComponentModel; namespace SofrwareInstallationContracts.ViewModels { public class ComponentViewModel : IComponentModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("Название компонента")] + [Column("Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 80)] public double Cost { get; set; } } } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ImplementerViewModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ImplementerViewModel.cs index 0c5edac..cba59f1 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ImplementerViewModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/ImplementerViewModel.cs @@ -1,22 +1,24 @@ -using SoftwareInstallationDataModels.Models; +using SofrwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System.ComponentModel; namespace SofrwareInstallationContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Пароль")] + [Column("Пароль", width: 150)] public string Password { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column("Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int WorkExperience { get; set; } - [DisplayName("Квалификация")] + [Column("Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Qualification { get; set; } } } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs index 464ecc4..1da8f98 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs @@ -1,24 +1,30 @@ -using SoftwareInstallationDataModels.Models; +using SofrwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System.ComponentModel; namespace SofrwareInstallationContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { - public string MessageId { get; set; } = string.Empty; + [Column(visible: false)] + public string MessageId { get; set; } = string.Empty; - public int? ClientId { get; set; } + [Column(visible: false)] + public int? ClientId { get; set; } - [DisplayName("Имя отправителя")] + [Column("Имя отправителя", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата отправления")] + [Column("Дата отправления", width: 100)] public DateTime DateDelivery { get; set; } - [DisplayName("Тема")] + [Column("Тема", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Содержание")] + [Column("Содержание", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; - } + [Column(visible: false)] + public int Id => throw new NotImplementedException(); + + } } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/OrderViewModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/OrderViewModel.cs index a05bc39..0defe28 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/OrderViewModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/OrderViewModel.cs @@ -1,4 +1,5 @@ -using SoftwareInstallationDataModels.Enums; +using SofrwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Enums; using SoftwareInstallationDataModels.Models; using System.ComponentModel; @@ -6,33 +7,38 @@ namespace SofrwareInstallationContracts.ViewModels { public class OrderViewModel : IOrderModel { - public int PackageId { get; set; } - public int ClientId { get; set; } + [Column(visible: false)] + public int PackageId { get; set; } + + [Column(visible: false)] + public int ClientId { get; set; } + + [Column(visible: false)] public int? ImplementerId { get; set; } - [DisplayName("Номер")] + [Column("Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column("ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Название изделия")] + [Column("Название изделия", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public string PackageName { get; set; } = string.Empty; - [DisplayName("Клиент")] + [Column("ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Количество")] + [Column("Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Count { get; set; } - [DisplayName("Сумма")] + [Column("Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public double Sum { get; set; } - [DisplayName("Статус")] + [Column("Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [Column("Дата создания", width: 100)] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [Column("Дата выполнения", width: 100)] public DateTime? DateImplement { get; set; } diff --git a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/PackageViewModel.cs b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/PackageViewModel.cs index 337bd6f..1390c38 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/PackageViewModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/PackageViewModel.cs @@ -1,18 +1,21 @@ -using SoftwareInstallationDataModels.Models; +using SofrwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System.ComponentModel; namespace SofrwareInstallationContracts.ViewModels { public class PackageViewModel : IPackageModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("Название изделия")] + [Column("Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string PackageName { get; set; } = string.Empty; - [DisplayName("Цена")] + [Column("Цена", width: 100)] public double Price { get; set; } + [Column(visible: false)] - public Dictionary PackageComponents { get; set; } = new(); + public Dictionary PackageComponents { get; set; } = new(); } } diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/BackUpLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..d3ce4f6 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/BackUpLogic.cs @@ -0,0 +1,113 @@ +using Microsoft.Extensions.Logging; +using SofrwareInstallationContracts.BindingModels; +using SofrwareInstallationContracts.BusinessLogicsContracts; +using SofrwareInstallationContracts.StoragesContracts; +using SoftwareInstallationDataModels; +using System.IO.Compression; +using System.Reflection; +using System.Runtime.Serialization.Json; + + +namespace SoftwareInstallationBusinessLogic.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/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj b/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj index e28b947..b98599e 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/SoftwareInstallationBusinessLogic.csproj @@ -8,6 +8,7 @@ + diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/DatabaseImplementationExtension.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/DatabaseImplementationExtension.cs new file mode 100644 index 0000000..45d2492 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/DatabaseImplementationExtension.cs @@ -0,0 +1,23 @@ +using SofrwareInstallationContracts.DI; +using SofrwareInstallationContracts.StoragesContracts; +using SoftwareInstallationDataBaseImplement.Implements; + +namespace SoftwareInstallationDataBaseImplement +{ + 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/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Implements/BackUpInfo.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..e1c7f02 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Implements/BackUpInfo.cs @@ -0,0 +1,29 @@ +using SofrwareInstallationContracts.StoragesContracts; + +namespace SoftwareInstallationDataBaseImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + using var context = new SoftwareInstallationDataBase(); + 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/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Client.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Client.cs index b3ebc88..7fb1fcd 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Client.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Client.cs @@ -3,18 +3,24 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } [Required] - public string ClientFIO { get; set; } = string.Empty; + [DataMember] + public string ClientFIO { get; set; } = string.Empty; [Required] - public string Email { get; set; } = string.Empty; + [DataMember] + public string Email { get; set; } = string.Empty; [Required] - public string Password { get; set; } = string.Empty; + [DataMember] + public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Component.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Component.cs index b33c9c0..4ffcb46 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Component.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Component.cs @@ -3,18 +3,23 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } [Required] - public string ComponentName { get; private set; } = string.Empty; + [DataMember] + public string ComponentName { get; private set; } = string.Empty; [Required] - public double Cost { get; set; } + [DataMember] + public double Cost { get; set; } [ForeignKey("ComponentId")] public virtual List PackageComponents { get; set; } = new(); diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Implementer.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Implementer.cs index fd6fdd6..17bb53b 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Implementer.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Implementer.cs @@ -3,24 +3,31 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { [Required] - public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; [Required] - public string Password { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; [Required] - public int WorkExperience { get; private set; } + [DataMember] + public int WorkExperience { get; private set; } [Required] - public int Qualification { get; private set; } - - public int Id { get; private set; } + [DataMember] + public int Qualification { get; private set; } + + [DataMember] + public int Id { get; private set; } [ForeignKey("ImplementerId")] public virtual List Orders { get; private set; } = new(); diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs index 2f1b063..b621322 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs @@ -2,22 +2,30 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { - public class Message : IMessageInfoModel + [DataContract] + public class Message : IMessageInfoModel { [Key] - public string MessageId { get; private set; } = string.Empty; - public int? ClientId { get; private set; } + [DataMember] + public string MessageId { get; private set; } = string.Empty; + [DataMember] + public int? ClientId { get; private set; } [Required] - public string SenderName { get; private set; } = string.Empty; + [DataMember] + public string SenderName { get; private set; } = string.Empty; [Required] - public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; [Required] - public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Subject { get; private set; } = string.Empty; [Required] - public string Body { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; public virtual Client Client { get; set; } @@ -47,5 +55,6 @@ namespace SoftwareInstallationDataBaseImplement.Models SenderName = SenderName, DateDelivery = DateDelivery, }; - } + public int Id => throw new NotImplementedException(); + } } diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Order.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Order.cs index 8651535..cfb54a2 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Order.cs @@ -3,33 +3,45 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Enums; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int Id { get; private set; } + [DataMember] + public int Id { get; private set; } - public int PackageId { get; private set; } + [DataMember] + public int PackageId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } [Required] - public int ClientId { get; set; } - public string PackageName { get; private set; } = string.Empty; + [DataMember] + public int ClientId { get; set; } + [DataMember] + public string PackageName { get; private set; } = string.Empty; [Required] - public int Count { get; private set; } + [DataMember] + public int Count { get; private set; } [Required] - public double Sum { get; private set; } + [DataMember] + public double Sum { get; private set; } [Required] - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [Required] - public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] + public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + [DataMember] + public DateTime? DateImplement { get; private set; } public virtual Package Package { get; set; } public Client Client { get; set; } diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Package.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Package.cs index a8cf74e..9ac9df7 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Package.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Package.cs @@ -3,23 +3,29 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { - public class Package : IPackageModel + [DataContract] + public class Package : IPackageModel { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } [Required] - public string PackageName { get; set; } = string.Empty; + [DataMember] + public string PackageName { get; set; } = string.Empty; [Required] - public double Price { get; set; } + [DataMember] + public double Price { get; set; } private Dictionary? _packageComponents = null; [NotMapped] - public Dictionary PackageComponents + [DataMember] + public Dictionary PackageComponents { get { diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBaseImplement.csproj b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBaseImplement.csproj index d1ba06b..49bf0db 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBaseImplement.csproj +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBaseImplement.csproj @@ -16,5 +16,8 @@ + + + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs index a27b3f7..2b7e330 100644 --- a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs +++ b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs @@ -1,7 +1,7 @@ namespace SoftwareInstallationDataModels.Models { - public interface IMessageInfoModel - { + public interface IMessageInfoModel : IId + { string MessageId { get; } int? ClientId { get; } string SenderName { get; } diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/FileImplementationExtension.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/FileImplementationExtension.cs new file mode 100644 index 0000000..bae4390 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/FileImplementationExtension.cs @@ -0,0 +1,22 @@ +using SofrwareInstallationContracts.DI; +using SofrwareInstallationContracts.StoragesContracts; +using SoftwareInstallationFileImplement.Implements; + +namespace SoftwareInstallationFileImplement +{ + 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/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/BackUpInfo.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..d24b7b2 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Implements/BackUpInfo.cs @@ -0,0 +1,32 @@ +using SofrwareInstallationContracts.StoragesContracts; + +namespace SoftwareInstallationFileImplement.Implements +{ + public class BackUpInfo : IBackUpInfo + { + public List? GetList() where T : class, new() + { + var source = DataFileSingleton.GetInstance(); + + 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/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Client.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Client.cs index d5af947..2f2eca8 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Client.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Client.cs @@ -1,16 +1,22 @@ using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { - public class Client : IClientModel + [DataContract] + public class Client : IClientModel { - public int Id { get; private set; } - public string ClientFIO { get; private set; } = string.Empty; - public string Email { get; set; } = string.Empty; - public string Password { get; set; } = string.Empty; + [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) { if (model == null) diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs index bf0a97a..d1af364 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs @@ -1,17 +1,20 @@ -using System.Xml.Linq; +using System.Runtime.Serialization; +using System.Xml.Linq; using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; namespace SoftwareInstallationFileImplement.Models { - public class Component : IComponentModel + [DataContract] + public class Component : IComponentModel { - public string ComponentName { get; private set; } = string.Empty; - - public double Cost { get; set; } - - public int Id { get; private set; } + [DataMember] + public string ComponentName { get; private set; } = string.Empty; + [DataMember] + public double Cost { get; set; } + [DataMember] + public int Id { get; private set; } public static Component? Create(ComponentBindingModel model) { diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs index 148a310..9984d03 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs @@ -1,21 +1,24 @@ using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { - public class Implementer : IImplementerModel + [DataContract] + public class Implementer : IImplementerModel { - public string ImplementerFIO { get; private set; } = string.Empty; - - public string Password { get; private set; } = string.Empty; - - public int WorkExperience { get; private set; } - - public int Qualification { get; private set; } - - public int Id { get; private set; } + [DataMember] + public string ImplementerFIO { get; private set; } = string.Empty; + [DataMember] + public string Password { get; private set; } = string.Empty; + [DataMember] + public int WorkExperience { get; private set; } + [DataMember] + public int Qualification { get; private set; } + [DataMember] + public int Id { get; private set; } public static Implementer? Create(XElement element) { diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs index cb19a04..2d2c1b8 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs @@ -1,23 +1,26 @@ using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { - public class Message : IMessageInfoModel + [DataContract] + public class Message : IMessageInfoModel { - public string MessageId { get; private set; } = string.Empty; - - public int? ClientId { get; private set; } - - public string SenderName { get; private set; } = string.Empty; - - public DateTime DateDelivery { get; private set; } = DateTime.Now; - - public string Subject { get; private set; } = string.Empty; - - public string Body { get; private set; } = string.Empty; + [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 Message? Create(MessageInfoBindingModel model) { @@ -71,5 +74,7 @@ namespace SoftwareInstallationFileImplement.Models new XAttribute("SenderName", SenderName), new XAttribute("DateDelivery", DateDelivery) ); - } + + public int Id => throw new NotImplementedException(); + } } diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs index a653c1e..c2e11f8 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs @@ -2,28 +2,34 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Enums; using SoftwareInstallationDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { - public class Order : IOrderModel + [DataContract] + public class Order : IOrderModel { - public int PackageId { get; private set; } + [DataMember] + public int PackageId { get; private set; } + [DataMember] public int? ImplementerId { get; set; } - + [DataMember] public string PackageName { get; private set; } = string.Empty; - public int ClientId { get; private set; } - public int Count { get; private set; } - - public double Sum { get; private set; } - - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - - public DateTime DateCreate { get; private set; } = DateTime.Now; - - public DateTime? DateImplement { get; private set; } - - public int Id { get; private set; } + [DataMember] + public int ClientId { get; private set; } + [DataMember] + public int Count { get; private set; } + [DataMember] + public double Sum { get; private set; } + [DataMember] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [DataMember] + public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] + public DateTime? DateImplement { get; private set; } + [DataMember] + public int Id { get; private set; } public static Order? Create(OrderBindingModel model) { @@ -52,22 +58,21 @@ namespace SoftwareInstallationFileImplement.Models { return null; } + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); - var order = new Order() + var order = new Order() { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), + PackageName = element.Element("PackageName")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.Value), ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), PackageId = Convert.ToInt32(element.Element("PackageId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), - PackageName = element.Element("PackageName")!.Value, Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), - Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), - DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null) - }; - - DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); - order.DateImplement = dateImpl; + Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), + DateImplement = dateImpl + }; return order; } diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs index 7123acc..f3db0bb 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs @@ -1,21 +1,24 @@ using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { - public class Package : IPackageModel + [DataContract] + public class Package : IPackageModel { - public string PackageName { get; private set; } = string.Empty; - - public double Price { get; private set; } + [DataMember] + public string PackageName { get; private set; } = string.Empty; + [DataMember] + public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); public Dictionary _packageComponents = null; - - public Dictionary PackageComponents + [DataMember] + public Dictionary PackageComponents { get { @@ -27,8 +30,9 @@ namespace SoftwareInstallationFileImplement.Models return _packageComponents; } } + [DataMember] - public int Id { get; private set; } + public int Id { get; private set; } public static Package? Create(PackageBindingModel model) { diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj b/SoftwareInstallation/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj index 61c3e77..7072cb9 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj @@ -21,4 +21,5 @@ + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Implements/BackUpInfo.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/BackUpInfo.cs new file mode 100644 index 0000000..5061713 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Implements/BackUpInfo.cs @@ -0,0 +1,17 @@ +using SofrwareInstallationContracts.StoragesContracts; + +namespace SoftwareInstallationListImplement.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/SoftwareInstallation/SoftwareInstallationListImplement/ListImplementationExtension.cs b/SoftwareInstallation/SoftwareInstallationListImplement/ListImplementationExtension.cs new file mode 100644 index 0000000..c1adfa8 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/ListImplementationExtension.cs @@ -0,0 +1,23 @@ +using SofrwareInstallationContracts.DI; +using SofrwareInstallationContracts.StoragesContracts; +using SoftwareInstallationListImplement.Implements; + +namespace SoftwareInstallationListImplement +{ + 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/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs index 47cfc9e..3b38e50 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs @@ -49,5 +49,6 @@ namespace SoftwareInstallationListImplement.Models ClientId = ClientId, MessageId = MessageId }; - } + public int Id => throw new NotImplementedException(); + } } diff --git a/SoftwareInstallation/SoftwareInstallationView/DataGridViewExtension.cs b/SoftwareInstallation/SoftwareInstallationView/DataGridViewExtension.cs new file mode 100644 index 0000000..b2526ba --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/DataGridViewExtension.cs @@ -0,0 +1,53 @@ +using SofrwareInstallationContracts.Attributes; + +namespace SoftwareInstallationView +{ + 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/SoftwareInstallation/SoftwareInstallationView/FormClients.cs b/SoftwareInstallation/SoftwareInstallationView/FormClients.cs index 807d1be..99987e1 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormClients.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormClients.cs @@ -55,14 +55,8 @@ namespace SoftwareInstallationView { try { - var list = _logic.ReadList(null); - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка клиентов"); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) { diff --git a/SoftwareInstallation/SoftwareInstallationView/FormComponents.cs b/SoftwareInstallation/SoftwareInstallationView/FormComponents.cs index 01f514e..bf4d54d 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormComponents.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormComponents.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.Logging; using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.BusinessLogicsContracts; +using SofrwareInstallationContracts.DI; +using System.Windows.Forms; namespace SoftwareInstallationView { @@ -26,16 +28,8 @@ namespace SoftwareInstallationView { try { - var list = _logic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - - _logger.LogInformation("Загрузка компонентов"); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) @@ -47,30 +41,21 @@ namespace SoftwareInstallationView private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - - if (service is FormComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); } } private void ChangeButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); - - if (service is FormComponent form) - { - form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); - - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); } } } diff --git a/SoftwareInstallation/SoftwareInstallationView/FormImplementers.cs b/SoftwareInstallation/SoftwareInstallationView/FormImplementers.cs index b4a4305..249b6d9 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormImplementers.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormImplementers.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.BusinessLogicsContracts; +using SofrwareInstallationContracts.DI; using System; using System.Collections.Generic; using System.ComponentModel; @@ -26,14 +27,11 @@ namespace SoftwareInstallationView private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormImplementer form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); } } @@ -41,14 +39,14 @@ namespace SoftwareInstallationView { 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(); } } } @@ -98,16 +96,8 @@ namespace SoftwareInstallationView { try { - var list = _logic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - - _logger.LogInformation("Загрузка исполнителей"); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка исполнителей"); } catch (Exception ex) diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMails.cs b/SoftwareInstallation/SoftwareInstallationView/FormMails.cs index ebfb22b..a43e8ad 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMails.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMails.cs @@ -21,15 +21,8 @@ namespace SoftwareInstallationView { 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/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs index 299c020..2f4aa8e 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs @@ -36,14 +36,15 @@ this.списокИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.элПисьмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DataGridView = new System.Windows.Forms.DataGridView(); this.CreateOrderButton = new System.Windows.Forms.Button(); this.TakeOrderInWorkButton = new System.Windows.Forms.Button(); this.OrderReadyButton = new System.Windows.Forms.Button(); this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); - this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.элПисьмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.создатьБекапToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -54,7 +55,8 @@ this.СправочникиToolStripMenuItem, this.отчетыToolStripMenuItem, this.запускРаботToolStripMenuItem, - this.элПисьмаToolStripMenuItem}); + this.элПисьмаToolStripMenuItem, + this.создатьБекапToolStripMenuItem}); this.MenuStrip.Location = new System.Drawing.Point(0, 0); this.MenuStrip.Name = "MenuStrip"; this.MenuStrip.Size = new System.Drawing.Size(865, 24); @@ -115,6 +117,18 @@ this.списокЗаказовToolStripMenuItem.Text = "Список Заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(92, 20); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + // + // элПисьмаToolStripMenuItem + // + this.элПисьмаToolStripMenuItem.Name = "элПисьмаToolStripMenuItem"; + this.элПисьмаToolStripMenuItem.Size = new System.Drawing.Size(82, 20); + this.элПисьмаToolStripMenuItem.Text = "Эл. Письма"; + // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -174,17 +188,11 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // - // запускРаботToolStripMenuItem + // создатьБекапToolStripMenuItem // - this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; - this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(92, 20); - this.запускРаботToolStripMenuItem.Text = "Запуск работ"; - // - // элПисьмаToolStripMenuItem - // - this.элПисьмаToolStripMenuItem.Name = "элПисьмаToolStripMenuItem"; - this.элПисьмаToolStripMenuItem.Size = new System.Drawing.Size(82, 20); - this.элПисьмаToolStripMenuItem.Text = "Эл. Письма"; + this.создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem"; + this.создатьБекапToolStripMenuItem.Size = new System.Drawing.Size(97, 20); + this.создатьБекапToolStripMenuItem.Text = "Создать Бекап"; // // FormMain // @@ -227,5 +235,6 @@ private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem элПисьмаToolStripMenuItem; + private ToolStripMenuItem создатьБекапToolStripMenuItem; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs index 47e6bb4..1fa1c7f 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs @@ -1,9 +1,8 @@ using Microsoft.Extensions.Logging; using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.BusinessLogicsContracts; -using SoftwareInstallationBusinessLogic.BusinessLogic; -using SoftwareInstallationDataModels.Enums; -using System.Windows.Forms; +using SofrwareInstallationContracts.DI; + namespace SoftwareInstallationView { @@ -13,16 +12,18 @@ namespace SoftwareInstallationView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - private readonly IWorkProcess _workProcess; + private readonly IWorkProcess _workProcess; + private readonly IBackUpLogic _backUpLogic; - public FormMain(ILogger logger, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic) + public FormMain(ILogger logger, IBackUpLogic backUpLogic, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; - _workProcess = workProcess; - LoadData(); + _workProcess = workProcess; + _backUpLogic = backUpLogic; + LoadData(); } private void FormMain_Load(object sender, EventArgs e) @@ -36,16 +37,7 @@ namespace SoftwareInstallationView try { - var list = _orderLogic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["PackageId"].Visible = false; - DataGridView.Columns["ClientId"].Visible = false; - DataGridView.Columns["ImplementerId"].Visible = false; - } - + DataGridView.FillandConfigGrid(_orderLogic.ReadList(null)); _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -57,33 +49,21 @@ namespace SoftwareInstallationView 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(FormPackages)); - - if (service is FormPackages form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void CreateOrderButton_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 TakeOrderInWorkButton_Click(object sender, EventArgs e) @@ -194,52 +174,60 @@ namespace SoftwareInstallationView private void компонентыПоИзделиямToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormReportPackageComponents)); - if (service is FormReportPackageComponents 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) + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + private void элПисьмаToolStripMenuItem_Click(object sender, EventArgs e) + { + 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 BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } - private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) - { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - - private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - - if (service is FormImplementers form) - { - form.ShowDialog(); - } - } - private void элПисьмаToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) - { - form.ShowDialog(); - } - } - } + } } diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackage.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackage.cs index 4732133..82942b3 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormPackage.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackage.cs @@ -3,6 +3,8 @@ using SofrwareInstallationContracts.BusinessLogicsContracts; using SofrwareInstallationContracts.SearchModels; using SoftwareInstallationDataModels.Models; using Microsoft.Extensions.Logging; +using SofrwareInstallationContracts.DI; +using System.Windows.Forms; namespace SoftwareInstallationView @@ -77,59 +79,52 @@ namespace SoftwareInstallationView } private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPackageComponent)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormPackageComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - - _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - - if (_packageComponents.ContainsKey(form.Id)) - { - _packageComponents[form.Id] = (form.ComponentModel, form.Count); - } - - else - { - _packageComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - - LoadData(); + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; } - } + _logger.LogInformation("Добавление нового компонента: { ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count); + + if (_packageComponents.ContainsKey(form.Id)) + { + _packageComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _packageComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + + LoadData(); + } } private void ChangeButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPackageComponent)); + var form = DependencyManager.Instance.Resolve(); + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value); - if (service is FormPackageComponent form) - { - int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _packageComponents[id].Item2; + form.Id = id; + form.Count = _packageComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - _packageComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); - } - } - } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + _packageComponents[id] = (form.ComponentModel, form.Count); + + LoadData(); + } + } } private void DeleteButton_Click(object sender, EventArgs e) diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackages.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackages.cs index 9c3b5cc..e0436b9 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormPackages.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackages.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.Logging; using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.BusinessLogicsContracts; +using SofrwareInstallationContracts.DI; +using System.Windows.Forms; namespace SoftwareInstallationView { @@ -26,17 +28,8 @@ namespace SoftwareInstallationView { try { - var list = _logic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["PackageName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["PackageComponents"].Visible = false; - } - - _logger.LogInformation("Загрузка изделий"); + DataGridView.FillandConfigGrid(_logic.ReadList(null)); + _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) @@ -48,33 +41,27 @@ namespace SoftwareInstallationView private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPackage)); + var form = DependencyManager.Instance.Resolve(); - if (service is FormPackage form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - private void ChangeButton_Click(object sender, EventArgs e) + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + private void ChangeButton_Click(object sender, EventArgs e) { - if (DataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormPackage)); + if (DataGridView.SelectedRows.Count == 1) + { + var form = DependencyManager.Instance.Resolve(); - if (service is FormPackage form) - { - form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - } + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } private void DeleteButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) diff --git a/SoftwareInstallation/SoftwareInstallationView/Program.cs b/SoftwareInstallation/SoftwareInstallationView/Program.cs index f2d209f..9c5e611 100644 --- a/SoftwareInstallation/SoftwareInstallationView/Program.cs +++ b/SoftwareInstallation/SoftwareInstallationView/Program.cs @@ -1,33 +1,26 @@ using SoftwareInstallationBusinessLogic.BusinessLogic; -using Microsoft.Extensions.DependencyInjection; using SofrwareInstallationContracts.BusinessLogicsContracts; -using SofrwareInstallationContracts.StoragesContracts; -using SoftwareInstallationFileImplement.Implements; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using SoftwareInstallationBusinessLogic.OfficePackage; using SoftwareInstallationBusinessLogic.OfficePackage.Implements; using SofrwareInstallationContracts.BindingModels; using SoftwareInstallationBusinessLogic.MailWorker; +using SofrwareInstallationContracts.DI; namespace SoftwareInstallationView { internal static class Program { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - [STAThread] static void Main() { 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, @@ -42,51 +35,51 @@ namespace SoftwareInstallationView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); + var logger = DependencyManager.Instance.Resolve(); logger?.LogError(ex, "Error"); } - Application.Run(_serviceProvider.GetRequiredService()); - } + Application.Run(DependencyManager.Instance.Resolve()); + } - private static void ConfigureServices(ServiceCollection services) - { - services.AddLogging(option => - { + private static void InitDependency() + { + 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.AddSingleton(); - 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(); - 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(true); + + 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(); + 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