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 +++++++++++++++------------------------ Source/Assistant/SkuExtension.cs | 12 ----------- Source/Assistant/SkuExtensions.cs | 12 +++++++++++ 3 files changed, 29 insertions(+), 40 deletions(-) delete mode 100644 Source/Assistant/SkuExtension.cs create mode 100644 Source/Assistant/SkuExtensions.cs (limited to 'Source/Assistant') 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 diff --git a/Source/Assistant/SkuExtension.cs b/Source/Assistant/SkuExtension.cs deleted file mode 100644 index 51aaf6c..0000000 --- a/Source/Assistant/SkuExtension.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.RegularExpressions; - -namespace RehauSku.Assistant -{ - static class SkuExtension - { - public static bool IsRehauSku(this string line) - { - return Regex.IsMatch(line, @"^[1]\d{6}[1]\d{3}$"); - } - } -} \ No newline at end of file diff --git a/Source/Assistant/SkuExtensions.cs b/Source/Assistant/SkuExtensions.cs new file mode 100644 index 0000000..e39807b --- /dev/null +++ b/Source/Assistant/SkuExtensions.cs @@ -0,0 +1,12 @@ +using System.Text.RegularExpressions; + +namespace RehauSku.Assistant +{ + static class SkuExtensions + { + public static bool IsRehauSku(this string line) + { + return Regex.IsMatch(line, @"^[1]\d{6}[1]\d{3}$"); + } + } +} \ No newline at end of file -- cgit v1.2.3