Commit 7faabd3d by AlexNasyr

Добавьте файлы проекта.

parent d8795a32

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DDO_Application", "DDO_Application\DDO_Application.csproj", "{D568A3F5-FA39-4244-8CD8-0B179626F4F8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D568A3F5-FA39-4244-8CD8-0B179626F4F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D568A3F5-FA39-4244-8CD8-0B179626F4F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D568A3F5-FA39-4244-8CD8-0B179626F4F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D568A3F5-FA39-4244-8CD8-0B179626F4F8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {249CAA4E-FC26-4E8D-AA8B-ED46749BCB95}
EndGlobalSection
EndGlobal
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using DDO_Application.Model;
using System;
using System.Threading.Tasks;
namespace DDO_Application.Controllers {
[ApiController]
public class apiController : ControllerBase {
public IServiceProvider Services { get; }
private IUploadService _uploadService;
public apiController(IServiceProvider services) {
Services = services;
using (var scope = Services.CreateScope()) {
var uploadProcessingService =
scope.ServiceProvider
.GetRequiredService<IUploadService>();
_uploadService = uploadProcessingService;
}
}
[HttpGet]
[Route("[controller]")]
public async Task<ActionResult<apiStatus>> Get() {
return new apiStatus();
}
[HttpGet]
[Route("[controller]/lifetime")]
public int GetLifetime() => _uploadService.Counter;
}
public class apiStatus {
public string name { get; set; } = "DDO_Application";
public string version { get; set; } = "0.0.0.1";
public string staus { get; set; } = "Ok";
}
}
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
</Project>
using Microsoft.Extensions.Hosting;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace DDO_Application.Model {
public interface IUploadService{
public int Counter { get; }
Task DoWork(CancellationToken stoppingToken);
}
}
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace DDO_Application {
public class Program {
public static void Main(string[] args) {
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => {
webBuilder.UseStartup<Startup>();
});
}
}
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:41712",
"sslPort": 44362
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"DDO_Application": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using DDO_Application.Model;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace DDO_Application.Services {
public class UploadHostedService : BackgroundService {
public IServiceProvider Services { get; }
public UploadHostedService(IServiceProvider services) {
Services = services;
}
private async Task DoWork(CancellationToken stoppingToken) {
using (var scope = Services.CreateScope()) {
var uploadProcessingService =
scope.ServiceProvider
.GetRequiredService<IUploadService>();
await uploadProcessingService.DoWork(stoppingToken);
}
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
await DoWork(stoppingToken);
}
public override async Task StopAsync(CancellationToken stoppingToken) {
await base.StopAsync(stoppingToken);
}
}
}
using Microsoft.Extensions.Hosting;
using DDO_Application.Model;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace DDO_Application.Services {
public class UploadProcessingService : IUploadService {
private int _counter = 0;
public int Counter { get => _counter; }
public UploadProcessingService() {
}
public async Task DoWork(CancellationToken stoppingToken) {
while (!stoppingToken.IsCancellationRequested) {
_counter++;
//что то тут опрашивается... куда то там добавляется....
await Task.Delay(10000, stoppingToken);
}
}
}
}
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using DDO_Application.Model;
using DDO_Application.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace DDO_Application {
public class Startup {
public Startup(IConfiguration configuration) {
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) {
services.AddControllers();
services.AddSwaggerGen(c => {c.SwaggerDoc("v1", new OpenApiInfo { Title = "DDO_Application", Version = "v1" }); });
services.AddHostedService<UploadHostedService>();
services.AddSingleton<IUploadService, UploadProcessingService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "DDO_Application v1"));
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints => {
endpoints.MapControllers();
});
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment