84 lines
2.7 KiB
C#
84 lines
2.7 KiB
C#
using System.Net;
|
|
using ExcelDna.IntelliSense;
|
|
#if !NET472
|
|
using System.Runtime.Versioning;
|
|
#endif
|
|
|
|
namespace RhSolutions.AddIn;
|
|
|
|
#if !NET472
|
|
[SupportedOSPlatform("windows")]
|
|
#endif
|
|
public sealed class RhSolutionsAddIn : IExcelAddIn
|
|
{
|
|
public static Application Excel { get; private set; }
|
|
public static ServiceProvider ServiceProvider { get; private set; }
|
|
public static IAddInConfiguration Configuration { get; private set; }
|
|
|
|
public void AutoOpen()
|
|
{
|
|
IServiceCollection Services = new ServiceCollection();
|
|
|
|
Services.AddHttpClient()
|
|
.AddMemoryCache()
|
|
.AddSingleton((Application)ExcelDnaUtil.Application)
|
|
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
|
|
.AddSingleton<IDatabaseClient, DatabaseClient>()
|
|
.AddSingleton<ICurrencyClient, CurrencyClient>()
|
|
.AddSingleton<ISleevesCalculator, SleevesCalculator>()
|
|
.AddTransient<IFileDialog, FileDialog>();
|
|
|
|
Services.AddSingleton<WriterFactory>();
|
|
Services.AddTransient<NewPriceWriter>()
|
|
.AddTransient<IWriter, NewPriceWriter>(s => s.GetService<NewPriceWriter>());
|
|
Services.AddTransient<DxfWriter>()
|
|
.AddTransient<IWriter, DxfWriter>(s => s.GetService<DxfWriter>());
|
|
Services.AddTransient<CurrentPriceWriter>()
|
|
.AddTransient<IWriter, CurrentPriceWriter>(s => s.GetService<CurrentPriceWriter>());
|
|
|
|
Services.AddSingleton<ReaderFactory>();
|
|
Services.AddTransient<ExcelReader>()
|
|
.AddTransient<IReader, ExcelReader>(s => s.GetService<ExcelReader>());
|
|
Services.AddTransient<GuessReader>()
|
|
.AddTransient<IReader, GuessReader>(s => s.GetService<GuessReader>());
|
|
|
|
Services.AddSingleton<ToolFactory>();
|
|
|
|
ServiceProvider = Services.BuildServiceProvider();
|
|
Configuration = ServiceProvider.GetService<IAddInConfiguration>();
|
|
Excel = ServiceProvider.GetService<Application>();
|
|
|
|
EventsUtil.Initialize();
|
|
|
|
bool isTesting = Environment.GetEnvironmentVariable("ISTESTING") switch
|
|
{
|
|
"true" => true,
|
|
"false" => false,
|
|
_ => false
|
|
};
|
|
if (!isTesting)
|
|
{
|
|
IntelliSenseServer.Install();
|
|
}
|
|
|
|
ServicePointManager.SecurityProtocol =
|
|
SecurityProtocolType.Tls12;
|
|
}
|
|
|
|
public void AutoClose()
|
|
{
|
|
EventsUtil.Uninitialize();
|
|
|
|
bool isTesting = Environment.GetEnvironmentVariable("ISTESTING") switch
|
|
{
|
|
"true" => true,
|
|
"false" => false,
|
|
_ => false
|
|
};
|
|
if (!isTesting)
|
|
{
|
|
IntelliSenseServer.Uninstall();
|
|
}
|
|
}
|
|
}
|