RhSolutions-AddIn/Source/ExcelDNA/Functions.cs
2021-12-03 13:24:31 +03:00

42 lines
1.2 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 if (result == null)
{
return "Не найдено";
}
else
{
MemoryCache.Default.Add(request, result, System.DateTime.Now.AddMinutes(10));
return result.ToString();
}
}
}
}
}