diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/ImplementationBusinessLogicExtension.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/ImplementationBusinessLogicExtension.cs new file mode 100644 index 0000000..dc08a78 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/ImplementationBusinessLogicExtension.cs @@ -0,0 +1,34 @@ +using PlumbingRepairBusinessLogic.BusinessLogics; +using PlumbingRepairBusinessLogic.MailWorker; +using PlumbingRepairBusinessLogic.OfficePackage.Implements; +using PlumbingRepairBusinessLogic.OfficePackage; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.DI; + +namespace PlumbingRepairBusinessLogic +{ + public class ImplementationBusinessLogicExtension : IImplementationBusinessLogicExtension + { + 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(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + + DependencyManager.Instance.RegisterType(true); + + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + DependencyManager.Instance.RegisterType(); + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj b/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj index 5c2a82d..e5325a5 100644 --- a/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs b/PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs index c73044d..a3b01f9 100644 --- a/PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs +++ b/PlumbingRepair/PlumbingRepairContracts/Attributes/ColumnAttribute.cs @@ -12,14 +12,16 @@ public GridViewAutoSize GridViewAutoSize { get; private set; } public bool IsUseAutoSize { get; private set; } + public string Format { get; private set; } - public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false) + public ColumnAttribute(string title = "", bool visible = true, int width = 0, GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false, string format = "") { Title = title; Visible = visible; Width = width; GridViewAutoSize = gridViewAutoSize; IsUseAutoSize = isUseAutoSize; + Format = format; } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/DI/DependencyManager.cs b/PlumbingRepair/PlumbingRepairContracts/DI/DependencyManager.cs index 906def0..d79eef9 100644 --- a/PlumbingRepair/PlumbingRepairContracts/DI/DependencyManager.cs +++ b/PlumbingRepair/PlumbingRepairContracts/DI/DependencyManager.cs @@ -29,6 +29,14 @@ namespace PlumbingRepairContracts.DI } // регистрируем зависимости ext.RegisterServices(); + + var bsExtensions = ServiceProviderLoader.GetBusinessLogicImplementationExtensions(); + if (bsExtensions == null) + { + throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей бизнес-логики"); + } + // регистрируем зависимости + bsExtensions.RegisterServices(); } /// diff --git a/PlumbingRepair/PlumbingRepairContracts/DI/IImplementationBusinessLogicExtension.cs b/PlumbingRepair/PlumbingRepairContracts/DI/IImplementationBusinessLogicExtension.cs new file mode 100644 index 0000000..7810107 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/DI/IImplementationBusinessLogicExtension.cs @@ -0,0 +1,7 @@ +namespace PlumbingRepairContracts.DI +{ + public interface IImplementationBusinessLogicExtension + { + public void RegisterServices(); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/DI/ServiceProviderLoader.cs b/PlumbingRepair/PlumbingRepairContracts/DI/ServiceProviderLoader.cs index e09daa2..d731f35 100644 --- a/PlumbingRepair/PlumbingRepairContracts/DI/ServiceProviderLoader.cs +++ b/PlumbingRepair/PlumbingRepairContracts/DI/ServiceProviderLoader.cs @@ -36,7 +36,34 @@ namespace PlumbingRepairContracts.DI } return source; } - + public static IImplementationBusinessLogicExtension? GetBusinessLogicImplementationExtensions() + { + IImplementationBusinessLogicExtension? source = null; + var files = Directory.GetFiles(TryGetBusinessLogicImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories); + foreach (var file in files.Distinct()) + { + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IImplementationBusinessLogicExtension).IsAssignableFrom(t)) + { + source = (IImplementationBusinessLogicExtension)Activator.CreateInstance(t)!; + break; + } + } + } + return source; + } + private static string TryGetBusinessLogicImplementationExtensionsFolder() + { + var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); + while (directory != null && !directory.GetDirectories("BusinessLogicImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "BusinessLogicImplementationExtensions")) + { + directory = directory.Parent; + } + return $"{directory?.FullName}\\BusinessLogicImplementationExtensions"; + } + private static string TryGetImplementationExtensionsFolder() { var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs index 983f9fa..c8a1c5e 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/MessageInfoViewModel.cs @@ -12,7 +12,7 @@ namespace PlumbingRepairContracts.ViewModels public int? ClientId { get; set; } [Column(title: "Отправитель", width: 150)] public string SenderName { get; set; } = string.Empty; - [Column(title: "Дата отправления", width: 150)] + [Column(title: "Дата отправления", width: 150, format: "Date: dd/MM/yyyy")] public DateTime DateDelivery { get; set; } [Column(title: "Заголовок", width: 150)] public string Subject { get; set; } = string.Empty; diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs index 897ffdb..28e71d0 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs @@ -36,10 +36,10 @@ namespace PlumbingRepairContracts.ViewModels [Column(title: "Статус", width: 150)] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [Column(title: "Дата создания", width: 150)] + [Column(title: "Дата создания", width: 150, format: "Date: dd/MM/yyyy")] public DateTime DateCreate { get; set; } = DateTime.Now; - [Column(title: "Дата выполнения", width: 150)] + [Column(title: "Дата выполнения", width: 150, format: "Date: dd/MM/yyyy")] public DateTime? DateImplement { get; set; } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ShopViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ShopViewModel.cs index f673997..a8ad960 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ShopViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ShopViewModel.cs @@ -1,20 +1,22 @@ -using PlumbingRepairDataModels.Models; +using PlumbingRepairContracts.Attributes; +using PlumbingRepairDataModels.Models; using System.ComponentModel; namespace PlumbingRepairContracts.ViewModels { public class ShopViewModel { - public int Id { get; set; } + [Column(visible: false)] + public int Id { get; set; } - [DisplayName("Название магазина")] - public string ShopName { get; set; } = string.Empty; + [Column(title: "Название магазина", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string ShopName { get; set; } = string.Empty; - [DisplayName("Адрес")] - public string Address { get; set; } = string.Empty; - [DisplayName("Максимальное количество работ")] - public int maxCountWorks { get; set; } - [DisplayName("Дата открытия")] + [Column(title: "Адрес", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)] + public string Address { get; set; } = string.Empty; + [Column(title: "Максимальное количество работ", width: 150)] + public int maxCountWorks { get; set; } + [Column(title: "Дата открытия", width: 150, format: "Date: dd/MM/yyyy")] public DateTime DateOpening { get; set; } public Dictionary ShopWorks { get; set; } = new(); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Shop.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Shop.cs index 6be7a5a..d6a3209 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Shop.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Shop.cs @@ -4,26 +4,34 @@ using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; namespace PlumbingRepairDatabaseImplement.Models { - public class Shop + [DataContract] + public class Shop { - public int Id { get; set; } + [DataMember] + public int Id { get; set; } [Required] - public string ShopName { get; set; } = string.Empty; + [DataMember] + public string ShopName { get; set; } = string.Empty; [Required] - public string Address { get; set; } = string.Empty; + [DataMember] + public string Address { get; set; } = string.Empty; [Required] - public DateTime DateOpening { get; set; } + [DataMember] + public DateTime DateOpening { get; set; } [Required] - public int maxCountWorks { get; set; } + [DataMember] + public int maxCountWorks { get; set; } private Dictionary? _shopWorks = null; [NotMapped] - public Dictionary ShopWorks + [DataMember] + public Dictionary ShopWorks { get { diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Work.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Work.cs index bb9420a..e8b0445 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Work.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Work.cs @@ -24,7 +24,8 @@ namespace PlumbingRepairDatabaseImplement.Models private Dictionary? _workComponents = null; [NotMapped] - public Dictionary WorkComponents + [DataMember] + public Dictionary WorkComponents { get { diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Shop.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Shop.cs index 6620ee0..69112f8 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Models/Shop.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Shop.cs @@ -1,23 +1,28 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; using System.Xml.Linq; namespace PlumbingRepairFileImplement.Models { + [DataContract] public class Shop : IShopModel { - public int Id { get; private set; } - - public string ShopName { get; private set; } = string.Empty; - public string Address { get; private set; } = string.Empty; - - public DateTime DateOpening { get; private set; } + [DataMember] + public int Id { get; private set; } + [DataMember] + public string ShopName { get; private set; } = string.Empty; + [DataMember] + public string Address { get; private set; } = string.Empty; + [DataMember] + public DateTime DateOpening { get; private set; } public Dictionary Works { get; private set; } = new(); private Dictionary? _shopWorks = null; - public Dictionary ShopWorks + [DataMember] + public Dictionary ShopWorks { get { diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs index 01e3282..4e5afcd 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Work.cs @@ -19,8 +19,8 @@ namespace PlumbingRepairFileImplement.Models public Dictionary Components { get; private set; } = new(); private Dictionary? _workComponents = null; - - public Dictionary WorkComponents + [DataMember] + public Dictionary WorkComponents { get { diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Shop.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Shop.cs index 45c2122..58b08f7 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/Models/Shop.cs +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Shop.cs @@ -1,21 +1,25 @@ using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using System.Runtime.Serialization; namespace PlumbingRepairListImplement.Models { - public class Shop + [DataContract] + public class Shop { + [DataMember] public int Id { get; private set; } - - public string ShopName { get; private set; } = string.Empty; - - public string Address { get; private set; } = string.Empty; - public DateTime DateOpening { get; private set; } - - public Dictionary ShopWorks { get; private set; } = new Dictionary(); - - public int maxCountWorks { get; private set; } + [DataMember] + public string ShopName { get; private set; } = string.Empty; + [DataMember] + public string Address { get; private set; } = string.Empty; + [DataMember] + public DateTime DateOpening { get; private set; } + [DataMember] + public Dictionary ShopWorks { get; private set; } = new Dictionary(); + [DataMember] + public int maxCountWorks { get; private set; } public static Shop? Create(ShopBindingModel? model) { diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs index ce957f9..d27f304 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Work.cs @@ -14,8 +14,8 @@ namespace PlumbingRepairListImplement.Models public string WorkName { get; private set; } = string.Empty; [DataMember] public double Price { get; private set; } - - public Dictionary WorkComponents { get; private set; } = new Dictionary(); + [DataMember] + public Dictionary WorkComponents { get; private set; } = new Dictionary(); public static Work? Create(WorkBindingModel? model) { diff --git a/PlumbingRepair/PlumbingRepairView/Program.cs b/PlumbingRepair/PlumbingRepairView/Program.cs index db7e3b6..0cdd226 100644 --- a/PlumbingRepair/PlumbingRepairView/Program.cs +++ b/PlumbingRepair/PlumbingRepairView/Program.cs @@ -57,16 +57,6 @@ namespace PlumbingRepairView option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - - 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(); @@ -80,13 +70,15 @@ namespace PlumbingRepairView 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) => DependencyManager.Instance.Resolve()?.MailCheck(); }