From fa646ceab39636b0ec65a05f6beac79e3004a2b5 Mon Sep 17 00:00:00 2001 From: tongfei <244188119@qq.com> Date: Tue, 17 Oct 2023 17:15:46 +0800 Subject: [PATCH] new --- .dockerignore | 25 +++++++++ Dockerfile | 22 ++++++++ WMS.Web.sln | 25 +++++++++ .../Controllers/WeatherForecastController.cs | 39 ++++++++++++++ src/WMS.Web.Api/Program.cs | 26 ++++++++++ .../Properties/launchSettings.json | 37 ++++++++++++++ src/WMS.Web.Api/Startup.cs | 51 +++++++++++++++++++ src/WMS.Web.Api/WMS.Web.Api.csproj | 15 ++++++ src/WMS.Web.Api/WeatherForecast.cs | 15 ++++++ src/WMS.Web.Api/appsettings.Development.json | 9 ++++ src/WMS.Web.Api/appsettings.json | 10 ++++ 11 files changed, 274 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 WMS.Web.sln create mode 100644 src/WMS.Web.Api/Controllers/WeatherForecastController.cs create mode 100644 src/WMS.Web.Api/Program.cs create mode 100644 src/WMS.Web.Api/Properties/launchSettings.json create mode 100644 src/WMS.Web.Api/Startup.cs create mode 100644 src/WMS.Web.Api/WMS.Web.Api.csproj create mode 100644 src/WMS.Web.Api/WeatherForecast.cs create mode 100644 src/WMS.Web.Api/appsettings.Development.json create mode 100644 src/WMS.Web.Api/appsettings.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..3729ff0c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..718f2594 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build +WORKDIR /src +COPY ["src/WMS.Web.Api/WMS.Web.Api.csproj", "src/WMS.Web.Api/"] +RUN dotnet restore "src/WMS.Web.Api/WMS.Web.Api.csproj" +COPY . . +WORKDIR "/src/src/WMS.Web.Api" +RUN dotnet build "WMS.Web.Api.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "WMS.Web.Api.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "WMS.Web.Api.dll"] \ No newline at end of file diff --git a/WMS.Web.sln b/WMS.Web.sln new file mode 100644 index 00000000..0e5febb2 --- /dev/null +++ b/WMS.Web.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31729.503 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WMS.Web.Api", "src\WMS.Web.Api\WMS.Web.Api.csproj", "{6BC3A5E0-0590-4F16-B7A0-DAAC5591001C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6BC3A5E0-0590-4F16-B7A0-DAAC5591001C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6BC3A5E0-0590-4F16-B7A0-DAAC5591001C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6BC3A5E0-0590-4F16-B7A0-DAAC5591001C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6BC3A5E0-0590-4F16-B7A0-DAAC5591001C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {21BBA12F-F22D-49DA-BA61-F5598323B09C} + EndGlobalSection +EndGlobal diff --git a/src/WMS.Web.Api/Controllers/WeatherForecastController.cs b/src/WMS.Web.Api/Controllers/WeatherForecastController.cs new file mode 100644 index 00000000..e020b077 --- /dev/null +++ b/src/WMS.Web.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 WMS.Web.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/src/WMS.Web.Api/Program.cs b/src/WMS.Web.Api/Program.cs new file mode 100644 index 00000000..63f7ff8b --- /dev/null +++ b/src/WMS.Web.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 WMS.Web.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/src/WMS.Web.Api/Properties/launchSettings.json b/src/WMS.Web.Api/Properties/launchSettings.json new file mode 100644 index 00000000..e0e3f142 --- /dev/null +++ b/src/WMS.Web.Api/Properties/launchSettings.json @@ -0,0 +1,37 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:58992", + "sslPort": 44388 + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "WMS.Web.Api": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast", + "publishAllPorts": true, + "useSSL": true + } + } +} \ No newline at end of file diff --git a/src/WMS.Web.Api/Startup.cs b/src/WMS.Web.Api/Startup.cs new file mode 100644 index 00000000..c82e83f9 --- /dev/null +++ b/src/WMS.Web.Api/Startup.cs @@ -0,0 +1,51 @@ +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 System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace WMS.Web.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(); + } + + // 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.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/src/WMS.Web.Api/WMS.Web.Api.csproj b/src/WMS.Web.Api/WMS.Web.Api.csproj new file mode 100644 index 00000000..a44c9f0d --- /dev/null +++ b/src/WMS.Web.Api/WMS.Web.Api.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + 090fb557-3527-4995-8546-69cdb53a420a + Linux + ..\.. + + + + + + + + diff --git a/src/WMS.Web.Api/WeatherForecast.cs b/src/WMS.Web.Api/WeatherForecast.cs new file mode 100644 index 00000000..0a3d4600 --- /dev/null +++ b/src/WMS.Web.Api/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace WMS.Web.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/src/WMS.Web.Api/appsettings.Development.json b/src/WMS.Web.Api/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/src/WMS.Web.Api/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/src/WMS.Web.Api/appsettings.json b/src/WMS.Web.Api/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/src/WMS.Web.Api/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}