Move responseOrder field to AddIn class

This commit is contained in:
Sergey Chebotar 2021-12-05 21:19:28 +03:00
parent cd96e10aa4
commit 589246aaef
3 changed files with 14 additions and 12 deletions

View File

@ -30,14 +30,14 @@ namespace Rehau.Sku.Assist
return await context.OpenAsync(req => req.Content(content.Result));
}
public static Uri ConvertToUri(this string request, ResponseOrder order)
public static Uri ConvertToUri(this string request)
{
UriBuilder baseUri = new UriBuilder("https", "shop-rehau.ru");
baseUri.Path = "/catalogsearch/result/index/";
string cleanedRequest = request._CleanRequest();
switch (order)
switch (AddIn.responseOrder)
{
case ResponseOrder.Relevance:
baseUri.Query = "dir=asc&order=relevance&q=" + cleanedRequest;

View File

@ -10,15 +10,6 @@ using System.Threading.Tasks;
namespace Rehau.Sku.Assist
{
public enum ResponseOrder
{
NoSettings,
Relevance,
Name,
Price,
Series
}
public enum ProductField
{
Name,
@ -30,7 +21,7 @@ namespace Rehau.Sku.Assist
{
public static async Task<IProduct> GetProduct(string request)
{
Uri uri = request.ConvertToUri(ResponseOrder.NoSettings);
Uri uri = request.ConvertToUri();
Task<string> contentTask = Task.Run(() => HttpClientUtil.GetContentByUriAsync(uri));
Task<IDocument> documentTask = await contentTask.ContinueWith(content => HttpClientUtil.ContentToDocAsync(content));

View File

@ -4,13 +4,24 @@ using System.Net.Http;
namespace Rehau.Sku.Assist
{
public enum ResponseOrder
{
NoSettings,
Relevance,
Name,
Price,
Series
}
public class AddIn : IExcelAddIn
{
public static readonly HttpClient httpClient = new HttpClient();
public static ResponseOrder responseOrder;
public void AutoOpen()
{
RegisterFunctions();
responseOrder = ResponseOrder.NoSettings;
}
public void AutoClose()