2021-12-03 12:57:22 +03:00
|
|
|
|
using ExcelDna.Integration;
|
|
|
|
|
using System.Runtime.Caching;
|
2021-12-03 19:30:35 +03:00
|
|
|
|
using System.Threading.Tasks;
|
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
|
|
|
|
|
{
|
2021-12-03 19:30:35 +03:00
|
|
|
|
object result = ExcelAsyncUtil.Run("RauName", new[] { request },
|
2021-12-03 12:57:22 +03:00
|
|
|
|
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));
|
|
|
|
|
return product.Name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ExcelFunction]
|
|
|
|
|
public static object RAUSKU(string request)
|
|
|
|
|
{
|
|
|
|
|
if (MemoryCache.Default.Contains(request))
|
|
|
|
|
{
|
2021-12-03 19:30:35 +03:00
|
|
|
|
IProduct product = MemoryCache.Default[request] as IProduct;
|
|
|
|
|
return product.Id;
|
2021-12-03 14:15:16 +03:00
|
|
|
|
}
|
|
|
|
|
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));
|
2021-12-03 19:30:35 +03:00
|
|
|
|
return product.Id;
|
2021-12-03 12:57:22 +03:00
|
|
|
|
}
|
2021-11-11 16:33:40 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|