diff --git a/FlowerShopContracts/Attributes/ColumnAttribute.cs b/FlowerShopContracts/Attributes/ColumnAttribute.cs new file mode 100644 index 0000000..1ca901e --- /dev/null +++ b/FlowerShopContracts/Attributes/ColumnAttribute.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.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/FlowerShopContracts/Attributes/GridViewAutoSize.cs b/FlowerShopContracts/Attributes/GridViewAutoSize.cs new file mode 100644 index 0000000..98f4eb0 --- /dev/null +++ b/FlowerShopContracts/Attributes/GridViewAutoSize.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.Attributes +{ + public enum GridViewAutoSize + { + NotSet = 0, + None = 1, + ColumnHeader = 2, + AllCellsExceptHeader = 4, + AllCells = 6, + DisplayedCellsExceptHeader = 8, + DisplayedCells = 10, + Fill = 16 + } +} diff --git a/FlowerShopContracts/BindingModels/BackUpSaveBindingModel.cs b/FlowerShopContracts/BindingModels/BackUpSaveBindingModel.cs new file mode 100644 index 0000000..4d12df6 --- /dev/null +++ b/FlowerShopContracts/BindingModels/BackUpSaveBindingModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.BindingModels +{ + public class BackUpSaveBinidngModel + { + public string FolderName { get; set; } = string.Empty; + } +} diff --git a/FlowerShopContracts/BindingModels/MessageInfoBindingModel.cs b/FlowerShopContracts/BindingModels/MessageInfoBindingModel.cs index 8b5fd4b..d6db511 100644 --- a/FlowerShopContracts/BindingModels/MessageInfoBindingModel.cs +++ b/FlowerShopContracts/BindingModels/MessageInfoBindingModel.cs @@ -15,5 +15,6 @@ namespace FlowerShopContracts.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/FlowerShopContracts/BusinessLogicsContracts/IBackUpLogic.cs b/FlowerShopContracts/BusinessLogicsContracts/IBackUpLogic.cs new file mode 100644 index 0000000..904dafd --- /dev/null +++ b/FlowerShopContracts/BusinessLogicsContracts/IBackUpLogic.cs @@ -0,0 +1,14 @@ +using FlowerShopContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.BusinessLogicsContracts +{ + public interface IBackUpLogic + { + void CreateBackUp(BackUpSaveBinidngModel model); + } +} diff --git a/FlowerShopContracts/DI/DependancyManager.cs b/FlowerShopContracts/DI/DependancyManager.cs new file mode 100644 index 0000000..87294b1 --- /dev/null +++ b/FlowerShopContracts/DI/DependancyManager.cs @@ -0,0 +1,46 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.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/FlowerShopContracts/DI/IDependencyContainer.cs b/FlowerShopContracts/DI/IDependencyContainer.cs new file mode 100644 index 0000000..04ab01c --- /dev/null +++ b/FlowerShopContracts/DI/IDependencyContainer.cs @@ -0,0 +1,18 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.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/FlowerShopContracts/DI/IImplementationExtension.cs b/FlowerShopContracts/DI/IImplementationExtension.cs new file mode 100644 index 0000000..8a2a7ea --- /dev/null +++ b/FlowerShopContracts/DI/IImplementationExtension.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.DI +{ + public interface IImplementationExtension + { + public int Priority { get; } + public void RegisterServices(); + } +} diff --git a/FlowerShopContracts/DI/ServiceDependencyContainer.cs b/FlowerShopContracts/DI/ServiceDependencyContainer.cs new file mode 100644 index 0000000..3ccbbb7 --- /dev/null +++ b/FlowerShopContracts/DI/ServiceDependencyContainer.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.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 T : class + { + if (isSingle) + { + _serviceCollection.AddSingleton(); + } + else + { + _serviceCollection.AddTransient(); + } + _serviceProvider = null; + } + + public void RegisterType(bool isSingle) where U : class, T 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/FlowerShopContracts/DI/ServiceProviderLoader.cs b/FlowerShopContracts/DI/ServiceProviderLoader.cs new file mode 100644 index 0000000..6e3fddb --- /dev/null +++ b/FlowerShopContracts/DI/ServiceProviderLoader.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.DI +{ + public static partial 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/FlowerShopContracts/FlowerShopContracts.csproj b/FlowerShopContracts/FlowerShopContracts.csproj index 901b7f6..ee93d96 100644 --- a/FlowerShopContracts/FlowerShopContracts.csproj +++ b/FlowerShopContracts/FlowerShopContracts.csproj @@ -7,6 +7,7 @@ + diff --git a/FlowerShopContracts/StoragesContracts/IBackUpInfo.cs b/FlowerShopContracts/StoragesContracts/IBackUpInfo.cs new file mode 100644 index 0000000..87e8e34 --- /dev/null +++ b/FlowerShopContracts/StoragesContracts/IBackUpInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.StoragesContracts +{ + public interface IBackUpInfo + { + List? GetList() where T : class, new(); + Type? GetTypeByModelInterface(string modelInterfaceName); + } +} diff --git a/FlowerShopContracts/ViewModels/ClientViewModel.cs b/FlowerShopContracts/ViewModels/ClientViewModel.cs index 79577d0..5c72c27 100644 --- a/FlowerShopContracts/ViewModels/ClientViewModel.cs +++ b/FlowerShopContracts/ViewModels/ClientViewModel.cs @@ -1,4 +1,5 @@ -using FlowerShopDataModels.Models; +using FlowerShopContracts.Attributes; +using FlowerShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,12 +11,13 @@ namespace FlowerShopContracts.ViewModels { public class ClientViewModel : IClientModel { - public int Id { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] - public string Email { get; set; } = string.Empty; - [DisplayName("Пароль")] - public string Password { get; set; } = string.Empty; - } + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "ФИО клиента", width: 150)] + public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Email клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Email { get; set; } = string.Empty; + [Column(title: "Пароль", width: 150)] + public string Password { get; set; } = string.Empty; + } } diff --git a/FlowerShopContracts/ViewModels/ComponentViewModel.cs b/FlowerShopContracts/ViewModels/ComponentViewModel.cs index 667f0bb..ab18bc5 100644 --- a/FlowerShopContracts/ViewModels/ComponentViewModel.cs +++ b/FlowerShopContracts/ViewModels/ComponentViewModel.cs @@ -1,4 +1,5 @@ -using FlowerShopDataModels.Models; +using FlowerShopContracts.Attributes; +using FlowerShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,10 +11,11 @@ namespace FlowerShopContracts.ViewModels { public class ComponentViewModel : IComponentModel { - public int Id { get; set; } - [DisplayName("Название компонента")] - public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Cost { get; set; } - } + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "Название компонента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ComponentName { get; set; } = string.Empty; + [Column(title: "Цена", width: 80)] + public double Cost { get; set; } + } } diff --git a/FlowerShopContracts/ViewModels/FlowerViewModel.cs b/FlowerShopContracts/ViewModels/FlowerViewModel.cs index 0010c97..75cc88e 100644 --- a/FlowerShopContracts/ViewModels/FlowerViewModel.cs +++ b/FlowerShopContracts/ViewModels/FlowerViewModel.cs @@ -1,4 +1,5 @@ -using FlowerShopDataModels.Models; +using FlowerShopContracts.Attributes; +using FlowerShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,13 +11,15 @@ namespace FlowerShopContracts.ViewModels { public class FlowerViewModel : IFlowerModel { - public int Id { get; set; } - [DisplayName("Название изделия")] - public string FlowerName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Price { get; set; } - public Dictionary FlowerComponents - { + [Column(visible: false)] + public int Id { get; set; } + [Column(title: "Название цветка", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string FlowerName { get; set; } = string.Empty; + [Column(title: "Цена", width: 100)] + public double Price { get; set; } + [Column(visible: false)] + public Dictionary FlowerComponents + { get; set; } = new(); diff --git a/FlowerShopContracts/ViewModels/ImplementerViewModel.cs b/FlowerShopContracts/ViewModels/ImplementerViewModel.cs index 7c43f92..518b7c5 100644 --- a/FlowerShopContracts/ViewModels/ImplementerViewModel.cs +++ b/FlowerShopContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,5 @@ -using FlowerShopDataModels.Models; +using FlowerShopContracts.Attributes; +using FlowerShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,14 +11,15 @@ namespace FlowerShopContracts.ViewModels { public class ImplementerViewModel : IImplementerModel { + [Column(visible: false)] public int Id { get; set; } - [DisplayName("ФИО исполнителя")] + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Стаж работы")] + [Column(title: "Стаж работы", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int WorkExperience { get; set; } = 0; - [DisplayName("Квалификация")] + [Column(title: "Квалификация", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] public int Qualification { get; set; } = 0; - [DisplayName("Пароль")] + [Column(title: "Пароль", width: 150)] public string Password { get; set; } = string.Empty; } } diff --git a/FlowerShopContracts/ViewModels/MessageInfoViewModel.cs b/FlowerShopContracts/ViewModels/MessageInfoViewModel.cs index 3f5339b..601736c 100644 --- a/FlowerShopContracts/ViewModels/MessageInfoViewModel.cs +++ b/FlowerShopContracts/ViewModels/MessageInfoViewModel.cs @@ -1,4 +1,5 @@ -using FlowerShopDataModels.Models; +using FlowerShopContracts.Attributes; +using FlowerShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,15 +11,19 @@ namespace FlowerShopContracts.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(title: "Отправитель", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)] public string SenderName { get; set; } = string.Empty; - [DisplayName("Дата письма")] + [Column(title: "Дата письма", width: 100)] public DateTime DateDelivery { get; set; } - [DisplayName("Заголовок")] + [Column(title: "Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; - [DisplayName("Текст")] + [Column(title: "Текст", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string Body { get; set; } = string.Empty; + [Column(visible: false)] + public int Id => throw new NotImplementedException(); } } diff --git a/FlowerShopContracts/ViewModels/OrderViewModel.cs b/FlowerShopContracts/ViewModels/OrderViewModel.cs index 05602be..1127c09 100644 --- a/FlowerShopContracts/ViewModels/OrderViewModel.cs +++ b/FlowerShopContracts/ViewModels/OrderViewModel.cs @@ -6,31 +6,35 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using FlowerShopContracts.Attributes; namespace FlowerShopContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] - public int Id { get; set; } - public int FlowerId { get; set; } + [Column(title: "Номер", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Id { get; set; } + [Column(visible: false)] + public int FlowerId { get; set; } + [Column(visible: false)] public int? ImplementerId { get; set; } = null; - [DisplayName("Изделие")] - public string FlowerName { get; set; } = string.Empty; - [DisplayName("Исполнитель")] + [Column(visible: false)] + public int ClientId { get; set; } + [Column(title: "Цветок", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public string FlowerName { get; set; } = string.Empty; + [Column(title: "ФИО исполнителя", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] public string ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } - [DisplayName("Сумма")] - public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } - public int ClientId { get; set; } - [DisplayName("Клиент")] - public string ClientFIO { get; set; } = string.Empty; + [Column(title: "Количество", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public int Count { get; set; } + [Column(title: "Сумма", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public double Sum { get; set; } + [Column(title: "Статус", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [Column(title: "Дата создания", width: 100)] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Column(title: "Дата выполнения", width: 100)] + public DateTime? DateImplement { get; set; } + [Column(title: "ФИО клиента", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ClientFIO { get; set; } = string.Empty; } } diff --git a/FlowerShopDataModels/IMessageInfoModel.cs b/FlowerShopDataModels/IMessageInfoModel.cs index b03660a..2712a5c 100644 --- a/FlowerShopDataModels/IMessageInfoModel.cs +++ b/FlowerShopDataModels/IMessageInfoModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace FlowerShopDataModels.Models { - public interface IMessageInfoModel + public interface IMessageInfoModel : IId { string MessageId { get; } int? ClientId { get; }