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;
|
||||||
|
|
||||||
|
|
@ -36,4 +37,4 @@ public class PluginController : ControllerBase
|
||||||
return StatusCode(StatusCodes.Status500InternalServerError, false);
|
return StatusCode(StatusCodes.Status500InternalServerError, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -59,12 +59,9 @@ public class ServerController : ControllerBase
|
||||||
// check for valid service
|
// check for valid service
|
||||||
if (_serverQueryService == null)
|
if (_serverQueryService == null)
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
@ -74,9 +71,9 @@ public class ServerController : ControllerBase
|
||||||
var stopWatch = Stopwatch.StartNew();
|
var stopWatch = Stopwatch.StartNew();
|
||||||
|
|
||||||
var result = _serverQueryService.CheckServerStatus(managerCode, managerVersion, ipString, port);
|
var result = _serverQueryService.CheckServerStatus(managerCode, managerVersion, ipString, port);
|
||||||
var response = new ServerStatusResponse
|
var response = new ServerStatusResponse
|
||||||
{
|
{
|
||||||
Available = result.ToString()
|
Available = result.ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
stopWatch.Stop();
|
stopWatch.Stop();
|
||||||
|
|
@ -85,22 +82,19 @@ public class ServerController : ControllerBase
|
||||||
}
|
}
|
||||||
catch (ServerManagerApiException ex)
|
catch (ServerManagerApiException ex)
|
||||||
{
|
{
|
||||||
var response = new ErrorResponse
|
var response = new ErrorResponse
|
||||||
{
|
{
|
||||||
Errors = ex.Messages
|
Errors = ex.Messages
|
||||||
};
|
};
|
||||||
return StatusCode(ex.StatusCode, response);
|
return StatusCode(ex.StatusCode, response);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11,8 +11,8 @@ public static class ServerQueryExtensions
|
||||||
{
|
{
|
||||||
var settings = configuration.GetSectionAs<ServerQuerySettings>();
|
var settings = configuration.GetSectionAs<ServerQuerySettings>();
|
||||||
services.AddSingleton(settings);
|
services.AddSingleton(settings);
|
||||||
|
|
||||||
services.AddScoped<IServerQueryService, QueryMasterService>();
|
services.AddScoped<IServerQueryService, QueryMasterService>();
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11,4 +11,4 @@ public static class ServiceCollectionExtensions
|
||||||
|
|
||||||
return configuration.GetSection(sectionName).Get<T>();
|
return configuration.GetSection(sectionName).Get<T>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
@ -52,4 +44,4 @@ public class SwaggerDefaultValues : IOperationFilter
|
||||||
parameter.Required |= description.IsRequired;
|
parameter.Required |= description.IsRequired;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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; } = [];
|
||||||
}
|
}
|
||||||
|
|
@ -11,4 +11,4 @@ public class ServerStatusResponse
|
||||||
[Required]
|
[Required]
|
||||||
[Description("True if the server is available; otherwise false.")]
|
[Description("True if the server is available; otherwise false.")]
|
||||||
public string Available { get; set; } = false.ToString();
|
public string Available { get; set; } = false.ToString();
|
||||||
}
|
}
|
||||||
|
|
@ -9,4 +9,4 @@ public class ManagerCode
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public string Code { get; set; } = string.Empty;
|
public string Code { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
@ -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>();
|
||||||
}
|
}
|
||||||
|
|
@ -16,4 +16,4 @@ public class Program
|
||||||
{
|
{
|
||||||
webBuilder.UseStartup<Startup>();
|
webBuilder.UseStartup<Startup>();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -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",
|
||||||
|
|
@ -28,4 +28,4 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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,14 +16,16 @@
|
||||||
</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>
|
||||||
<ProjectReference Include="..\QueryMaster\QueryMaster.csproj" />
|
<ProjectReference Include="..\QueryMaster\QueryMaster.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -3,4 +3,4 @@
|
||||||
public interface IServerQueryService
|
public interface IServerQueryService
|
||||||
{
|
{
|
||||||
bool CheckServerStatus(string managerCode, string managerVersion, string ipString, int port);
|
bool CheckServerStatus(string managerCode, string managerVersion, string ipString, int port);
|
||||||
}
|
}
|
||||||
|
|
@ -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 =>
|
||||||
|
|
@ -105,4 +97,4 @@ public class Startup
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ApplicationInsights": {
|
"ApplicationInsights": {
|
||||||
"InstrumentationKey": ""
|
"ConnectionString": ""
|
||||||
},
|
},
|
||||||
|
|
||||||
"EnableSwagger": true,
|
"EnableSwagger": true,
|
||||||
|
|
@ -26,4 +26,4 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,4 +18,4 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -12,4 +12,4 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue