diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-24 16:22:03 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-24 16:22:03 +0300 |
commit | 24024b5729c1c44bb01cb29813868743d1753e31 (patch) | |
tree | 673a1c1102e04adee36be8ded4934d2e40794fef /Source/AddIn | |
parent | 2a4076d6eef1b4556f6af8cb074638d440927c5e (diff) |
MergeTool, MemoryUtil anf stuff
Diffstat (limited to 'Source/AddIn')
-rw-r--r-- | Source/AddIn/AddIn.cs | 8 | ||||
-rw-r--r-- | Source/AddIn/FileDialog.cs | 24 | ||||
-rw-r--r-- | Source/AddIn/MemoryCacheUtil.cs | 37 | ||||
-rw-r--r-- | Source/AddIn/RegistryUtil.cs | 6 |
4 files changed, 49 insertions, 26 deletions
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<IProduct> 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; |