aboutsummaryrefslogtreecommitdiff
path: root/Source/Assistant
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2021-12-22 17:07:37 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2021-12-22 17:07:37 +0300
commitce5597d042062c820288c63b4e571ee77ac23ab0 (patch)
tree9400511fce89ae4b6d4df205b605f560778dcb57 /Source/Assistant
parentf97d344f39c46b5e2f883765e8859e78007a11b0 (diff)
RegistryUtil and some fixes
Diffstat (limited to 'Source/Assistant')
-rw-r--r--Source/Assistant/ParseUtil.cs45
-rw-r--r--Source/Assistant/SkuExtensions.cs (renamed from Source/Assistant/SkuExtension.cs)2
2 files changed, 18 insertions, 29 deletions
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<StoreResponce>(json);
- IProduct product = storeResponse
- .Ecommerce
- .Impressions
- .Where(p => p.Id.IsRehauSku())
- .FirstOrDefault();
+ if (!json.Contains("impressions"))
+ return null;
- return product;
- }
+ StoreResponce storeResponse = JsonConvert.DeserializeObject<StoreResponce>(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/SkuExtensions.cs
index 51aaf6c..e39807b 100644
--- a/Source/Assistant/SkuExtension.cs
+++ b/Source/Assistant/SkuExtensions.cs
@@ -2,7 +2,7 @@
namespace RehauSku.Assistant
{
- static class SkuExtension
+ static class SkuExtensions
{
public static bool IsRehauSku(this string line)
{