From e175a634cefc6e8c0ecd49514a89b1d4f30ce33b Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Mon, 13 Dec 2021 20:39:41 +0300 Subject: Refactoring. ExcelDNA.IntelliSense library add. Add description to Excel functions. --- Source/Assistant/ParseUtil.cs | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Source/Assistant/ParseUtil.cs (limited to 'Source/Assistant/ParseUtil.cs') diff --git a/Source/Assistant/ParseUtil.cs b/Source/Assistant/ParseUtil.cs new file mode 100644 index 0000000..571c6b0 --- /dev/null +++ b/Source/Assistant/ParseUtil.cs @@ -0,0 +1,55 @@ +using AngleSharp; +using AngleSharp.Dom; +using Newtonsoft.Json; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace RehauSku.Assistant +{ + static class ParseUtil + { + public async static Task ContentToDocAsync(string content) + { + IConfiguration config = Configuration.Default; + IBrowsingContext context = BrowsingContext.New(config); + + return await context.OpenAsync(req => req.Content(content)); + } + + public static IProduct GetProduct(IDocument document) + { + try + { + string script = document + .Scripts + .Where(s => s.InnerHtml.Contains("dataLayer")) + .FirstOrDefault() + .InnerHtml; + + string json = script + .Substring(script.IndexOf("push(") + 5) + .TrimEnd(new[] { ')', ';', '\n', ' ' }); + + if (!json.Contains("impressions")) + return null; + + StoreResponce storeResponse = JsonConvert.DeserializeObject(json); + IProduct product = storeResponse + .Ecommerce + .Impressions + .Where(p => p.Id.IsRehauSku()) + .FirstOrDefault(); + + return product; + } + + catch (NullReferenceException e) + { + MessageBox.Show(e.Message, "Ошибка получения данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return null; + } + } + } +} \ No newline at end of file -- cgit v1.2.3 From ce5597d042062c820288c63b4e571ee77ac23ab0 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Wed, 22 Dec 2021 17:07:37 +0300 Subject: RegistryUtil and some fixes --- Source/Assistant/ParseUtil.cs | 45 ++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) (limited to 'Source/Assistant/ParseUtil.cs') diff --git a/Source/Assistant/ParseUtil.cs b/Source/Assistant/ParseUtil.cs index 571c6b0..a93c658 100644 --- a/Source/Assistant/ParseUtil.cs +++ b/Source/Assistant/ParseUtil.cs @@ -1,10 +1,8 @@ using AngleSharp; using AngleSharp.Dom; using Newtonsoft.Json; -using System; using System.Linq; using System.Threading.Tasks; -using System.Windows.Forms; namespace RehauSku.Assistant { @@ -20,36 +18,27 @@ namespace RehauSku.Assistant public static IProduct GetProduct(IDocument document) { - try - { - string script = document - .Scripts - .Where(s => s.InnerHtml.Contains("dataLayer")) - .FirstOrDefault() - .InnerHtml; + string script = document + .Scripts + .Where(s => s.InnerHtml.Contains("dataLayer")) + .FirstOrDefault() + .InnerHtml; - string json = script - .Substring(script.IndexOf("push(") + 5) - .TrimEnd(new[] { ')', ';', '\n', ' ' }); + string json = script + .Substring(script.IndexOf("push(") + 5) + .TrimEnd(new[] { ')', ';', '\n', ' ' }); - if (!json.Contains("impressions")) - return null; - - StoreResponce storeResponse = JsonConvert.DeserializeObject(json); - IProduct product = storeResponse - .Ecommerce - .Impressions - .Where(p => p.Id.IsRehauSku()) - .FirstOrDefault(); + if (!json.Contains("impressions")) + return null; - return product; - } + StoreResponce storeResponse = JsonConvert.DeserializeObject(json); + IProduct product = storeResponse + .Ecommerce + .Impressions + .Where(p => p.Id.IsRehauSku()) + .FirstOrDefault(); - catch (NullReferenceException e) - { - MessageBox.Show(e.Message, "Ошибка получения данных", MessageBoxButtons.OK, MessageBoxIcon.Error); - return null; - } + return product; } } } \ No newline at end of file -- cgit v1.2.3