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