diff --git a/BackgroundService/AppSettingConfiguration.cs b/BackgroundService/AppSettingConfiguration.cs new file mode 100644 index 00000000..3abad3fb --- /dev/null +++ b/BackgroundService/AppSettingConfiguration.cs @@ -0,0 +1,6 @@ +namespace ServiceHost; + +public class AppSettingConfiguration +{ + public string Domain { get; set; } +} \ No newline at end of file diff --git a/BackgroundService/BackgroundService.csproj b/BackgroundService/BackgroundService.csproj new file mode 100644 index 00000000..04656488 --- /dev/null +++ b/BackgroundService/BackgroundService.csproj @@ -0,0 +1,26 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + + + + + + + diff --git a/BackgroundService/FileUploader.cs b/BackgroundService/FileUploader.cs new file mode 100644 index 00000000..71073a3a --- /dev/null +++ b/BackgroundService/FileUploader.cs @@ -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}"; + } + + + } +} diff --git a/BackgroundService/Jobs/JobSchedulerRegistrator.cs b/BackgroundService/Jobs/JobSchedulerRegistrator.cs new file mode 100644 index 00000000..f7ed9d53 --- /dev/null +++ b/BackgroundService/Jobs/JobSchedulerRegistrator.cs @@ -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 + ); + } +} \ No newline at end of file diff --git a/BackgroundService/Jobs/Test/ITestService.cs b/BackgroundService/Jobs/Test/ITestService.cs new file mode 100644 index 00000000..80e2bf42 --- /dev/null +++ b/BackgroundService/Jobs/Test/ITestService.cs @@ -0,0 +1,6 @@ +namespace BackgroundService.Services; + +public interface ITestService +{ + void Execute(); +} \ No newline at end of file diff --git a/BackgroundService/Jobs/Test/TestService.cs b/BackgroundService/Jobs/Test/TestService.cs new file mode 100644 index 00000000..0a52c791 --- /dev/null +++ b/BackgroundService/Jobs/Test/TestService.cs @@ -0,0 +1,9 @@ +namespace BackgroundService.Services; + +public class TestService:ITestService +{ + public void Execute() + { + Console.WriteLine("Hello World!"); + } +} \ No newline at end of file diff --git a/BackgroundService/JobsBootstrapper.cs b/BackgroundService/JobsBootstrapper.cs new file mode 100644 index 00000000..356c3e09 --- /dev/null +++ b/BackgroundService/JobsBootstrapper.cs @@ -0,0 +1,13 @@ +using BackgroundService.Jobs; +using BackgroundService.Services; + +namespace BackgroundService; + +public class JobsBootstrapper +{ + public static void Configure(IServiceCollection services) + { + services.AddTransient(); + services.AddTransient(); + } +} \ No newline at end of file diff --git a/BackgroundService/Program.cs b/BackgroundService/Program.cs new file mode 100644 index 00000000..5a27404b --- /dev/null +++ b/BackgroundService/Program.cs @@ -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(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.Configure(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(); + jobScheduler.Register(); +} + +app.Run(); \ No newline at end of file diff --git a/BackgroundService/Properties/launchSettings.json b/BackgroundService/Properties/launchSettings.json new file mode 100644 index 00000000..1e0366b9 --- /dev/null +++ b/BackgroundService/Properties/launchSettings.json @@ -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" + } + } + } +} diff --git a/BackgroundService/appsettings.Development.json b/BackgroundService/appsettings.Development.json new file mode 100644 index 00000000..6fb4e9d1 --- /dev/null +++ b/BackgroundService/appsettings.Development.json @@ -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" +} diff --git a/BackgroundService/appsettings.json b/BackgroundService/appsettings.json new file mode 100644 index 00000000..f372fc70 --- /dev/null +++ b/BackgroundService/appsettings.json @@ -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": "*" +} diff --git a/DadmehrGostar.sln b/DadmehrGostar.sln index 2a84d932..ef48c55e 100644 --- a/DadmehrGostar.sln +++ b/DadmehrGostar.sln @@ -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