Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lambda/MAS.Tests/MAS.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<EnableDefaultContentItems>False</EnableDefaultContentItems>
<UserSecretsId>adafe3d8-65fb-49fd-885e-03341a36dc88</UserSecretsId>
</PropertyGroup>
Expand Down Expand Up @@ -66,7 +66,7 @@
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.3.100.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Shouldly" Version="3.0.2" />
Expand Down
5 changes: 3 additions & 2 deletions lambda/MAS.Tests/UnitTests/Services/ViewRendererTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.AspNetCore.Mvc.Rendering;
using System.Collections.Generic;
using System;
using Microsoft.Extensions.Hosting;

namespace MAS.Tests.UnitTests
{
Expand All @@ -39,7 +40,7 @@ public async Task RendersViewToString()
mockController.Object.TempData = Mock.Of<ITempDataDictionary>();

//Act
var viewRenderer = new ViewRenderer(Mock.Of<ILogger<ViewRenderer>>(), mockViewEngine.Object, Mock.Of<IHostingEnvironment>());
var viewRenderer = new ViewRenderer(Mock.Of<ILogger<ViewRenderer>>(), mockViewEngine.Object, Mock.Of<IHostEnvironment>());
var result = await viewRenderer.RenderViewAsync(mockController.Object, "~/AMockedView.cshtml", Mock.Of<Item>(), false);

//Assert
Expand All @@ -63,7 +64,7 @@ public async Task FailingToFindViewThrowsException()
mockController.Object.TempData = Mock.Of<ITempDataDictionary>();

//Act + Assert
var viewRenderer = new ViewRenderer(Mock.Of<ILogger<ViewRenderer>>(), mockViewEngine.Object, Mock.Of<IHostingEnvironment>());
var viewRenderer = new ViewRenderer(Mock.Of<ILogger<ViewRenderer>>(), mockViewEngine.Object, Mock.Of<IHostEnvironment>());
await Should.ThrowAsync<Exception>(() => viewRenderer.RenderViewAsync(mockController.Object, "~/AMockedView.cshtml", Mock.Of<Item>(), false));
}
}
Expand Down
6 changes: 0 additions & 6 deletions lambda/MAS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.29025.244
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MAS", "MAS\MAS.csproj", "{03318747-CBA5-46D5-9B39-C08B169612E3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MAS.Tests", "MAS.Tests\MAS.Tests.csproj", "{75974ECB-FA2B-4C8F-9F88-24BA1D636048}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,10 +15,6 @@ Global
{03318747-CBA5-46D5-9B39-C08B169612E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03318747-CBA5-46D5-9B39-C08B169612E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03318747-CBA5-46D5-9B39-C08B169612E3}.Release|Any CPU.Build.0 = Release|Any CPU
{75974ECB-FA2B-4C8F-9F88-24BA1D636048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75974ECB-FA2B-4C8F-9F88-24BA1D636048}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75974ECB-FA2B-4C8F-9F88-24BA1D636048}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75974ECB-FA2B-4C8F-9F88-24BA1D636048}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 10 additions & 6 deletions lambda/MAS/LambdaEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using System.IO;
using Amazon.Lambda.APIGatewayEvents;
using Amazon.Lambda.AspNetCoreServer.Internal;
using Amazon.Lambda.Core;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using static Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest;
using Microsoft.AspNetCore.Hosting;

namespace MAS
{
Expand All @@ -30,22 +31,25 @@ public class LambdaEntryPoint :

private ILogger<LambdaEntryPoint> _logger;

protected override void PostCreateWebHost(IWebHost webHost)
protected override void PostCreateHost(IHost webHost)
{
_logger = webHost.Services.GetRequiredService<ILogger<LambdaEntryPoint>>();

base.PostCreateWebHost(webHost);
base.PostCreateHost(webHost);
}

/// <summary>
/// The builder has configuration, logging and Amazon API Gateway already configured. The startup class
/// needs to be configured in this method using the UseStartup<>() method.
/// </summary>
/// <param name="builder"></param>
protected override void Init(IWebHostBuilder builder)
protected override void Init(IHostBuilder builder)
{
builder
.UseStartup<Startup>();
builder.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
.UseStartup<Startup>();
});
}

public override Task<APIGatewayProxyResponse> FunctionHandlerAsync(APIGatewayProxyRequest request, ILambdaContext lambdaContext)
Expand Down
34 changes: 30 additions & 4 deletions lambda/MAS/MAS.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<RuntimeIdentifiers>linux-x64;win7-x64</RuntimeIdentifiers>
<AWSProjectType>Lambda</AWSProjectType>
<UserSecretsId>adafe3d8-65fb-49fd-885e-03341a36dc88</UserSecretsId>
</PropertyGroup>
Expand All @@ -15,13 +16,12 @@
<PackageReference Include="AWSSDK.CloudFront" Version="3.3.101.95" />
<PackageReference Include="MailChimp.Net.V3" Version="4.2.1" />
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="AWSSDK.S3" Version="3.3.102.15" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.3.100.1" />
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="3.1.0" />
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.10" />
<PackageReference Include="Nager.Date" Version="1.25.9" />
<PackageReference Include="NICE.Logging" Version="6.0.22" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
</ItemGroup>
<ItemGroup>
Expand All @@ -32,4 +32,30 @@
<ItemGroup>
<Folder Include="Views\Shared\" />
</ItemGroup>
<ItemGroup>
<Reference Include="NICE.Logging">
<HintPath>nice.logging\6.0.22\lib\netstandard1.6\NICE.Logging.dll</HintPath>
<Private>true</Private>
</Reference>
<Reference Include="RabbitMQ.Client">
<HintPath>nice.logging.quickfix\rabbitmq.client\4.1.1\lib\netstandard1.5\RabbitMQ.Client.dll</HintPath>
<Private>true</Private>
</Reference>
<Reference Include="Serilog">
<HintPath>nice.logging.quickfix\serilog\2.5.0\lib\netstandard1.3\Serilog.dll</HintPath>
<Private>true</Private>
</Reference>
<Reference Include="Serilog.Extensions.Logging">
<HintPath>nice.logging.quickfix\serilog.extensions.logging\1.2.0\lib\netstandard1.3\Serilog.Extensions.Logging.dll</HintPath>
<Private>true</Private>
</Reference>
<Reference Include="Serilog.Sinks.PeriodicBatching">
<HintPath>nice.logging.quickfix\serilog.sinks.periodicbatching\2.1.0\lib\netstandard1.2\Serilog.Sinks.PeriodicBatching.dll</HintPath>
<Private>true</Private>
</Reference>
<Reference Include="Serilog.Sinks.RollingFile">
<HintPath>nice.logging.quickfix\serilog.sinks.rollingfile\3.2.0\lib\netstandard1.3\Serilog.Sinks.RollingFile.dll</HintPath>
<Private>true</Private>
</Reference>
</ItemGroup>
</Project>
9 changes: 5 additions & 4 deletions lambda/MAS/SeriLogger.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MAS.Configuration;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NICE.Logging;
using NICE.Logging.Sinks.RabbitMQ;
Expand All @@ -12,18 +13,18 @@ namespace MAS.Logging
{
public interface ISeriLogger
{
void Configure(ILoggerFactory loggerFactory, IConfiguration configuration, IApplicationLifetime appLifetime, IHostingEnvironment env, EnvironmentConfig environmentConfig);
void Configure(ILoggerFactory loggerFactory, IConfiguration configuration, Microsoft.Extensions.Hosting.IApplicationLifetime appLifetime, IHostEnvironment env, EnvironmentConfig environmentConfig);
}

public class SeriLogger : ISeriLogger
{
public void Configure(ILoggerFactory loggerFactory, IConfiguration configuration, IApplicationLifetime appLifetime, IHostingEnvironment env, EnvironmentConfig environmentConfig)
public void Configure(ILoggerFactory loggerFactory, IConfiguration configuration, Microsoft.Extensions.Hosting.IApplicationLifetime appLifetime, IHostEnvironment env, EnvironmentConfig environmentConfig)
{
// read appsettings
var logCfg = configuration.GetSection("Logging");

loggerFactory.AddConsole(logCfg); // add provider to send logs to System.Console.WriteLine()
loggerFactory.AddDebug(); // add provider to send logs to System.Diagnostics.Debug.WriteLine()
//loggerFactory.AddConsole(logCfg); // add provider to send logs to System.Console.WriteLine()
//loggerFactory.AddDebug(); // add provider to send logs to System.Diagnostics.Debug.WriteLine()

var rabbitSettingsFound = int.TryParse(logCfg["RabbitMQPort"], out var rPort);
bool.TryParse(logCfg["UseRabbit"], out var useRabbit);
Expand Down
7 changes: 4 additions & 3 deletions lambda/MAS/Services/ViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
Expand All @@ -21,9 +22,9 @@ public class ViewRenderer : IViewRenderer

private readonly ILogger<ViewRenderer> _logger;
private readonly ICompositeViewEngine _compositeViewEngine;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IHostEnvironment _hostingEnvironment;

public ViewRenderer(ILogger<ViewRenderer> logger, ICompositeViewEngine compositeViewEngine, IHostingEnvironment hostingEnvironment)
public ViewRenderer(ILogger<ViewRenderer> logger, ICompositeViewEngine compositeViewEngine, IHostEnvironment hostingEnvironment)
{
_logger = logger;
_compositeViewEngine = compositeViewEngine;
Expand All @@ -41,7 +42,7 @@ public async Task<string> RenderViewAsync<TModel>(Controller controller, string

using (var writer = new StringWriter())
{
var viewResult = _compositeViewEngine.GetView(_hostingEnvironment.WebRootPath, viewName, !isPartial);
var viewResult = _compositeViewEngine.GetView(_hostingEnvironment.ContentRootPath, viewName, !isPartial);

if (viewResult.Success == false)
{
Expand Down
27 changes: 18 additions & 9 deletions lambda/MAS/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using IHostingEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;

namespace MAS
{
public class Startup
{
public static readonly RegionEndpoint Region = RegionEndpoint.EUWest1;
public static IConfiguration Configuration { get; private set; }
public IHostingEnvironment Environment { get; }
public IHostEnvironment Environment { get; }

public Startup(IConfiguration configuration, IHostingEnvironment env)
public Startup(IConfiguration configuration, IHostEnvironment env)
{
Configuration = configuration;
Environment = env;
Expand Down Expand Up @@ -91,32 +93,39 @@ public void ConfigureServices(IServiceCollection services)
return new AmazonCloudFrontClient(awsConfig.AccessKey, awsConfig.SecretKey, cloudfrontConfig);
});

services.AddControllers();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
IHostEnvironment env,
ILoggerFactory loggerFactory,
ISeriLogger seriLogger,
IApplicationLifetime appLifetime,
//ISeriLogger seriLogger,
IHostApplicationLifetime appLifetime,
EnvironmentConfig environmentConfig)
{
seriLogger.Configure(loggerFactory, Configuration, appLifetime, env, environmentConfig);
//seriLogger.Configure(loggerFactory, Configuration, appLifetime, env, environmentConfig);
loggerFactory.CreateLogger<Startup>();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
//loggerFactory.AddConsole(Configuration.GetSection("Logging"));
//loggerFactory.AddDebug();
}
else
{
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseMvc();

app.UseRouting();
app.UseEndpoints(endpoints => {
endpoints.MapControllers();
});


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": 2,
"contentHash": "IIsw1u7GXvZ5kVPILD8JhLlXvjUuqbjKu1xM4NEW6lvQlBjQYrbe97Ar5eyyosMyWlBse7a9u4bQCUj6qMQhZQ==",
"source": "https://teamcity.nice.org.uk/httpAuth/app/nuget/feed/_Root/default/v2"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IIsw1u7GXvZ5kVPILD8JhLlXvjUuqbjKu1xM4NEW6lvQlBjQYrbe97Ar5eyyosMyWlBse7a9u4bQCUj6qMQhZQ==
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>NICE.Logging</id>
<version>6.0.22</version>
<authors>NICE.Logging</authors>
<owners>NICE.Logging</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package Description</description>
<dependencies>
<group targetFramework=".NETStandard1.6">
<dependency id="NETStandard.Library" version="1.6.1" exclude="Build,Analyzers" />
<dependency id="RabbitMQ.Client" version="4.1.1" exclude="Build,Analyzers" />
<dependency id="Serilog" version="2.3.0" exclude="Build,Analyzers" />
<dependency id="Serilog.Extensions.Logging" version="1.2.0" exclude="Build,Analyzers" />
<dependency id="Serilog.Sinks.PeriodicBatching" version="2.1.0" exclude="Build,Analyzers" />
<dependency id="Serilog.Sinks.RollingFile" version="3.2.0" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": 2,
"contentHash": "KrIEo53c7/WGez9cdA38VOg7dbvBY0RacVqE8eoz/WXtBtpfeNO7tolND+H5J3JbVrFujhkQf4I5cq5ACeBpTg==",
"source": "https://api.nuget.org/v3/index.json"
}
Binary file not shown.
Binary file not shown.
Loading