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

43 lines
1.3 KiB
C#
Raw Normal View History

2021-11-29 15:50:24 +03:00
using ExcelDna.Integration;
using ExcelDna.IntelliSense;
2023-03-27 07:12:04 +03:00
using Microsoft.Extensions.DependencyInjection;
2022-01-09 15:47:54 +03:00
using Microsoft.Office.Interop.Excel;
2022-12-20 12:27:47 +03:00
using RhSolutions.Services;
2023-03-28 07:25:10 +03:00
using System;
2022-12-20 12:58:30 +03:00
using System.Net;
2021-12-24 16:22:03 +03:00
2022-12-20 12:41:46 +03:00
namespace RhSolutions.AddIn
2021-11-29 15:50:24 +03:00
{
2023-03-27 07:12:04 +03:00
public class RhSolutionsAddIn : IExcelAddIn
2021-11-29 15:50:24 +03:00
{
public static Application Excel { get; private set; }
2023-03-27 07:12:04 +03:00
public static ServiceProvider ServiceProvider { get; set; }
2023-03-28 07:25:10 +03:00
public static IAddInConfiguration Configuration { get; set; }
2021-11-29 15:50:24 +03:00
public void AutoOpen()
{
2023-03-27 07:12:04 +03:00
IServiceCollection Services = new ServiceCollection();
2023-03-27 13:55:58 +03:00
Excel = (Application)ExcelDnaUtil.Application;
Services.AddHttpClient()
2023-03-28 07:25:10 +03:00
.AddSingleton<IDatabaseClient, RhDatabaseClient>()
.AddSingleton<IAddInConfiguration, AddInConfiguration>();
2023-03-27 13:55:58 +03:00
2023-03-27 07:12:04 +03:00
ServiceProvider = Services.BuildServiceProvider();
2023-03-28 07:25:10 +03:00
Configuration = ServiceProvider.GetService<IAddInConfiguration>();
IntelliSenseServer.Install();
2022-02-05 12:59:16 +03:00
EventsUtil.Initialize();
2022-12-20 12:58:30 +03:00
ServicePointManager.SecurityProtocol =
2022-12-26 15:02:45 +03:00
SecurityProtocolType.Tls12;
2021-11-29 15:50:24 +03:00
}
public void AutoClose()
{
IntelliSenseServer.Uninstall();
2022-02-05 12:59:16 +03:00
EventsUtil.Uninitialize();
2021-11-29 15:50:24 +03:00
}
}
}