commit 8e156ba3569ec895eb22b05e3ac671fd24381b99 Author: Daniel Gerst Date: Tue Jun 15 10:59:47 2021 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..25b3ffc --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +################################################################################ +# This .gitignore file was automatically created by Microsoft(R) Visual Studio. +################################################################################ + +[Dd]ebug/ +[Rr]elease/ +[Ll]og/ +[Bb]in/ +[Oo]bj/ +.vs/ + +*.user +*.suo +*.dll +*.pdb +*.xml diff --git a/GerstITS.Examples.Api/Common/ExceptionHandling/Transformations/EntityNotFoundExceptionTransformation.cs b/GerstITS.Examples.Api/Common/ExceptionHandling/Transformations/EntityNotFoundExceptionTransformation.cs new file mode 100644 index 0000000..40ef533 --- /dev/null +++ b/GerstITS.Examples.Api/Common/ExceptionHandling/Transformations/EntityNotFoundExceptionTransformation.cs @@ -0,0 +1,19 @@ +using System.Net; +using GerstITS.Data; +using GerstITS.Web.Api.ExceptionHandling; + +namespace GerstITS.Examples.Api.ExceptionHandling +{ + public class EntityNotFoundExceptionTransformation : ExceptionTransformationBase + { + protected override ExceptionTransformationInfo CreateExceptionTransformationInfo(EntityNotFoundException exception, string ticketId) + { + return new ExceptionTransformationInfo + { + StatusCode = HttpStatusCode.NotFound, + ReasonPhrase = "Enitity nicht gefunden", + Details = exception.Message + }; + } + } +} diff --git a/GerstITS.Examples.Api/Common/ExceptionHandling/Transformations/ValidationExceptionTransformation.cs b/GerstITS.Examples.Api/Common/ExceptionHandling/Transformations/ValidationExceptionTransformation.cs new file mode 100644 index 0000000..c04002e --- /dev/null +++ b/GerstITS.Examples.Api/Common/ExceptionHandling/Transformations/ValidationExceptionTransformation.cs @@ -0,0 +1,23 @@ +using System.ComponentModel.DataAnnotations; +using System.Net; +using GerstITS.Web.Api.ExceptionHandling; + +namespace GerstITS.Examples.Api.ExceptionHandling +{ + internal sealed class ValidationExceptionTransformation : ExceptionTransformationBase + { + #region Methods + + protected override ExceptionTransformationInfo CreateExceptionTransformationInfo(ValidationException exception, string ticketId) + { + return new ExceptionTransformationInfo + { + StatusCode = HttpStatusCode.BadRequest, + ReasonPhrase = "Validierungsfehler", + Details = exception.Message + }; + } + + #endregion + } +} diff --git a/GerstITS.Examples.Api/Common/StartupTasks/ExampleStartupTask.cs b/GerstITS.Examples.Api/Common/StartupTasks/ExampleStartupTask.cs new file mode 100644 index 0000000..786ab98 --- /dev/null +++ b/GerstITS.Examples.Api/Common/StartupTasks/ExampleStartupTask.cs @@ -0,0 +1,39 @@ +using System.Diagnostics; +using GerstITS.Examples.Logic.Example; +using GerstITS.IoC; +using GerstITS.System.Json; + +namespace GerstITS.Examples.Api.StartupTasks +{ + internal class ExampleStartupTask : IStartupTask + { + #region Fields# + + private readonly IExampleProvider _provider; + private readonly IJsonConvert _jsonConvert; + + #endregion + + #region Construtcors + + public ExampleStartupTask(IExampleProvider provider, + IJsonConvert jsonConvert) + { + _jsonConvert = jsonConvert; + _provider = provider; + } + + #endregion + + #region IStartupTask + + public StartupPriorities Priority => StartupPriorities.Normal; + + public void Execute() + { + Debug.WriteLine($"---> {nameof(ExampleStartupTask)}: {_jsonConvert.Serialize(_provider.GetById(123))}"); + } + + #endregion + } +} diff --git a/GerstITS.Examples.Api/Common/Swagger/Configuration/LicenseConfiguration.cs b/GerstITS.Examples.Api/Common/Swagger/Configuration/LicenseConfiguration.cs new file mode 100644 index 0000000..85098f5 --- /dev/null +++ b/GerstITS.Examples.Api/Common/Swagger/Configuration/LicenseConfiguration.cs @@ -0,0 +1,15 @@ +using System; +using GerstITS.Web.Api.Swagger; + +namespace GerstITS.Examples.Api.Swagger +{ + internal class LicenseConfiguration : ILicense + { + #region Properties + + public string Name { get; set; } + public Uri Url { get; set; } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Api/Common/Swagger/Configuration/SwaggerSecurityConfiguration.cs b/GerstITS.Examples.Api/Common/Swagger/Configuration/SwaggerSecurityConfiguration.cs new file mode 100644 index 0000000..cbe6b9d --- /dev/null +++ b/GerstITS.Examples.Api/Common/Swagger/Configuration/SwaggerSecurityConfiguration.cs @@ -0,0 +1,19 @@ +using GerstITS.Web.Api.Swagger; +using Microsoft.OpenApi.Models; + +namespace GerstITS.Examples.Api.Swagger +{ + internal sealed class SwaggerSecurityConfiguration : IOpenApiSecuritySchemeConfiguration + { + #region Properties + + public bool AllowAnonymous { get; set; } + public string HttpHeaderKey { get; set; } + public string Scheme { get; set; } + public SecuritySchemeType SchemeType { get; set; } + public ParameterLocation ParameterLocation { get; set; } + public string Description { get; set; } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Api/Common/Swagger/Configuration/WebApiConfiguration.cs b/GerstITS.Examples.Api/Common/Swagger/Configuration/WebApiConfiguration.cs new file mode 100644 index 0000000..2662a22 --- /dev/null +++ b/GerstITS.Examples.Api/Common/Swagger/Configuration/WebApiConfiguration.cs @@ -0,0 +1,49 @@ +using System; +using System.Diagnostics; +using GerstITS.System.Configurations; +using GerstITS.Web.Api.Swagger; + +namespace GerstITS.Examples.Api.Swagger +{ + internal class WebApiConfiguration : ISwaggerConfiguration, IConfiguration + { + #region Constructors + + public WebApiConfiguration() + { + var currentAssembly = typeof(WebApiConfiguration).Assembly; + var fileVersionInfo = FileVersionInfo.GetVersionInfo(currentAssembly.Location); + + Company = fileVersionInfo.CompanyName; + Name = fileVersionInfo.ProductName; + Release = currentAssembly.GetName().Version; + + TermsOfService = new Uri("https://en.wikipedia.org/wiki/Terms_of_service"); + License = new LicenseConfiguration + { + Name = "MIT", + Url = new Uri("https://opensource.org/licenses/MIT") + }; + SupportEMail = "info@examples.net"; + + Security = new SwaggerSecurityConfiguration + { + AllowAnonymous = true + }; + } + + #endregion + + #region ISwaggerConfiguration + + public string Name { get; } + public string Company { get; } + public string SupportEMail { get; } + public Uri TermsOfService { get; } + public ILicense License { get; } + public Version Release { get; } + public IOpenApiSecuritySchemeConfiguration Security { get; } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Api/Common/Versioning/Versions.cs b/GerstITS.Examples.Api/Common/Versioning/Versions.cs new file mode 100644 index 0000000..14522f3 --- /dev/null +++ b/GerstITS.Examples.Api/Common/Versioning/Versions.cs @@ -0,0 +1,12 @@ +namespace GerstITS.Examples.Api.Versioning +{ + public static class Versions + { + #region Versions + + public const string _1_0 = "1.0"; + public const string _1_1 = "1.1"; + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Api/Controllers/1.0/ExampleController.cs b/GerstITS.Examples.Api/Controllers/1.0/ExampleController.cs new file mode 100644 index 0000000..28df7a0 --- /dev/null +++ b/GerstITS.Examples.Api/Controllers/1.0/ExampleController.cs @@ -0,0 +1,52 @@ +using GerstITS.Examples.Api.Versioning; +using GerstITS.Examples.Logic.Example; +using GerstITS.Validation; +using GerstITS.Web.Api; +using GerstITS.Web.Api.FluentApi; +using Microsoft.AspNetCore.Mvc; + +namespace GerstITS.Examples.Api.Controllers +{ + /// + /// Controller is deprecated use newer version. + /// + [ApiController, + ApiVersion(Versions._1_0, Deprecated = true), + Route(ApplicationEnvironment.WebApi.ControllerRouteTemplate)] + public class ExampleController : FluentApiControllerBase + { + #region Fields + + private readonly IExampleProvider _provider; + + #endregion + + #region Constructors + + public ExampleController(IExampleProvider provider, + IValidator validator) + : base(validator) + { + _provider = provider; + } + + #endregion + + #region Methods + + /// + /// Gets the example data by id. + /// + /// + /// Returns Example data. + [HttpGet, + Route("{id}")] + public IActionResult Get(int id) + { + return Api().Use(id) + .Get(_provider.GetById); + } + + #endregion + } +} diff --git a/GerstITS.Examples.Api/Controllers/1.1/ExampleController.cs b/GerstITS.Examples.Api/Controllers/1.1/ExampleController.cs new file mode 100644 index 0000000..e18791b --- /dev/null +++ b/GerstITS.Examples.Api/Controllers/1.1/ExampleController.cs @@ -0,0 +1,52 @@ +using GerstITS.Examples.Api.Versioning; +using GerstITS.Examples.Logic.Example; +using GerstITS.Validation; +using GerstITS.Web.Api; +using GerstITS.Web.Api.FluentApi; +using Microsoft.AspNetCore.Mvc; + +namespace GerstITS.Examples.Api.Controllers._1._1 +{ + /// + /// Is responsible to get employee organization assignment examples. + /// + [ApiController, + ApiVersion(Versions._1_1), + Route(ApplicationEnvironment.WebApi.ControllerRouteTemplate)] + public class ExampleController : FluentApiControllerBase + { + #region Fields + + private readonly IExampleProvider _provider; + + #endregion + + #region Constructors + + public ExampleController(IExampleProvider provider, + IValidator validator) + : base(validator) + { + _provider = provider; + } + + #endregion + + #region Methods + + /// + /// Gets a employee organization assignment by specified id. + /// + /// Id of the employee organization assignment. + /// Returns an employee organization assignment + [HttpGet, + Route("{id}")] + public IActionResult Get(int id) + { + return Api().Use(id) + .Get(_provider.GetById_v1_1); + } + + #endregion + } +} diff --git a/GerstITS.Examples.Api/GerstITS - Backup (1).Examples.Api.csproj b/GerstITS.Examples.Api/GerstITS - Backup (1).Examples.Api.csproj new file mode 100644 index 0000000..8971df2 --- /dev/null +++ b/GerstITS.Examples.Api/GerstITS - Backup (1).Examples.Api.csproj @@ -0,0 +1,65 @@ + + + + ITSCare GbR + ITSCare GbR + Copyright © ITSCare GbR 2021 + ITSCare Example WebApi + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + + net5.0 + latest + + + + true + true + + 1591 + bin\Debug\net5.0\ITSCare.Example.Api.xml + + + + + true + true + + 1591 + bin\Release\net5.0\ITSCare.Example.Api.xml + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GerstITS.Examples.Api/GerstITS - Backup (2).Examples.Api.csproj b/GerstITS.Examples.Api/GerstITS - Backup (2).Examples.Api.csproj new file mode 100644 index 0000000..1fa8a45 --- /dev/null +++ b/GerstITS.Examples.Api/GerstITS - Backup (2).Examples.Api.csproj @@ -0,0 +1,63 @@ + + + + ITSCare GbR + ITSCare GbR + Copyright © ITSCare GbR 2021 + ITSCare Example WebApi + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + + net5.0 + latest + + + + true + true + + 1591 + bin\Debug\net5.0\ITSCare.Example.Api.xml + + + + + true + true + + 1591 + bin\Release\net5.0\ITSCare.Example.Api.xml + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + diff --git a/GerstITS.Examples.Api/GerstITS - Backup (3).Examples.Api.csproj b/GerstITS.Examples.Api/GerstITS - Backup (3).Examples.Api.csproj new file mode 100644 index 0000000..793020b --- /dev/null +++ b/GerstITS.Examples.Api/GerstITS - Backup (3).Examples.Api.csproj @@ -0,0 +1,59 @@ + + + + ITSCare GbR + ITSCare GbR + Copyright © ITSCare GbR 2021 + ITSCare Example WebApi + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + + net5.0 + latest + + + + true + true + + 1591 + bin\Debug\net5.0\ITSCare.Example.Api.xml + + + + + true + true + + 1591 + bin\Release\net5.0\ITSCare.Example.Api.xml + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + diff --git a/GerstITS.Examples.Api/GerstITS - Backup.Examples.Api.csproj b/GerstITS.Examples.Api/GerstITS - Backup.Examples.Api.csproj new file mode 100644 index 0000000..5ca0958 --- /dev/null +++ b/GerstITS.Examples.Api/GerstITS - Backup.Examples.Api.csproj @@ -0,0 +1,68 @@ + + + + ITSCare GbR + ITSCare GbR + Copyright © ITSCare GbR 2021 + ITSCare Example WebApi + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + + net5.0 + latest + + + + true + true + + 1591 + bin\Debug\net5.0\ITSCare.Example.Api.xml + + + + + true + true + + 1591 + bin\Release\net5.0\ITSCare.Example.Api.xml + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GerstITS.Examples.Api/GerstITS.Examples.Api.csproj b/GerstITS.Examples.Api/GerstITS.Examples.Api.csproj new file mode 100644 index 0000000..ad72364 --- /dev/null +++ b/GerstITS.Examples.Api/GerstITS.Examples.Api.csproj @@ -0,0 +1,67 @@ + + + + ITSCare GbR + ITSCare GbR + Copyright © ITSCare GbR 2021 + ITSCare Example WebApi + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + + net5.0 + latest + + + + true + true + + 1591 + bin\Debug\net5.0\ITSCare.Example.Api.xml + + + + + true + true + + 1591 + bin\Release\net5.0\ITSCare.Example.Api.xml + + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/GerstITS.Examples.Api/GerstITS.Examples.Api.csproj.DotSettings b/GerstITS.Examples.Api/GerstITS.Examples.Api.csproj.DotSettings new file mode 100644 index 0000000..b9d2022 --- /dev/null +++ b/GerstITS.Examples.Api/GerstITS.Examples.Api.csproj.DotSettings @@ -0,0 +1,7 @@ + + True + True + True + False + True + True \ No newline at end of file diff --git a/GerstITS.Examples.Api/Module.ExceptionHandling.cs b/GerstITS.Examples.Api/Module.ExceptionHandling.cs new file mode 100644 index 0000000..4a60561 --- /dev/null +++ b/GerstITS.Examples.Api/Module.ExceptionHandling.cs @@ -0,0 +1,18 @@ +using GerstITS.Examples.Api.ExceptionHandling; +using GerstITS.Web.Api.ExceptionHandling.Extensions; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.Api +{ + public sealed partial class Module + { + #region Methods + + private static void RegisterExceptionHandling(IServiceCollection container) + { + container.RegisterExceptionTransformationsOf(); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Api/Module.Mvc.cs b/GerstITS.Examples.Api/Module.Mvc.cs new file mode 100644 index 0000000..b6cf062 --- /dev/null +++ b/GerstITS.Examples.Api/Module.Mvc.cs @@ -0,0 +1,22 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.Api +{ + public sealed partial class Module + { + #region Methods + + private static void RegisterMvc(IServiceCollection container) + { + //container.AddTransient, ApiMvcOptions>(); + //container.AddTransient, MvcJsonOptions>(); + + container.AddMvc() + .AddNewtonsoftJson() + .SetCompatibilityVersion(CompatibilityVersion.Latest); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Api/Module.StartupTasks.cs b/GerstITS.Examples.Api/Module.StartupTasks.cs new file mode 100644 index 0000000..7295fd7 --- /dev/null +++ b/GerstITS.Examples.Api/Module.StartupTasks.cs @@ -0,0 +1,18 @@ +using GerstITS.Examples.Api.StartupTasks; +using GerstITS.IoC.DotNetCore; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.Api +{ + public sealed partial class Module + { + #region Methods + + private static void RegisterStartupTasks(IServiceCollection container) + { + container.RegisterStartupTasksOf(); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Api/Module.Swagger.cs b/GerstITS.Examples.Api/Module.Swagger.cs new file mode 100644 index 0000000..2e3e444 --- /dev/null +++ b/GerstITS.Examples.Api/Module.Swagger.cs @@ -0,0 +1,18 @@ +using GerstITS.Examples.Api.Swagger; +using GerstITS.Web.Api.Swagger; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.Api +{ + public sealed partial class Module + { + #region Methods + + private static void RegisterSwagger(IServiceCollection container) + { + container.AddSingleton(); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Api/Module.cs b/GerstITS.Examples.Api/Module.cs new file mode 100644 index 0000000..0fa9519 --- /dev/null +++ b/GerstITS.Examples.Api/Module.cs @@ -0,0 +1,20 @@ +using GerstITS.IoC; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.Api +{ + public sealed partial class Module : IIoCModule + { + #region IIoCModule + + public void RegisterComponents(IServiceCollection container) + { + RegisterExceptionHandling(container); + RegisterMvc(container); + RegisterStartupTasks(container); + RegisterSwagger(container); + } + + #endregion + } +} diff --git a/GerstITS.Examples.Api/Program.cs b/GerstITS.Examples.Api/Program.cs new file mode 100644 index 0000000..2b14cdd --- /dev/null +++ b/GerstITS.Examples.Api/Program.cs @@ -0,0 +1,21 @@ +using GerstITS.Web.Api.Hosting; + +namespace GerstITS.Examples.Api +{ + public class Program : ProgramBase + { + #region Methods + + public static void Main(string[] args) + { + Run(args); + } + + protected override void ConfigureWebHost(IWebHostBuilder webHostBuilder) + { + webHostBuilder.UseStartup(); + } + + #endregion + } +} diff --git a/GerstITS.Examples.Api/Properties/launchSettings.json b/GerstITS.Examples.Api/Properties/launchSettings.json new file mode 100644 index 0000000..364757a --- /dev/null +++ b/GerstITS.Examples.Api/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:61531/", + "sslPort": 44353 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "ITSCare.Example.Api": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" + } + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Api/Startup.cs b/GerstITS.Examples.Api/Startup.cs new file mode 100644 index 0000000..649ea1e --- /dev/null +++ b/GerstITS.Examples.Api/Startup.cs @@ -0,0 +1,32 @@ +using GerstITS.Web.Api; +using GerstITS.Web.Api.Builder; +using GerstITS.Web.Api.Hosting; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace GerstITS.Examples.Api +{ + public class Startup : BootstrapperStartupBase + { + #region Methods + + protected override void ConfigureApplication(IApplicationBuilder applicationBuilder, IWebHostEnvironment webHostEnvironment) + { + if (webHostEnvironment.IsDevelopment()) + applicationBuilder.UseDeveloperExceptionPage() + .UseSwagger(); + else + applicationBuilder.UseHsts(); + + applicationBuilder.UseHttpsRedirection() + .UseAuthentication() + .UseAuthorization() + .UseRouting() + .UseEndpoints(endpoints => endpoints.MapControllers()) + .UseRewriteUnknownPathsToIndexSite(ApplicationEnvironment.WebApi.BaseUrl) + .UseStaticFiles(); + } + + #endregion + } +} diff --git a/GerstITS.Examples.Api/appsettings.json b/GerstITS.Examples.Api/appsettings.json new file mode 100644 index 0000000..a3900f2 --- /dev/null +++ b/GerstITS.Examples.Api/appsettings.json @@ -0,0 +1,22 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "WebApi": { + "SupportEMail": "support@itscare.de" + }, + "SkyNet": { + "AppId": 86, + "Audience": "39CE2111-475C-42FE-88F7-9B7A29D0262C" + }, + "LogPath": "log/{Date}.log", + "SayHelloWorldJob": { + "CronExpression": "*/30 * * * * ? *", + "Name": "Example Job" + } +} diff --git a/GerstITS.Examples.Jobs.SayHelloWorld/Configurations/SayHelloWorldJobConfiguration.cs b/GerstITS.Examples.Jobs.SayHelloWorld/Configurations/SayHelloWorldJobConfiguration.cs new file mode 100644 index 0000000..15f13b4 --- /dev/null +++ b/GerstITS.Examples.Jobs.SayHelloWorld/Configurations/SayHelloWorldJobConfiguration.cs @@ -0,0 +1,27 @@ +using GerstITS.Job.Scheduling; +using GerstITS.System.Configurations; +using Microsoft.Extensions.Configuration; + +namespace GerstITS.Examples.Jobs.SayHelloWorld.Configurations +{ + public class SayHelloWorldJobConfiguration : JobSchedulingConfigurationBase + { + #region Properties + + public string Name { get; } + + #endregion + + #region Constructors + + public SayHelloWorldJobConfiguration(Microsoft.Extensions.Configuration.IConfiguration configuration) + : base(configuration) + { + var prefix = this.ToConfigurationPrefix(); + + Name = configuration.GetValue($"{prefix}:{nameof(Name)}"); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Jobs.SayHelloWorld/GerstITS.Examples.Jobs.SayHelloWorld.csproj b/GerstITS.Examples.Jobs.SayHelloWorld/GerstITS.Examples.Jobs.SayHelloWorld.csproj new file mode 100644 index 0000000..43e7005 --- /dev/null +++ b/GerstITS.Examples.Jobs.SayHelloWorld/GerstITS.Examples.Jobs.SayHelloWorld.csproj @@ -0,0 +1,48 @@ + + + + ITSCare GbR + ITSCare GbR + Copyright © ITSCare GbR 2021 + ITSCare GbR Example Job + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + + net5.0 + latest + + + + true + true + + + + + + true + true + + + + + + + + + + + + + + + + Module.cs + + + + diff --git a/GerstITS.Examples.Jobs.SayHelloWorld/GerstITS.Examples.Jobs.SayHelloWorld.csproj.DotSettings b/GerstITS.Examples.Jobs.SayHelloWorld/GerstITS.Examples.Jobs.SayHelloWorld.csproj.DotSettings new file mode 100644 index 0000000..0fc265d --- /dev/null +++ b/GerstITS.Examples.Jobs.SayHelloWorld/GerstITS.Examples.Jobs.SayHelloWorld.csproj.DotSettings @@ -0,0 +1,2 @@ + + False \ No newline at end of file diff --git a/GerstITS.Examples.Jobs.SayHelloWorld/Jobs/SayHelloWorldJob.cs b/GerstITS.Examples.Jobs.SayHelloWorld/Jobs/SayHelloWorldJob.cs new file mode 100644 index 0000000..c0cf976 --- /dev/null +++ b/GerstITS.Examples.Jobs.SayHelloWorld/Jobs/SayHelloWorldJob.cs @@ -0,0 +1,51 @@ +using System.Diagnostics; +using System.Threading; +using GerstITS.Data; +using GerstITS.Examples.Jobs.SayHelloWorld.Configurations; +using GerstITS.Job; +using GerstITS.System.Environment; +using Quartz; + +namespace GerstITS.Examples.Jobs.SayHelloWorld.Jobs +{ + [DisallowConcurrentExecution] + public class SayHelloWorldJob : JobBase + { + #region Fields + + private readonly SayHelloWorldJobConfiguration _configuration; + private readonly Stopwatch _stopWatch; + private readonly IRepository _repository; + private readonly ISystemClock _systemClock; + + #endregion + + #region Cosntructors + + public SayHelloWorldJob(SayHelloWorldJobConfiguration configuration, + IRepository repository, + ISystemClock systemClock) + { + _systemClock = systemClock; + _repository = repository; + _configuration = configuration; + _stopWatch = new Stopwatch(); + } + + #endregion + + #region Methods + + protected override void Execute() + { + _stopWatch.Restart(); + Thread.Sleep(4000); + var now = _systemClock.UtcNow; + + _stopWatch.Stop(); + Debug.WriteLine($"---> Say hello to world from {_configuration.Name}, Duration: {_stopWatch.ElapsedMilliseconds / 1000}s"); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Jobs.SayHelloWorld/Module.cs b/GerstITS.Examples.Jobs.SayHelloWorld/Module.cs new file mode 100644 index 0000000..0a506d7 --- /dev/null +++ b/GerstITS.Examples.Jobs.SayHelloWorld/Module.cs @@ -0,0 +1,20 @@ +using GerstITS.Examples.Jobs.SayHelloWorld.Configurations; +using GerstITS.Examples.Jobs.SayHelloWorld.Jobs; +using GerstITS.IoC; +using GerstITS.Job.Scheduling; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.Jobs.SayHelloWorld +{ + public sealed class Module : IIoCModule + { + #region IIoCModule + + public void RegisterComponents(IServiceCollection container) + { + container.RegisterJob(); + } + + #endregion + } +} diff --git a/GerstITS.Examples.Logic/Example/Contracts/Example.cs b/GerstITS.Examples.Logic/Example/Contracts/Example.cs new file mode 100644 index 0000000..b1151e0 --- /dev/null +++ b/GerstITS.Examples.Logic/Example/Contracts/Example.cs @@ -0,0 +1,13 @@ +namespace GerstITS.Examples.Logic.Example +{ + public class Example + { + #region Properties + + public string FirstName { get; set; } + public string LastName { get; set; } + public string Description { get; set; } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Logic/Example/Contracts/IExampleProvider.cs b/GerstITS.Examples.Logic/Example/Contracts/IExampleProvider.cs new file mode 100644 index 0000000..e97a562 --- /dev/null +++ b/GerstITS.Examples.Logic/Example/Contracts/IExampleProvider.cs @@ -0,0 +1,8 @@ +namespace GerstITS.Examples.Logic.Example +{ + public interface IExampleProvider + { + Example GetById(int id); + Example GetById_v1_1(int id); + } +} diff --git a/GerstITS.Examples.Logic/Example/ExampleProvider.cs b/GerstITS.Examples.Logic/Example/ExampleProvider.cs new file mode 100644 index 0000000..e986db0 --- /dev/null +++ b/GerstITS.Examples.Logic/Example/ExampleProvider.cs @@ -0,0 +1,51 @@ +using AutoMapper; +using GerstITS.Data; + +namespace GerstITS.Examples.Logic.Example +{ + internal sealed class ExampleProvider : IExampleProvider + { + #region Fields + + private readonly IMapper _mapper; + + #endregion + + #region Constructors + + public ExampleProvider(IMapper mapper) + { + _mapper = mapper; + } + + #endregion + + #region IExampleProvider + + public Example GetById(int id) + { + ThrowsAnExceptionIfEntityIsNotFound(id); + + return _mapper.Map(id); + } + + public Example GetById_v1_1(int id) + { + ThrowsAnExceptionIfEntityIsNotFound(id); + + return _mapper.Map(id); + } + + #endregion + + #region Methods + + private static void ThrowsAnExceptionIfEntityIsNotFound(int id) + { + if (id % 2 == 0) + throw new EntityNotFoundException($"Example mit der Id '{id}' nicht gefunden."); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Logic/Example/Mappings/IntegerMapping.cs b/GerstITS.Examples.Logic/Example/Mappings/IntegerMapping.cs new file mode 100644 index 0000000..43f086b --- /dev/null +++ b/GerstITS.Examples.Logic/Example/Mappings/IntegerMapping.cs @@ -0,0 +1,19 @@ +using AutoMapper; + +namespace GerstITS.Examples.Logic.Example +{ + internal sealed class IntegerMapping : Profile + { + #region Construtcors + + public IntegerMapping() + { + CreateMap() + .ForMember(x => x.FirstName, m => m.MapFrom((s,t) => $"First Name {s}")) + .ForMember(x => x.LastName, m => m.MapFrom((s,t) => $"Last Name {s}")) + .ForMember(x => x.Description, m => m.MapFrom((s,t) => $"Useful description for id '{s}'")); + } + + #endregion + } +} diff --git a/GerstITS.Examples.Logic/GerstITS.Examples.Logic.csproj b/GerstITS.Examples.Logic/GerstITS.Examples.Logic.csproj new file mode 100644 index 0000000..3ac851d --- /dev/null +++ b/GerstITS.Examples.Logic/GerstITS.Examples.Logic.csproj @@ -0,0 +1,54 @@ + + + + ITSCare GbR + ITSCare GbR + Copyright © ITSCare GbR 2021 + ITSCare GbR Example Logic + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + + net5.0 + latest + + + + true + true + + + + + + true + true + + + + + + + + + + + + + + + + + + + Module.cs + + + Module.cs + + + + diff --git a/GerstITS.Examples.Logic/GerstITS.Examples.Logic.csproj.DotSettings b/GerstITS.Examples.Logic/GerstITS.Examples.Logic.csproj.DotSettings new file mode 100644 index 0000000..78da81e --- /dev/null +++ b/GerstITS.Examples.Logic/GerstITS.Examples.Logic.csproj.DotSettings @@ -0,0 +1,13 @@ + + True + True + True + True + True + True + True + True + True + True + True + True \ No newline at end of file diff --git a/GerstITS.Examples.Logic/Module.Example.cs b/GerstITS.Examples.Logic/Module.Example.cs new file mode 100644 index 0000000..5100845 --- /dev/null +++ b/GerstITS.Examples.Logic/Module.Example.cs @@ -0,0 +1,20 @@ +using GerstITS.AutoMapper; +using GerstITS.Examples.Logic.Example; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.Logic +{ + public sealed partial class Module + { + #region Methods + + private static void RegisterExample(IServiceCollection container) + { + container.RegisterMappingsOf(); + + container.AddScoped(); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Logic/Module.Shared.cs b/GerstITS.Examples.Logic/Module.Shared.cs new file mode 100644 index 0000000..59c9c4f --- /dev/null +++ b/GerstITS.Examples.Logic/Module.Shared.cs @@ -0,0 +1,22 @@ +using GerstITS.Examples.Logic.Shared.Search.Sorting; +using GerstITS.Examples.Logic.Shared.Validation; +using GerstITS.Search; +using GerstITS.Validation; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.Logic +{ + public sealed partial class Module + { + #region Methods + + private static void RegisterShared(IServiceCollection container) + { + container.RegisterValidationRulesOf(); + + container.AddScoped(); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Logic/Module.cs b/GerstITS.Examples.Logic/Module.cs new file mode 100644 index 0000000..7732508 --- /dev/null +++ b/GerstITS.Examples.Logic/Module.cs @@ -0,0 +1,18 @@ +using GerstITS.IoC; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.Logic +{ + public sealed partial class Module : IIoCModule + { + #region IIoCModule + + public void RegisterComponents(IServiceCollection container) + { + RegisterExample(container); + RegisterShared(container); + } + + #endregion + } +} diff --git a/GerstITS.Examples.Logic/Shared/Extensions/IReadOnlyRepositoryExtensions.cs b/GerstITS.Examples.Logic/Shared/Extensions/IReadOnlyRepositoryExtensions.cs new file mode 100644 index 0000000..fbd48de --- /dev/null +++ b/GerstITS.Examples.Logic/Shared/Extensions/IReadOnlyRepositoryExtensions.cs @@ -0,0 +1,31 @@ +using System; +using System.Linq; +using System.Linq.Expressions; +using GerstITS.Common; +using GerstITS.Data; + +namespace GerstITS.Examples.Logic.Shared +{ + internal static class ISearchEngineExtensions + { + #region Methods + + public static TEntity QueryBy(this IReadOnlyRepository repository, Expression> condition) + where TEntity : IEntity + { + return repository.Query() + .Where(condition) + .FirstOrDefault(); + } + + public static TModel ThrowsAnExceptionIfNotFound(this TModel model, TKey id) + { + if (model.IsNull()) + throw new EntityNotFoundException($"{typeof(TModel).Name} with id '{id}' not found."); + + return model; + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.Logic/Shared/Search/Sorting/ISortable.cs b/GerstITS.Examples.Logic/Shared/Search/Sorting/ISortable.cs new file mode 100644 index 0000000..5b5ab28 --- /dev/null +++ b/GerstITS.Examples.Logic/Shared/Search/Sorting/ISortable.cs @@ -0,0 +1,6 @@ +namespace GerstITS.Examples.Logic.Shared.Search.Sorting +{ + internal interface ISortable + { + } +} diff --git a/GerstITS.Examples.Logic/Shared/Search/Sorting/SortingProvider.cs b/GerstITS.Examples.Logic/Shared/Search/Sorting/SortingProvider.cs new file mode 100644 index 0000000..7c0d332 --- /dev/null +++ b/GerstITS.Examples.Logic/Shared/Search/Sorting/SortingProvider.cs @@ -0,0 +1,50 @@ +using System; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using GerstITS.Common; +using GerstITS.Search; + +namespace GerstITS.Examples.Logic.Shared.Search.Sorting +{ + internal class SortingProvider : ISortingProvider + { + #region ISortingProvider + + public bool CanSort(IQueryable query) + { + return typeof(TItem).IsAssignableTo(typeof(ISortable)); + } + + public IQueryable Sort(IQueryable query, ISorting sorting) + { + var propertyInfo = typeof(TItem).GetProperties() + .SingleOrDefault(i => string.Equals(i.Name, sorting.SortBy, StringComparison.InvariantCultureIgnoreCase)); + + if (!CanSort(query) || propertyInfo.IsNull()) + return query; + + var sortExpression = CreateSortExpression(propertyInfo); + + return (sorting.SortDirection == SortingDirections.Ascending + ? query.OrderBy(sortExpression) + : query.OrderByDescending(sortExpression)) + .AsQueryable(); + } + + #endregion + + #region Methods + + private static Expression> CreateSortExpression(MemberInfo propertyInfo) + { + var parameterExpression = Expression.Parameter(typeof(TItem), "x"); + var propertyExpression = Expression.Property(parameterExpression, propertyInfo.Name); + var convertExpression = Expression.Convert(propertyExpression, typeof(object)); + + return Expression.Lambda>(convertExpression, parameterExpression); + } + + #endregion + } +} diff --git a/GerstITS.Examples.Logic/Shared/Validation/IdValidationRule.cs b/GerstITS.Examples.Logic/Shared/Validation/IdValidationRule.cs new file mode 100644 index 0000000..9333325 --- /dev/null +++ b/GerstITS.Examples.Logic/Shared/Validation/IdValidationRule.cs @@ -0,0 +1,19 @@ +using FluentValidation; +using GerstITS.Validation; + +namespace GerstITS.Examples.Logic.Shared.Validation +{ + internal sealed class IdValidationRule : ValidationRuleBase + { + #region Constructors + + public IdValidationRule() + { + RuleFor(x => x) + .GreaterThan(0) + .OverridePropertyName("id"); + } + + #endregion + } +} diff --git a/GerstITS.Examples.WebClient.Console/GerstITS.Examples.WebClient.Console.csproj b/GerstITS.Examples.WebClient.Console/GerstITS.Examples.WebClient.Console.csproj new file mode 100644 index 0000000..2e80845 --- /dev/null +++ b/GerstITS.Examples.WebClient.Console/GerstITS.Examples.WebClient.Console.csproj @@ -0,0 +1,60 @@ + + + + ITSCare GbR + ITSCare GbR + Copyright © ITSCare GbR 2021 + ITSCare GbR Example WebApi Client + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + + net5.0 + latest + Exe + + + + true + true + + + + + + true + true + + + + + + + + + + + Always + + + + + + + + + + + + + + + + + + + + diff --git a/GerstITS.Examples.WebClient.Console/GerstITS.Examples.WebClient.Console.csproj.DotSettings b/GerstITS.Examples.WebClient.Console/GerstITS.Examples.WebClient.Console.csproj.DotSettings new file mode 100644 index 0000000..8d897c9 --- /dev/null +++ b/GerstITS.Examples.WebClient.Console/GerstITS.Examples.WebClient.Console.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/GerstITS.Examples.WebClient.Console/Module.cs b/GerstITS.Examples.WebClient.Console/Module.cs new file mode 100644 index 0000000..2ae07ed --- /dev/null +++ b/GerstITS.Examples.WebClient.Console/Module.cs @@ -0,0 +1,25 @@ +using System; +using GerstITS.Examples.WebClient.Console.Tests; +using GerstITS.IoC; +using GerstITS.IoC.DotNetCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.WebClient.Console +{ + public class Module : IIoCModule + { + #region IIoCModule + + public void RegisterComponents(IServiceCollection container) + { + container.AddTransient(); + + container.AddTransient(c => new ConfigurationBuilder().SetBasePath(AppDomain.CurrentDomain.BaseDirectory) + .AddJsonFile("appsettings.json", false, true) + .Build()); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.WebClient.Console/Program.cs b/GerstITS.Examples.WebClient.Console/Program.cs new file mode 100644 index 0000000..5f7d531 --- /dev/null +++ b/GerstITS.Examples.WebClient.Console/Program.cs @@ -0,0 +1,31 @@ +using GerstITS.IoC.DotNetCore; + +namespace GerstITS.Examples.WebClient.Console +{ + internal class Program + { + #region Fields + + private static readonly DotNetCoreApplicationBootstrapper _bootstrapper; + + #endregion + + #region Constructors + + static Program() + { + _bootstrapper = new DotNetCoreApplicationBootstrapper(); + } + + #endregion + + #region Methods + + private static void Main(string[] args) + { + _bootstrapper.Run(); + } + + #endregion + } +} diff --git a/GerstITS.Examples.WebClient.Console/Tests/TestRunner.cs b/GerstITS.Examples.WebClient.Console/Tests/TestRunner.cs new file mode 100644 index 0000000..b7b1079 --- /dev/null +++ b/GerstITS.Examples.WebClient.Console/Tests/TestRunner.cs @@ -0,0 +1,51 @@ +using System; +using System.Linq; +using GerstITS.Examples.WebClients.Examples.Api; +using GerstITS.IoC.DotNetCore; +using GerstITS.Web.WebClients; + +namespace GerstITS.Examples.WebClient.Console.Tests +{ + internal sealed class TestRunner : IApplicationStart + { + #region Fields + + private readonly IWebClient _webClient; + + #endregion + + #region Construtors + + public TestRunner(IWebClient webClient) + { + _webClient = webClient; + } + + #endregion + + #region ITestRunner + + public void Run() + { + var result1 = _webClient.Request() + .Execute(c => c.Search(new SearchCriteria + { SortBy = nameof(Country.Name), SortDirection = SortingDirections.Descending, Skip = 5, Take = 5})); + + var result2 = _webClient.Request() + .Execute(c => c.Get(result1.Value.Result.First().Id)); + + var test3 = _webClient.Request() + .Execute(c => c.Create(new Country {Name = $"Country-{Guid.NewGuid()}"})); + + test3.Value.Name += "_Renamed"; + + var test4 = _webClient.Request() + .Execute(c => c.Update(test3.Value)); + + var test5 = _webClient.Request() + .Execute(c => c.Delete(test3.Value.Id)); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.Examples.WebClient.Console/appsettings.json b/GerstITS.Examples.WebClient.Console/appsettings.json new file mode 100644 index 0000000..df91a93 --- /dev/null +++ b/GerstITS.Examples.WebClient.Console/appsettings.json @@ -0,0 +1,13 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "ExampleApiClient": { + "BaseUrl": "https://localhost:44350/api/v1.1/" + } +} diff --git a/GerstITS.Examples.sln b/GerstITS.Examples.sln new file mode 100644 index 0000000..efc6454 --- /dev/null +++ b/GerstITS.Examples.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31321.278 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GerstITS.Examples.Api", "GerstITS.Examples.Api\GerstITS.Examples.Api.csproj", "{417B5C77-05BF-4562-9A1A-AEE0531B59C1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GerstITS.Examples.Jobs.SayHelloWorld", "GerstITS.Examples.Jobs.SayHelloWorld\GerstITS.Examples.Jobs.SayHelloWorld.csproj", "{A2E37A84-9331-48C7-8CCA-991528063087}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GerstITS.Examples.Logic", "GerstITS.Examples.Logic\GerstITS.Examples.Logic.csproj", "{4A83DB6A-01BB-4B56-B38B-268444F22B1E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GerstITS.Examples.WebClient.Console", "GerstITS.Examples.WebClient.Console\GerstITS.Examples.WebClient.Console.csproj", "{A7AD8A07-C9C0-480B-A96B-2D03ACD57060}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GerstITS.Examples.WebClients.Examples.Api", "GerstITS.WebClients.Example.Api\GerstITS.Examples.WebClients.Examples.Api.csproj", "{34720C2D-09AD-41F4-B7CC-D703D9F24EDD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {417B5C77-05BF-4562-9A1A-AEE0531B59C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {417B5C77-05BF-4562-9A1A-AEE0531B59C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {417B5C77-05BF-4562-9A1A-AEE0531B59C1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {417B5C77-05BF-4562-9A1A-AEE0531B59C1}.Release|Any CPU.Build.0 = Release|Any CPU + {A2E37A84-9331-48C7-8CCA-991528063087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A2E37A84-9331-48C7-8CCA-991528063087}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A2E37A84-9331-48C7-8CCA-991528063087}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A2E37A84-9331-48C7-8CCA-991528063087}.Release|Any CPU.Build.0 = Release|Any CPU + {4A83DB6A-01BB-4B56-B38B-268444F22B1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A83DB6A-01BB-4B56-B38B-268444F22B1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A83DB6A-01BB-4B56-B38B-268444F22B1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A83DB6A-01BB-4B56-B38B-268444F22B1E}.Release|Any CPU.Build.0 = Release|Any CPU + {A7AD8A07-C9C0-480B-A96B-2D03ACD57060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7AD8A07-C9C0-480B-A96B-2D03ACD57060}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A7AD8A07-C9C0-480B-A96B-2D03ACD57060}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A7AD8A07-C9C0-480B-A96B-2D03ACD57060}.Release|Any CPU.Build.0 = Release|Any CPU + {34720C2D-09AD-41F4-B7CC-D703D9F24EDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {34720C2D-09AD-41F4-B7CC-D703D9F24EDD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {34720C2D-09AD-41F4-B7CC-D703D9F24EDD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {34720C2D-09AD-41F4-B7CC-D703D9F24EDD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3AADD521-AFE4-4615-A0A3-2E89FE7E8559} + EndGlobalSection +EndGlobal diff --git a/GerstITS.Examples.sln.DotSettings b/GerstITS.Examples.sln.DotSettings new file mode 100644 index 0000000..d080d81 --- /dev/null +++ b/GerstITS.Examples.sln.DotSettings @@ -0,0 +1,3 @@ + + <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + True \ No newline at end of file diff --git a/GerstITS.WebClients.Example.Api/Configurations/ExampleApiClientConfiguration.cs b/GerstITS.WebClients.Example.Api/Configurations/ExampleApiClientConfiguration.cs new file mode 100644 index 0000000..c3d8606 --- /dev/null +++ b/GerstITS.WebClients.Example.Api/Configurations/ExampleApiClientConfiguration.cs @@ -0,0 +1,17 @@ +using GerstITS.Web.Rest.WebClients; +using Microsoft.Extensions.Configuration; + +namespace GerstITS.Examples.WebClients.Examples.Api.Configurations +{ + internal class ExampleApiClientConfiguration : RestWebServiceConfigurationBase + { + #region Constructors + + public ExampleApiClientConfiguration(IConfiguration configuration) + : base(configuration) + { + } + + #endregion + } +} diff --git a/GerstITS.WebClients.Example.Api/Contracts/ICountry.cs b/GerstITS.WebClients.Example.Api/Contracts/ICountry.cs new file mode 100644 index 0000000..173997b --- /dev/null +++ b/GerstITS.WebClients.Example.Api/Contracts/ICountry.cs @@ -0,0 +1,27 @@ +using GerstITS.Web.WebClients; + +namespace GerstITS.Examples.WebClients.Examples.Api +{ + public interface ICountry : IWebService + { + [WebMethod(WebMethods.Get), + ResourceUrl("Country/{id}")] + Country Get(int id); + + [WebMethod(WebMethods.Get), + ResourceUrl("Country/Search")] + SearchResult Search(SearchCriteria criteria); + + [WebMethod(WebMethods.Post), + ResourceUrl("Country")] + Country Create(Country model); + + [WebMethod(WebMethods.Put), + ResourceUrl("Country")] + void Update(Country model); + + [WebMethod(WebMethods.Delete), + ResourceUrl("Country/{id}")] + void Delete(int id); + } +} \ No newline at end of file diff --git a/GerstITS.WebClients.Example.Api/Contracts/Serialization/Country.cs b/GerstITS.WebClients.Example.Api/Contracts/Serialization/Country.cs new file mode 100644 index 0000000..cca6f8a --- /dev/null +++ b/GerstITS.WebClients.Example.Api/Contracts/Serialization/Country.cs @@ -0,0 +1,12 @@ +namespace GerstITS.Examples.WebClients.Examples.Api +{ + public class Country + { + #region Properties + + public int Id { get; set; } + public string Name { get; set; } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.WebClients.Example.Api/Contracts/Serialization/SearchCriteria.cs b/GerstITS.WebClients.Example.Api/Contracts/Serialization/SearchCriteria.cs new file mode 100644 index 0000000..5a1e789 --- /dev/null +++ b/GerstITS.WebClients.Example.Api/Contracts/Serialization/SearchCriteria.cs @@ -0,0 +1,18 @@ +namespace GerstITS.Examples.WebClients.Examples.Api +{ + public class SearchCriteria + { + #region Properties + + internal int Id { get; set; } + public string Name { get; set; } + + public int? Skip { get; set; } + public int? Take { get; set; } + + public string SortBy { get; set; } + public SortingDirections SortDirection { get; set; } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.WebClients.Example.Api/Contracts/Serialization/SearchResult.cs b/GerstITS.WebClients.Example.Api/Contracts/Serialization/SearchResult.cs new file mode 100644 index 0000000..a930c9c --- /dev/null +++ b/GerstITS.WebClients.Example.Api/Contracts/Serialization/SearchResult.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; + +namespace GerstITS.Examples.WebClients.Examples.Api +{ + public class SearchResult + { + #region Properties + + public int TotalCount { get; set; } + public IEnumerable Result { get; set; } + + #endregion + + #region Constructors + + public SearchResult() + { + Result = Array.Empty(); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.WebClients.Example.Api/Contracts/Serialization/SortingDirections.cs b/GerstITS.WebClients.Example.Api/Contracts/Serialization/SortingDirections.cs new file mode 100644 index 0000000..cfc3930 --- /dev/null +++ b/GerstITS.WebClients.Example.Api/Contracts/Serialization/SortingDirections.cs @@ -0,0 +1,8 @@ +namespace GerstITS.Examples.WebClients.Examples.Api +{ + public enum SortingDirections + { + Ascending = 0, + Descending + } +} \ No newline at end of file diff --git a/GerstITS.WebClients.Example.Api/CreationRules/ExampleApiClientCreatingRule.cs b/GerstITS.WebClients.Example.Api/CreationRules/ExampleApiClientCreatingRule.cs new file mode 100644 index 0000000..4b4bca1 --- /dev/null +++ b/GerstITS.WebClients.Example.Api/CreationRules/ExampleApiClientCreatingRule.cs @@ -0,0 +1,25 @@ +using System; +using GerstITS.Examples.WebClients.Examples.Api.Configurations; +using GerstITS.Web.Rest.WebClients; + +namespace GerstITS.Examples.WebClients.Examples.Api.CreationRules +{ + internal sealed class ExampleApiClientCreatingRule : RestApiClientCreationRuleBase + { + #region Properties + + protected override Type[] SupportedTypes => new[] { typeof(ICountry) }; + + #endregion + + #region Constructors + + public ExampleApiClientCreatingRule(ExampleApiClientConfiguration configuration, + Func restWebServiceClientFactory) + : base(configuration, restWebServiceClientFactory) + { + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.WebClients.Example.Api/GerstITS.Examples.WebClients.Examples.Api.csproj b/GerstITS.WebClients.Example.Api/GerstITS.Examples.WebClients.Examples.Api.csproj new file mode 100644 index 0000000..8c0ade2 --- /dev/null +++ b/GerstITS.WebClients.Example.Api/GerstITS.Examples.WebClients.Examples.Api.csproj @@ -0,0 +1,50 @@ + + + + ITSCare GbR + ITSCare GbR + Copyright © ITSCare GbR 2021 + ITSCare GbR Example WebClient + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + 0.0.0.0 + + + + net5.0 + latest + + + + true + true + + + + + + true + true + + + + + + + + + + + + + + + Module.cs + + + Module.cs + + + + diff --git a/GerstITS.WebClients.Example.Api/GerstITS.Examples.WebClients.Examples.Api.csproj.DotSettings b/GerstITS.WebClients.Example.Api/GerstITS.Examples.WebClients.Examples.Api.csproj.DotSettings new file mode 100644 index 0000000..4ba8ab5 --- /dev/null +++ b/GerstITS.WebClients.Example.Api/GerstITS.Examples.WebClients.Examples.Api.csproj.DotSettings @@ -0,0 +1,3 @@ + + True + True \ No newline at end of file diff --git a/GerstITS.WebClients.Example.Api/Module.Configurations.cs b/GerstITS.WebClients.Example.Api/Module.Configurations.cs new file mode 100644 index 0000000..c128521 --- /dev/null +++ b/GerstITS.WebClients.Example.Api/Module.Configurations.cs @@ -0,0 +1,17 @@ +using GerstITS.Examples.WebClients.Examples.Api.Configurations; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.WebClients.Examples.Api +{ + public sealed partial class Module + { + #region Methods + + private static void RegisterConfigurations(IServiceCollection container) + { + container.AddSingleton(); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.WebClients.Example.Api/Module.CreationRules.cs b/GerstITS.WebClients.Example.Api/Module.CreationRules.cs new file mode 100644 index 0000000..92a0042 --- /dev/null +++ b/GerstITS.WebClients.Example.Api/Module.CreationRules.cs @@ -0,0 +1,18 @@ +using GerstITS.Examples.WebClients.Examples.Api.CreationRules; +using GerstITS.Web.WebClients; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.WebClients.Examples.Api +{ + public sealed partial class Module + { + #region Methods + + private static void RegisterCreationRules(IServiceCollection container) + { + container.AddTransient(); + } + + #endregion + } +} \ No newline at end of file diff --git a/GerstITS.WebClients.Example.Api/Module.cs b/GerstITS.WebClients.Example.Api/Module.cs new file mode 100644 index 0000000..afb5a61 --- /dev/null +++ b/GerstITS.WebClients.Example.Api/Module.cs @@ -0,0 +1,18 @@ +using GerstITS.IoC; +using Microsoft.Extensions.DependencyInjection; + +namespace GerstITS.Examples.WebClients.Examples.Api +{ + public sealed partial class Module : IIoCModule + { + #region IIoCModule + + public void RegisterComponents(IServiceCollection container) + { + RegisterConfigurations(container); + RegisterCreationRules(container); + } + + #endregion + } +} \ No newline at end of file diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..09ba228 --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29