diff --git a/OcrClient/Models/OcrResponse.cs b/OcrClient/Models/OcrResponse.cs new file mode 100644 index 0000000..2afc041 --- /dev/null +++ b/OcrClient/Models/OcrResponse.cs @@ -0,0 +1,5 @@ +namespace OcrClient.Models; + +public class OcrResponse +{ +} \ No newline at end of file diff --git a/VisionClient/VisionClient.csproj b/OcrClient/OcrClient.csproj similarity index 100% rename from VisionClient/VisionClient.csproj rename to OcrClient/OcrClient.csproj diff --git a/OcrClient/Services/IOcrClient.cs b/OcrClient/Services/IOcrClient.cs new file mode 100644 index 0000000..c8b1a86 --- /dev/null +++ b/OcrClient/Services/IOcrClient.cs @@ -0,0 +1,8 @@ +using OcrClient.Models; + +namespace OcrClient.Services; + +public interface IOcrClient +{ + public Task ProcessImage(string base64Image); +} diff --git a/OcrClient/Services/OcrClient.cs b/OcrClient/Services/OcrClient.cs new file mode 100644 index 0000000..e4cfef3 --- /dev/null +++ b/OcrClient/Services/OcrClient.cs @@ -0,0 +1,19 @@ +using OcrClient.Models; +using System.Net.Http; + +namespace OcrClient.Services; + +public class YandexOcrClient : IOcrClient +{ + private readonly HttpClient _httpClient; + + public YandexOcrClient(HttpClient httpClient) + { + _httpClient = httpClient; + } + + public Task ProcessImage(string base64Image) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs b/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs index ac83200..58ffdf2 100644 --- a/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs +++ b/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs @@ -1,5 +1,5 @@ using System.Net; -using VisionClient.Services; +using OcrClient.Services; namespace RhSolutions.AddIn; @@ -41,7 +41,7 @@ public sealed class RhSolutionsAddIn : IExcelAddIn Services.AddTransient() .AddTransient(s => s.GetService()); - Services.AddTransient(); + Services.AddTransient(); Services.AddSingleton(); diff --git a/RhSolutions.AddIn/RhSolutions.AddIn.csproj b/RhSolutions.AddIn/RhSolutions.AddIn.csproj index 6e34066..ca11644 100644 --- a/RhSolutions.AddIn/RhSolutions.AddIn.csproj +++ b/RhSolutions.AddIn/RhSolutions.AddIn.csproj @@ -30,7 +30,7 @@ - + diff --git a/RhSolutions.AddIn/Tools/OcrTool.cs b/RhSolutions.AddIn/Tools/OcrTool.cs index b717bba..56909f8 100644 --- a/RhSolutions.AddIn/Tools/OcrTool.cs +++ b/RhSolutions.AddIn/Tools/OcrTool.cs @@ -1,30 +1,38 @@ using System.Threading.Tasks; using SnippingTool; -using VisionClient.Services; +using OcrClient.Services; namespace RhSolutions.Tools; internal class OcrTool : Tool { public Application Application { get; set; } - private IYandexVisionClient client; - public OcrTool(ReaderFactory readerFactory, WriterFactory writerFactory, Application application, IYandexVisionClient visionClient) : base(readerFactory, writerFactory) - { - Application = application; - client = visionClient; - } + private IOcrClient client = RhSolutionsAddIn.ServiceProvider.GetService(); - public override void Execute() + public OcrTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory) + { + } + + public override void Execute() { - Application.Visible = false; - Task.Run(async delegate + try { - await Task.Delay(100); - }).Wait(); - - string shot = Snipper.SnipBase64(); - var result = client.ProcessImage(shot); - - Application.Visible = true; + RhSolutionsAddIn.Excel.Visible = false; + Task.Run(async delegate + { + await Task.Delay(250); + }).Wait(); + + string shot = Snipper.SnipBase64(); + var result = client.ProcessImage(shot); + } + catch (Exception) + { + throw; + } + finally + { + RhSolutionsAddIn.Excel.Visible = true; + } } } \ No newline at end of file diff --git a/RhSolutions.AddIn/Tools/ToolFactory.cs b/RhSolutions.AddIn/Tools/ToolFactory.cs index 0cb740c..a7f7afc 100644 --- a/RhSolutions.AddIn/Tools/ToolFactory.cs +++ b/RhSolutions.AddIn/Tools/ToolFactory.cs @@ -1,4 +1,4 @@ -using VisionClient.Services; +using OcrClient.Services; namespace RhSolutions.Tools; @@ -7,9 +7,6 @@ internal class ToolFactory static ReaderFactory readerFactory = RhSolutionsAddIn.ServiceProvider.GetService(); static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService(); static FittingsCalculatorFactory fittingsCalculatorFactory = RhSolutionsAddIn.ServiceProvider.GetService(); - static Application application = RhSolutionsAddIn.ServiceProvider.GetService(); - static IYandexVisionClient yandexClinet = RhSolutionsAddIn.ServiceProvider.GetService(); - public Tool GetTool(string toolName) { Tool tool = toolName switch @@ -21,7 +18,7 @@ internal class ToolFactory "guess" => new GuessTool(readerFactory, writerFactory), "fillsleeves" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Sleeves"), "fillcouplings" => new FittingsTool(readerFactory, writerFactory, fittingsCalculatorFactory, "Couplings"), - "ocr" => new OcrTool(readerFactory, writerFactory, application, yandexClinet), + "ocr" => new OcrTool(readerFactory, writerFactory), _ => throw new Exception($"Неизвестный инструмент {toolName}"), }; return tool; diff --git a/RhSolutions.sln b/RhSolutions.sln index ccbd318..54c4ab1 100644 --- a/RhSolutions.sln +++ b/RhSolutions.sln @@ -11,7 +11,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.ProductSku", "R EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnippingTool", "SnippingTool\SnippingTool.csproj", "{DDB517C7-DF61-4C26-B691-956D0E5906C3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisionClient", "VisionClient\VisionClient.csproj", "{53F322B3-F477-4831-8E16-EA76934A0D59}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OcrClient", "OcrClient\OcrClient.csproj", "{53F322B3-F477-4831-8E16-EA76934A0D59}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/VisionClient/Models/VisionResponse.cs b/VisionClient/Models/VisionResponse.cs deleted file mode 100644 index 23a32fd..0000000 --- a/VisionClient/Models/VisionResponse.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace VisionClient.Models; - -public class VisionResponse -{ -} \ No newline at end of file diff --git a/VisionClient/Services/IYandexVisionClient.cs b/VisionClient/Services/IYandexVisionClient.cs deleted file mode 100644 index 77105be..0000000 --- a/VisionClient/Services/IYandexVisionClient.cs +++ /dev/null @@ -1,24 +0,0 @@ -using VisionClient.Models; -using System.Net.Http; - -namespace VisionClient.Services; - -public interface IYandexVisionClient -{ - public Task ProcessImage(string base64Image); -} - -public class YandexVisionClient : IYandexVisionClient -{ - private readonly HttpClient _httpClient; - - public YandexVisionClient(HttpClient httpClient) - { - _httpClient = httpClient; - } - - public Task ProcessImage(string base64Image) - { - throw new NotImplementedException(); - } -} \ No newline at end of file