Add disabled artifacts

This commit is contained in:
CodeLiturgy 2022-08-13 18:15:43 +01:00
parent a54ee3c909
commit 47b61fb3b2
14 changed files with 174 additions and 50 deletions

View File

@ -5,16 +5,16 @@
<LangVersion>10</LangVersion>
<RootNamespace>BlueWest.WebApi</RootNamespace>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
<PublishDependencyDocumentationFiles>true</PublishDependencyDocumentationFiles>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.41.0" />
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.41.0" />
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.41.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.2.3" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>

View File

@ -17,6 +17,26 @@ public class CountryController : ControllerBase
}
/// <summary>
/// Add Country
/// </summary>
/// <param name="country"></param>
/// <returns>The newly created country</returns>
/// /// <summary>
/// Creates a Country.
/// </summary>
/// <remarks>
/// Sample request:
///
/// POST /Countries
/// {
/// "code": 1,
/// "stateName": "United States of America",
/// "tld": "us"
/// }
///
/// </remarks>
/// <response code="201">Returns the newly created country</response>
[ProducesResponseType(StatusCodes.Status201Created)]
[HttpPost]
public ActionResult AddCountry(Country country)
@ -26,23 +46,54 @@ public class CountryController : ControllerBase
return CreatedAtRoute(nameof(GetCountryById), new {countryId = country.Code}, country);
}
/// <summary>
/// Updates a Country
/// </summary>
/// <param name="countryToUpdate">Payload with country data to update. Note that the Code is the primary key and can't be changed.</param>
/// <returns></returns>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[HttpPut("countries/{country.Code}")]
public ActionResult UpdateCountry(Country country)
public ActionResult UpdateCountry(Country countryToUpdate)
{
var array = _dbContext.Countries.FirstOrDefault(x => x.Code == country.Code);
var country = _dbContext.Countries.FirstOrDefault(x => x.Code == countryToUpdate.Code);
if (array != null)
if (country != null)
{
return Ok(array);
var updatedCountry = new Country(country.Code, countryToUpdate.StateName, countryToUpdate.TLD);
_dbContext.Countries.Update(updatedCountry);
return Ok(updatedCountry);
}
return new NotFoundResult();
}
/// <summary>
/// Get countries
/// </summary>
/// <returns></returns>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpGet("countries")]
public ActionResult GetCountries()
{
var array = _dbContext.Countries;
if (array != null)
{
return Ok(array.ToArray());
}
return new NotFoundResult();
}
/// <summary>
/// Get Country by Id
/// </summary>
/// <param name="countryId"></param>
/// <returns></returns>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpGet("countries/{countryId}", Name = nameof(GetCountryById))]

View File

@ -19,6 +19,6 @@ RUN dotnet publish "BlueWest.Api/BlueWest.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
#ENV ASPNETCORE_URLS http://0.0.0.0:80
ENV ASPNETCORE_URLS http://0.0.0.0:80
WORKDIR /app
ENTRYPOINT ["dotnet", "BlueWest.Api.dll" ]

View File

@ -4,6 +4,9 @@ using Microsoft.Extensions.Configuration;
namespace BlueWest.WebApi.MySQL;
/// <summary>
/// Table containing countries
/// </summary>
public class CountriesDbContext : DbContext
{
@ -15,7 +18,11 @@ public class CountriesDbContext : DbContext
public IConfiguration Configuration;
public CountriesDbContext(DbContextOptions<UserDbContext> options) : base(options)
/// <summary>
/// Options to be injected in the app
/// </summary>
/// <param name="options"></param>
public CountriesDbContext(DbContextOptions<CountriesDbContext> options) : base(options)
{
Database.EnsureCreated();
@ -29,8 +36,23 @@ public class CountriesDbContext : DbContext
);*/
}
/// <summary>
/// The country number is the primary key
/// The currency code is the primary key
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Country>(builder =>
{
builder.HasKey(x => x.Code);
});
modelBuilder.Entity<Currency>(builder =>
{
builder.HasKey(x => x.Num);
});
}

View File

@ -4,6 +4,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using BlueWest.Core;
@ -35,20 +36,15 @@ namespace BlueWest.WebApi
public static void Main(string[] args)
{
Host1 = CreateHostBuilder(args).Build();
Host1 = CreateHostBuilder(args)
.UseContentRoot(Directory.GetCurrentDirectory())
.Build();
Host1.RunAsync();
System.Threading.Thread.Sleep(2500);
_threadServer = new ThreadServer(EventManager);
BlueWestConsoleBanner();
_threadServer.Init();
}
private static void BlueWestConsoleBanner()
{
Console.WriteLine(" |------------------------------«");
Console.WriteLine(" » Blue West «");
Console.WriteLine(" |------------------------------«\n");
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)

View File

@ -24,7 +24,7 @@
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Production"
}
}
}

View File

@ -8,7 +8,9 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using BlueWest.WebApi.MySQL;
using BlueWest.WebApi.Tools;
@ -52,9 +54,26 @@ namespace BlueWest.WebApi
options.SchemaFilter<SwaggerEnumSchemaFilter>();
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "BlueWest.Api",
Version = "v1"
Title = "BlueWest.Api Documentation",
Version = "v1",
Description = "A simple example ASP.NET Core Web API",
TermsOfService = new Uri("https://example.com/terms"),
Contact = new OpenApiContact
{
Name = "Benny",
Email = string.Empty,
Url = new Uri("https://git.codeliturgy.com"),
},
License = new OpenApiLicense
{
Name = "Use under LICX",
Url = new Uri("https://git.codeliturgy.com/license"),
}
});
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
options.IncludeXmlComments(xmlPath);
});
services.AddDbContextPool<UserDbContext>(options =>
options.GetSqlSettings(Configuration));
@ -72,12 +91,17 @@ namespace BlueWest.WebApi
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
//app.UseStaticFiles();
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BlueWest.Api v1"));
}
app.UseSwaggerUI(c =>
{
c.RoutePrefix = "swagger";
c.SwaggerEndpoint("/swagger/v1/swagger.json", "BlueWest.Api v1");
});
//app.UseHttpsRedirection();

View File

@ -4,7 +4,19 @@ namespace BlueWest.Data;
public class Country
{
[Key] public int Code { get; }
public string StateName { get; }
public string TLD { get; }
public int Code { get; set; } // Primary key
public string StateName { get; set; }
public string TLD { get; set; }
public Country(int code, string stateName, string tld)
{
Code = code;
StateName = stateName;
TLD = tld;
}
public Country()
{
}
}

View File

@ -2,7 +2,7 @@ namespace BlueWest.Data;
public class Currency
{
public string Code { get; }
public int Num { get; }
public Country Country { get; }
public int Num { get; set; } // Primary key
public string Code { get; set; }
public Country Country { get; set; }
}

View File

@ -1,6 +1,7 @@
using System;
using BlueWest.Core.ComponentSystem;
using BlueWest.Tools;
using PerformanceSolution.Core.System;
namespace PerformanceSolution.Artefacts
{

View File

@ -3,10 +3,11 @@ using System.IO;
using BlueWest.Core.ComponentSystem;
using BlueWest.Tools;
using PerformanceSolution.Artefacts;
using PerformanceSolution.Core.System;
namespace BlueWest.Core
{
public sealed class BlueConsole : Artefact
public sealed class BlueConsole : DisabledArtefact
{
private static string _consolePrompt = ">> ";

View File

@ -5,23 +5,11 @@ using System.Data;
using System.Threading;
using BlueWest.Coroutines;
using BlueWest.Tools;
using PerformanceSolution.Core.System;
namespace BlueWest.Core.ComponentSystem
{
public enum ArtefactFrequency
{
T120Hz,
T60Hz,
T30Hz,
T20Hz,
T10Hz,
T4Hz ,
T3Hz ,
T2Hz ,
T1Hz
}
public class Artefact
{
@ -59,8 +47,6 @@ namespace BlueWest.Core.ComponentSystem
private int _componentsCount = 0;
private readonly ArtefactFrequency BehaviorType;
// OLD STUFF
@ -76,7 +62,7 @@ namespace BlueWest.Core.ComponentSystem
{
_eventManager = eventManager;
switch (BehaviorType)
switch (Frequency)
{
case ArtefactFrequency.T1Hz:

View File

@ -0,0 +1,15 @@
namespace PerformanceSolution.Core.System;
public enum ArtefactFrequency
{
T120Hz,
T60Hz,
T30Hz,
T20Hz,
T10Hz,
T4Hz ,
T3Hz ,
T2Hz ,
T1Hz
}

View File

@ -0,0 +1,16 @@
using BlueWest.Tools;
namespace PerformanceSolution.Core.System;
public class DisabledArtefact
{
protected internal ArtefactFrequency Frequency;
protected EventManager _eventManager;
protected virtual void Update(double delta)
{
}
}