* Maintain FaKrosno api to handle Hangfire
* Added checking of missing EdiCo based on EdiCoTranslate and send email every 30 minutes * Added Admin Scheduler view
This commit is contained in:
@@ -1,35 +1,60 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.Text;
|
||||
using FaKrosnoApi.Models;
|
||||
using FaKrosnoApi.Services;
|
||||
using FaKrosnoEfDataModel;
|
||||
using FaKrosnoEfDataModel.Services;
|
||||
using Hangfire;
|
||||
using Hangfire.SqlServer;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using OrdersManagementDataModel;
|
||||
using OrdersManagementDataModel.Services;
|
||||
using SytelineSaAppEfDataModel;
|
||||
using SytelineSaAppEfDataModel.Services;
|
||||
using FaKrosnoMappingProfile = FaKrosnoEfDataModel.MappingProfile;
|
||||
using SytelineSaAppMappingProfile = SytelineSaAppEfDataModel.MappingProfile;
|
||||
using OrdersManagementMappingProfile = OrdersManagementDataModel.MappingProfile;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var configuration = builder.Configuration;
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddDbContext<FaKrosnoDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("FaKrosnoConnection")));
|
||||
builder.Services.AddDbContext<SytelineSaAppDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("SytelineSaAppConnection")));
|
||||
builder.Services.AddDbContext<OrdersManagementDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("OrdersManagementConnection")));
|
||||
|
||||
builder.Services.Configure<EmailSettingsModel>(builder.Configuration.GetSection("EmailSettings"));
|
||||
builder.Services.Configure<JobSettingsModel>(builder.Configuration.GetSection("JobSettings"));
|
||||
|
||||
builder.WebHost.UseUrls("http://*:5555");
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddOpenApiDocument(config =>
|
||||
{
|
||||
config.Title = "FaKrosnoApi";
|
||||
config.Version = "v1";
|
||||
});
|
||||
|
||||
builder.Services.AddHangfire(config => config
|
||||
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
.UseSimpleAssemblyNameTypeSerializer()
|
||||
.UseRecommendedSerializerSettings()
|
||||
.UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions
|
||||
{
|
||||
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
|
||||
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
|
||||
QueuePollInterval = TimeSpan.Zero,
|
||||
UseRecommendedIsolationLevel = true,
|
||||
DisableGlobalLocks = true
|
||||
}));
|
||||
builder.Services.AddHangfireServer();
|
||||
|
||||
// Configure AutoMapper
|
||||
builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile));
|
||||
builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile),
|
||||
typeof(OrdersManagementMappingProfile));
|
||||
|
||||
// Configure JWT Authentication
|
||||
builder.Services.AddAuthentication(options =>
|
||||
@@ -55,15 +80,15 @@ builder.Services.AddScoped<IScheduleOrderDetailsService, ScheduleOrderDetailsSer
|
||||
builder.Services.AddScoped<IEdiCustomerOrderService, EdiCustomerOrderService>();
|
||||
builder.Services.AddScoped<IErrorLogService, ErrorLogService>();
|
||||
builder.Services.AddScoped<ICustomerOrderService, CustomerOrderService>();
|
||||
builder.Services.AddScoped<IEmailService, EmailService>();
|
||||
builder.Services.AddScoped<IScheduleJobService, ScheduleJobService>();
|
||||
builder.Services.AddScoped<ITaskSchedulerService, TaskSchedulerService>();
|
||||
builder.Services.AddHostedService<TimedHostedService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
//if (app.Environment.IsDevelopment())
|
||||
//{
|
||||
app.UseOpenApi(); // Serwuje dokument OpenAPI
|
||||
app.UseSwaggerUi(); // Dodaje interfejs u<>ytkownika Swagger
|
||||
//}
|
||||
app.UseOpenApi();
|
||||
app.UseSwaggerUi();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
@@ -72,4 +97,13 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.UseHangfireDashboard();
|
||||
|
||||
// var scopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();
|
||||
// using (var scope = scopeFactory.CreateScope())
|
||||
// {
|
||||
// var scheduledJob = scope.ServiceProvider.GetRequiredService<IScheduleJobService>();
|
||||
// scheduledJob.Start();
|
||||
// }
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user