Initial commit

This commit is contained in:
Sergey Nazarov 2024-03-19 23:44:39 +04:00
commit 98f56ed212
19 changed files with 504 additions and 0 deletions

25
.dockerignore Normal file
View File

@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

231
.gitignore vendored Normal file
View File

@ -0,0 +1,231 @@
# The 5 approved on boarding samples that need wwwroot/lib/ can add a local .gitignore that allows wwwroot/lib/.
# with 2.1 templates and excluding .min & .map -> 27 files and < 1 KB
# 3.0 templates should be even less
# wwwroot/lib/
# When wwwroot/lib/ is commented out, excluse .min and .map files
*.min.css
*.min.js
*.map
_build/
_site/
Properties/
Project_Readme.html
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
.vscode/
!.vscode/extensions.json
!.vscode/settings.json
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
.idea/
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
# Visual Studo 2015 cache/options directory
.vs/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding addin-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
*.[Cc]ache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
project.lock.json
__pycache__/
#Mac OSX
.DS_Store
# Windows thumbnail cache files
Thumbs.db
# idea
.idea/
# custom
/**/**/appsettings.protected.json
**/**/deployment.yml

5
Directory.Build.props Normal file
View File

@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
</Project>

16
Directory.Packages.props Normal file
View File

@ -0,0 +1,16 @@
<Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<MicrosoftVersion>8.0.0</MicrosoftVersion>
</PropertyGroup>
<ItemGroup Label="Serilog">
<PackageVersion Include="Serilog" Version="3.1.1"/>
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1"/>
<PackageVersion Include="Serilog.Settings.Configuration" Version="8.0.0"/>
</ItemGroup>
<ItemGroup Label="Microsoft">
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftVersion)"/>
</ItemGroup>
</Project>

36
Nocr.TextMatcher.sln Normal file
View File

@ -0,0 +1,36 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9CF552C7-A0FB-4C13-A156-8A9EA6C85EC1}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
.gitignore = .gitignore
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nocr.TextMatcher.Core", "src\Nocr.TextMatcher.Core\Nocr.TextMatcher.Core.csproj", "{3E87693C-78DF-469B-BAA3-CB103F8EA80B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nocr.TextMatcher.AppServices", "src\Nocr.TextMatcher.AppServices\Nocr.TextMatcher.AppServices.csproj", "{5CCB085C-860A-4C4C-907C-10183ABCEA9B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nocr.TextMatcher.Host", "src\Nocr.TextMatcher.Host\Nocr.TextMatcher.Host.csproj", "{58D5C9FD-75A9-4FFB-9FBD-BE8E9FCE3016}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3E87693C-78DF-469B-BAA3-CB103F8EA80B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E87693C-78DF-469B-BAA3-CB103F8EA80B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E87693C-78DF-469B-BAA3-CB103F8EA80B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E87693C-78DF-469B-BAA3-CB103F8EA80B}.Release|Any CPU.Build.0 = Release|Any CPU
{5CCB085C-860A-4C4C-907C-10183ABCEA9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5CCB085C-860A-4C4C-907C-10183ABCEA9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5CCB085C-860A-4C4C-907C-10183ABCEA9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5CCB085C-860A-4C4C-907C-10183ABCEA9B}.Release|Any CPU.Build.0 = Release|Any CPU
{58D5C9FD-75A9-4FFB-9FBD-BE8E9FCE3016}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58D5C9FD-75A9-4FFB-9FBD-BE8E9FCE3016}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58D5C9FD-75A9-4FFB-9FBD-BE8E9FCE3016}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58D5C9FD-75A9-4FFB-9FBD-BE8E9FCE3016}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

2
README.md Normal file
View File

@ -0,0 +1,2 @@
Nocr text matcher
===

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nocr.TextMatcher.Core\Nocr.TextMatcher.Core.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,16 @@
using Microsoft.Extensions.DependencyInjection;
namespace Nocr.TextMatcher.AppServices;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddAppServices(this IServiceCollection services)
{
if (services == null)
throw new ArgumentNullException(nameof(services));
// Add registrations here
return services;
}
}

View File

@ -0,0 +1,6 @@
namespace Nocr.TextMatcher.Core.Dates;
public sealed class DefaultCurrentDateProvider : ICurrentDateProvider
{
public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
}

View File

@ -0,0 +1,6 @@
namespace Nocr.TextMatcher.Core.Dates;
public interface ICurrentDateProvider
{
public DateTimeOffset UtcNow { get; }
}

View File

@ -0,0 +1,2 @@
<Project Sdk="Microsoft.NET.Sdk">
</Project>

View File

@ -0,0 +1,20 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "src/Nocr.TextMatcher.Host/Nocr.TextMatcher.Host.csproj"
WORKDIR "/src/src/Nocr.TextMatcher.Host"
RUN dotnet build "Nocr.TextMatcher.Host.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Nocr.TextMatcher.Host.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Nocr.TextMatcher.Host.dll"]

View File

@ -0,0 +1,26 @@
using Serilog;
namespace Nocr.TextMatcher.Host.Infrastructure;
public class HostBuilderFactory<TStartup> where TStartup : class
{
public IHostBuilder CreateHostBuilder(string[] args, string? baseDirectory = null)
{
var builder = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((_, configurationBuilder) =>
{
if (!string.IsNullOrWhiteSpace(baseDirectory))
configurationBuilder.SetBasePath(baseDirectory);
configurationBuilder.AddJsonFile("appsettings.protected.json", false);
})
.ConfigureWebHostDefaults(host => { host.UseStartup<TStartup>(); })
.UseSerilog((ctx, logBuilder) =>
{
logBuilder.ReadFrom.Configuration(ctx.Configuration)
.Enrich.FromLogContext();
});
return builder;
}
}

View File

@ -0,0 +1,25 @@
using Nocr.TextMatcher.AppServices;
using Nocr.TextMatcher.Core.Dates;
namespace Nocr.TextMatcher.Host.Infrastructure;
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<ICurrentDateProvider, DefaultCurrentDateProvider>();
services.AddAppServices();
}
public void Configure(IApplicationBuilder app)
{
}
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nocr.TextMatcher.AppServices\Nocr.TextMatcher.AppServices.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>
</Project>

View File

@ -0,0 +1,7 @@
using Nocr.TextMatcher.Host.Infrastructure;
var host = new HostBuilderFactory<Startup>()
.CreateHostBuilder(args)
.Build();
await host.RunAsync();

View File

@ -0,0 +1,12 @@
{
"Serilog": {
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Level:u3}] {Timestamp:MM-dd HH:mm:ss} {TraceId} {SourceContext:l} {Message:lj}{NewLine}{Exception}"
}
}
]
}
}

View File

@ -0,0 +1,25 @@
{
"Serilog": {
"MinimumLevel": {
"Default": "Information"
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Level:u3}] {Timestamp:MM-dd HH:mm:ss} {TraceId} {SourceContext:l} {Message:lj}{NewLine}{Exception}"
}
},
{
"Name": "File",
"Args": {
"path": "/var/log/nocr/text-matcher/nocr-text-matcher-.log",
"outputTemplate": "[{Level:u3}] {Timestamp:dd-MM-yyyy HH:mm:ss} {TraceId} {SourceContext:l} {Message:lj}{NewLine}{Exception}",
"fileSizeLimitBytes": 104857600,
"rollingInterval": "Day",
"rollOnFileSizeLimit": true
}
}
]
}
}

View File

@ -0,0 +1,12 @@
{
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Information",
"Microsoft.AspNetCore": "Error",
"System.Net.Http.HttpClient": "Warning"
}
}
}
}