diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b82c9a7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "cSpell.words": [ + "cref", + "registrator" + ] +} \ No newline at end of file diff --git a/src/Simplify.Web.Multipart/CHANGELOG.md b/src/Simplify.Web.Multipart/CHANGELOG.md index 230ea52..4678ac3 100644 --- a/src/Simplify.Web.Multipart/CHANGELOG.md +++ b/src/Simplify.Web.Multipart/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [1.4.5] - 2022-05-18 + +### Added + +- Explicit .NET 6 targeting + +### Dependencies + +- Simplify.Web bump to 4.6 (PR#36) + ## [1.4.4] - 2022-03-13 ### Dependencies diff --git a/src/Simplify.Web.Multipart/Model/Binding/HttpMultipartFormModelBinder.cs b/src/Simplify.Web.Multipart/Model/Binding/HttpMultipartFormModelBinder.cs index 90a9ad5..9866604 100644 --- a/src/Simplify.Web.Multipart/Model/Binding/HttpMultipartFormModelBinder.cs +++ b/src/Simplify.Web.Multipart/Model/Binding/HttpMultipartFormModelBinder.cs @@ -3,38 +3,37 @@ using HttpMultipartParser; using Simplify.Web.Model.Binding; -namespace Simplify.Web.Multipart.Model.Binding +namespace Simplify.Web.Multipart.Model.Binding; + +/// +/// Provides form multipart data to object binding +/// +/// +public class HttpMultipartFormModelBinder : IModelBinder { /// - /// Provides form multipart data to object binding + /// Binds the model. /// - /// - public class HttpMultipartFormModelBinder : IModelBinder + /// Model type + /// The instance containing the event data. + public async Task BindAsync(ModelBinderEventArgs args) { - /// - /// Binds the model. - /// - /// Model type - /// The instance containing the event data. - public async Task BindAsync(ModelBinderEventArgs args) - { - if (!args.Context.Request.ContentType.Contains("multipart/form-data")) - return; + if (!args.Context.Request.ContentType.Contains("multipart/form-data")) + return; - var multipartModelType = typeof(MultipartViewModel); + var multipartModelType = typeof(MultipartViewModel); - if (typeof(T) != multipartModelType) - throw new ModelBindingException("For HTTP multipart form data model type should be: " + multipartModelType.Name); + if (typeof(T) != multipartModelType) + throw new ModelBindingException("For HTTP multipart form data model type should be: " + multipartModelType.Name); - var parser = await MultipartFormDataParser.ParseAsync(args.Context.Request.Body); - var obj = Activator.CreateInstance(); + var parser = await MultipartFormDataParser.ParseAsync(args.Context.Request.Body); + var obj = Activator.CreateInstance(); - var model = (MultipartViewModel)(object)obj; + var model = (MultipartViewModel)(object)obj; - model.Files = parser.Files; - model.Parameters = parser.Parameters; + model.Files = parser.Files; + model.Parameters = parser.Parameters; - args.SetModel(obj); - } + args.SetModel(obj); } } \ No newline at end of file diff --git a/src/Simplify.Web.Multipart/Model/MultipartViewModel.cs b/src/Simplify.Web.Multipart/Model/MultipartViewModel.cs index 072581f..84f2943 100644 --- a/src/Simplify.Web.Multipart/Model/MultipartViewModel.cs +++ b/src/Simplify.Web.Multipart/Model/MultipartViewModel.cs @@ -1,27 +1,26 @@ using System.Collections.Generic; using HttpMultipartParser; -namespace Simplify.Web.Multipart.Model +namespace Simplify.Web.Multipart.Model; + +/// +/// HTTP multipart form data model +/// +public class MultipartViewModel { /// - /// HTTP multipart form data model + /// HTTP multipart form data files /// - public class MultipartViewModel - { - /// - /// HTTP multipart form data files - /// - /// - /// The files. - /// - public IReadOnlyList Files { get; set; } + /// + /// The files. + /// + public IReadOnlyList Files { get; set; } - /// - /// HTTP multipart form data parameters - /// - /// - /// The parameters. - /// - public IReadOnlyList Parameters { get; set; } - } + /// + /// HTTP multipart form data parameters + /// + /// + /// The parameters. + /// + public IReadOnlyList Parameters { get; set; } } \ No newline at end of file diff --git a/src/Simplify.Web.Multipart/Simplify.Web.Multipart.csproj b/src/Simplify.Web.Multipart/Simplify.Web.Multipart.csproj index 77563e4..26e7988 100644 --- a/src/Simplify.Web.Multipart/Simplify.Web.Multipart.csproj +++ b/src/Simplify.Web.Multipart/Simplify.Web.Multipart.csproj @@ -1,14 +1,13 @@  - net5.0;netstandard2.0 - 9.0 - bin\Any CPU\$(Configuration)\ + net6.0;net5.0;netstandard2.0 + latest true true snupkg true - 1.4.4 + 1.4.5 Alexander Krylkov Simplify diff --git a/src/Simplify.Web.Multipart/SimplifyDIRegistratorExtensions.cs b/src/Simplify.Web.Multipart/SimplifyDIRegistratorExtensions.cs index 948a469..1e74927 100644 --- a/src/Simplify.Web.Multipart/SimplifyDIRegistratorExtensions.cs +++ b/src/Simplify.Web.Multipart/SimplifyDIRegistratorExtensions.cs @@ -1,18 +1,17 @@ using Simplify.DI; using Simplify.Web.Multipart.Model.Binding; -namespace Simplify.Web.Multipart +namespace Simplify.Web.Multipart; + +/// +/// Provides Simplify.Web.Json default registration +/// +public static class SimplifyDIRegistratorExtensions { /// - /// Provides Simplify.Web.Json default registration + /// Registers Simplify.Web.Json JsonModelBinder. /// - public static class SimplifyDIRegistratorExtensions - { - /// - /// Registers Simplify.Web.Json JsonModelBinder. - /// - /// The registrator. - public static IDIRegistrator RegisterHttpMultipartFormModelBinder(this IDIRegistrator registrator) => - registrator.Register(LifetimeType.Singleton); - } + /// The registrator. + public static IDIRegistrator RegisterHttpMultipartFormModelBinder(this IDIRegistrator registrator) => + registrator.Register(LifetimeType.Singleton); } \ No newline at end of file diff --git a/src/TestClient/Program.cs b/src/TestClient/Program.cs index 8402b25..aef9945 100644 --- a/src/TestClient/Program.cs +++ b/src/TestClient/Program.cs @@ -2,28 +2,19 @@ using System.Text; using RestSharp; -namespace TestClient -{ - internal class Program - { - private static void Main() - { - var client = new RestClient("http://localhost:5000/"); +var client = new RestClient("http://localhost:5000/"); - var request = new RestRequest("api/v1/testIn", Method.Post) - { - AlwaysMultipartFormData = true - }; +var request = new RestRequest("api/v1/testIn", Method.Post) +{ + AlwaysMultipartFormData = true +}; - request.AddFile("test file", Encoding.UTF8.GetBytes("Hello World!!!"), "MyFile.txt", "text/plain"); +request.AddFile("test file", Encoding.UTF8.GetBytes("Hello World!!!"), "MyFile.txt", "text/plain"); - var result = client.ExecuteAsync(request).Result; +var result = client.ExecuteAsync(request).Result; - if (result.IsSuccessful != true) - throw new InvalidOperationException("Error sending file: " + result.Content); +if (result.IsSuccessful != true) + throw new InvalidOperationException("Error sending file: " + result.Content); - Console.WriteLine("HTTP status: " + result.StatusCode); - Console.ReadLine(); - } - } -} \ No newline at end of file +Console.WriteLine("HTTP status: " + result.StatusCode); +Console.ReadLine(); diff --git a/src/TestServer/Controllers/Api/v1/TestInController.cs b/src/TestServer/Controllers/Api/v1/TestInController.cs index 641a0a7..3b01e78 100644 --- a/src/TestServer/Controllers/Api/v1/TestInController.cs +++ b/src/TestServer/Controllers/Api/v1/TestInController.cs @@ -7,33 +7,32 @@ using Simplify.Web.Attributes; using Simplify.Web.Multipart.Model; -namespace TestServer.Controllers.Api.v1 +namespace TestServer.Controllers.Api.v1; + +[Post("/api/v1/testIn")] +public class TestInController : AsyncController { - [Post("/api/v1/testIn")] - public class TestInController : AsyncController + public override async Task Invoke() { - public override async Task Invoke() - { - var file = Model.Files.FirstOrDefault() ?? throw new ArgumentException("No files in model"); - using var stream = new StreamReader(file.Data); - var fileData = await stream.ReadToEndAsync(); + var file = Model.Files.FirstOrDefault() ?? throw new ArgumentException("No files in model"); + using var stream = new StreamReader(file.Data); + var fileData = await stream.ReadToEndAsync(); - Trace.WriteLine($"Files count: '{Model.Files.Count}'"); - Trace.WriteLine($"File name: '{file.FileName}'"); - Trace.WriteLine($"File content: '{fileData}'"); + Trace.WriteLine($"Files count: '{Model.Files.Count}'"); + Trace.WriteLine($"File name: '{file.FileName}'"); + Trace.WriteLine($"File content: '{fileData}'"); - // Assert + // Assert - if (file.Name != "test file") - return Content($"Wrong name, actual: '{file.Name}'", 500); + if (file.Name != "test file") + return Content($"Wrong name, actual: '{file.Name}'", 500); - if (file.FileName != "MyFile.txt") - return Content($"Wrong file name, actual: '{file.FileName}'", 500); + if (file.FileName != "MyFile.txt") + return Content($"Wrong file name, actual: '{file.FileName}'", 500); - if (fileData != "Hello World!!!") - return Content($"Wrong file data, actual: '{fileData}'", 500); + if (fileData != "Hello World!!!") + return Content($"Wrong file data, actual: '{fileData}'", 500); - return NoContent(); - } + return NoContent(); } } \ No newline at end of file diff --git a/src/TestServer/Controllers/StatusController.cs b/src/TestServer/Controllers/StatusController.cs index 1f02200..63bdddc 100644 --- a/src/TestServer/Controllers/StatusController.cs +++ b/src/TestServer/Controllers/StatusController.cs @@ -1,14 +1,10 @@ using Simplify.Web; using Simplify.Web.Attributes; -namespace TestServer.Controllers +namespace TestServer.Controllers; + +[Get("status")] +public class StatusController : Controller { - [Get("status")] - public class StatusController : Controller - { - public override ControllerResponse Invoke() - { - return Content("Service is running!"); - } - } + public override ControllerResponse Invoke() => Content("Service is running!"); } \ No newline at end of file diff --git a/src/TestServer/Program.cs b/src/TestServer/Program.cs index a0a0ebe..cbfdeb5 100644 --- a/src/TestServer/Program.cs +++ b/src/TestServer/Program.cs @@ -1,14 +1,13 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -namespace TestServer +namespace TestServer; + +public class Program { - public class Program - { - public static void Main(string[] args) => CreateWebHostBuilder(args).Build().Run(); + public static void Main(string[] args) => CreateWebHostBuilder(args).Build().Run(); - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); - } + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); } \ No newline at end of file diff --git a/src/TestServer/Setup/IocRegistrations.cs b/src/TestServer/Setup/IocRegistrations.cs index 61544e2..5f51481 100644 --- a/src/TestServer/Setup/IocRegistrations.cs +++ b/src/TestServer/Setup/IocRegistrations.cs @@ -1,13 +1,9 @@ using Simplify.DI; using Simplify.Web.Multipart; -namespace TestServer.Setup +namespace TestServer.Setup; + +public static class IocRegistrations { - public static class IocRegistrations - { - public static void Register() - { - DIContainer.Current.RegisterHttpMultipartFormModelBinder(); - } - } + public static void Register() => DIContainer.Current.RegisterHttpMultipartFormModelBinder(); } \ No newline at end of file diff --git a/src/TestServer/Startup.cs b/src/TestServer/Startup.cs index 8232f03..cd7e4e8 100644 --- a/src/TestServer/Startup.cs +++ b/src/TestServer/Startup.cs @@ -7,22 +7,21 @@ using Simplify.Web.Multipart.Model.Binding; using TestServer.Setup; -namespace TestServer +namespace TestServer; + +public class Startup { - public class Startup + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - IocRegistrations.Register(); + IocRegistrations.Register(); - if (env.IsDevelopment()) - app.UseDeveloperExceptionPage(); + if (env.IsDevelopment()) + app.UseDeveloperExceptionPage(); - HttpModelHandler.RegisterModelBinder(); + HttpModelHandler.RegisterModelBinder(); - app.UseSimplifyWeb(); + app.UseSimplifyWeb(); - DIContainer.Current.Verify(); - } + DIContainer.Current.Verify(); } } \ No newline at end of file