From 8a869e73fb1873b1f85203b7a4a18dc8a2325a11 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 8 Dec 2021 14:38:23 +0300 Subject: Rename dir ExcelDNA -> AddIn --- Source/AddIn/AddIn.cs | 53 +++++++++++++++++++++++++++++++++++++++++++++++ Source/AddIn/Functions.cs | 19 +++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Source/AddIn/AddIn.cs create mode 100644 Source/AddIn/Functions.cs (limited to 'Source/AddIn') diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs new file mode 100644 index 0000000..3c82406 --- /dev/null +++ b/Source/AddIn/AddIn.cs @@ -0,0 +1,53 @@ +using ExcelDna.Integration; +using ExcelDna.Registration; +using Microsoft.Win32; +using System.Net.Http; + +namespace RehauSku.Assist +{ + public enum ResponseOrder + { + Default, + Relevance, + Name, + Price, + Series + } + + public class AddIn : IExcelAddIn + { + public static readonly HttpClient httpClient = new HttpClient(); + public static ResponseOrder responseOrder; + public static string priceListPath; + + public void AutoOpen() + { + RegisterFunctions(); + GetRegistryKeys(); + } + + public void AutoClose() + { + + } + + void RegisterFunctions() + { + ExcelRegistration.GetExcelFunctions() + .ProcessAsyncRegistrations(nativeAsyncIfAvailable: false) + .RegisterFunctions(); + } + + void GetRegistryKeys() + { + RegistryKey addInKeys = Registry + .CurrentUser + .OpenSubKey("SOFTWARE") + .OpenSubKey("REHAU") + .OpenSubKey("SkuAssist"); + + responseOrder = (ResponseOrder)addInKeys.GetValue("ResponseOrder"); + priceListPath = (string)addInKeys.GetValue("PriceListPath"); + } + } +} diff --git a/Source/AddIn/Functions.cs b/Source/AddIn/Functions.cs new file mode 100644 index 0000000..6d94e24 --- /dev/null +++ b/Source/AddIn/Functions.cs @@ -0,0 +1,19 @@ +using ExcelDna.Integration; + +namespace RehauSku.Assist +{ + public class Functions + { + [ExcelFunction] + public static object RAUNAME(string request) + => SkuAssist.GetProduct(request, ProductField.Name); + + [ExcelFunction] + public static object RAUSKU(string request) + => SkuAssist.GetProduct(request, ProductField.Id); + + [ExcelFunction] + public static object RAUPRICE(string request) + => SkuAssist.GetProduct(request, ProductField.Price); + } +} \ No newline at end of file -- cgit v1.2.3 From dc1fc8b221e9324fe0f82c4ea4a32d87d282bd25 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 8 Dec 2021 14:45:14 +0300 Subject: refactoring namespaces --- Source/AddIn/AddIn.cs | 2 +- Source/AddIn/Functions.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'Source/AddIn') diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs index 3c82406..5255e2e 100644 --- a/Source/AddIn/AddIn.cs +++ b/Source/AddIn/AddIn.cs @@ -3,7 +3,7 @@ using ExcelDna.Registration; using Microsoft.Win32; using System.Net.Http; -namespace RehauSku.Assist +namespace RehauSku { public enum ResponseOrder { diff --git a/Source/AddIn/Functions.cs b/Source/AddIn/Functions.cs index 6d94e24..c6e9da4 100644 --- a/Source/AddIn/Functions.cs +++ b/Source/AddIn/Functions.cs @@ -1,6 +1,7 @@ using ExcelDna.Integration; +using RehauSku.Assistant; -namespace RehauSku.Assist +namespace RehauSku { public class Functions { -- cgit v1.2.3 From b7c65d64e98092049fddc1b482bfc7aa97759d60 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 10 Dec 2021 13:56:28 +0300 Subject: Refactoring --- Source/AddIn/AddIn.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Source/AddIn') diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs index 5255e2e..e29c070 100644 --- a/Source/AddIn/AddIn.cs +++ b/Source/AddIn/AddIn.cs @@ -17,8 +17,8 @@ namespace RehauSku public class AddIn : IExcelAddIn { public static readonly HttpClient httpClient = new HttpClient(); - public static ResponseOrder responseOrder; - public static string priceListPath; + public static ResponseOrder StoreResponse { get; set; } + public static string PriceListPath { get; set; } public void AutoOpen() { @@ -46,8 +46,8 @@ namespace RehauSku .OpenSubKey("REHAU") .OpenSubKey("SkuAssist"); - responseOrder = (ResponseOrder)addInKeys.GetValue("ResponseOrder"); - priceListPath = (string)addInKeys.GetValue("PriceListPath"); + StoreResponse = (ResponseOrder)addInKeys.GetValue("ResponseOrder"); + PriceListPath = (string)addInKeys.GetValue("PriceListPath"); } } } -- cgit v1.2.3 From e175a634cefc6e8c0ecd49514a89b1d4f30ce33b Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Mon, 13 Dec 2021 20:39:41 +0300 Subject: Refactoring. ExcelDNA.IntelliSense library add. Add description to Excel functions. --- Source/AddIn/AddIn.cs | 4 +++- Source/AddIn/Functions.cs | 54 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 10 deletions(-) (limited to 'Source/AddIn') diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs index e29c070..5cae777 100644 --- a/Source/AddIn/AddIn.cs +++ b/Source/AddIn/AddIn.cs @@ -1,4 +1,5 @@ using ExcelDna.Integration; +using ExcelDna.IntelliSense; using ExcelDna.Registration; using Microsoft.Win32; using System.Net.Http; @@ -24,11 +25,12 @@ namespace RehauSku { RegisterFunctions(); GetRegistryKeys(); + IntelliSenseServer.Install(); } public void AutoClose() { - + IntelliSenseServer.Uninstall(); } void RegisterFunctions() diff --git a/Source/AddIn/Functions.cs b/Source/AddIn/Functions.cs index c6e9da4..2ae22e4 100644 --- a/Source/AddIn/Functions.cs +++ b/Source/AddIn/Functions.cs @@ -5,16 +5,52 @@ namespace RehauSku { public class Functions { - [ExcelFunction] - public static object RAUNAME(string request) - => SkuAssist.GetProduct(request, ProductField.Name); + [ExcelFunction(Description = "Получение названия первого продукта по запросу в интернет-магазин REHAU")] + public static object RAUNAME([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request) + => MakeRequest(request, ProductField.Name); - [ExcelFunction] - public static object RAUSKU(string request) - => SkuAssist.GetProduct(request, ProductField.Id); + [ExcelFunction(Description = "Получение артикула первого продукта по запросу в интернет-магазин REHAU")] + public static object RAUSKU([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request) + => MakeRequest(request, ProductField.Id); - [ExcelFunction] - public static object RAUPRICE(string request) - => SkuAssist.GetProduct(request, ProductField.Price); + [ExcelFunction(Description = "Получение цены первого продукта по запросу в интернет-магазин REHAU")] + public static object RAUPRICE([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request) + => MakeRequest(request, ProductField.Price); + + private static object MakeRequest(string request, ProductField field) + { + object result; + + if (request.IsCached()) + result = request.GetFromCache(); + + else + { + result = ExcelAsyncUtil.Run("Request", request, delegate + { + return request.RequestAndCache().GetAwaiter().GetResult(); + }); + } + + if (result == null) + return "Не найдено :("; + + if (result.Equals(ExcelError.ExcelErrorNA)) + return "Загрузка..."; + + IProduct product = result as IProduct; + + switch (field) + { + case ProductField.Name: + return product.Name; + case ProductField.Id: + return product.Id; + case ProductField.Price: + return double.Parse(product.Price, System.Globalization.CultureInfo.InvariantCulture); + default: + return null; + } + } } } \ No newline at end of file -- cgit v1.2.3 From 2511d1b4440d7c450eb50e1eafdc2ac11b42a5e0 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 17 Dec 2021 09:07:03 +0300 Subject: Add RegistryUtil --- Source/AddIn/AddIn.cs | 18 ++--------- Source/AddIn/RegistryUtil.cs | 76 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 Source/AddIn/RegistryUtil.cs (limited to 'Source/AddIn') diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs index 5cae777..7a2be5d 100644 --- a/Source/AddIn/AddIn.cs +++ b/Source/AddIn/AddIn.cs @@ -1,7 +1,6 @@ using ExcelDna.Integration; using ExcelDna.IntelliSense; using ExcelDna.Registration; -using Microsoft.Win32; using System.Net.Http; namespace RehauSku @@ -18,13 +17,12 @@ namespace RehauSku public class AddIn : IExcelAddIn { public static readonly HttpClient httpClient = new HttpClient(); - public static ResponseOrder StoreResponse { get; set; } - public static string PriceListPath { get; set; } + public static ResponseOrder StoreResponseOrder = RegistryUtil.StoreResponseOrder; + public static string PriceListPath = RegistryUtil.PriceListPath; public void AutoOpen() { RegisterFunctions(); - GetRegistryKeys(); IntelliSenseServer.Install(); } @@ -39,17 +37,5 @@ namespace RehauSku .ProcessAsyncRegistrations(nativeAsyncIfAvailable: false) .RegisterFunctions(); } - - void GetRegistryKeys() - { - RegistryKey addInKeys = Registry - .CurrentUser - .OpenSubKey("SOFTWARE") - .OpenSubKey("REHAU") - .OpenSubKey("SkuAssist"); - - StoreResponse = (ResponseOrder)addInKeys.GetValue("ResponseOrder"); - PriceListPath = (string)addInKeys.GetValue("PriceListPath"); - } } } diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs new file mode 100644 index 0000000..105d5af --- /dev/null +++ b/Source/AddIn/RegistryUtil.cs @@ -0,0 +1,76 @@ +using Microsoft.Win32; + +namespace RehauSku +{ + static class RegistryUtil + { + public static string PriceListPath + { + get + { + _GetRootKey(); + + if (_RootKey == null) + { + return @"D:\Dropbox\Рабочее\Таблица заказов ИС EAE_2021.xlsm"; + } + + else return (string)_RootKey.GetValue("PriceListPath"); + } + + private set + { + _GetRootKey(); + + if (_RootKey == null) + { + RegistryKey PriceListPath = Registry.CurrentUser + .CreateSubKey("SOFTWARE") + .CreateSubKey("REHAU") + .CreateSubKey("SkuAssist"); + } + + _RootKey.SetValue("PriceListPath", value); + } + } + + public static ResponseOrder StoreResponseOrder + { + get + { + _GetRootKey(); + + if (_RootKey == null) + { + return ResponseOrder.Default; + } + + return (ResponseOrder)_RootKey.GetValue("ResponseOrder"); + } + + private set + { + if (_RootKey == null) + { + RegistryKey PriceListPath = Registry.CurrentUser + .CreateSubKey("SOFTWARE") + .CreateSubKey("REHAU") + .CreateSubKey("SkuAssist"); + } + + _RootKey.SetValue("ResponseOrder", value); + } + } + + private static RegistryKey _RootKey { get; set; } + + private static void _GetRootKey() + { + _RootKey = Registry + .CurrentUser + .OpenSubKey("SOFTWARE") + .OpenSubKey("REHAU") + .OpenSubKey("SkuAssist"); + } + } +} -- cgit v1.2.3 From f97d344f39c46b5e2f883765e8859e78007a11b0 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 22 Dec 2021 08:26:54 +0300 Subject: Add Registry Util --- Source/AddIn/AddIn.cs | 4 +-- Source/AddIn/Functions.cs | 12 +++---- Source/AddIn/RegistryUtil.cs | 74 ++++++++++++-------------------------------- 3 files changed, 27 insertions(+), 63 deletions(-) (limited to 'Source/AddIn') diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs index 7a2be5d..4a26f55 100644 --- a/Source/AddIn/AddIn.cs +++ b/Source/AddIn/AddIn.cs @@ -16,9 +16,7 @@ namespace RehauSku public class AddIn : IExcelAddIn { - public static readonly HttpClient httpClient = new HttpClient(); - public static ResponseOrder StoreResponseOrder = RegistryUtil.StoreResponseOrder; - public static string PriceListPath = RegistryUtil.PriceListPath; + public static HttpClient httpClient = new HttpClient(); public void AutoOpen() { diff --git a/Source/AddIn/Functions.cs b/Source/AddIn/Functions.cs index 2ae22e4..618d17d 100644 --- a/Source/AddIn/Functions.cs +++ b/Source/AddIn/Functions.cs @@ -5,16 +5,16 @@ namespace RehauSku { public class Functions { - [ExcelFunction(Description = "Получение названия первого продукта по запросу в интернет-магазин REHAU")] - public static object RAUNAME([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request) + [ExcelFunction(description: "Получение названия первого продукта в поиске")] + public static object RAUNAME([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request) => MakeRequest(request, ProductField.Name); - [ExcelFunction(Description = "Получение артикула первого продукта по запросу в интернет-магазин REHAU")] - public static object RAUSKU([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request) + [ExcelFunction(Description = "Получение артикула первого продукта в поиске")] + public static object RAUSKU([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request) => MakeRequest(request, ProductField.Id); - [ExcelFunction(Description = "Получение цены первого продукта по запросу в интернет-магазин REHAU")] - public static object RAUPRICE([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request) + [ExcelFunction(Description = "Получение цены первого продукта в поиске")] + public static object RAUPRICE([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request) => MakeRequest(request, ProductField.Price); private static object MakeRequest(string request, ProductField field) diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs index 105d5af..6ab7682 100644 --- a/Source/AddIn/RegistryUtil.cs +++ b/Source/AddIn/RegistryUtil.cs @@ -6,71 +6,37 @@ namespace RehauSku { public static string PriceListPath { - get - { - _GetRootKey(); - - if (_RootKey == null) - { - return @"D:\Dropbox\Рабочее\Таблица заказов ИС EAE_2021.xlsm"; - } - - else return (string)_RootKey.GetValue("PriceListPath"); - } - - private set - { - _GetRootKey(); - - if (_RootKey == null) - { - RegistryKey PriceListPath = Registry.CurrentUser - .CreateSubKey("SOFTWARE") - .CreateSubKey("REHAU") - .CreateSubKey("SkuAssist"); - } - - _RootKey.SetValue("PriceListPath", value); - } + get => (string)_RootKey.GetValue("PriceListPath"); } public static ResponseOrder StoreResponseOrder { - get - { - _GetRootKey(); - - if (_RootKey == null) - { - return ResponseOrder.Default; - } - - return (ResponseOrder)_RootKey.GetValue("ResponseOrder"); - } + get => (ResponseOrder)_RootKey.GetValue("StoreResponseOrder"); + } - private set + private static RegistryKey _RootKey + { + get { - if (_RootKey == null) - { - RegistryKey PriceListPath = Registry.CurrentUser - .CreateSubKey("SOFTWARE") - .CreateSubKey("REHAU") - .CreateSubKey("SkuAssist"); - } - - _RootKey.SetValue("ResponseOrder", value); + return _OpenRootKey() ?? _CreateRootKey(); } } - private static RegistryKey _RootKey { get; set; } + private static RegistryKey _OpenRootKey() + { + return Registry.CurrentUser + .OpenSubKey(@"SOFTWARE\REHAU\SkuAssist"); + } - private static void _GetRootKey() + private static RegistryKey _CreateRootKey() { - _RootKey = Registry - .CurrentUser - .OpenSubKey("SOFTWARE") - .OpenSubKey("REHAU") - .OpenSubKey("SkuAssist"); + RegistryKey key = Registry.CurrentUser + .CreateSubKey(@"SOFTWARE\REHAU\SkuAssist"); + + key.SetValue("PriceListPath", @"D:\Dropbox\Рабочее\Таблица заказов ИС EAE_2021.xlsm"); + key.SetValue("StoreResponseOrder", 0); + + return key; } } } -- cgit v1.2.3 From ce5597d042062c820288c63b4e571ee77ac23ab0 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 22 Dec 2021 17:07:37 +0300 Subject: RegistryUtil and some fixes --- Source/AddIn/AddIn.cs | 1 + Source/AddIn/FileDialog.cs | 24 +++++++++++++++++++ Source/AddIn/RegistryUtil.cs | 57 +++++++++++++++++++++++++++++--------------- 3 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 Source/AddIn/FileDialog.cs (limited to 'Source/AddIn') diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs index 4a26f55..08b6dcf 100644 --- a/Source/AddIn/AddIn.cs +++ b/Source/AddIn/AddIn.cs @@ -22,6 +22,7 @@ namespace RehauSku { RegisterFunctions(); IntelliSenseServer.Install(); + RegistryUtil.Initialize(); } public void AutoClose() diff --git a/Source/AddIn/FileDialog.cs b/Source/AddIn/FileDialog.cs new file mode 100644 index 0000000..a7e2144 --- /dev/null +++ b/Source/AddIn/FileDialog.cs @@ -0,0 +1,24 @@ +using System.Windows.Forms; + +namespace RehauSku +{ + static class FileDialog + { + public static string GetFilePath() + { + string filePath = string.Empty; + + using (OpenFileDialog dialog = new OpenFileDialog()) + { + dialog.Filter = "Все файлы (*.*)|*.*"; + + if (dialog.ShowDialog() == DialogResult.OK) + { + filePath = dialog.FileName; + } + } + + return filePath; + } + } +} diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs index 6ab7682..19f48b8 100644 --- a/Source/AddIn/RegistryUtil.cs +++ b/Source/AddIn/RegistryUtil.cs @@ -1,42 +1,61 @@ using Microsoft.Win32; +using System.IO; namespace RehauSku { static class RegistryUtil { - public static string PriceListPath + private static string _priceListPath; + private static int? _storeResponseOrder; + private static RegistryKey _RootKey { get; set; } + + public static void Initialize() { - get => (string)_RootKey.GetValue("PriceListPath"); + _RootKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\REHAU\SkuAssist"); + _priceListPath = _RootKey.GetValue("PriceListPath") as string; + _storeResponseOrder = _RootKey.GetValue("StoreResponseOrder") as int?; } - public static ResponseOrder StoreResponseOrder + public static bool IsPriceListPathEmpty() { - get => (ResponseOrder)_RootKey.GetValue("StoreResponseOrder"); + return string.IsNullOrEmpty(_priceListPath); } - private static RegistryKey _RootKey + public static string PriceListPath { get { - return _OpenRootKey() ?? _CreateRootKey(); - } - } + if (IsPriceListPathEmpty() || !File.Exists(_priceListPath)) + { + string fileName = FileDialog.GetFilePath(); + _priceListPath = fileName; + _RootKey.SetValue("PriceListPath", fileName); + return _priceListPath; + } - private static RegistryKey _OpenRootKey() - { - return Registry.CurrentUser - .OpenSubKey(@"SOFTWARE\REHAU\SkuAssist"); + else + { + return _priceListPath; + } + } } - private static RegistryKey _CreateRootKey() + public static ResponseOrder StoreResponseOrder { - RegistryKey key = Registry.CurrentUser - .CreateSubKey(@"SOFTWARE\REHAU\SkuAssist"); - - key.SetValue("PriceListPath", @"D:\Dropbox\Рабочее\Таблица заказов ИС EAE_2021.xlsm"); - key.SetValue("StoreResponseOrder", 0); + get + { + if (_storeResponseOrder == null) + { + _RootKey.SetValue("StoreResponseOrder", (int)ResponseOrder.Default); + _storeResponseOrder = (int)ResponseOrder.Default; + return (ResponseOrder)_storeResponseOrder.Value; + } - return key; + else + { + return (ResponseOrder)_storeResponseOrder.Value; + } + } } } } -- cgit v1.2.3 From 0513ac5ad7c7de498b794c27728c2c8ff306f941 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Thu, 23 Dec 2021 15:31:23 +0300 Subject: Rename to ExportTool --- Source/AddIn/AddIn.cs | 1 + Source/AddIn/RegistryUtil.cs | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'Source/AddIn') diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs index 08b6dcf..014b607 100644 --- a/Source/AddIn/AddIn.cs +++ b/Source/AddIn/AddIn.cs @@ -28,6 +28,7 @@ namespace RehauSku public void AutoClose() { IntelliSenseServer.Uninstall(); + RegistryUtil.Uninitialize(); } void RegisterFunctions() diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs index 19f48b8..ef1398e 100644 --- a/Source/AddIn/RegistryUtil.cs +++ b/Source/AddIn/RegistryUtil.cs @@ -16,6 +16,11 @@ namespace RehauSku _storeResponseOrder = _RootKey.GetValue("StoreResponseOrder") as int?; } + public static void Uninitialize() + { + _RootKey.Close(); + } + public static bool IsPriceListPathEmpty() { return string.IsNullOrEmpty(_priceListPath); -- cgit v1.2.3 From 24024b5729c1c44bb01cb29813868743d1753e31 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 24 Dec 2021 16:22:03 +0300 Subject: MergeTool, MemoryUtil anf stuff --- Source/AddIn/AddIn.cs | 8 +++++++- Source/AddIn/FileDialog.cs | 24 ------------------------ Source/AddIn/MemoryCacheUtil.cs | 37 +++++++++++++++++++++++++++++++++++++ Source/AddIn/RegistryUtil.cs | 6 +++++- 4 files changed, 49 insertions(+), 26 deletions(-) delete mode 100644 Source/AddIn/FileDialog.cs create mode 100644 Source/AddIn/MemoryCacheUtil.cs (limited to 'Source/AddIn') diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs index 014b607..67cdcc8 100644 --- a/Source/AddIn/AddIn.cs +++ b/Source/AddIn/AddIn.cs @@ -2,6 +2,8 @@ using ExcelDna.IntelliSense; using ExcelDna.Registration; using System.Net.Http; +using System.Runtime.Caching; + namespace RehauSku { @@ -16,10 +18,13 @@ namespace RehauSku public class AddIn : IExcelAddIn { - public static HttpClient httpClient = new HttpClient(); + public static HttpClient httpClient; + public static MemoryCache memoryCache; public void AutoOpen() { + httpClient = new HttpClient(); + memoryCache = new MemoryCache("RehauSku"); RegisterFunctions(); IntelliSenseServer.Install(); RegistryUtil.Initialize(); @@ -29,6 +34,7 @@ namespace RehauSku { IntelliSenseServer.Uninstall(); RegistryUtil.Uninitialize(); + memoryCache.Dispose(); } void RegisterFunctions() diff --git a/Source/AddIn/FileDialog.cs b/Source/AddIn/FileDialog.cs deleted file mode 100644 index a7e2144..0000000 --- a/Source/AddIn/FileDialog.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Windows.Forms; - -namespace RehauSku -{ - static class FileDialog - { - public static string GetFilePath() - { - string filePath = string.Empty; - - using (OpenFileDialog dialog = new OpenFileDialog()) - { - dialog.Filter = "Все файлы (*.*)|*.*"; - - if (dialog.ShowDialog() == DialogResult.OK) - { - filePath = dialog.FileName; - } - } - - return filePath; - } - } -} diff --git a/Source/AddIn/MemoryCacheUtil.cs b/Source/AddIn/MemoryCacheUtil.cs new file mode 100644 index 0000000..1d42e14 --- /dev/null +++ b/Source/AddIn/MemoryCacheUtil.cs @@ -0,0 +1,37 @@ +using System; +using System.Runtime.Caching; +using System.Threading.Tasks; +using RehauSku.Assistant; + +namespace RehauSku +{ + static class MemoryCacheUtil + { + public static bool IsCached(this string request) + { + return AddIn.memoryCache.Contains(request); + } + + public static IProduct GetFromCache(this string request) + { + return AddIn.memoryCache[request] as IProduct; + } + + public static async Task RequestAndCache(this string request) + { + IProduct product = await SkuAssist.GetProductAsync(request); + + if (product == null) + return null; + + AddIn.memoryCache.Add(request, product, DateTime.Now.AddMinutes(10)); + return product; + } + + public static void ClearCache() + { + AddIn.memoryCache.Dispose(); + AddIn.memoryCache = new MemoryCache("RehauSku"); + } + } +} \ No newline at end of file diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs index ef1398e..3e7c120 100644 --- a/Source/AddIn/RegistryUtil.cs +++ b/Source/AddIn/RegistryUtil.cs @@ -1,5 +1,7 @@ using Microsoft.Win32; using System.IO; +using RehauSku.Forms; +using System.Windows.Forms; namespace RehauSku { @@ -19,6 +21,7 @@ namespace RehauSku public static void Uninitialize() { _RootKey.Close(); + } public static bool IsPriceListPathEmpty() @@ -32,7 +35,8 @@ namespace RehauSku { if (IsPriceListPathEmpty() || !File.Exists(_priceListPath)) { - string fileName = FileDialog.GetFilePath(); + MessageBox.Show("Прайс-лист отсутствует или неверный файл прайс-листа", "Укажите файл прайс-листа", MessageBoxButtons.OK, MessageBoxIcon.Warning); + string fileName = Dialog.GetFilePath(); _priceListPath = fileName; _RootKey.SetValue("PriceListPath", fileName); return _priceListPath; -- cgit v1.2.3 From 20cfbfcca3a779c04aecdca5e4b465651e2be42a Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Fri, 24 Dec 2021 17:42:20 +0300 Subject: New release --- Source/AddIn/RegistryUtil.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Source/AddIn') diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs index 3e7c120..40d0ec2 100644 --- a/Source/AddIn/RegistryUtil.cs +++ b/Source/AddIn/RegistryUtil.cs @@ -47,6 +47,12 @@ namespace RehauSku return _priceListPath; } } + + set + { + _priceListPath = value; + _RootKey.SetValue("PriceListPath", value); + } } public static ResponseOrder StoreResponseOrder -- cgit v1.2.3