RhSolutions-AddIn/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs

50 lines
1.6 KiB
C#
Raw Normal View History

2023-04-06 21:38:01 +03:00
using System.Net;
2023-04-06 08:29:39 +03:00
#if !NET472
using System.Runtime.Versioning;
#endif
2021-12-24 16:22:03 +03:00
2023-03-28 10:03:19 +03:00
namespace RhSolutions.AddIn;
2023-04-06 08:29:39 +03:00
#if !NET472
[SupportedOSPlatform("windows")]
#endif
2023-03-28 10:03:19 +03:00
public sealed class RhSolutionsAddIn : IExcelAddIn
2021-11-29 15:50:24 +03:00
{
2023-03-28 10:03:19 +03:00
public static Application Excel { get; private set; }
public static ServiceProvider ServiceProvider { get; private set; }
public static IAddInConfiguration Configuration { get; private set; }
2023-03-28 10:03:19 +03:00
public void AutoOpen()
{
IServiceCollection Services = new ServiceCollection();
Services.AddHttpClient()
2023-04-06 08:29:39 +03:00
.AddSingleton((Application)ExcelDnaUtil.Application)
.AddSingleton<IAddInConfiguration, RhAddInConfiguration>()
2023-04-17 08:49:26 +03:00
.AddSingleton<IDatabaseClient, RhDatabaseClient>()
2023-04-06 08:29:39 +03:00
.AddTransient<IFileDialog, ExcelFileDialog>()
2023-04-17 08:49:26 +03:00
.AddTransient<IExcelReader, RhExcelReader>();
Services.AddSingleton<WriterFactory>();
Services.AddTransient<RhExcelWriter>()
.AddTransient<IExcelWriter, RhExcelWriter>(s => s.GetService<RhExcelWriter>());
Services.AddTransient<RhDxfWriter>()
.AddTransient<IExcelWriter, RhDxfWriter>(s => s.GetService<RhDxfWriter>());
2023-03-28 10:03:19 +03:00
2023-04-14 08:08:46 +03:00
Services.AddSingleton<ToolFactory>();
2023-03-28 10:03:19 +03:00
ServiceProvider = Services.BuildServiceProvider();
Configuration = ServiceProvider.GetService<IAddInConfiguration>();
Excel = ServiceProvider.GetService<Application>();
EventsUtil.Initialize();
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12;
}
public void AutoClose()
2021-11-29 15:50:24 +03:00
{
2023-03-28 10:03:19 +03:00
EventsUtil.Uninitialize();
2021-11-29 15:50:24 +03:00
}
}