From ac1d398e6935111312f6ca874e23b62b29fdd2ac Mon Sep 17 00:00:00 2001 From: lzwnet <605106923@qq.com> Date: Sun, 10 Oct 2021 16:43:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9F=BA=E7=A1=80=E6=A1=86?= =?UTF-8?q?=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yi.Framework/Yi.Framework.sln | 25 ++++++++ .../Controllers/WeatherForecastController.cs | 39 ++++++++++++ Yi.Framework/Yi.Framework/Program.cs | 26 ++++++++ .../Properties/launchSettings.json | 31 ++++++++++ Yi.Framework/Yi.Framework/Startup.cs | 59 +++++++++++++++++++ Yi.Framework/Yi.Framework/WeatherForecast.cs | 15 +++++ Yi.Framework/Yi.Framework/Yi.Framework.csproj | 11 ++++ .../Yi.Framework/appsettings.Development.json | 9 +++ Yi.Framework/Yi.Framework/appsettings.json | 10 ++++ 9 files changed, 225 insertions(+) create mode 100644 Yi.Framework/Yi.Framework.sln create mode 100644 Yi.Framework/Yi.Framework/Controllers/WeatherForecastController.cs create mode 100644 Yi.Framework/Yi.Framework/Program.cs create mode 100644 Yi.Framework/Yi.Framework/Properties/launchSettings.json create mode 100644 Yi.Framework/Yi.Framework/Startup.cs create mode 100644 Yi.Framework/Yi.Framework/WeatherForecast.cs create mode 100644 Yi.Framework/Yi.Framework/Yi.Framework.csproj create mode 100644 Yi.Framework/Yi.Framework/appsettings.Development.json create mode 100644 Yi.Framework/Yi.Framework/appsettings.json diff --git a/Yi.Framework/Yi.Framework.sln b/Yi.Framework/Yi.Framework.sln new file mode 100644 index 00000000..1f1b400a --- /dev/null +++ b/Yi.Framework/Yi.Framework.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31515.178 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework", "Yi.Framework\Yi.Framework.csproj", "{6CFCF22D-B8D2-4828-9550-A81CEC6E648A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6CFCF22D-B8D2-4828-9550-A81CEC6E648A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CFCF22D-B8D2-4828-9550-A81CEC6E648A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CFCF22D-B8D2-4828-9550-A81CEC6E648A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CFCF22D-B8D2-4828-9550-A81CEC6E648A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1ED77A6E-377F-4EEF-A3D0-D65C94657DAF} + EndGlobalSection +EndGlobal diff --git a/Yi.Framework/Yi.Framework/Controllers/WeatherForecastController.cs b/Yi.Framework/Yi.Framework/Controllers/WeatherForecastController.cs new file mode 100644 index 00000000..85f9e9ed --- /dev/null +++ b/Yi.Framework/Yi.Framework/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 Yi.Framework.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/Yi.Framework/Yi.Framework/Program.cs b/Yi.Framework/Yi.Framework/Program.cs new file mode 100644 index 00000000..a67477ef --- /dev/null +++ b/Yi.Framework/Yi.Framework/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 Yi.Framework +{ + 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/Yi.Framework/Yi.Framework/Properties/launchSettings.json b/Yi.Framework/Yi.Framework/Properties/launchSettings.json new file mode 100644 index 00000000..6758692d --- /dev/null +++ b/Yi.Framework/Yi.Framework/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:52790", + "sslPort": 44379 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Yi.Framework": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Yi.Framework/Yi.Framework/Startup.cs b/Yi.Framework/Yi.Framework/Startup.cs new file mode 100644 index 00000000..90cf0fbd --- /dev/null +++ b/Yi.Framework/Yi.Framework/Startup.cs @@ -0,0 +1,59 @@ +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 Yi.Framework +{ + 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 = "Yi.Framework", 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(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Yi.Framework v1")); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Yi.Framework/Yi.Framework/WeatherForecast.cs b/Yi.Framework/Yi.Framework/WeatherForecast.cs new file mode 100644 index 00000000..149144ca --- /dev/null +++ b/Yi.Framework/Yi.Framework/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace Yi.Framework +{ + 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/Yi.Framework/Yi.Framework/Yi.Framework.csproj b/Yi.Framework/Yi.Framework/Yi.Framework.csproj new file mode 100644 index 00000000..28847161 --- /dev/null +++ b/Yi.Framework/Yi.Framework/Yi.Framework.csproj @@ -0,0 +1,11 @@ + + + + net5.0 + + + + + + + diff --git a/Yi.Framework/Yi.Framework/appsettings.Development.json b/Yi.Framework/Yi.Framework/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/Yi.Framework/Yi.Framework/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/Yi.Framework/Yi.Framework/appsettings.json b/Yi.Framework/Yi.Framework/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/Yi.Framework/Yi.Framework/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}