diff --git a/SoftwareInstallation/ImplementationExtensions/SofrwareInstallationContracts.dll b/SoftwareInstallation/ImplementationExtensions/SofrwareInstallationContracts.dll new file mode 100644 index 0000000..1b2541c Binary files /dev/null and b/SoftwareInstallation/ImplementationExtensions/SofrwareInstallationContracts.dll differ diff --git a/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationDataBaseImplement.dll b/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationDataBaseImplement.dll new file mode 100644 index 0000000..9adf05b Binary files /dev/null and b/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationDataBaseImplement.dll differ diff --git a/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationDataModels.dll b/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationDataModels.dll new file mode 100644 index 0000000..7e768e3 Binary files /dev/null and b/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationDataModels.dll differ diff --git a/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationFileImplement.dll b/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationFileImplement.dll new file mode 100644 index 0000000..957d746 Binary files /dev/null and b/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationFileImplement.dll differ diff --git a/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationListImplement.dll b/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationListImplement.dll new file mode 100644 index 0000000..aa637ce Binary files /dev/null and b/SoftwareInstallation/ImplementationExtensions/SoftwareInstallationListImplement.dll differ 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..9bb6344 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,7 @@ 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 0c8e243..9ef1d66 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..7727563 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 { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО клиента")] + [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..c153f5b 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 { + [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..8d44aae 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 { + [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..2f8eb90 100644 --- a/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs +++ b/SoftwareInstallation/SofrwareInstallationContracts/ViewModels/MessageInfoViewModel.cs @@ -1,24 +1,29 @@ -using SoftwareInstallationDataModels.Models; +using SofrwareInstallationContracts.Attributes; +using SoftwareInstallationDataModels.Models; using System.ComponentModel; namespace SofrwareInstallationContracts.ViewModels { public class MessageInfoViewModel : IMessageInfoModel { + [Column(visible: false)] public string MessageId { get; set; } = string.Empty; - + + [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 9685e75..f2583fc 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,37 +7,40 @@ namespace SofrwareInstallationContracts.ViewModels { public class OrderViewModel : IOrderModel { + [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("Количество")] - public int Count { get; set; } + [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 e43c8e2..8b4761a 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 { + [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(); } } diff --git a/SoftwareInstallation/SoftwareInstallation/DataGridViewExtension.cs b/SoftwareInstallation/SoftwareInstallation/DataGridViewExtension.cs new file mode 100644 index 0000000..b2526ba --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/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/SoftwareInstallation/FormClients.cs b/SoftwareInstallation/SoftwareInstallation/FormClients.cs index 807d1be..3700977 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormClients.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormClients.cs @@ -55,13 +55,7 @@ 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; - } + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка клиентов"); } catch (Exception ex) diff --git a/SoftwareInstallation/SoftwareInstallation/FormComponents.cs b/SoftwareInstallation/SoftwareInstallation/FormComponents.cs index 01f514e..8ef1187 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormComponents.cs +++ b/SoftwareInstallation/SoftwareInstallation/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,15 +28,7 @@ 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; - } - + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка компонентов"); } @@ -47,33 +41,26 @@ namespace SoftwareInstallationView private void AddButton_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) { + LoadData(); + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var form = DependencyManager.Instance.Resolve(); + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); 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(); - } - } - } - } private void DeleteButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs b/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs index b4a4305..202ac32 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs +++ b/SoftwareInstallation/SoftwareInstallation/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)); - - if (service is FormImplementer form) + var form = DependencyManager.Instance.Resolve(); + + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } @@ -41,14 +39,13 @@ 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,15 +95,7 @@ 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; - } - + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка исполнителей"); } diff --git a/SoftwareInstallation/SoftwareInstallation/FormMails.cs b/SoftwareInstallation/SoftwareInstallation/FormMails.cs index ebfb22b..511584d 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMails.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMails.cs @@ -21,14 +21,7 @@ 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; - } + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка писем"); } catch (Exception ex) diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs index 6fd62f8..a3d2aa1 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs @@ -39,13 +39,14 @@ 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.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -56,7 +57,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); @@ -140,6 +142,13 @@ this.запускРаботToolStripMenuItem.Text = "Запуск работ"; this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); // + // элПисьмаToolStripMenuItem + // + this.элПисьмаToolStripMenuItem.Name = "элПисьмаToolStripMenuItem"; + this.элПисьмаToolStripMenuItem.Size = new System.Drawing.Size(82, 20); + this.элПисьмаToolStripMenuItem.Text = "Эл. Письма"; + this.элПисьмаToolStripMenuItem.Click += new System.EventHandler(this.элПисьмаToolStripMenuItem_Click); + // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -199,12 +208,12 @@ 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(82, 20); - this.элПисьмаToolStripMenuItem.Text = "Эл. Письма"; - this.элПисьмаToolStripMenuItem.Click += new System.EventHandler(this.элПисьмаToolStripMenuItem_Click); + this.создатьБекапToolStripMenuItem.Name = "создатьБекапToolStripMenuItem"; + this.создатьБекапToolStripMenuItem.Size = new System.Drawing.Size(97, 20); + this.создатьБекапToolStripMenuItem.Text = "Создать Бекап"; + this.создатьБекапToolStripMenuItem.Click += new System.EventHandler(this.создатьБекапToolStripMenuItem_Click); // // FormMain // @@ -249,5 +258,6 @@ private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem элПисьмаToolStripMenuItem; + private ToolStripMenuItem создатьБекапToolStripMenuItem; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.cs index 5a8b1fa..467fce1 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.cs @@ -1,9 +1,7 @@ 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 { @@ -14,14 +12,16 @@ namespace SoftwareInstallationView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; 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; + _backUpLogic = backUpLogic; LoadData(); } @@ -36,16 +36,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 +48,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) @@ -195,55 +174,64 @@ 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) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) { - _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + _workProcess.DoWork(DependencyManager.Instance.Resolve(), _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - - if (service is FormImplementers form) - { - form.ShowDialog(); - } + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); } private void элПисьмаToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormMails)); - if (service is FormMails form) + var form = DependencyManager.Instance.Resolve(); + form.ShowDialog(); + } + + private void создатьБекапToolStripMenuItem_Click(object sender, EventArgs e) + { + try { - form.ShowDialog(); + if (_backUpLogic != null) + { + var fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + { + _backUpLogic.CreateBackUp(new BackUpSaveBinidngModel + { + FolderName = fbd.SelectedPath + }); + MessageBox.Show("Бекап создан", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } } diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackage.cs b/SoftwareInstallation/SoftwareInstallation/FormPackage.cs index 4732133..645cb60 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackage.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormPackage.cs @@ -3,7 +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,31 +78,27 @@ namespace SoftwareInstallationView } private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPackageComponent)); - - if (service is FormPackageComponent form) + var form = DependencyManager.Instance.Resolve(); + + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - - _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - - if (_packageComponents.ContainsKey(form.Id)) - { - _packageComponents[form.Id] = (form.ComponentModel, form.Count); - } - - else - { - _packageComponents.Add(form.Id, (form.ComponentModel, form.Count)); - } - - LoadData(); + 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(); } } @@ -109,25 +106,23 @@ namespace SoftwareInstallationView { 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) + form.Id = id; + form.Count = _packageComponents[id].Item2; + + if (form.ShowDialog() == DialogResult.OK) { - int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _packageComponents[id].Item2; - - if (form.ShowDialog() == DialogResult.OK) + if (form.ComponentModel == null) { - if (form.ComponentModel == null) - { - return; - } - - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - _packageComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); + return; } + + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + _packageComponents[id] = (form.ComponentModel, form.Count); + + LoadData(); } } } diff --git a/SoftwareInstallation/SoftwareInstallation/FormPackages.cs b/SoftwareInstallation/SoftwareInstallation/FormPackages.cs index 9c3b5cc..79891a0 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormPackages.cs +++ b/SoftwareInstallation/SoftwareInstallation/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,16 +28,7 @@ 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; - } - + DataGridView.FillandConfigGrid(_logic.ReadList(null)); _logger.LogInformation("Загрузка изделий"); } @@ -48,30 +41,24 @@ namespace SoftwareInstallationView private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormPackage)); - - if (service is FormPackage form) + var form = DependencyManager.Instance.Resolve(); + + if (form.ShowDialog() == DialogResult.OK) { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } + LoadData(); } } private void ChangeButton_Click(object sender, EventArgs e) { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormPackage)); - - if (service is FormPackage 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/SoftwareInstallation/SoftwareInstallation/Program.cs b/SoftwareInstallation/SoftwareInstallation/Program.cs index 364e422..0828d17 100644 --- a/SoftwareInstallation/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/SoftwareInstallation/Program.cs @@ -1,32 +1,26 @@ using SoftwareInstallationBusinessLogic.BusinessLogic; -using Microsoft.Extensions.DependencyInjection; using SofrwareInstallationContracts.BusinessLogicsContracts; -using SofrwareInstallationContracts.StoragesContracts; -using SoftwareInstallationDataBaseImplement.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, @@ -41,52 +35,54 @@ namespace SoftwareInstallationView } catch (Exception ex) { - var logger = _serviceProvider.GetService(); - logger?.LogError(ex, "Error"); + var logger = DependencyManager.Instance.Resolve(); + logger?.LogError(ex, ""); } - Application.Run(_serviceProvider.GetRequiredService()); + + Application.Run(DependencyManager.Instance.Resolve()); } - private static void ConfigureServices(ServiceCollection services) + private static void InitDependency() { - services.AddLogging(option => + DependencyManager.InitDependency(); + + DependencyManager.Instance.AddLogging(option => { option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.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(); } } diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/BackUpLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogic/BackUpLogic.cs new file mode 100644 index 0000000..bda90ea --- /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/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 f8a7864..27ee80d 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Client.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Client.cs @@ -3,17 +3,23 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { + [DataContract] public class Client : IClientModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ClientFIO { get; set; } = string.Empty; [Required] + [DataMember] public string Email { get; set; } = string.Empty; [Required] + [DataMember] public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Component.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Component.cs index fb1c505..cba8f31 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Component.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Component.cs @@ -3,17 +3,22 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { + [DataContract] public class Component : IComponentModel { + [DataMember] public int Id { get; private set; } [Required] + [DataMember] public string ComponentName { get; private set; } = string.Empty; [Required] + [DataMember] public double Cost { get; set; } [ForeignKey("ComponentId")] diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Implementer.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Implementer.cs index fd6fdd6..b77a8c0 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Implementer.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Implementer.cs @@ -3,23 +3,30 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { + [DataContract] public class Implementer : IImplementerModel { [Required] + [DataMember] public string ImplementerFIO { get; private set; } = string.Empty; [Required] + [DataMember] public string Password { get; private set; } = string.Empty; [Required] + [DataMember] public int WorkExperience { get; private set; } [Required] + [DataMember] public int Qualification { get; private set; } + [DataMember] public int Id { get; private set; } [ForeignKey("ImplementerId")] diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs index 2f1b063..4783d0b 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Message.cs @@ -2,21 +2,29 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { + [DataContract] public class Message : IMessageInfoModel { [Key] + [DataMember] public string MessageId { get; private set; } = string.Empty; + [DataMember] public int? ClientId { get; private set; } [Required] + [DataMember] public string SenderName { get; private set; } = string.Empty; [Required] + [DataMember] public DateTime DateDelivery { get; private set; } = DateTime.Now; [Required] + [DataMember] public string Subject { get; private set; } = string.Empty; [Required] + [DataMember] public string Body { get; private set; } = string.Empty; public virtual Client Client { get; set; } @@ -47,5 +55,7 @@ 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 d0416a2..d2ee276 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Order.cs @@ -3,34 +3,46 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Enums; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int Id { get; private set; } + [DataMember] public int PackageId { get; private set; } + [DataMember] public int? ImplementerId { get; private set; } [Required] + [DataMember] public int ClientId { get; set; } + [DataMember] public string PackageName { get; private set; } = string.Empty; [Required] + [DataMember] public int Count { get; private set; } [Required] + [DataMember] public double Sum { get; private set; } [Required] + [DataMember] public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [Required] + [DataMember] public DateTime DateCreate { get; private set; } = DateTime.Now; + [DataMember] public DateTime? DateImplement { get; private set; } public virtual Package Package { get; set; } diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Package.cs b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Package.cs index 426af27..86ecec8 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Package.cs +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/Models/Package.cs @@ -3,22 +3,28 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace SoftwareInstallationDataBaseImplement.Models { + [DataContract] public class Package : IPackageModel { + [DataMember] public int Id { get; set; } [Required] + [DataMember] public string PackageName { get; set; } = string.Empty; [Required] + [DataMember] public double Price { get; set; } private Dictionary? _packageComponents = null; [NotMapped] + [DataMember] public Dictionary PackageComponents { get diff --git a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBaseImplement.csproj b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBaseImplement.csproj index 8aec7ec..d5d65ad 100644 --- a/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBaseImplement.csproj +++ b/SoftwareInstallation/SoftwareInstallationDataBaseImplement/SoftwareInstallationDataBaseImplement.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs index a27b3f7..ed82604 100644 --- a/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs +++ b/SoftwareInstallation/SoftwareInstallationDataModels/Models/IMessageInfoModel.cs @@ -1,6 +1,6 @@ namespace SoftwareInstallationDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { 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..33d611a 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Client.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Client.cs @@ -1,15 +1,21 @@ using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.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/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs index f1fe801..07c0839 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Component.cs @@ -1,16 +1,19 @@ -using System.Xml.Linq; +using System.Runtime.Serialization; +using System.Xml.Linq; using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Component : IComponentModel { + [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..1fd45aa 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Implementer.cs @@ -1,20 +1,23 @@ using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Implementer : IImplementerModel { + [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..fb59645 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Message.cs @@ -1,22 +1,25 @@ using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Message : IMessageInfoModel { + [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 2e1e520..e63814a 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Order.cs @@ -2,30 +2,33 @@ using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Enums; using SoftwareInstallationDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Order : IOrderModel { + [DataMember] public int PackageId { get; private set; } - + [DataMember] public int? ImplementerId { get; set; } - + [DataMember] public int ClientId { get; private set; } - + [DataMember] public string PackageName { get; private set; } = string.Empty; - + [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) @@ -56,22 +59,22 @@ namespace SoftwareInstallationFileImplement.Models return null; } + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + var order = new Order() { + 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) + Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), + DateImplement = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), }; - DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); - order.DateImplement = dateImpl; - return order; } diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs index aab99ff..251b0c6 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Models/Package.cs @@ -1,20 +1,23 @@ using SofrwareInstallationContracts.BindingModels; using SofrwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace SoftwareInstallationFileImplement.Models { + [DataContract] public class Package : IPackageModel { + [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; - + [DataMember] public Dictionary PackageComponents { get @@ -27,7 +30,7 @@ namespace SoftwareInstallationFileImplement.Models return _packageComponents; } } - + [DataMember] 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 0fdeafe..dafc323 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj @@ -21,4 +21,8 @@ + + + + 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..611cdb6 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Models/Message.cs @@ -49,5 +49,7 @@ namespace SoftwareInstallationListImplement.Models ClientId = ClientId, MessageId = MessageId }; + + public int Id => throw new NotImplementedException(); } } diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj b/SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj index 916bb1e..0b5f35b 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj +++ b/SoftwareInstallation/SoftwareInstallationListImplement/SoftwareInstallationListImplement.csproj @@ -24,4 +24,8 @@ + + + +