mirror of
https://github.com/tribufu/ServerManagers
synced 2026-06-01 09:42:39 +00:00
Dotnet 8.x Update
- updated all nugets to latest 8.x versions - linting fixes - switched the application insights to use the connection string.
This commit is contained in:
parent
5d8fe6ca90
commit
f5a96f965a
19 changed files with 64 additions and 98 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Asp.Versioning;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
|
@ -61,10 +61,7 @@ public class ServerController : ControllerBase
|
|||
{
|
||||
var response = new ErrorResponse
|
||||
{
|
||||
Errors = new List<string>
|
||||
{
|
||||
"Server query service not available."
|
||||
}
|
||||
Errors = ["Server query service not available."]
|
||||
};
|
||||
return StatusCode(StatusCodes.Status503ServiceUnavailable, response);
|
||||
}
|
||||
|
|
@ -95,10 +92,7 @@ public class ServerController : ControllerBase
|
|||
{
|
||||
var response = new ErrorResponse
|
||||
{
|
||||
Errors = new List<string>
|
||||
{
|
||||
ex.Message
|
||||
}
|
||||
Errors = [ex.Message]
|
||||
};
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, response);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,27 +21,19 @@ public class SwaggerDefaultValues : IOperationFilter
|
|||
|
||||
foreach (var contentType in response.Content.Keys)
|
||||
{
|
||||
if (!responseType.ApiResponseFormats.Any(x => x.MediaType == contentType))
|
||||
{
|
||||
if (responseType.ApiResponseFormats.All(x => x.MediaType != contentType))
|
||||
response.Content.Remove(contentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (operation.Parameters is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var parameter in operation.Parameters)
|
||||
{
|
||||
var description = apiDescription.ParameterDescriptions
|
||||
.First(p => p.Name == parameter.Name);
|
||||
var description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name);
|
||||
|
||||
if (parameter.Description is null)
|
||||
{
|
||||
parameter.Description = description.ModelMetadata?.Description;
|
||||
}
|
||||
parameter.Description ??= description.ModelMetadata?.Description;
|
||||
|
||||
if (parameter.Schema.Default is null && description.DefaultValue is not null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,5 +11,5 @@ public class ErrorResponse
|
|||
/// </summary>
|
||||
[Required]
|
||||
[Description("List of errors.")]
|
||||
public ICollection<string> Errors { get; set; } = new List<string>();
|
||||
public ICollection<string> Errors { get; set; } = [];
|
||||
}
|
||||
|
|
@ -4,6 +4,6 @@ namespace ServerManager.WebApplication.Models.Data
|
|||
{
|
||||
public class ServerQuerySettings
|
||||
{
|
||||
public List<ManagerCode> ManagerCodes { get; set; }
|
||||
public List<ManagerCode> ManagerCodes { get; set; } = [];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ServerManager.WebApplication.Models;
|
||||
|
||||
public class ServerManagerApiException : Exception
|
||||
{
|
||||
public ServerManagerApiException() : base()
|
||||
public ServerManagerApiException()
|
||||
{ }
|
||||
|
||||
public ServerManagerApiException(int statusCode, ICollection<string> messages) : base()
|
||||
public ServerManagerApiException(int statusCode, ICollection<string> messages)
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
Messages = messages;
|
||||
}
|
||||
|
||||
public ServerManagerApiException(int statusCode, ICollection<string> messages, Exception innerException) : base(null, innerException)
|
||||
public ServerManagerApiException(int statusCode, ICollection<string> messages, Exception innerException)
|
||||
: base(null, innerException)
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
Messages = messages;
|
||||
}
|
||||
|
||||
protected ServerManagerApiException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{ }
|
||||
|
||||
public int StatusCode { get; private set; } = 0;
|
||||
public int StatusCode { get; private set; }
|
||||
|
||||
public ICollection<string> Messages { get; private set; } = new List<string>();
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
},
|
||||
"ServerManager.WebApplication": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": "true",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<ApplicationIcon>Art\favicon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
|
@ -16,10 +16,12 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
|
||||
<PackageReference Include="Asp.Versioning.Mvc" Version="8.1.0" />
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.23.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class QueryMasterService : IServerQueryService
|
|||
try
|
||||
{
|
||||
using var server = ServerQuery.GetServerInstance(EngineType.Source, ipString, (ushort)port);
|
||||
return server.GetInfo() != null;
|
||||
return server.GetInfo() is not null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -38,35 +38,23 @@ public class QueryMasterService : IServerQueryService
|
|||
var errors = new List<string>();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(managerCode))
|
||||
{
|
||||
errors.Add("Manager code is required.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var managerCodes = _settings.ManagerCodes ?? new List<ManagerCode>();
|
||||
var managerCodes = _settings.ManagerCodes ?? [];
|
||||
if (!managerCodes.Any(c => c.Code.Equals(managerCode, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
errors.Add("Manager code is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ipString))
|
||||
{
|
||||
errors.Add("IP Address is required.");
|
||||
}
|
||||
else if (!IPAddress.TryParse(ipString, out IPAddress _))
|
||||
{
|
||||
else if (!IPAddress.TryParse(ipString, out _))
|
||||
errors.Add("IP Address is invalid.");
|
||||
}
|
||||
|
||||
if (port <= ushort.MinValue || port >= ushort.MaxValue)
|
||||
{
|
||||
if (port is <= ushort.MinValue or >= ushort.MaxValue)
|
||||
errors.Add($"Valid port is required ({ushort.MinValue} to {ushort.MaxValue}).");
|
||||
}
|
||||
|
||||
if (errors.Count > 0)
|
||||
{
|
||||
throw new ServerManagerApiException(StatusCodes.Status400BadRequest, errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
using Asp.Versioning;
|
||||
using Asp.Versioning.ApiExplorer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.AspNetCore.Mvc.Versioning;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
|
@ -40,13 +39,10 @@ public class Startup
|
|||
new MediaTypeApiVersionReader("Version"),
|
||||
new HeaderApiVersionReader("X-Version")
|
||||
);
|
||||
});
|
||||
|
||||
services.AddVersionedApiExplorer(o =>
|
||||
}).AddApiExplorer(options =>
|
||||
{
|
||||
// add the versioned api explorer, which also adds IApiVersionDescriptionProvider service
|
||||
// note: the specified format code will format the version as "'v'major[.minor][-status]"
|
||||
o.GroupNameFormat = "'v'VVV";
|
||||
options.GroupNameFormat = "'v'VVV";
|
||||
options.SubstituteApiVersionInUrl = true;
|
||||
});
|
||||
|
||||
services.AddServerQueryServices(Configuration);
|
||||
|
|
@ -64,18 +60,14 @@ public class Startup
|
|||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApiVersionDescriptionProvider provider)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
var enableSwagger = Configuration.GetValue<bool>("EnableSwagger");
|
||||
if (enableSwagger)
|
||||
{
|
||||
var swaggerRoutePrefix = Configuration.GetValue<string>("SwaggerRoutePrefix");
|
||||
if (!string.IsNullOrWhiteSpace(swaggerRoutePrefix) && !swaggerRoutePrefix.EndsWith("/"))
|
||||
{
|
||||
swaggerRoutePrefix += "/";
|
||||
}
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(o =>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
}
|
||||
},
|
||||
"ApplicationInsights": {
|
||||
"InstrumentationKey": ""
|
||||
"ConnectionString": ""
|
||||
},
|
||||
|
||||
"EnableSwagger": true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue