Feature/webapps net5 migrationpull/1566/head
@ -1,76 +0,0 @@ | |||
using Grpc.Core; | |||
using Grpc.Net.Client; | |||
using Serilog; | |||
using System; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services | |||
{ | |||
public static class GrpcCallerService | |||
{ | |||
public static async Task<TResponse> CallService<TResponse>(string urlGrpc, Func<GrpcChannel, Task<TResponse>> func) | |||
{ | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); | |||
var channel = GrpcChannel.ForAddress(urlGrpc); | |||
/* | |||
using var httpClientHandler = new HttpClientHandler | |||
{ | |||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; } | |||
}; | |||
*/ | |||
Log.Information("Creating grpc client base address urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress} ", urlGrpc, channel.Target); | |||
try | |||
{ | |||
return await func(channel); | |||
} | |||
catch (RpcException e) | |||
{ | |||
Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); | |||
return default; | |||
} | |||
finally | |||
{ | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false); | |||
} | |||
} | |||
public static async Task CallService(string urlGrpc, Func<GrpcChannel, Task> func) | |||
{ | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); | |||
/* | |||
using var httpClientHandler = new HttpClientHandler | |||
{ | |||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; } | |||
}; | |||
*/ | |||
var channel = GrpcChannel.ForAddress(urlGrpc); | |||
Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", channel.Target); | |||
try | |||
{ | |||
await func(channel); | |||
} | |||
catch (RpcException e) | |||
{ | |||
Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); | |||
} | |||
finally | |||
{ | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false); | |||
} | |||
} | |||
} | |||
} |
@ -1,78 +0,0 @@ | |||
using Grpc.Core; | |||
using Grpc.Net.Client; | |||
using Serilog; | |||
using System; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services | |||
{ | |||
public static class GrpcCallerService | |||
{ | |||
public static async Task<TResponse> CallService<TResponse>(string urlGrpc, Func<GrpcChannel, Task<TResponse>> func) | |||
{ | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); | |||
var channel = GrpcChannel.ForAddress(urlGrpc); | |||
/* | |||
using var httpClientHandler = new HttpClientHandler | |||
{ | |||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; } | |||
}; | |||
*/ | |||
Log.Information("Creating grpc client base address urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress} ", urlGrpc, channel.Target); | |||
try | |||
{ | |||
return await func(channel); | |||
} | |||
catch (RpcException e) | |||
{ | |||
Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); | |||
return default; | |||
} | |||
finally | |||
{ | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false); | |||
} | |||
} | |||
public static async Task CallService(string urlGrpc, Func<GrpcChannel, Task> func) | |||
{ | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); | |||
/* | |||
using var httpClientHandler = new HttpClientHandler | |||
{ | |||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; } | |||
}; | |||
*/ | |||
var channel = GrpcChannel.ForAddress(urlGrpc); | |||
Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", channel.Target); | |||
try | |||
{ | |||
await func(channel); | |||
} | |||
catch (RpcException e) | |||
{ | |||
Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); | |||
} | |||
finally | |||
{ | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false); | |||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false); | |||
} | |||
} | |||
} | |||
} |
@ -1,11 +1,11 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>netstandard2.0</TargetFramework> | |||
<TargetFramework>net5.0</TargetFramework> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" /> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" /> | |||
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" /> | |||
</ItemGroup> | |||
</Project> |
@ -1,22 +1,23 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>netcoreapp3.1</TargetFramework> | |||
<TargetFramework>net5.0</TargetFramework> | |||
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="3.0.0-preview4-19123-01" /> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0"> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.1"> | |||
<PrivateAssets>all</PrivateAssets> | |||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |||
</PackageReference> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.0" /> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" /> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" /> | |||
<PackageReference Include="Microsoft.NETCore.Platforms" Version="3.1.0" /> | |||
<PackageReference Include="Polly" Version="7.2.0" /> | |||
<PackageReference Include="System.Data.SqlClient" Version="4.8.0" /> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.1" /> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.1" /> | |||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.1" /> | |||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" /> | |||
<PackageReference Include="Microsoft.NETCore.Platforms" Version="5.0.0" /> | |||
<PackageReference Include="Polly" Version="7.2.1" /> | |||
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" /> | |||
</ItemGroup> | |||
</Project> |
@ -1,79 +1,77 @@ | |||
using Microsoft.AspNetCore; | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.eShopOnContainers.WebMVC; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.Logging; | |||
using Serilog; | |||
using System; | |||
using System.IO; | |||
namespace Microsoft.eShopOnContainers.WebMVC | |||
{ | |||
public class Program | |||
{ | |||
public static readonly string Namespace = typeof(Program).Namespace; | |||
public static readonly string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1); | |||
var configuration = GetConfiguration(); | |||
public static int Main(string[] args) | |||
{ | |||
var configuration = GetConfiguration(); | |||
Log.Logger = CreateSerilogLogger(configuration); | |||
Log.Logger = CreateSerilogLogger(configuration); | |||
try | |||
{ | |||
Log.Information("Configuring web host ({ApplicationContext})...", Program.AppName); | |||
var host = BuildWebHost(configuration, args); | |||
try | |||
{ | |||
Log.Information("Configuring web host ({ApplicationContext})...", AppName); | |||
var host = BuildWebHost(configuration, args); | |||
Log.Information("Starting web host ({ApplicationContext})...", Program.AppName); | |||
host.Run(); | |||
Log.Information("Starting web host ({ApplicationContext})...", AppName); | |||
host.Run(); | |||
return 0; | |||
} | |||
catch (Exception ex) | |||
{ | |||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", Program.AppName); | |||
return 1; | |||
} | |||
finally | |||
{ | |||
Log.CloseAndFlush(); | |||
} | |||
IWebHost BuildWebHost(IConfiguration configuration, string[] args) => | |||
WebHost.CreateDefaultBuilder(args) | |||
.CaptureStartupErrors(false) | |||
.ConfigureAppConfiguration(x => x.AddConfiguration(configuration)) | |||
.UseStartup<Startup>() | |||
.UseSerilog() | |||
.Build(); | |||
return 0; | |||
} | |||
catch (Exception ex) | |||
{ | |||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", AppName); | |||
return 1; | |||
} | |||
finally | |||
{ | |||
Log.CloseAndFlush(); | |||
} | |||
} | |||
Serilog.ILogger CreateSerilogLogger(IConfiguration configuration) | |||
{ | |||
var seqServerUrl = configuration["Serilog:SeqServerUrl"]; | |||
var logstashUrl = configuration["Serilog:LogstashgUrl"]; | |||
var cfg = new LoggerConfiguration() | |||
.ReadFrom.Configuration(configuration) | |||
.Enrich.WithProperty("ApplicationContext", Program.AppName) | |||
.Enrich.FromLogContext() | |||
.WriteTo.Console(); | |||
if (!string.IsNullOrWhiteSpace(seqServerUrl)) | |||
{ | |||
cfg.WriteTo.Seq(seqServerUrl); | |||
} | |||
if (!string.IsNullOrWhiteSpace(logstashUrl)) | |||
{ | |||
cfg.WriteTo.Http(logstashUrl); | |||
} | |||
return cfg.CreateLogger(); | |||
} | |||
private static IWebHost BuildWebHost(IConfiguration configuration, string[] args) => | |||
WebHost.CreateDefaultBuilder(args) | |||
.CaptureStartupErrors(false) | |||
.ConfigureAppConfiguration(x => x.AddConfiguration(configuration)) | |||
.UseStartup<Startup>() | |||
.UseSerilog() | |||
.Build(); | |||
IConfiguration GetConfiguration() | |||
{ | |||
var builder = new ConfigurationBuilder() | |||
.SetBasePath(Directory.GetCurrentDirectory()) | |||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | |||
.AddEnvironmentVariables(); | |||
private static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration) | |||
{ | |||
var seqServerUrl = configuration["Serilog:SeqServerUrl"]; | |||
var logstashUrl = configuration["Serilog:LogstashgUrl"]; | |||
var cfg = new LoggerConfiguration() | |||
.ReadFrom.Configuration(configuration) | |||
.Enrich.WithProperty("ApplicationContext", AppName) | |||
.Enrich.FromLogContext() | |||
.WriteTo.Console(); | |||
if (!string.IsNullOrWhiteSpace(seqServerUrl)) { | |||
cfg.WriteTo.Seq(seqServerUrl); | |||
} | |||
if (!string.IsNullOrWhiteSpace(logstashUrl)) { | |||
cfg.WriteTo.Http(logstashUrl); | |||
} | |||
return cfg.CreateLogger(); | |||
} | |||
return builder.Build(); | |||
} | |||
private static IConfiguration GetConfiguration() | |||
{ | |||
var builder = new ConfigurationBuilder() | |||
.SetBasePath(Directory.GetCurrentDirectory()) | |||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | |||
.AddEnvironmentVariables(); | |||
return builder.Build(); | |||
} | |||
} | |||
public class Program | |||
{ | |||
private static readonly string _namespace = typeof(Startup).Namespace; | |||
public static readonly string AppName = _namespace.Substring(_namespace.LastIndexOf('.', _namespace.LastIndexOf('.') - 1) + 1); | |||
} |
@ -1,8 +1,8 @@ | |||
namespace WebMVC.Services.ModelDTOs | |||
{ | |||
public class LocationDTO | |||
public record LocationDTO | |||
{ | |||
public double Longitude { get; set; } | |||
public double Latitude { get; set; } | |||
public double Longitude { get; init; } | |||
public double Latitude { get; init; } | |||
} | |||
} |
@ -1,18 +1,13 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
{ | |||
public class BasketItem | |||
public record BasketItem | |||
{ | |||
public string Id { get; set; } | |||
public string ProductId { get; set; } | |||
public string ProductName { get; set; } | |||
public decimal UnitPrice { get; set; } | |||
public decimal OldUnitPrice { get; set; } | |||
public int Quantity { get; set; } | |||
public string PictureUrl { get; set; } | |||
public string Id { get; init; } | |||
public string ProductId { get; init; } | |||
public string ProductName { get; init; } | |||
public decimal UnitPrice { get; init; } | |||
public decimal OldUnitPrice { get; init; } | |||
public int Quantity { get; init; } | |||
public string PictureUrl { get; init; } | |||
} | |||
} |
@ -1,12 +1,12 @@ | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
{ | |||
using System.Collections.Generic; | |||
using System.Collections.Generic; | |||
public class Campaign | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
{ | |||
public record Campaign | |||
{ | |||
public int PageIndex { get; set; } | |||
public int PageSize { get; set; } | |||
public int Count { get; set; } | |||
public List<CampaignItem> Data { get; set; } | |||
public int PageIndex { get; init; } | |||
public int PageSize { get; init; } | |||
public int Count { get; init; } | |||
public List<CampaignItem> Data { get; init; } | |||
} | |||
} |
@ -1,20 +1,20 @@ | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
{ | |||
using System; | |||
using System; | |||
public class CampaignItem | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
{ | |||
public record CampaignItem | |||
{ | |||
public int Id { get; set; } | |||
public int Id { get; init; } | |||
public string Name { get; set; } | |||
public string Name { get; init; } | |||
public string Description { get; set; } | |||
public string Description { get; init; } | |||
public DateTime From { get; set; } | |||
public DateTime From { get; init; } | |||
public DateTime To { get; set; } | |||
public DateTime To { get; init; } | |||
public string PictureUri { get; set; } | |||
public string DetailsUri { get; set; } | |||
public string PictureUri { get; init; } | |||
public string DetailsUri { get; init; } | |||
} | |||
} |
@ -1,15 +1,12 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using System.Collections.Generic; | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
{ | |||
public class Catalog | |||
public record Catalog | |||
{ | |||
public int PageIndex { get; set; } | |||
public int PageSize { get; set; } | |||
public int Count { get; set; } | |||
public List<CatalogItem> Data { get; set; } | |||
public int PageIndex { get; init; } | |||
public int PageSize { get; init; } | |||
public int Count { get; init; } | |||
public List<CatalogItem> Data { get; init; } | |||
} | |||
} |
@ -1,18 +1,15 @@ | |||
using System; | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
{ | |||
public class CatalogItem | |||
public record CatalogItem | |||
{ | |||
public int Id { get; set; } | |||
public string Name { get; set; } | |||
public string Description { get; set; } | |||
public decimal Price { get; set; } | |||
public string PictureUri { get; set; } | |||
public int CatalogBrandId { get; set; } | |||
public string CatalogBrand { get; set; } | |||
public int CatalogTypeId { get; set; } | |||
public string CatalogType { get; set; } | |||
public int Id { get; init; } | |||
public string Name { get; init; } | |||
public string Description { get; init; } | |||
public decimal Price { get; init; } | |||
public string PictureUri { get; init; } | |||
public int CatalogBrandId { get; init; } | |||
public string CatalogBrand { get; init; } | |||
public int CatalogTypeId { get; init; } | |||
public string CatalogType { get; init; } | |||
} | |||
} |
@ -1,10 +1,8 @@ | |||
using System; | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
{ | |||
public class Header | |||
public record Header | |||
{ | |||
public string Controller { get; set; } | |||
public string Text { get; set; } | |||
public string Controller { get; init; } | |||
public string Text { get; init; } | |||
} | |||
} |
@ -1,22 +1,17 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
namespace Microsoft.eShopOnContainers.WebMVC.ViewModels | |||
{ | |||
public class OrderItem | |||
public record OrderItem | |||
{ | |||
public int ProductId { get; set; } | |||
public int ProductId { get; init; } | |||
public string ProductName { get; set; } | |||
public string ProductName { get; init; } | |||
public decimal UnitPrice { get; set; } | |||
public decimal UnitPrice { get; init; } | |||
public decimal Discount { get; set; } | |||
public decimal Discount { get; init; } | |||
public int Units { get; set; } | |||
public int Units { get; init; } | |||
public string PictureUrl { get; set; } | |||
public string PictureUrl { get; init; } | |||
} | |||
} |
@ -1,24 +1,10 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.IO; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.AspNetCore; | |||
using Microsoft.AspNetCore; | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.Extensions.Configuration; | |||
using Microsoft.Extensions.Logging; | |||
using WebhookClient; | |||
namespace WebhookClient | |||
{ | |||
public class Program | |||
{ | |||
public static void Main(string[] args) | |||
{ | |||
CreateWebHostBuilder(args).Build().Run(); | |||
} | |||
CreateWebHostBuilder(args).Build().Run(); | |||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => | |||
WebHost.CreateDefaultBuilder(args) | |||
.UseStartup<Startup>(); | |||
} | |||
} | |||
IWebHostBuilder CreateWebHostBuilder(string[] args) => | |||
WebHost.CreateDefaultBuilder(args) | |||
.UseStartup<Startup>(); |