diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2021-11-29 15:50:24 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2021-11-29 15:50:24 +0300 |
commit | 3eb118d6db672eb8e27f2b2478b0688141782654 (patch) | |
tree | 02fc5455edfbc0d5bcdf17e366185985531c1441 /Functions.cs | |
parent | 0fe8e038af7f33eae824bba263e7c54dea829679 (diff) |
Async/await ready solution init commit
Diffstat (limited to 'Functions.cs')
-rw-r--r-- | Functions.cs | 49 |
1 files changed, 7 insertions, 42 deletions
diff --git a/Functions.cs b/Functions.cs index 9d3eb28..ab6cedf 100644 --- a/Functions.cs +++ b/Functions.cs @@ -1,53 +1,18 @@ -using ExcelDna.Integration; -using System.Runtime.Caching; +using System; +using ExcelDna.Integration; using System.Net.Http; +using System.Threading.Tasks; namespace Rehau.Sku.Assist { - public class Functions : IExcelAddIn + public class Functions { - private static HttpClient _httpClient; - private static ObjectCache _resultCache = MemoryCache.Default; - - public void AutoClose() - { - } - public void AutoOpen() - { - _httpClient = new HttpClient(); - } + private static HttpClient httpClient = new HttpClient(); [ExcelFunction] - public static object RAUNAME(string request) + public static async Task<string> RAUNAME(string request) { - string cachedResult = _resultCache[request] as string; - - if (cachedResult != null) - { - return cachedResult; - } - - else - { - object result = ExcelAsyncUtil.Run("RAUNAME", null, - delegate - { - var document = SkuAssist.GetDocumentAsync(request, _httpClient).Result; - var product = SkuAssist.GetProductFromDocument(document); - return product.ToString(); - }); - - if (result.Equals(ExcelError.ExcelErrorNA)) - { - return "Загрузка..."; - } - - else - { - _resultCache.Add(request, result, System.DateTime.Now.AddMinutes(20)); - return result.ToString(); - } - } + throw new NotImplementedException(); } } }
\ No newline at end of file |