Merged PR 68: .NET 6 upgrade

- .NET 6 upgrade
- .NET 6 upgrade
- publish profile update
master
Tudor Stanciu 2023-01-15 00:15:43 +00:00
parent 939efdb781
commit c4b129a565
55 changed files with 182 additions and 331 deletions

View File

@ -1,7 +1,7 @@
<Project>
<Import Project="dependencies.props" />
<PropertyGroup>
<Version>1.0.7</Version>
<Version>1.1.0</Version>
<Authors>Tudor Stanciu</Authors>
<Company>STA</Company>
<PackageTags>NetworkResurrector</PackageTags>

View File

@ -38,4 +38,10 @@
• Exposing two new methods "/ping" and "/version" in a new controller "/system".
</Content>
</Note>
<Note>
<Version>1.1.0</Version>
<Content>
.NET 6 upgrade
</Content>
</Note>
</ReleaseNotes>

View File

@ -1,18 +1,18 @@
<Project>
<PropertyGroup Label="Package Versions">
<MicrosoftExtensionsPackageVersion>5.0.0</MicrosoftExtensionsPackageVersion>
<MicrosoftExtensionsHostingPackageVersion>5.0.1</MicrosoftExtensionsHostingPackageVersion>
<SerilogPackageVersion>4.1.0</SerilogPackageVersion>
<SerilogExtensionsPackageVersion>3.1.0</SerilogExtensionsPackageVersion>
<SerilogSinksConsolePackageVersion>4.0.0</SerilogSinksConsolePackageVersion>
<SerilogSinksMSSqlServerPackageVersion>5.6.1</SerilogSinksMSSqlServerPackageVersion>
<AutoMapperPackageVersion>10.1.1</AutoMapperPackageVersion>
<AutoMapperExtensionsPackageVersion>8.1.1</AutoMapperExtensionsPackageVersion>
<MediatRPackageVersion>6.0.0</MediatRPackageVersion>
<EntityFrameworkCorePackageVersion>5.0.12</EntityFrameworkCorePackageVersion>
<NDBExtensionsSwaggerPackageVersion>1.0.4</NDBExtensionsSwaggerPackageVersion>
<NDBApplicationPackageVersion>1.0.0</NDBApplicationPackageVersion>
<NDBSecurityAuthenticationPackageVersion>1.0.7</NDBSecurityAuthenticationPackageVersion>
<NDBDatabaseMigrationPackageVersion>1.1.3</NDBDatabaseMigrationPackageVersion>
<MicrosoftExtensionsPackageVersion>6.0.0</MicrosoftExtensionsPackageVersion>
<MicrosoftExtensionsHostingPackageVersion>6.0.1</MicrosoftExtensionsHostingPackageVersion>
<SerilogPackageVersion>4.1.0</SerilogPackageVersion>
<SerilogExtensionsPackageVersion>3.1.0</SerilogExtensionsPackageVersion>
<SerilogSinksConsolePackageVersion>4.0.1</SerilogSinksConsolePackageVersion>
<SerilogSinksMSSqlServerPackageVersion>5.6.1</SerilogSinksMSSqlServerPackageVersion>
<AutoMapperPackageVersion>10.1.1</AutoMapperPackageVersion>
<AutoMapperExtensionsPackageVersion>8.1.1</AutoMapperExtensionsPackageVersion>
<MediatRPackageVersion>9.0.0</MediatRPackageVersion>
<EntityFrameworkCorePackageVersion>6.0.1</EntityFrameworkCorePackageVersion>
<NetmashExtensionsSwaggerPackageVersion>1.0.6</NetmashExtensionsSwaggerPackageVersion>
<NetmashApplicationPackageVersion>1.0.1</NetmashApplicationPackageVersion>
<NetmashSecurityAuthenticationPackageVersion>1.0.8</NetmashSecurityAuthenticationPackageVersion>
<NetmashDatabaseMigrationPackageVersion>1.2.0</NetmashDatabaseMigrationPackageVersion>
</PropertyGroup>
</Project>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
@ -10,7 +10,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
<PackageReference Include="Netmash.Application.DataContracts" Version="$(NetmashApplicationPackageVersion)" />
<PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
</ItemGroup>

View File

@ -1,5 +1,5 @@
using MediatR;
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using System;
using System.Threading;
using System.Threading.Tasks;

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Agent.PublishedLanguage.Dto;
using NetworkResurrector.Agent.PublishedLanguage.Events;

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Agent.PublishedLanguage.Dto;
using NetworkResurrector.Agent.PublishedLanguage.Events;

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Agent.PublishedLanguage.Dto;
using NetworkResurrector.Agent.PublishedLanguage.Events;

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Agent.PublishedLanguage.Dto;
using NetworkResurrector.Agent.PublishedLanguage.Events;

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Agent.PublishedLanguage.Dto;
using NetworkResurrector.Agent.PublishedLanguage.Events;

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Agent.PublishedLanguage.Dto;
using NetworkResurrector.Agent.PublishedLanguage.Events;

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Description>Network resurrector agent published language nuget package</Description>
<PackageProjectUrl>https://dev.azure.com/tstanciu94/NetworkResurrector</PackageProjectUrl>
<RepositoryUrl>https://dev.azure.com/tstanciu94/NetworkResurrector</RepositoryUrl>
@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
<PackageReference Include="Netmash.Application.DataContracts" Version="$(NetmashApplicationPackageVersion)" />
</ItemGroup>
</Project>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Description>Network resurrector agent wrapper nuget package</Description>
<PackageProjectUrl>https://dev.azure.com/tstanciu94/NetworkResurrector</PackageProjectUrl>
<RepositoryType>Git</RepositoryType>

View File

@ -1,20 +0,0 @@
using Serilog.Sinks.MSSqlServer;
namespace NetworkResurrector.Agent.Extensions.Serilog.Sinks.MSSqlServer
{
public static class ColumnOptionsExtension
{
public static ColumnOptions AsStandard(this ColumnOptions columnOptions)
{
columnOptions.Store.Remove(StandardColumn.Properties);
columnOptions.Store.Remove(StandardColumn.MessageTemplate);
columnOptions.Store.Add(StandardColumn.LogEvent);
columnOptions.AdditionalColumns = new System.Collections.ObjectModel.Collection<SqlColumn>
{
new SqlColumn() { ColumnName = "Agent", DataType = System.Data.SqlDbType.VarChar, DataLength = 100 }
};
return columnOptions;
}
}
}

View File

@ -1,38 +1,26 @@
using MediatR;
using MediatR.Pipeline;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NDB.Extensions.Swagger;
using NDB.Extensions.Swagger.Constants;
using NDB.Security.Authentication.Identity;
using Netmash.Extensions.Swagger;
using Netmash.Extensions.Swagger.Constants;
using Netmash.Security.Authentication.Identity;
using NetworkResurrector.Agent.Application;
using Newtonsoft.Json;
using System.Reflection;
namespace NetworkResurrector.Agent
namespace NetworkResurrector.Agent.Extensions
{
public class Startup
public static class StartupExtensions
{
private readonly IConfiguration _configuration;
public Startup(IConfiguration configuration)
{
_configuration = configuration;
}
private string AgentCode => _configuration.GetValue<string>("Agent:Code");
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
public static void ConfigureServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddControllers()
.AddNewtonsoftJson(o => o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc);
// Add basic authentication
services.AddIdentityAuthentication(_configuration.GetSection("IdentityServer")["BaseAddress"]);
services.AddIdentityAuthentication(configuration.GetSection("IdentityServer")["BaseAddress"]);
// MediatR
services.AddMediatR(GetMediatRAssemblies());
@ -43,7 +31,8 @@ namespace NetworkResurrector.Agent
services.AddAutoMapper(typeof(Application.Mappings.MappingProfile).Assembly);
// Swagger
services.AddSwagger($"NetworkResurrectorAgent {AgentCode}", AuthorizationType.InhouseIdentity);
var agentCode = configuration.GetValue<string>("Agent:Code");
services.AddSwagger($"NetworkResurrectorAgent {agentCode}", AuthorizationType.InhouseIdentity);
// Data access
// services.AddDataAccess();
@ -52,14 +41,14 @@ namespace NetworkResurrector.Agent
services.AddApplicationServices();
}
private Assembly[] GetMediatRAssemblies()
private static Assembly[] GetMediatRAssemblies()
{
var assembly = typeof(Application.Queries.GetSystemVersion).Assembly;
return new Assembly[] { assembly };
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public static void Configure(this IApplicationBuilder app, IConfiguration configuration)
{
// global cors policy
app.UseCors(x => x
@ -67,11 +56,6 @@ namespace NetworkResurrector.Agent
.AllowAnyMethod()
.AllowAnyHeader());
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
@ -79,7 +63,9 @@ namespace NetworkResurrector.Agent
{
endpoints.MapControllers();
});
app.ConfigureSwagger($"NetworkResurrectorAgent {AgentCode}");
var agentCode = configuration.GetValue<string>("Agent:Code");
app.ConfigureSwagger($"NetworkResurrectorAgent {agentCode}");
}
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
@ -10,8 +10,8 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="NDB.Extensions.Swagger" Version="$(NDBExtensionsSwaggerPackageVersion)" />
<PackageReference Include="NDB.Security.Authentication.Identity" Version="$(NDBSecurityAuthenticationPackageVersion)" />
<PackageReference Include="Netmash.Extensions.Swagger" Version="$(NetmashExtensionsSwaggerPackageVersion)" />
<PackageReference Include="Netmash.Security.Authentication.Identity" Version="$(NetmashSecurityAuthenticationPackageVersion)" />
<PackageReference Include="Serilog.AspNetCore" Version="$(SerilogPackageVersion)" />
<PackageReference Include="Serilog.Extensions.Logging" Version="$(SerilogExtensionsPackageVersion)" />
<PackageReference Include="Serilog.Sinks.Console" Version="$(SerilogSinksConsolePackageVersion)" />

View File

@ -1,16 +1,14 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using NetworkResurrector.Agent.Extensions;
using NetworkResurrector.Agent.Extensions.Serilog;
using NetworkResurrector.Agent.Extensions.Serilog.Sinks.MSSqlServer;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using Serilog.Sinks.MSSqlServer;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace NetworkResurrector.Agent
{
@ -18,76 +16,65 @@ namespace NetworkResurrector.Agent
{
public static void Main(string[] args)
{
var isConsole = Debugger.IsAttached || args.Contains("--console");
if (!isConsole)
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((_, lc) =>
{
var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
Directory.SetCurrentDirectory(pathToContentRoot);
}
var connectionString = builder.Configuration.GetConnectionString("DatabaseConnection");
var loggingLevelParam = builder.Configuration.GetValue<string>("Logging:LogLevel:Default");
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var loggingLevelOk = Enum.TryParse(loggingLevelParam, out LogEventLevel loggingLevel);
if (!loggingLevelOk)
throw new Exception($"Logging level '{loggingLevelParam}' is not valid.");
var connectionString = configuration.GetConnectionString("DatabaseConnection");
var loggingLevelParam = configuration.GetValue<string>("Logging:LogLevel:Default");
var loggingLevelSwitch = new LoggingLevelSwitch(loggingLevel);
var loggingLevelOk = Enum.TryParse(loggingLevelParam, out LogEventLevel loggingLevel);
if (!loggingLevelOk)
throw new Exception($"Logging level '{loggingLevelParam}' is not valid.");
var columnOptions = new ColumnOptions();
columnOptions.Store.Remove(StandardColumn.Properties);
columnOptions.Store.Remove(StandardColumn.MessageTemplate);
columnOptions.Store.Add(StandardColumn.LogEvent);
var mssqlSinkOptions = new MSSqlServerSinkOptions() { AutoCreateSqlTable = true, TableName = "__Logs_Agent" };
var loggingLevelSwitch = new LoggingLevelSwitch(loggingLevel);
var columnOptions = new ColumnOptions().AsStandard();
var mssqlSinkOptions = new MSSqlServerSinkOptions() { AutoCreateSqlTable = true, TableName = "__Logs_Agent" };
Log.Logger = new LoggerConfiguration()
lc
.MinimumLevel.ControlledBy(loggingLevelSwitch)
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.Enrich.With(new AgentCodeEventEnricher(configuration))
.Enrich.With(new AgentCodeEventEnricher(builder.Configuration))
.WriteTo.Console()
.WriteTo.MSSqlServer(connectionString, mssqlSinkOptions, columnOptions: columnOptions)
.CreateLogger();
.WriteTo.MSSqlServer(connectionString, mssqlSinkOptions, columnOptions: columnOptions);
});
builder.Services.ConfigureServices(builder.Configuration);
var useWindowsService = builder.Configuration.GetValue<bool>("Host:UseWindowsService");
if (useWindowsService)
builder.Host.UseWindowsService();
var app = builder.Build();
app.Configure(builder.Configuration);
var exitCode = 0;
try
{
var urls = configuration.GetValue<string>("Urls");
var agentCode = configuration.GetValue<string>("Agent:Code");
var urls = builder.Configuration.GetValue<string>("Urls");
var agentCode = builder.Configuration.GetValue<string>("Agent:Code");
Log.Information($"Starting network resurrector agent {agentCode}...");
Log.Information($"Network resurrector agent {agentCode} listening on {urls}");
Log.Information($"Hostname: {Environment.MachineName}");
Console.WriteLine("Application started. Press Ctrl+C to shut down.");
CreateHostBuilder(args, configuration, !isConsole).Build().Run();
app.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Network resurrector agent host terminated unexpectedly");
exitCode = 1;
}
finally
{
Log.CloseAndFlush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration configuration, bool useWindowsService)
{
var builder = Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseConfiguration(configuration)
.UseSerilog();
});
if (useWindowsService)
builder.UseWindowsService();
return builder;
Environment.Exit(exitCode);
}
}
}

View File

@ -4,16 +4,16 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeApp_Data>False</ExcludeApp_Data>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<DeleteExistingFiles>false</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Release\net5.0\publish\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>c8c4ca6f-39e2-46fe-89e2-0a81d2f4161e</ProjectGuid>
<SelfContained>true</SelfContained>

View File

@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@ -3,6 +3,9 @@
"ConnectionStrings": {
"DatabaseConnection": "Server=#########;Database=#########;User Id=#########;Password=#########;MultipleActiveResultSets=true"
},
"Host": {
"UseWindowsService": true
},
"Logging": {
"LogLevel": {
"Default": "Debug",

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
@ -10,7 +10,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
<PackageReference Include="Netmash.Application.DataContracts" Version="$(NetmashApplicationPackageVersion)" />
<PackageReference Include="NetworkResurrector.Agent.Wrapper" Version="1.0.3.1" />
<PackageReference Include="NetworkResurrector.Server.Wrapper" Version="1.0.3.3" />
</ItemGroup>

View File

@ -1,6 +1,6 @@
using AutoMapper;
using MediatR;
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Api.Domain.Repositories;
using System.Threading;
using System.Threading.Tasks;

View File

@ -1,5 +1,5 @@
using MediatR;
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using System;
using System.IO;
using System.Reflection;

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Api.PublishedLanguage.Events;
namespace NetworkResurrector.Api.PublishedLanguage.Commands

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Api.PublishedLanguage.Events;
namespace NetworkResurrector.Api.PublishedLanguage.Commands

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Api.PublishedLanguage.Events;
namespace NetworkResurrector.Api.PublishedLanguage.Commands

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Api.PublishedLanguage.Events;
namespace NetworkResurrector.Api.PublishedLanguage.Commands

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Api.PublishedLanguage.Events;
namespace NetworkResurrector.Api.PublishedLanguage.Commands

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Api.PublishedLanguage.Events;
namespace NetworkResurrector.Api.PublishedLanguage.Commands

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Api.PublishedLanguage.Events;
namespace NetworkResurrector.Api.PublishedLanguage.Commands

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Api.PublishedLanguage.Events;
namespace NetworkResurrector.Api.PublishedLanguage.Commands

View File

@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
<PackageReference Include="Netmash.Application.DataContracts" Version="$(NetmashApplicationPackageVersion)" />
</ItemGroup>
</Project>

View File

@ -1,10 +1,10 @@
#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:5.0-buster-slim AS base
FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build
WORKDIR /src
COPY dependencies.props .
COPY Directory.Build.props .

View File

@ -1,14 +1,13 @@
using MediatR;
using MediatR;
using MediatR.Pipeline;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NDB.Extensions.Swagger;
using NDB.Extensions.Swagger.Constants;
using NDB.Infrastructure.DatabaseMigration;
using NDB.Infrastructure.DatabaseMigration.Constants;
using NDB.Security.Authentication.Identity;
using Netmash.Extensions.Swagger;
using Netmash.Extensions.Swagger.Constants;
using Netmash.Infrastructure.DatabaseMigration;
using Netmash.Infrastructure.DatabaseMigration.Constants;
using Netmash.Security.Authentication.Identity;
using NetworkResurrector.Agent.Wrapper;
using NetworkResurrector.Api.Application;
using NetworkResurrector.Api.Domain.Abstractions;
@ -18,25 +17,17 @@ using NetworkResurrector.Server.Wrapper;
using Newtonsoft.Json;
using System.Reflection;
namespace NetworkResurrector.Api
namespace NetworkResurrector.Api.Extensions
{
public class Startup
public static class StartupExtensions
{
private readonly IConfiguration _configuration;
public Startup(IConfiguration configuration)
{
_configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
public static void ConfigureServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddControllers()
.AddNewtonsoftJson(o => o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc);
// Add basic authentication
services.AddIdentityAuthentication(_configuration.GetSection("IdentityServer")["BaseAddress"]);
services.AddIdentityAuthentication(configuration.GetSection("IdentityServer")["BaseAddress"]);
services.AddHttpContextAccessor();
services.AddScoped<IUserService, UserService>();
@ -53,7 +44,7 @@ namespace NetworkResurrector.Api
services.AddSwagger("NetworkResurrector API", AuthorizationType.InhouseIdentity);
// Add network resurrector server services
services.UseResurrectorServices(_configuration.GetSection("NetworkResurrectorServer")["BaseAddress"]);
services.UseResurrectorServices(configuration.GetSection("NetworkResurrectorServer")["BaseAddress"]);
// Add network resurrector agent services
services.UseResurrectorAgentServices();
@ -66,14 +57,13 @@ namespace NetworkResurrector.Api
services.AddApplicationServices();
}
private Assembly[] GetMediatRAssemblies()
private static Assembly[] GetMediatRAssemblies()
{
var assembly = typeof(Application.Queries.GetMachines).Assembly;
return new Assembly[] { assembly };
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public static void Configure(this IApplicationBuilder app)
{
// global cors policy
app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
@ -11,9 +11,9 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="NDB.Extensions.Swagger" Version="$(NDBExtensionsSwaggerPackageVersion)" />
<PackageReference Include="NDB.Infrastructure.DatabaseMigration" Version="$(NDBDatabaseMigrationPackageVersion)" />
<PackageReference Include="NDB.Security.Authentication.Identity" Version="$(NDBSecurityAuthenticationPackageVersion)" />
<PackageReference Include="Netmash.Extensions.Swagger" Version="$(NetmashExtensionsSwaggerPackageVersion)" />
<PackageReference Include="Netmash.Infrastructure.DatabaseMigration" Version="$(NetmashDatabaseMigrationPackageVersion)" />
<PackageReference Include="Netmash.Security.Authentication.Identity" Version="$(NetmashSecurityAuthenticationPackageVersion)" />
<PackageReference Include="Serilog.AspNetCore" Version="$(SerilogPackageVersion)" />
<PackageReference Include="Serilog.Extensions.Logging" Version="$(SerilogExtensionsPackageVersion)" />
<PackageReference Include="Serilog.Sinks.Console" Version="$(SerilogSinksConsolePackageVersion)" />

View File

@ -1,40 +0,0 @@
Docker commands:
*****************
Create image:
--from solution folder:
docker image build -t "network-resurrector-api:1.0.1" -f "src/api/NetworkResurrector.Api/Docker/amd64/Dockerfile" .
Run image:
docker run -p 5053:80 -it network-resurrector-api:1.0.1
Push image to registry:
--tag image
docker tag network-resurrector-api:1.0.1 alpine-nexus:8500/network-resurrector/network-resurrector-api:1.0.1
--login to registry
docker login --username=admin --password="*********" alpine-nexus:8500
--push image
docker push alpine-nexus:8500/network-resurrector/network-resurrector-api:1.0.1
Pull image from registry
--login to registry
--pull image
docker pull alpine-nexus:8500/network-resurrector/network-resurrector-api:1.0.1
Stop old container
docker stop network-resurrector-api
docker rm network-resurrector-api
Run container in prod env
docker run -d --name network-resurrector-api --restart=always -p 5008:80 alpine-nexus:8500/network-resurrector/network-resurrector-api:1.0.1
docker run -d --name network-resurrector-api --restart=always -p 5008:80 tstanciu/sta-registry:nr-api-1.0.1-arm
Remove old image
docker rmi alpine-nexus:8500/network-resurrector/network-resurrector-api:1.0.0
#######################################################################################################################################################
Docker container last version: 1.0.1
##############################################################################################

View File

@ -1,33 +0,0 @@
Docker commands:
*****************
Create image and push it:
--login to registry
docker login --username=tstanciu --password="*********"
--from solution folder:
docker buildx build --platform linux/arm/v7 -t "tstanciu/sta-registry:network-resurrector-api-1.0.1-arm32v7" -f "src/api/NetworkResurrector.Api/Docker/arm32/Dockerfile" --push .
# With insecure registry
docker buildx build --platform linux/arm/v7 -t "alpine-nexus:8500/network-resurrector/network-resurrector-api:1.0.1-arm" -f "src/api/NetworkResurrector.Api/Docker/arm32v7/Dockerfile" --push .
https://docs.docker.com/engine/reference/commandline/buildx_create/
https://stackoverflow.com/questions/63409755/how-to-use-docker-buildx-pushing-image-to-registry-use-http-protocol
Pull image from registry
--login to registry
--pull image
docker pull tstanciu/sta-registry:network-resurrector-api-1.0.1-arm32v7
Stop old container
docker stop network-resurrector-api && docker rm network-resurrector-api
Run container in prod env
docker run -d --name network-resurrector-api --restart=always -p 5008:80 tstanciu/sta-registry:network-resurrector-api-1.0.1-arm32v7
Remove old image
docker rmi tstanciu/sta-registry:network-resurrector-api-1.0.1-arm32v7
docker run -d --name network-resurrector-api --restart=always -p 5008:80 alpine-nexus:8500/network-resurrector/network-resurrector-api:1.0.1
#######################################################################################################################################################

View File

@ -1,14 +1,13 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using NetworkResurrector.Api.Extensions;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using Serilog.Sinks.MSSqlServer;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace NetworkResurrector.Api
{
@ -16,76 +15,58 @@ namespace NetworkResurrector.Api
{
public static void Main(string[] args)
{
var isConsole = args.Contains("--console");
if (!isConsole)
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((_, lc) =>
{
var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
Directory.SetCurrentDirectory(pathToContentRoot);
}
var connectionString = builder.Configuration.GetConnectionString("DatabaseConnection");
var loggingLevelParam = builder.Configuration.GetValue<string>("Logging:LogLevel:Default");
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var loggingLevelOk = Enum.TryParse(loggingLevelParam, out LogEventLevel loggingLevel);
if (!loggingLevelOk)
throw new Exception($"Logging level '{loggingLevelParam}' is not valid.");
var connectionString = configuration.GetConnectionString("DatabaseConnection");
var loggingLevelParam = configuration.GetValue<string>("Logging:LogLevel:Default");
var loggingLevelSwitch = new LoggingLevelSwitch(loggingLevel);
var loggingLevelOk = Enum.TryParse(loggingLevelParam, out LogEventLevel loggingLevel);
if (!loggingLevelOk)
throw new Exception($"Logging level '{loggingLevelParam}' is not valid.");
var columnOptions = new ColumnOptions();
columnOptions.Store.Remove(StandardColumn.Properties);
columnOptions.Store.Remove(StandardColumn.MessageTemplate);
columnOptions.Store.Add(StandardColumn.LogEvent);
var mssqlSinkOptions = new MSSqlServerSinkOptions() { AutoCreateSqlTable = true, TableName = "__Logs" };
var loggingLevelSwitch = new LoggingLevelSwitch(loggingLevel);
var columnOptions = new ColumnOptions();
columnOptions.Store.Remove(StandardColumn.Properties);
columnOptions.Store.Remove(StandardColumn.MessageTemplate);
columnOptions.Store.Add(StandardColumn.LogEvent);
var mssqlSinkOptions = new MSSqlServerSinkOptions() { AutoCreateSqlTable = true, TableName = "__Logs" };
Log.Logger = new LoggerConfiguration()
lc
.MinimumLevel.ControlledBy(loggingLevelSwitch)
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.MSSqlServer(connectionString, mssqlSinkOptions, columnOptions: columnOptions)
.CreateLogger();
.WriteTo.MSSqlServer(connectionString, mssqlSinkOptions, columnOptions: columnOptions);
});
builder.Services.ConfigureServices(builder.Configuration);
var app = builder.Build();
app.Configure();
var exitCode = 0;
try
{
var urls = configuration.GetValue<string>("urls");
var urls = builder.Configuration.GetValue<string>("urls");
Log.Information("Starting network resurrector API...");
Log.Information($"Network resurrector API listening on {urls}");
Console.WriteLine("Application started. Press Ctrl+C to shut down.");
CreateHostBuilder(args, configuration, !isConsole).Build().Run();
app.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Network resurrector API host terminated unexpectedly");
exitCode = 1;
}
finally
{
Log.CloseAndFlush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration configuration, bool useWindowsService)
{
var builder = Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseConfiguration(configuration)
.UseSerilog();
});
if (useWindowsService)
builder.UseWindowsService();
return builder;
Environment.Exit(exitCode);
}
}
}

View File

@ -39,7 +39,7 @@ namespace NetworkResurrector.Api.Services
public bool UserIsGuest()
{
var userIsGuest = _httpAccessor.HttpContext.User?.Claims.FirstOrDefault(z => z.Type == NDB.Security.Authentication.Identity.Constants.ClaimTypes.IsGuestUser)?.Value;
var userIsGuest = _httpAccessor.HttpContext.User?.Claims.FirstOrDefault(z => z.Type == Netmash.Security.Authentication.Identity.Constants.ClaimTypes.IsGuestUser)?.Value;
return !string.IsNullOrEmpty(userIsGuest) && bool.TrueString == userIsGuest;
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Server.PublishedLanguage.Events;
using System;

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Server.PublishedLanguage.Events;
using System;

View File

@ -1,4 +1,4 @@
using NDB.Application.DataContracts;
using Netmash.Application.DataContracts;
using NetworkResurrector.Server.PublishedLanguage.Events;
using System;

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Description>Network resurrector server published language nuget package</Description>
<RepositoryUrl>https://dev.azure.com/tstanciu94/NetworkResurrector</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
@ -10,6 +10,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
<PackageReference Include="Netmash.Application.DataContracts" Version="$(NetmashApplicationPackageVersion)" />
</ItemGroup>
</Project>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Description>Network resurrector server wrapper nuget package</Description>
<PackageProjectUrl>https://dev.azure.com/tstanciu94/NetworkResurrector</PackageProjectUrl>
<RepositoryUrl>https://dev.azure.com/tstanciu94/NetworkResurrector</RepositoryUrl>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
@ -10,8 +10,8 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="NDB.Extensions.Swagger" Version="$(NDBExtensionsSwaggerPackageVersion)" />
<PackageReference Include="NDB.Security.Authentication.Identity" Version="$(NDBSecurityAuthenticationPackageVersion)" />
<PackageReference Include="Netmash.Extensions.Swagger" Version="$(NetmashExtensionsSwaggerPackageVersion)" />
<PackageReference Include="Netmash.Security.Authentication.Identity" Version="$(NetmashSecurityAuthenticationPackageVersion)" />
<PackageReference Include="Serilog.AspNetCore" Version="$(SerilogPackageVersion)" />
<PackageReference Include="Serilog.Extensions.Logging" Version="$(SerilogExtensionsPackageVersion)" />
<PackageReference Include="Serilog.Sinks.Console" Version="$(SerilogSinksConsolePackageVersion)" />

View File

@ -4,16 +4,16 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeApp_Data>False</ExcludeApp_Data>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<DeleteExistingFiles>false</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Release\net5.0\publish\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>f6600491-5d79-4548-8745-59d9d337d3db</ProjectGuid>
<SelfContained>true</SelfContained>

View File

@ -5,9 +5,9 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NDB.Extensions.Swagger;
using NDB.Extensions.Swagger.Constants;
using NDB.Security.Authentication.Identity;
using Netmash.Extensions.Swagger;
using Netmash.Extensions.Swagger.Constants;
using Netmash.Security.Authentication.Identity;
using NetworkResurrector.Server.Application;
using NetworkResurrector.Server.Extensions;
using Newtonsoft.Json;
@ -45,7 +45,7 @@ namespace NetworkResurrector.Server
typeof(Application.Mappings.MappingProfile).Assembly);
// Swagger
services.AddSwagger("NetworkResurrector API", AuthorizationType.InhouseIdentity);
services.AddSwagger("NetworkResurrector Server API", AuthorizationType.InhouseIdentity);
// Application
services.AddApplicationServices();
@ -75,7 +75,7 @@ namespace NetworkResurrector.Server
{
endpoints.MapControllers();
});
app.ConfigureSwagger("NetworkResurrector API");
app.ConfigureSwagger("NetworkResurrector Server API");
}
private Assembly[] GetMediatRAssemblies()

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>