Eliseev E.E. LabWork08_Hard #18
@ -55,8 +55,11 @@ namespace BlacksmithWorkshop
|
||||
{
|
||||
column.Width = columnAttr.Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
column.DefaultCellStyle.Format = columnAttr.Format;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ namespace BlacksmithWorkshop
|
||||
|
||||
private void ImplementerToolStripMenuItem_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
var form = DependencyManager.Instance.Resolve<FormReportOrders>();
|
||||
var form = DependencyManager.Instance.Resolve<FormImplementers>();
|
||||
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
@ -64,23 +64,6 @@ namespace BlacksmithWorkshop
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
|
||||
DependencyManager.Instance.RegisterType<IWorkPieceLogic, WorkPieceLogic>();
|
||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||
DependencyManager.Instance.RegisterType<IManufactureLogic, ManufactureLogic>();
|
||||
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
||||
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
||||
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
||||
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
||||
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
|
||||
|
||||
DependencyManager.Instance.RegisterType<FormMain>();
|
||||
DependencyManager.Instance.RegisterType<FormWorkPiece>();
|
||||
DependencyManager.Instance.RegisterType<FormWorkPieces>();
|
||||
|
@ -21,4 +21,8 @@
|
||||
<ProjectReference Include="..\BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)BusinessLogicImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,40 @@
|
||||
using BlacksmithWorkshopBusinessLogic.BusinessLogic;
|
||||
using BlacksmithWorkshopBusinessLogic.MailWorker;
|
||||
using BlacksmithWorkshopBusinessLogic.OfficePackage.Implements;
|
||||
using BlacksmithWorkshopBusinessLogic.OfficePackage;
|
||||
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
|
||||
using BlacksmithWorkshopContracts.DI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlacksmithWorkshopBusinessLogic
|
||||
{
|
||||
public class BusinessLogicImplementationExtension : IBusinessLogicImplementationExtension
|
||||
{
|
||||
public int Priority => 0;
|
||||
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IWorkPieceLogic, WorkPieceLogic>();
|
||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||
DependencyManager.Instance.RegisterType<IManufactureLogic, ManufactureLogic>();
|
||||
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
||||
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
||||
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
||||
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
|
||||
|
||||
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
|
||||
}
|
||||
}
|
||||
}
|
@ -45,7 +45,17 @@ namespace BlacksmithWorkshopContracts.DI
|
||||
|
||||
// регистрируем зависимости
|
||||
ext.RegisterServices();
|
||||
}
|
||||
|
||||
var extBusiness = ServiceProviderLoader.GetBusinessLogicImplementationExtensions();
|
||||
|
||||
if (extBusiness == null)
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
||||
}
|
||||
|
||||
// регистрируем зависимости
|
||||
extBusiness.RegisterServices();
|
||||
}
|
||||
|
||||
//Регистрация логгера
|
||||
public void AddLogging(Action<ILoggingBuilder> configure) => _dependencyManager.AddLogging(configure);
|
||||
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlacksmithWorkshopContracts.DI
|
||||
{
|
||||
public interface IBusinessLogicImplementationExtension
|
||||
{
|
||||
public int Priority { get; }
|
||||
|
||||
//Регистрация сервисов
|
||||
public void RegisterServices();
|
||||
}
|
||||
}
|
@ -57,5 +57,51 @@ namespace BlacksmithWorkshopContracts.DI
|
||||
|
||||
return $"{directory?.FullName}\\ImplementationExtensions";
|
||||
}
|
||||
}
|
||||
|
||||
public static IBusinessLogicImplementationExtension? GetBusinessLogicImplementationExtensions()
|
||||
{
|
||||
IBusinessLogicImplementationExtension? 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(IBusinessLogicImplementationExtension).IsAssignableFrom(t))
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
source = (IBusinessLogicImplementationExtension)Activator.CreateInstance(t)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSource = (IBusinessLogicImplementationExtension)Activator.CreateInstance(t)!;
|
||||
|
||||
if (newSource.Priority > source.Priority)
|
||||
{
|
||||
source = newSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user