2021-12-03 12:57:22 +03:00
|
|
|
|
using AngleSharp;
|
|
|
|
|
using AngleSharp.Dom;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2021-12-08 14:45:14 +03:00
|
|
|
|
namespace RehauSku.Assistant
|
2021-12-03 12:57:22 +03:00
|
|
|
|
{
|
|
|
|
|
static class HttpClientUtil
|
|
|
|
|
{
|
|
|
|
|
private static HttpClient _httpClient = AddIn.httpClient;
|
|
|
|
|
|
|
|
|
|
public async static Task<string> GetContentByUriAsync(Uri uri)
|
|
|
|
|
{
|
|
|
|
|
ServicePointManager.SecurityProtocol =
|
|
|
|
|
SecurityProtocolType.Tls12 |
|
|
|
|
|
SecurityProtocolType.Tls11 |
|
|
|
|
|
SecurityProtocolType.Tls;
|
|
|
|
|
|
|
|
|
|
return await _httpClient.GetStringAsync(uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async static Task<IDocument> ContentToDocAsync(Task<string> content)
|
|
|
|
|
{
|
|
|
|
|
IConfiguration config = Configuration.Default;
|
|
|
|
|
IBrowsingContext context = BrowsingContext.New(config);
|
|
|
|
|
|
|
|
|
|
return await context.OpenAsync(req => req.Content(content.Result));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 21:19:28 +03:00
|
|
|
|
public static Uri ConvertToUri(this string request)
|
2021-12-03 12:57:22 +03:00
|
|
|
|
{
|
|
|
|
|
UriBuilder baseUri = new UriBuilder("https", "shop-rehau.ru");
|
|
|
|
|
|
|
|
|
|
baseUri.Path = "/catalogsearch/result/index/";
|
2021-12-08 09:44:23 +03:00
|
|
|
|
string cleanedRequest = request.CleanRequest();
|
2021-12-03 12:57:22 +03:00
|
|
|
|
|
2021-12-05 21:19:28 +03:00
|
|
|
|
switch (AddIn.responseOrder)
|
2021-12-03 12:57:22 +03:00
|
|
|
|
{
|
|
|
|
|
case ResponseOrder.Relevance:
|
|
|
|
|
baseUri.Query = "dir=asc&order=relevance&q=" + cleanedRequest;
|
|
|
|
|
break;
|
|
|
|
|
case ResponseOrder.Name:
|
|
|
|
|
baseUri.Query = "dir=asc&order=name&q=" + cleanedRequest;
|
|
|
|
|
break;
|
|
|
|
|
case ResponseOrder.Price:
|
|
|
|
|
baseUri.Query = "dir=asc&order=price&q=" + cleanedRequest;
|
|
|
|
|
break;
|
|
|
|
|
case ResponseOrder.Series:
|
|
|
|
|
baseUri.Query = "dir=asc&order=sch_product_series&q=" + cleanedRequest;
|
|
|
|
|
break;
|
2021-12-07 08:34:48 +03:00
|
|
|
|
default:
|
2021-12-03 12:57:22 +03:00
|
|
|
|
baseUri.Query = "q=" + cleanedRequest;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return baseUri.Uri;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|