RhSolutions-AddIn/Source/ExcelDNA/Functions.cs

42 lines
1.2 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 "Загрузка...";
}
2021-12-03 13:24:31 +03:00
else if (result == null)
{
return "Не найдено";
}
else
{
MemoryCache.Default.Add(request, result, System.DateTime.Now.AddMinutes(10));
2021-12-03 13:24:31 +03:00
return result.ToString();
}
}
2021-11-11 16:33:40 +03:00
}
}
}