Add RauSku Function. Some refactoring.

This commit is contained in:
Sergey Chebotar 2021-12-03 14:15:16 +03:00
parent 2f7c5688dd
commit c748be35c4

View File

@ -10,32 +10,60 @@ namespace Rehau.Sku.Assist
public static object RAUNAME(string request) public static object RAUNAME(string request)
{ {
if (MemoryCache.Default.Contains(request)) if (MemoryCache.Default.Contains(request))
return MemoryCache.Default[request].ToString(); {
IProduct product = MemoryCache.Default[request] as IProduct;
return product.Name;
}
else else
{ {
object result = ExcelAsyncUtil.Run("Rauname", new[] { request }, object result = ExcelAsyncUtil.Run("Rauname", new[] { request },
delegate delegate
{ {
Task<IProduct> product = Task.Run(() => SkuAssist.GetProduct(request)); Task<IProduct> p = Task.Run(() => SkuAssist.GetProduct(request));
return product.Result; return p.Result;
}); });
if (Equals(result, ExcelError.ExcelErrorNA)) if (result == null)
{
return "Загрузка...";
}
else if (result == null)
{
return "Не найдено"; return "Не найдено";
if (result.Equals(ExcelError.ExcelErrorNA))
return "Загрузка...";
IProduct product = result as IProduct;
MemoryCache.Default.Add(request, product, System.DateTime.Now.AddMinutes(10));
//MemoryCache.Default.Add(product.Name, product, System.DateTime.Now.AddMinutes(10));
return product.Name;
}
} }
[ExcelFunction]
public static object RAUSKU(string request)
{
if (MemoryCache.Default.Contains(request))
{
IProduct result = MemoryCache.Default[request] as IProduct;
return result.Sku;
}
else else
{ {
MemoryCache.Default.Add(request, result, System.DateTime.Now.AddMinutes(10)); object result = ExcelAsyncUtil.Run("RauSku", new[] { request },
return result.ToString(); delegate
} {
Task<IProduct> p = Task.Run(() => SkuAssist.GetProduct(request));
return p.Result;
});
if (result == null)
return "Не найдено";
if (result.Equals(ExcelError.ExcelErrorNA))
return "Загрузка...";
IProduct product = result as IProduct;
MemoryCache.Default.Add(request, product, System.DateTime.Now.AddMinutes(10));
//MemoryCache.Default.Add(product.Sku, product, System.DateTime.Now.AddMinutes(10));
return product.Sku;
} }
} }
} }