add Hangfire Prj
This commit is contained in:
6
BackgroundService/AppSettingConfiguration.cs
Normal file
6
BackgroundService/AppSettingConfiguration.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace ServiceHost;
|
||||
|
||||
public class AppSettingConfiguration
|
||||
{
|
||||
public string Domain { get; set; }
|
||||
}
|
||||
26
BackgroundService/BackgroundService.csproj
Normal file
26
BackgroundService/BackgroundService.csproj
Normal file
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Hangfire" Version="1.8.20" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.20" />
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AccountManagement.Configuration\AccountManagement.Configuration.csproj" />
|
||||
<ProjectReference Include="..\PersonalContractingParty.Config\PersonalContractingParty.Config.csproj" />
|
||||
<ProjectReference Include="..\Query.Bootstrapper\Query.Bootstrapper.csproj" />
|
||||
<ProjectReference Include="..\WorkFlow\Infrastructure\WorkFlow.Infrastructure.Config\WorkFlow.Infrastructure.Config.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Jobs\Task\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
32
BackgroundService/FileUploader.cs
Normal file
32
BackgroundService/FileUploader.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using _0_Framework.Application;
|
||||
|
||||
namespace BackgroundService
|
||||
{
|
||||
public class FileUploader : IFileUploader
|
||||
{
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
|
||||
public FileUploader(IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
}
|
||||
|
||||
public string Upload(IFormFile file, string path)
|
||||
{
|
||||
if (file == null) return "";
|
||||
|
||||
var directoryPath = $"{_webHostEnvironment.WebRootPath}\\ProductPictures\\{path}";
|
||||
|
||||
if (!Directory.Exists(directoryPath))
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
|
||||
var fileName = $"{DateTime.Now.ToFileName()}-{file.FileName}";
|
||||
var filePath = $"{directoryPath}\\{fileName}";
|
||||
var output = System.IO.File.Create(filePath);
|
||||
file.CopyTo(output);
|
||||
return $"{path}/{fileName}";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
23
BackgroundService/Jobs/JobSchedulerRegistrator.cs
Normal file
23
BackgroundService/Jobs/JobSchedulerRegistrator.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using BackgroundService.Services;
|
||||
using Hangfire;
|
||||
|
||||
namespace BackgroundService.Jobs;
|
||||
|
||||
public class JobSchedulerRegistrator
|
||||
{
|
||||
|
||||
private readonly ITestService _testService;
|
||||
public JobSchedulerRegistrator(ITestService testService)
|
||||
{
|
||||
_testService = testService;
|
||||
}
|
||||
|
||||
public void Register()
|
||||
{
|
||||
RecurringJob.AddOrUpdate(
|
||||
"job1",
|
||||
() => _testService.Execute(),
|
||||
Cron.Hourly
|
||||
);
|
||||
}
|
||||
}
|
||||
6
BackgroundService/Jobs/Test/ITestService.cs
Normal file
6
BackgroundService/Jobs/Test/ITestService.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace BackgroundService.Services;
|
||||
|
||||
public interface ITestService
|
||||
{
|
||||
void Execute();
|
||||
}
|
||||
9
BackgroundService/Jobs/Test/TestService.cs
Normal file
9
BackgroundService/Jobs/Test/TestService.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace BackgroundService.Services;
|
||||
|
||||
public class TestService:ITestService
|
||||
{
|
||||
public void Execute()
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
13
BackgroundService/JobsBootstrapper.cs
Normal file
13
BackgroundService/JobsBootstrapper.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using BackgroundService.Jobs;
|
||||
using BackgroundService.Services;
|
||||
|
||||
namespace BackgroundService;
|
||||
|
||||
public class JobsBootstrapper
|
||||
{
|
||||
public static void Configure(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<ITestService, TestService>();
|
||||
services.AddTransient<JobSchedulerRegistrator>();
|
||||
}
|
||||
}
|
||||
46
BackgroundService/Program.cs
Normal file
46
BackgroundService/Program.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using _0_Framework.Application;
|
||||
using _0_Framework.Application.Sms;
|
||||
using _0_Framework.Application.UID;
|
||||
using AccountManagement.Configuration;
|
||||
using BackgroundService;
|
||||
using BackgroundService.Jobs;
|
||||
using BackgroundService.Services;
|
||||
using Hangfire;
|
||||
using PersonalContractingParty.Config;
|
||||
using Query.Bootstrapper;
|
||||
using ServiceHost;
|
||||
using WorkFlow.Infrastructure.Config;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var hangfireConnectionString = builder.Configuration.GetConnectionString("HangfireDb");
|
||||
builder.Services.AddHangfire(x => x.UseSqlServerStorage(hangfireConnectionString));
|
||||
builder.Services.AddHangfireServer();
|
||||
var connectionString = builder.Configuration.GetConnectionString("MesbahDb");
|
||||
var connectionStringTestDb = builder.Configuration.GetConnectionString("TestDb");
|
||||
builder.Services.AddSingleton<IPasswordHasher, PasswordHasher>();
|
||||
builder.Services.AddTransient<IAuthHelper, AuthHelper>();
|
||||
builder.Services.AddTransient<ISmsService, SmsService>();
|
||||
builder.Services.AddTransient<IUidService, UidService>();
|
||||
builder.Services.AddTransient<IFileUploader, FileUploader>();
|
||||
builder.Services.Configure<AppSettingConfiguration>(builder.Configuration);
|
||||
|
||||
PersonalBootstrapper.Configure(builder.Services, connectionString);
|
||||
TestDbBootStrapper.Configure(builder.Services, connectionStringTestDb);
|
||||
AccountManagementBootstrapper.Configure(builder.Services, connectionString);
|
||||
WorkFlowBootstrapper.Configure(builder.Services, connectionString);
|
||||
QueryBootstrapper.Configure(builder.Services);
|
||||
JobsBootstrapper.Configure(builder.Services);
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapHangfireDashboard();
|
||||
app.MapGet("/", () => "Hello World!");
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var jobScheduler = scope.ServiceProvider.GetRequiredService<JobSchedulerRegistrator>();
|
||||
jobScheduler.Register();
|
||||
}
|
||||
|
||||
app.Run();
|
||||
38
BackgroundService/Properties/launchSettings.json
Normal file
38
BackgroundService/Properties/launchSettings.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:38468",
|
||||
"sslPort": 44358
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5105",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7000;http://localhost:5105",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
BackgroundService/appsettings.Development.json
Normal file
26
BackgroundService/appsettings.Development.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
//تست
|
||||
//"MesbahDb": "Data Source=DESKTOP-NUE119G\\MSNEW;Initial Catalog=Mesbah_db;Integrated Security=True"
|
||||
|
||||
//server
|
||||
//"MesbahDb": "Data Source=171.22.24.15;Initial Catalog=mesbah_db;Persist Security Info=False;User ID=ir_db;Password=R2rNp[170]18[3019]#@ATt;TrustServerCertificate=true;",
|
||||
|
||||
|
||||
//local
|
||||
"MesbahDb": "Data Source=.;Initial Catalog=mesbah_db;Integrated Security=True;TrustServerCertificate=true;",
|
||||
"hangfireDb": "Data Source=.;Initial Catalog=hangfire_db;Integrated Security=True;TrustServerCertificate=true;",
|
||||
|
||||
"TestDb": "Data Source=.;Initial Catalog=TestDb;Integrated Security=True;TrustServerCertificate=true;"
|
||||
|
||||
//mahan Docker
|
||||
//"MesbahDb": "Data Source=localhost,5069;Initial Catalog=mesbah_db;User ID=sa;Password=YourPassword123;TrustServerCertificate=True;"
|
||||
},
|
||||
"Domain": ".gozareshgir.ir"
|
||||
}
|
||||
26
BackgroundService/appsettings.json
Normal file
26
BackgroundService/appsettings.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
//تست
|
||||
//"MesbahDb": "Data Source=DESKTOP-NUE119G\\MSNEW;Initial Catalog=Mesbah_db;Integrated Security=True"
|
||||
|
||||
//server
|
||||
//"MesbahDb": "Data Source=171.22.24.15;Initial Catalog=mesbah_db;Persist Security Info=False;User ID=ir_db;Password=R2rNp[170]18[3019]#@ATt;TrustServerCertificate=true;",
|
||||
|
||||
|
||||
//local
|
||||
"MesbahDb": "Data Source=.;Initial Catalog=mesbah_db;Integrated Security=True;TrustServerCertificate=true;",
|
||||
|
||||
"TestDb": "Data Source=.;Initial Catalog=TestDb;Integrated Security=True;TrustServerCertificate=true;"
|
||||
|
||||
//mahan Docker
|
||||
//"MesbahDb": "Data Source=localhost,5069;Initial Catalog=mesbah_db;User ID=sa;Password=YourPassword123;TrustServerCertificate=True;"
|
||||
},
|
||||
"Domain": ".gozareshgir.ir",
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@@ -80,6 +80,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Query.Bootstrapper", "Query
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompanyManagement.Infrastructure.Excel", "CompanyManagement.Infrastructure.Excel\CompanyManagement.Infrastructure.Excel.csproj", "{BF98173C-42AF-4897-A7CB-4CACEB2B52A2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BackgroundService", "BackgroundService\BackgroundService.csproj", "{6C97118D-0497-48A6-846B-E44402FB824F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -178,6 +180,10 @@ Global
|
||||
{BF98173C-42AF-4897-A7CB-4CACEB2B52A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BF98173C-42AF-4897-A7CB-4CACEB2B52A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BF98173C-42AF-4897-A7CB-4CACEB2B52A2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6C97118D-0497-48A6-846B-E44402FB824F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6C97118D-0497-48A6-846B-E44402FB824F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6C97118D-0497-48A6-846B-E44402FB824F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6C97118D-0497-48A6-846B-E44402FB824F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user