aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2021-12-22 08:26:54 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2021-12-22 08:26:54 +0300
commitf97d344f39c46b5e2f883765e8859e78007a11b0 (patch)
tree48bbacaaff6f776a42201bbea02828151e565544
parentaaaa6b45859e74c791f35e18c220118a54a345ad (diff)
Add Registry Util
-rw-r--r--Source/AddIn/AddIn.cs4
-rw-r--r--Source/AddIn/Functions.cs12
-rw-r--r--Source/AddIn/RegistryUtil.cs74
-rw-r--r--Source/Assistant/HttpClientUtil.cs2
-rw-r--r--Source/DataExport/Exporter.cs4
5 files changed, 30 insertions, 66 deletions
diff --git a/Source/AddIn/AddIn.cs b/Source/AddIn/AddIn.cs
index 7a2be5d..4a26f55 100644
--- a/Source/AddIn/AddIn.cs
+++ b/Source/AddIn/AddIn.cs
@@ -16,9 +16,7 @@ namespace RehauSku
public class AddIn : IExcelAddIn
{
- public static readonly HttpClient httpClient = new HttpClient();
- public static ResponseOrder StoreResponseOrder = RegistryUtil.StoreResponseOrder;
- public static string PriceListPath = RegistryUtil.PriceListPath;
+ public static HttpClient httpClient = new HttpClient();
public void AutoOpen()
{
diff --git a/Source/AddIn/Functions.cs b/Source/AddIn/Functions.cs
index 2ae22e4..618d17d 100644
--- a/Source/AddIn/Functions.cs
+++ b/Source/AddIn/Functions.cs
@@ -5,16 +5,16 @@ namespace RehauSku
{
public class Functions
{
- [ExcelFunction(Description = "Получение названия первого продукта по запросу в интернет-магазин REHAU")]
- public static object RAUNAME([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request)
+ [ExcelFunction(description: "Получение названия первого продукта в поиске")]
+ public static object RAUNAME([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request)
=> MakeRequest(request, ProductField.Name);
- [ExcelFunction(Description = "Получение артикула первого продукта по запросу в интернет-магазин REHAU")]
- public static object RAUSKU([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request)
+ [ExcelFunction(Description = "Получение артикула первого продукта в поиске")]
+ public static object RAUSKU([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request)
=> MakeRequest(request, ProductField.Id);
- [ExcelFunction(Description = "Получение цены первого продукта по запросу в интернет-магазин REHAU")]
- public static object RAUPRICE([ExcelArgument(Name = "Запрос", Description = "Запрос в свободной форме или ячейка с запросом")] string request)
+ [ExcelFunction(Description = "Получение цены первого продукта в поиске")]
+ public static object RAUPRICE([ExcelArgument(Name = "\"Запрос\"", Description = "в свободной форме или ячейка с запросом")] string request)
=> MakeRequest(request, ProductField.Price);
private static object MakeRequest(string request, ProductField field)
diff --git a/Source/AddIn/RegistryUtil.cs b/Source/AddIn/RegistryUtil.cs
index 105d5af..6ab7682 100644
--- a/Source/AddIn/RegistryUtil.cs
+++ b/Source/AddIn/RegistryUtil.cs
@@ -6,71 +6,37 @@ namespace RehauSku
{
public static string PriceListPath
{
- get
- {
- _GetRootKey();
-
- if (_RootKey == null)
- {
- return @"D:\Dropbox\Рабочее\Таблица заказов ИС EAE_2021.xlsm";
- }
-
- else return (string)_RootKey.GetValue("PriceListPath");
- }
-
- private set
- {
- _GetRootKey();
-
- if (_RootKey == null)
- {
- RegistryKey PriceListPath = Registry.CurrentUser
- .CreateSubKey("SOFTWARE")
- .CreateSubKey("REHAU")
- .CreateSubKey("SkuAssist");
- }
-
- _RootKey.SetValue("PriceListPath", value);
- }
+ get => (string)_RootKey.GetValue("PriceListPath");
}
public static ResponseOrder StoreResponseOrder
{
- get
- {
- _GetRootKey();
-
- if (_RootKey == null)
- {
- return ResponseOrder.Default;
- }
-
- return (ResponseOrder)_RootKey.GetValue("ResponseOrder");
- }
+ get => (ResponseOrder)_RootKey.GetValue("StoreResponseOrder");
+ }
- private set
+ private static RegistryKey _RootKey
+ {
+ get
{
- if (_RootKey == null)
- {
- RegistryKey PriceListPath = Registry.CurrentUser
- .CreateSubKey("SOFTWARE")
- .CreateSubKey("REHAU")
- .CreateSubKey("SkuAssist");
- }
-
- _RootKey.SetValue("ResponseOrder", value);
+ return _OpenRootKey() ?? _CreateRootKey();
}
}
- private static RegistryKey _RootKey { get; set; }
+ private static RegistryKey _OpenRootKey()
+ {
+ return Registry.CurrentUser
+ .OpenSubKey(@"SOFTWARE\REHAU\SkuAssist");
+ }
- private static void _GetRootKey()
+ private static RegistryKey _CreateRootKey()
{
- _RootKey = Registry
- .CurrentUser
- .OpenSubKey("SOFTWARE")
- .OpenSubKey("REHAU")
- .OpenSubKey("SkuAssist");
+ RegistryKey key = Registry.CurrentUser
+ .CreateSubKey(@"SOFTWARE\REHAU\SkuAssist");
+
+ key.SetValue("PriceListPath", @"D:\Dropbox\Рабочее\Таблица заказов ИС EAE_2021.xlsm");
+ key.SetValue("StoreResponseOrder", 0);
+
+ return key;
}
}
}
diff --git a/Source/Assistant/HttpClientUtil.cs b/Source/Assistant/HttpClientUtil.cs
index 63be4a8..316ea07 100644
--- a/Source/Assistant/HttpClientUtil.cs
+++ b/Source/Assistant/HttpClientUtil.cs
@@ -28,7 +28,7 @@ namespace RehauSku.Assistant
baseUri.Path = "/catalogsearch/result/index/";
string cleanedRequest = request.CleanRequest();
- switch (AddIn.StoreResponseOrder)
+ switch (RegistryUtil.StoreResponseOrder)
{
case ResponseOrder.Relevance:
baseUri.Query = "dir=asc&order=relevance&q=" + cleanedRequest;
diff --git a/Source/DataExport/Exporter.cs b/Source/DataExport/Exporter.cs
index 40a1d5d..483dd0e 100644
--- a/Source/DataExport/Exporter.cs
+++ b/Source/DataExport/Exporter.cs
@@ -76,7 +76,7 @@ namespace RehauSku.DataExport
public void FillPriceList()
{
string exportFile = _GetExportFullPath();
- File.Copy(AddIn.PriceListPath, exportFile, true);
+ File.Copy(RegistryUtil.PriceListPath, exportFile, true);
Workbook wb = xlApp.Workbooks.Open(exportFile);
Worksheet ws = wb.ActiveSheet;
@@ -94,7 +94,7 @@ namespace RehauSku.DataExport
private string _GetExportFullPath()
{
- string fileExtension = Path.GetExtension(AddIn.PriceListPath);
+ string fileExtension = Path.GetExtension(RegistryUtil.PriceListPath);
return Path.GetTempFileName() + fileExtension;
}