2023-04-06 21:38:01 +03:00
|
|
|
|
using System.Net;
|
2023-05-17 07:40:26 +03:00
|
|
|
|
using ExcelDna.IntelliSense;
|
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-05-16 07:43:57 +03:00
|
|
|
|
.AddMemoryCache()
|
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>()
|
2023-05-15 06:33:24 +03:00
|
|
|
|
.AddTransient<ICurrencyClient, CurrencyClient>()
|
2023-04-20 09:37:07 +03:00
|
|
|
|
.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();
|
2023-05-17 07:40:26 +03:00
|
|
|
|
string variable = Environment.GetEnvironmentVariable("ISTESTING");
|
|
|
|
|
bool isTesting = variable switch
|
|
|
|
|
{
|
|
|
|
|
"true" => true,
|
|
|
|
|
"false" => false,
|
|
|
|
|
_ => false
|
|
|
|
|
};
|
|
|
|
|
if (!isTesting)
|
|
|
|
|
{
|
|
|
|
|
IntelliSenseServer.Install();
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-28 10:03:19 +03:00
|
|
|
|
ServicePointManager.SecurityProtocol =
|
|
|
|
|
SecurityProtocolType.Tls12;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AutoClose()
|
2021-11-29 15:50:24 +03:00
|
|
|
|
{
|
2023-05-17 07:40:26 +03:00
|
|
|
|
EventsUtil.Uninitialize(); bool isTesting = Environment.GetEnvironmentVariable("ISTESTING") switch
|
|
|
|
|
{
|
|
|
|
|
"true" => true,
|
|
|
|
|
"false" => false,
|
|
|
|
|
_ => false
|
|
|
|
|
};
|
|
|
|
|
if (!isTesting)
|
|
|
|
|
{
|
|
|
|
|
IntelliSenseServer.Uninstall();
|
|
|
|
|
}
|
2021-11-29 15:50:24 +03:00
|
|
|
|
}
|
|
|
|
|
}
|