aboutsummaryrefslogtreecommitdiff
path: root/src/AddIn/AddIn.cs
blob: b532bfbfd71d73ff3f29a57af74186fc13c7ca34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using ExcelDna.Integration;
using ExcelDna.IntelliSense;
using ExcelDna.Registration;
using Microsoft.Office.Interop.Excel;
using System.Net.Http;
using System.Runtime.Caching;

namespace RehauSku
{
    enum ResponseOrder
    {
        Default,
        Relevance,
        Name,
        Price,
        Series
    }

    class AddIn : IExcelAddIn
    {
        public static HttpClient httpClient;
        public static MemoryCache memoryCache;
        public static Application Excel;

        public void AutoOpen()
        {
            httpClient = new HttpClient();
            memoryCache = new MemoryCache("RehauSku");
            Excel = (Application)ExcelDnaUtil.Application;
            RegisterFunctions();
            IntelliSenseServer.Install();
            RegistryUtil.Initialize();
            EventsUtil.Initialize();
        }

        public void AutoClose()
        {
            IntelliSenseServer.Uninstall();
            RegistryUtil.Uninitialize();
            EventsUtil.Uninitialize();
            memoryCache.Dispose();
        }

        void RegisterFunctions()
        {
            ExcelRegistration.GetExcelFunctions()
                             .ProcessAsyncRegistrations(nativeAsyncIfAvailable: false)
                             .RegisterFunctions();
        }
    }
}