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; }
|
2023-04-06 21:36:24 +03:00
|
|
|
|
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)
|
2023-04-20 09:37:07 +03:00
|
|
|
|
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
|
|
|
|
|
.AddSingleton<IDatabaseClient, DatabaseClient>()
|
|
|
|
|
.AddTransient<IFileDialog, FileDialog>()
|
|
|
|
|
.AddTransient<IReader, ExcelReader>();
|
2023-04-17 08:49:26 +03:00
|
|
|
|
|
|
|
|
|
Services.AddSingleton<WriterFactory>();
|
2023-04-20 09:37:07 +03:00
|
|
|
|
Services.AddTransient<ExcelWriter>()
|
|
|
|
|
.AddTransient<IWriter, ExcelWriter>(s => s.GetService<ExcelWriter>());
|
|
|
|
|
Services.AddTransient<DxfWriter>()
|
|
|
|
|
.AddTransient<IWriter, DxfWriter>(s => s.GetService<DxfWriter>());
|
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
|
|
|
|
}
|
|
|
|
|
}
|