From 6137433aefde1257fa42e0823242e66f5bd57e22 Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Tue, 20 Dec 2022 12:41:46 +0300 Subject: Refactoring --- src/AddIn.cs | 31 ------------------------------- src/AddIn/AddIn.cs | 30 ++++++++++++++++++++++++++++++ src/AddIn/Functions.cs | 31 +++++++++++++++++++++++++++++++ src/Controllers/RibbonController.cs | 1 + src/Controllers/ToolBase.cs | 1 + src/Models/StatusbarBase.cs | 1 + src/RhSolutions.csproj | 4 ++-- src/Services/EventsUtil.cs | 1 + src/Services/Functions.cs | 31 ------------------------------- src/Services/RhDatabaseClient.cs | 1 + 10 files changed, 68 insertions(+), 64 deletions(-) delete mode 100644 src/AddIn.cs create mode 100644 src/AddIn/AddIn.cs create mode 100644 src/AddIn/Functions.cs delete mode 100644 src/Services/Functions.cs diff --git a/src/AddIn.cs b/src/AddIn.cs deleted file mode 100644 index 8c44821..0000000 --- a/src/AddIn.cs +++ /dev/null @@ -1,31 +0,0 @@ -using ExcelDna.Integration; -using ExcelDna.IntelliSense; -using Microsoft.Office.Interop.Excel; -using RhSolutions.Services; -using System.Net.Http; -using System.Runtime.Caching; - -namespace RhSolutions -{ - class RhSolutionsAddIn : IExcelAddIn - { - public static Application Excel; - public static HttpClient httpClient; - - public void AutoOpen() - { - Excel = (Application)ExcelDnaUtil.Application; - httpClient = new HttpClient(); - IntelliSenseServer.Install(); - RegistryUtil.Initialize(); - EventsUtil.Initialize(); - } - - public void AutoClose() - { - IntelliSenseServer.Uninstall(); - RegistryUtil.Uninitialize(); - EventsUtil.Uninitialize(); - } - } -} diff --git a/src/AddIn/AddIn.cs b/src/AddIn/AddIn.cs new file mode 100644 index 0000000..b747264 --- /dev/null +++ b/src/AddIn/AddIn.cs @@ -0,0 +1,30 @@ +using ExcelDna.Integration; +using ExcelDna.IntelliSense; +using Microsoft.Office.Interop.Excel; +using RhSolutions.Services; +using System.Net.Http; + +namespace RhSolutions.AddIn +{ + class RhSolutionsAddIn : IExcelAddIn + { + public static Application Excel; + public static HttpClient httpClient; + + public void AutoOpen() + { + Excel = (Application)ExcelDnaUtil.Application; + httpClient = new HttpClient(); + IntelliSenseServer.Install(); + RegistryUtil.Initialize(); + EventsUtil.Initialize(); + } + + public void AutoClose() + { + IntelliSenseServer.Uninstall(); + RegistryUtil.Uninitialize(); + EventsUtil.Uninitialize(); + } + } +} diff --git a/src/AddIn/Functions.cs b/src/AddIn/Functions.cs new file mode 100644 index 0000000..2be19fa --- /dev/null +++ b/src/AddIn/Functions.cs @@ -0,0 +1,31 @@ +using ExcelDna.Integration; +using RhSolutions.Services; + +namespace RhSolutions.AddIn +{ + public class Functions + { + [ExcelFunction(Description = "Запрос в удаленную базу данных")] + public static object RHSOLUTIONS([ExcelArgument(Name = "Запрос")] string line) + { + object result; + + result = ExcelAsyncUtil.Run("Database request", line, delegate + { + return RhDatabaseClient.GetProduct(line).GetAwaiter().GetResult(); + }); + + if (result == null) + { + return ExcelError.ExcelErrorNA; + } + + if (result.Equals(ExcelError.ExcelErrorNA)) + { + return "Загрузка..."; + } + + return result; + } + } +} \ No newline at end of file diff --git a/src/Controllers/RibbonController.cs b/src/Controllers/RibbonController.cs index 87c62e1..1175e91 100644 --- a/src/Controllers/RibbonController.cs +++ b/src/Controllers/RibbonController.cs @@ -1,5 +1,6 @@ using ExcelDna.Integration.CustomUI; using Microsoft.Office.Interop.Excel; +using RhSolutions.AddIn; using RhSolutions.Services; using System; using System.IO; diff --git a/src/Controllers/ToolBase.cs b/src/Controllers/ToolBase.cs index 87eb9d9..72f480e 100644 --- a/src/Controllers/ToolBase.cs +++ b/src/Controllers/ToolBase.cs @@ -1,4 +1,5 @@ using Microsoft.Office.Interop.Excel; +using RhSolutions.AddIn; using RhSolutions.Models; using RhSolutions.Services; using System; diff --git a/src/Models/StatusbarBase.cs b/src/Models/StatusbarBase.cs index a1be5ed..361d5a9 100644 --- a/src/Models/StatusbarBase.cs +++ b/src/Models/StatusbarBase.cs @@ -1,5 +1,6 @@ using ExcelDna.Integration; using Microsoft.Office.Interop.Excel; +using RhSolutions.AddIn; using System; using System.Threading; using System.Threading.Tasks; diff --git a/src/RhSolutions.csproj b/src/RhSolutions.csproj index 31c90cb..6fb6587 100644 --- a/src/RhSolutions.csproj +++ b/src/RhSolutions.csproj @@ -97,8 +97,8 @@ - - + + diff --git a/src/Services/EventsUtil.cs b/src/Services/EventsUtil.cs index 4b1d923..bb37125 100644 --- a/src/Services/EventsUtil.cs +++ b/src/Services/EventsUtil.cs @@ -1,4 +1,5 @@ using Microsoft.Office.Interop.Excel; +using RhSolutions.AddIn; using RhSolutions.Controllers; namespace RhSolutions.Services diff --git a/src/Services/Functions.cs b/src/Services/Functions.cs deleted file mode 100644 index 22b67e0..0000000 --- a/src/Services/Functions.cs +++ /dev/null @@ -1,31 +0,0 @@ -using ExcelDna.Integration; -using System; - -namespace RhSolutions.Services -{ - public class Functions - { - [ExcelFunction(Description = "Запрос в удаленную базу данных")] - public static object RHSOLUTIONS([ExcelArgument(Name = "Запрос")] string line) - { - object result; - - result = ExcelAsyncUtil.Run("Database request", line, delegate - { - return RhDatabaseClient.GetProduct(line).GetAwaiter().GetResult(); - }); - - if (result == null) - { - return ExcelError.ExcelErrorNA; - } - - if (result.Equals(ExcelError.ExcelErrorNA)) - { - return "Загрузка..."; - } - - return result; - } - } -} \ No newline at end of file diff --git a/src/Services/RhDatabaseClient.cs b/src/Services/RhDatabaseClient.cs index c57d4d8..d71a6ba 100644 --- a/src/Services/RhDatabaseClient.cs +++ b/src/Services/RhDatabaseClient.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using RhSolutions.AddIn; using System.Collections.Generic; using System.Linq; using System.Net; -- cgit v1.2.3