@ -1,79 +1,77 @@ | |||||
using Microsoft.AspNetCore; | using Microsoft.AspNetCore; | ||||
using Microsoft.AspNetCore.Hosting; | using Microsoft.AspNetCore.Hosting; | ||||
using Microsoft.eShopOnContainers.WebMVC; | |||||
using Microsoft.Extensions.Configuration; | using Microsoft.Extensions.Configuration; | ||||
using Microsoft.Extensions.Logging; | using Microsoft.Extensions.Logging; | ||||
using Serilog; | using Serilog; | ||||
using System; | using System; | ||||
using System.IO; | 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 | 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 | 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.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>(); |