2021-12-03 12:57:22 +03:00
|
|
|
|
using ExcelDna.Integration;
|
2021-11-29 15:50:24 +03:00
|
|
|
|
using System.Threading.Tasks;
|
2021-12-03 12:57:22 +03:00
|
|
|
|
using System.Runtime.Caching;
|
2021-11-11 16:33:40 +03:00
|
|
|
|
|
|
|
|
|
namespace Rehau.Sku.Assist
|
|
|
|
|
{
|
2021-11-29 15:50:24 +03:00
|
|
|
|
public class Functions
|
2021-11-11 16:33:40 +03:00
|
|
|
|
{
|
2021-11-29 11:26:25 +03:00
|
|
|
|
[ExcelFunction]
|
2021-12-03 12:57:22 +03:00
|
|
|
|
public static object RAUNAME(string request)
|
2021-11-11 16:33:40 +03:00
|
|
|
|
{
|
2021-12-03 12:57:22 +03:00
|
|
|
|
if (MemoryCache.Default.Contains(request))
|
2021-12-03 14:15:16 +03:00
|
|
|
|
{
|
|
|
|
|
IProduct product = MemoryCache.Default[request] as IProduct;
|
|
|
|
|
return product.Name;
|
|
|
|
|
}
|
2021-12-03 12:57:22 +03:00
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
object result = ExcelAsyncUtil.Run("Rauname", new[] { request },
|
|
|
|
|
delegate
|
|
|
|
|
{
|
2021-12-03 14:15:16 +03:00
|
|
|
|
Task<IProduct> p = Task.Run(() => SkuAssist.GetProduct(request));
|
|
|
|
|
return p.Result;
|
2021-12-03 12:57:22 +03:00
|
|
|
|
});
|
|
|
|
|
|
2021-12-03 14:15:16 +03:00
|
|
|
|
if (result == null)
|
|
|
|
|
return "Не найдено";
|
|
|
|
|
|
|
|
|
|
if (result.Equals(ExcelError.ExcelErrorNA))
|
2021-12-03 12:57:22 +03:00
|
|
|
|
return "Загрузка...";
|
2021-12-03 13:24:31 +03:00
|
|
|
|
|
2021-12-03 14:15:16 +03:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
object result = ExcelAsyncUtil.Run("RauSku", new[] { request },
|
|
|
|
|
delegate
|
|
|
|
|
{
|
|
|
|
|
Task<IProduct> p = Task.Run(() => SkuAssist.GetProduct(request));
|
|
|
|
|
return p.Result;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (result == null)
|
2021-12-03 13:24:31 +03:00
|
|
|
|
return "Не найдено";
|
|
|
|
|
|
2021-12-03 14:15:16 +03:00
|
|
|
|
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;
|
2021-12-03 12:57:22 +03:00
|
|
|
|
}
|
2021-11-11 16:33:40 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|