From 9b7fafebc655d0186782a796214c3934c1f59be9 Mon Sep 17 00:00:00 2001 From: wenjy Date: Thu, 26 Oct 2023 15:19:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Durkee.Mes.Api.sln | 25 +++++++ .../Controllers/WeatherForecastController.cs | 39 +++++++++++ Durkee.Mes.Api/Durkee.Mes.Api.csproj | 12 ++++ Durkee.Mes.Api/Program.cs | 26 +++++++ Durkee.Mes.Api/Properties/launchSettings.json | 30 ++++++++ Durkee.Mes.Api/Startup.cs | 68 +++++++++++++++++++ Durkee.Mes.Api/WeatherForecast.cs | 15 ++++ Durkee.Mes.Api/appsettings.Development.json | 9 +++ Durkee.Mes.Api/appsettings.json | 10 +++ 9 files changed, 234 insertions(+) create mode 100644 Durkee.Mes.Api.sln create mode 100644 Durkee.Mes.Api/Controllers/WeatherForecastController.cs create mode 100644 Durkee.Mes.Api/Durkee.Mes.Api.csproj create mode 100644 Durkee.Mes.Api/Program.cs create mode 100644 Durkee.Mes.Api/Properties/launchSettings.json create mode 100644 Durkee.Mes.Api/Startup.cs create mode 100644 Durkee.Mes.Api/WeatherForecast.cs create mode 100644 Durkee.Mes.Api/appsettings.Development.json create mode 100644 Durkee.Mes.Api/appsettings.json diff --git a/Durkee.Mes.Api.sln b/Durkee.Mes.Api.sln new file mode 100644 index 0000000..f172e5d --- /dev/null +++ b/Durkee.Mes.Api.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33502.453 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Durkee.Mes.Api", "Durkee.Mes.Api\Durkee.Mes.Api.csproj", "{30BF9893-8860-4267-BDDC-C1D220DF702C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {30BF9893-8860-4267-BDDC-C1D220DF702C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {30BF9893-8860-4267-BDDC-C1D220DF702C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {30BF9893-8860-4267-BDDC-C1D220DF702C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {30BF9893-8860-4267-BDDC-C1D220DF702C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8D909793-BE22-4157-85AC-DC8E04A4E777} + EndGlobalSection +EndGlobal diff --git a/Durkee.Mes.Api/Controllers/WeatherForecastController.cs b/Durkee.Mes.Api/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..8f11e65 --- /dev/null +++ b/Durkee.Mes.Api/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Durkee.Mes.Api.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/Durkee.Mes.Api/Durkee.Mes.Api.csproj b/Durkee.Mes.Api/Durkee.Mes.Api.csproj new file mode 100644 index 0000000..4944084 --- /dev/null +++ b/Durkee.Mes.Api/Durkee.Mes.Api.csproj @@ -0,0 +1,12 @@ + + + + netcoreapp3.1 + + + + + + + + diff --git a/Durkee.Mes.Api/Program.cs b/Durkee.Mes.Api/Program.cs new file mode 100644 index 0000000..494565b --- /dev/null +++ b/Durkee.Mes.Api/Program.cs @@ -0,0 +1,26 @@ +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 Durkee.Mes.Api +{ + 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(); + }); + } +} diff --git a/Durkee.Mes.Api/Properties/launchSettings.json b/Durkee.Mes.Api/Properties/launchSettings.json new file mode 100644 index 0000000..b3abb02 --- /dev/null +++ b/Durkee.Mes.Api/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:32147", + "sslPort": 44302 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + //"launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Durkee.Mes.Api": { + "commandName": "Project", + "launchBrowser": true, + //"launchUrl": "swagger", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Durkee.Mes.Api/Startup.cs b/Durkee.Mes.Api/Startup.cs new file mode 100644 index 0000000..5fbe708 --- /dev/null +++ b/Durkee.Mes.Api/Startup.cs @@ -0,0 +1,68 @@ +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 System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Durkee.Mes.Api +{ + 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(); + + //ÅäÖÃSwagger + services.AddSwaggerGen(swagger => + { + swagger.SwaggerDoc("v1", new OpenApiInfo { Title = "¶Å¿ÏMES Web Api", Version = "v1" }); + }); + } + + // 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(); + } + + //ÆôÓÃSwaggerÖмä¼þ + app.UseSwagger(); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "¶Å¿ÏMES Web Api"); + c.RoutePrefix = ""; + //c.DefaultModelRendering(ModelRendering.Example); // ÉèÖÃĬÈϵÄÄ£ÐÍäÖȾ·½Ê½£¨¿ÉÑ¡£© + //c.DisplayRequestDuration(); // ÏÔʾÇëÇó³ÖÐøʱ¼ä£¨¿ÉÑ¡£© + }); + + //app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Durkee.Mes.Api/WeatherForecast.cs b/Durkee.Mes.Api/WeatherForecast.cs new file mode 100644 index 0000000..2e13698 --- /dev/null +++ b/Durkee.Mes.Api/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace Durkee.Mes.Api +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git a/Durkee.Mes.Api/appsettings.Development.json b/Durkee.Mes.Api/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/Durkee.Mes.Api/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Durkee.Mes.Api/appsettings.json b/Durkee.Mes.Api/appsettings.json new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ b/Durkee.Mes.Api/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}