RhSolutions-AddIn/Source/ExcelDNA/Functions.cs

36 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ExcelDna.Integration;
using System.Threading.Tasks;
using System.Runtime.Caching;
namespace Rehau.Sku.Assist
{
public class Functions
{
[ExcelFunction]
public static object RAUNAME(string request)
{
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();
}
}
}
}
}