From 5f8b1e41ece925d646b8eb8696674fa34e233d52 Mon Sep 17 00:00:00 2001 From: Bradley Grainger Date: Sun, 15 May 2022 19:51:04 -0700 Subject: [PATCH 1/3] Update to .NET 7. --- .github/workflows/build.yml | 8 ++++---- FuGetGallery.csproj | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 941b840..a7b6e56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,12 +9,12 @@ jobs: steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - - name: Set up .NET 5.0 - uses: actions/setup-dotnet@v1 + - name: Set up .NET 7.0 + uses: actions/setup-dotnet@v3 with: - dotnet-version: 5.0.x + dotnet-version: 7.0.x - name: Build run: | diff --git a/FuGetGallery.csproj b/FuGetGallery.csproj index 9ff1690..a5e889a 100644 --- a/FuGetGallery.csproj +++ b/FuGetGallery.csproj @@ -1,22 +1,22 @@  - net5.0 + net7.0 9.0 - + - - - - - - + + + + + + From 17391737510cda5d06f22bb547ae595c79cd10ff Mon Sep 17 00:00:00 2001 From: Bradley Grainger Date: Tue, 8 Nov 2022 15:13:43 -0800 Subject: [PATCH 2/3] Use minimal APIs. --- Program.cs | 70 ++++++++++++++++++++++++++++++++++++++++++++------- Startup.cs | 74 ------------------------------------------------------ 2 files changed, 61 insertions(+), 83 deletions(-) delete mode 100644 Startup.cs diff --git a/Program.cs b/Program.cs index 403f9fc..008aab3 100644 --- a/Program.cs +++ b/Program.cs @@ -1,9 +1,61 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; - -Host.CreateDefaultBuilder (args) - .ConfigureWebHostDefaults (webBuilder => { - webBuilder.UseStartup (); - }) - .Build () - .Run (); +using System; +using System.Net; +using System.Net.Http; +using FuGetGallery; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.ResponseCompression; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +var builder = WebApplication.CreateBuilder (args); + +var services = builder.Services; + +try { + new Database ().MigrateAsync ().Wait (); + services.AddScoped (); +} +catch (Exception dbex) { + Console.WriteLine ($"Failed to open the database: {dbex}"); +} +services.AddControllers (); +services.AddRazorPages (options => +{ + options.Conventions.AddPageRoute ("/packages/details", "packages/{id}"); + options.Conventions.AddPageRoute ("/packages/badges", "packages/{id}/badges"); + options.Conventions.AddPageRoute ("/packages/dependents", "packages/{id}/dependents"); + options.Conventions.AddPageRoute ("/packages/details", "packages/{id}/{version}"); + options.Conventions.AddPageRoute ("/packages/details", "packages/{id}/{version}/{dir}"); + options.Conventions.AddPageRoute ("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}"); + options.Conventions.AddPageRoute ("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}/{assemblyName}"); + options.Conventions.AddPageRoute ("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}/{assemblyName}/{namespace}"); + options.Conventions.AddPageRoute ("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}/{assemblyName}/{namespace}/{typeName}"); +}); +services.Configure (options => options.Level = System.IO.Compression.CompressionLevel.Optimal); +services.AddResponseCompression (); +services.AddHttpClient ("") + .ConfigurePrimaryHttpMessageHandler (() => new HttpClientHandler { + AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, + }); + +var app = builder.Build (); + +NugetPackageSources.Configure (app.Configuration); + +app.UseResponseCompression (); + +if (app.Environment.IsDevelopment ()) { + app.UseDeveloperExceptionPage (); +} +else { + app.UseExceptionHandler ("/error"); +} + +app.UseStaticFiles (); +app.UseRouting (); + +app.MapControllers (); +app.MapRazorPages (); + +app.Run (); + diff --git a/Startup.cs b/Startup.cs deleted file mode 100644 index 11208a7..0000000 --- a/Startup.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Net; -using System.Net.Http; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.ResponseCompression; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace FuGetGallery -{ - public class Startup - { - public IConfiguration Configuration { get; } - - public Startup(IConfiguration configuration) - { - Configuration = configuration; - NugetPackageSources.Configure (Configuration); - } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - try { - new Database ().MigrateAsync ().Wait (); - services.AddScoped (); - } - catch (Exception dbex) { - Console.WriteLine ($"Failed to open the database: {dbex}"); - } - services.AddControllers(); - services.AddRazorPages(options => - { - options.Conventions.AddPageRoute("/packages/details", "packages/{id}"); - options.Conventions.AddPageRoute("/packages/badges", "packages/{id}/badges"); - options.Conventions.AddPageRoute("/packages/dependents", "packages/{id}/dependents"); - options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}"); - options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}/{dir}"); - options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}"); - options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}/{assemblyName}"); - options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}/{assemblyName}/{namespace}"); - options.Conventions.AddPageRoute("/packages/details", "packages/{id}/{version}/{dir}/{targetFramework}/{assemblyName}/{namespace}/{typeName}"); - }); - services.Configure(options => options.Level = System.IO.Compression.CompressionLevel.Optimal); - services.AddResponseCompression(); - services.AddHttpClient ("") - .ConfigurePrimaryHttpMessageHandler (() => new HttpClientHandler { - AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, - }); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - app.UseResponseCompression(); - - if (env.IsDevelopment()) { - app.UseDeveloperExceptionPage(); - } - else { - app.UseExceptionHandler("/error"); - } - - app.UseStaticFiles(); - app.UseRouting(); - app.UseEndpoints (configure => { - configure.MapControllers (); - configure.MapRazorPages (); - }); - } - } -} From 3907b3016493753e3fdee6e06343cfc0efdf54be Mon Sep 17 00:00:00 2001 From: Bradley Grainger Date: Tue, 14 Nov 2023 13:49:01 -0800 Subject: [PATCH 3/3] Update to .NET 8. --- .github/workflows/build.yml | 4 ++-- Controllers/BadgeController.cs | 2 +- Data/PackageDependents.cs | 4 ++-- FuGetGallery.csproj | 20 ++++++++++---------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a7b6e56..b6c4b9a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,10 +11,10 @@ jobs: - uses: actions/checkout@v3 - - name: Set up .NET 7.0 + - name: Set up .NET 8.0 uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x - name: Build run: | diff --git a/Controllers/BadgeController.cs b/Controllers/BadgeController.cs index 2d94b0b..15d3ac7 100644 --- a/Controllers/BadgeController.cs +++ b/Controllers/BadgeController.cs @@ -24,7 +24,7 @@ public async Task GetBadgeAsync (string id, string v) var content = DrawBadge (package); - HttpContext.Response.Headers.Add ("Cache-Control", "max-age=3600"); + HttpContext.Response.Headers["Cache-Control"] = "max-age=3600"; var r = Content(content); r.ContentType = "image/svg+xml"; return r; diff --git a/Data/PackageDependents.cs b/Data/PackageDependents.cs index f668ea9..c8d70e2 100644 --- a/Data/PackageDependents.cs +++ b/Data/PackageDependents.cs @@ -33,7 +33,7 @@ class PackageDependentsCache : DataCache { public PackageDependentsCache () : base (TimeSpan.FromMinutes (20)) { } - protected override async Task GetValueAsync (string lowerId, HttpClient httpClient, CancellationToken token) + protected override Task GetValueAsync (string lowerId, HttpClient httpClient, CancellationToken token) { // // ISSUE #155: Diabled due to database corruption. @@ -48,7 +48,7 @@ protected override async Task GetValueAsync (string lowerId, //catch (Exception ex) { // Console.WriteLine (ex); //} - return deps; + return Task.FromResult(deps); } } } diff --git a/FuGetGallery.csproj b/FuGetGallery.csproj index a5e889a..5afcce7 100644 --- a/FuGetGallery.csproj +++ b/FuGetGallery.csproj @@ -1,22 +1,22 @@  - net7.0 - 9.0 + net8.0 + 11.0 - - + + - - - + + + - - - + + +