RhSolutions-AddIn/Source/ExcelDNA/Functions.cs

36 lines
1.1 KiB
C#
Raw Normal View History

using ExcelDna.Integration;
2021-11-29 15:50:24 +03:00
using System.Threading.Tasks;
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
{
[ExcelFunction]
public static object RAUNAME(string request)
2021-11-11 16:33:40 +03:00
{
if (MemoryCache.Default.Contains(request))
return MemoryCache.Default[request].ToString();
else
{
object result = ExcelAsyncUtil.Run("Rauname", new[] { request },
delegate
{
Task<IProduct> product = Task.Run(() => SkuAssist.GetProduct(request));
return product.Result;
});
if (Equals(result, ExcelError.ExcelErrorNA))
{
return "Загрузка...";
}
else
{
MemoryCache.Default.Add(request, result, System.DateTime.Now.AddMinutes(10));
return result == null ? "Не найдено" : result.ToString();
}
}
2021-11-11 16:33:40 +03:00
}
}
}