OcrTool refactoring
This commit is contained in:
parent
cd9c2734f0
commit
cc52668afc
5
OcrClient/Models/OcrResponse.cs
Normal file
5
OcrClient/Models/OcrResponse.cs
Normal file
@ -0,0 +1,5 @@
|
||||
namespace OcrClient.Models;
|
||||
|
||||
public class OcrResponse
|
||||
{
|
||||
}
|
8
OcrClient/Services/IOcrClient.cs
Normal file
8
OcrClient/Services/IOcrClient.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using OcrClient.Models;
|
||||
|
||||
namespace OcrClient.Services;
|
||||
|
||||
public interface IOcrClient
|
||||
{
|
||||
public Task<OcrResponse> ProcessImage(string base64Image);
|
||||
}
|
19
OcrClient/Services/OcrClient.cs
Normal file
19
OcrClient/Services/OcrClient.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
@ -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>();
|
||||
|
||||
|
@ -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">
|
||||
|
@ -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 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -1,5 +0,0 @@
|
||||
namespace VisionClient.Models;
|
||||
|
||||
public class VisionResponse
|
||||
{
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user