aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerghei Cebotari <serghei@cebotari.ru>2024-11-09 22:34:58 +0300
committerSerghei Cebotari <serghei@cebotari.ru>2024-11-09 22:34:58 +0300
commitcc52668afc1d30720eb9dc42efdcf1539864179e (patch)
tree7ab15e23fc0d0790d9032e8735ef8cfb9183b748
parentcd9c2734f08f45d19e92f39c5c2c0b1344652b58 (diff)
OcrTool refactoring
-rw-r--r--OcrClient/Models/OcrResponse.cs5
-rw-r--r--OcrClient/OcrClient.csproj (renamed from VisionClient/VisionClient.csproj)0
-rw-r--r--OcrClient/Services/IOcrClient.cs8
-rw-r--r--OcrClient/Services/OcrClient.cs19
-rw-r--r--RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs4
-rw-r--r--RhSolutions.AddIn/RhSolutions.AddIn.csproj2
-rw-r--r--RhSolutions.AddIn/Tools/OcrTool.cs42
-rw-r--r--RhSolutions.AddIn/Tools/ToolFactory.cs7
-rw-r--r--RhSolutions.sln2
-rw-r--r--VisionClient/Models/VisionResponse.cs5
-rw-r--r--VisionClient/Services/IYandexVisionClient.cs24
11 files changed, 63 insertions, 55 deletions
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
index 4f78021..4f78021 100644
--- a/VisionClient/VisionClient.csproj
+++ b/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<OcrResponse> 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<OcrResponse> 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<SleevesCalculator>()
.AddTransient<IFittingsCalculator, SleevesCalculator>(s => s.GetService<SleevesCalculator>());
- Services.AddTransient<IYandexVisionClient, YandexVisionClient>();
+ Services.AddTransient<IOcrClient, YandexOcrClient>();
Services.AddSingleton<ToolFactory>();
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 @@
<ItemGroup>
<ProjectReference Include="..\RhSolutions.ProductSku\RhSolutions.ProductSku.csproj" />
<ProjectReference Include="..\SnippingTool\SnippingTool.csproj" />
- <ProjectReference Include="..\VisionClient\VisionClient.csproj" />
+ <ProjectReference Include="..\OcrClient\OcrClient.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Images\Coupling.png">
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<IOcrClient>();
+
+ public OcrTool(ReaderFactory readerFactory, WriterFactory writerFactory) : base(readerFactory, writerFactory)
+ {
+ }
- public override void Execute()
+ public override void Execute()
{
- Application.Visible = false;
- Task.Run(async delegate
+ try
+ {
+ 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
{
- await Task.Delay(100);
- }).Wait();
-
- string shot = Snipper.SnipBase64();
- var result = client.ProcessImage(shot);
-
- Application.Visible = true;
+ 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<ReaderFactory>();
static WriterFactory writerFactory = RhSolutionsAddIn.ServiceProvider.GetService<WriterFactory>();
static FittingsCalculatorFactory fittingsCalculatorFactory = RhSolutionsAddIn.ServiceProvider.GetService<FittingsCalculatorFactory>();
- static Application application = RhSolutionsAddIn.ServiceProvider.GetService<Application>();
- static IYandexVisionClient yandexClinet = RhSolutionsAddIn.ServiceProvider.GetService<IYandexVisionClient>();
-
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<VisionResponse> ProcessImage(string base64Image);
-}
-
-public class YandexVisionClient : IYandexVisionClient
-{
- private readonly HttpClient _httpClient;
-
- public YandexVisionClient(HttpClient httpClient)
- {
- _httpClient = httpClient;
- }
-
- public Task<VisionResponse> ProcessImage(string base64Image)
- {
- throw new NotImplementedException();
- }
-} \ No newline at end of file