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

59 lines
2.3 KiB
C#
Raw Normal View History

2023-04-06 21:38:01 +03:00
using System.Net;
2021-12-24 16:22:03 +03:00
2023-03-28 10:03:19 +03:00
namespace RhSolutions.AddIn;
public sealed class RhSolutionsAddIn : IExcelAddIn
2021-11-29 15:50:24 +03:00
{
2024-01-21 14:51:38 +03:00
public static readonly Application Excel = (Application)ExcelDnaUtil.Application;
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-05-16 07:43:57 +03:00
.AddMemoryCache()
2023-04-20 09:37:07 +03:00
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
.AddSingleton<IDatabaseClient, DatabaseClient>()
.AddSingleton<ICurrencyClient, CurrencyClient>()
2023-05-22 07:39:48 +03:00
.AddTransient<IFileDialog, FileDialog>();
2023-04-17 08:49:26 +03:00
Services.AddSingleton<WriterFactory>();
2023-06-20 07:25:44 +03:00
Services.AddTransient<NewPriceWriter>()
.AddTransient<IWriter, NewPriceWriter>(s => s.GetService<NewPriceWriter>());
2023-04-20 09:37:07 +03:00
Services.AddTransient<DxfWriter>()
.AddTransient<IWriter, DxfWriter>(s => s.GetService<DxfWriter>());
2023-06-20 09:46:52 +03:00
Services.AddTransient<CurrentPriceWriter>()
.AddTransient<IWriter, CurrentPriceWriter>(s => s.GetService<CurrentPriceWriter>());
2023-03-28 10:03:19 +03:00
2023-05-22 07:39:48 +03:00
Services.AddSingleton<ReaderFactory>();
Services.AddTransient<ExcelReader>()
.AddTransient<IReader, ExcelReader>(s => s.GetService<ExcelReader>());
2023-05-23 07:07:16 +03:00
Services.AddTransient<GuessReader>()
.AddTransient<IReader, GuessReader>(s => s.GetService<GuessReader>());
2023-05-22 07:39:48 +03:00
2023-11-09 23:34:52 +03:00
Services.AddSingleton<FittingsCalculatorFactory>();
Services.AddTransient<CouplingsCalculator>()
.AddTransient<IFittingsCalculator, CouplingsCalculator>(s => s.GetService<CouplingsCalculator>());
Services.AddTransient<SleevesCalculator>()
.AddTransient<IFittingsCalculator, SleevesCalculator>(s => s.GetService<SleevesCalculator>());
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>();
EventsUtil.Initialize();
2023-05-17 08:03:55 +03:00
2023-03-28 10:03:19 +03:00
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12;
2024-01-21 14:52:02 +03:00
ServicePointManager.DefaultConnectionLimit = 50;
2023-03-28 10:03:19 +03:00
}
public void AutoClose()
2021-11-29 15:50:24 +03:00
{
2023-11-12 14:57:43 +03:00
EventsUtil.Uninitialize();
2021-11-29 15:50:24 +03:00
}
}