aboutsummaryrefslogtreecommitdiff
path: root/src/AddIn
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2022-07-04 11:33:29 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2022-07-04 11:33:29 +0300
commitdca3481e9a91e1c9d5b86e1508b0a2993088e759 (patch)
tree208550ad4a4e541248a87583552e3beaa0713790 /src/AddIn
parent10e6a108f974b3e2541ec322f99e60ec5ab7d9f7 (diff)
Remove Store Functions
Diffstat (limited to 'src/AddIn')
-rw-r--r--src/AddIn/AddIn.cs5
-rw-r--r--src/AddIn/Functions.cs49
-rw-r--r--src/AddIn/MemoryCacheUtil.cs37
3 files changed, 0 insertions, 91 deletions
diff --git a/src/AddIn/AddIn.cs b/src/AddIn/AddIn.cs
index 035e50f..1606624 100644
--- a/src/AddIn/AddIn.cs
+++ b/src/AddIn/AddIn.cs
@@ -9,14 +9,10 @@ namespace RehauSku
{
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();
@@ -29,7 +25,6 @@ namespace RehauSku
IntelliSenseServer.Uninstall();
RegistryUtil.Uninitialize();
EventsUtil.Uninitialize();
- memoryCache.Dispose();
}
void RegisterFunctions()
diff --git a/src/AddIn/Functions.cs b/src/AddIn/Functions.cs
index efdec66..c202a3b 100644
--- a/src/AddIn/Functions.cs
+++ b/src/AddIn/Functions.cs
@@ -1,58 +1,9 @@
using ExcelDna.Integration;
-using RehauSku.Assistant;
namespace RehauSku
{
public class Functions
{
- [ExcelFunction(description: "Получение названия первого продукта в поиске")]
- public static object RAUNAME([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request)
- => MakeRequest(request, ProductField.Name);
-
- [ExcelFunction(Description = "Получение артикула первого продукта в поиске")]
- public static object RAUSKU([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request)
- => MakeRequest(request, ProductField.Id);
-
- [ExcelFunction(Description = "Получение цены первого продукта в поиске")]
- 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;
- }
- }
-
[ExcelFunction(Description = "Получение корректного артикула из строки")]
public static object GETRAUSKU([ExcelArgument(Name = "\"Строка\"", Description = "строка, содержащая актикул")] string line)
{
diff --git a/src/AddIn/MemoryCacheUtil.cs b/src/AddIn/MemoryCacheUtil.cs
deleted file mode 100644
index 1d42e14..0000000
--- a/src/AddIn/MemoryCacheUtil.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-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