Skip to content

Commit

Permalink
Net 7 (#71)
Browse files Browse the repository at this point in the history
* Update workflows

* Update .Net

* Update LangVersion

* Add PayPal.props

* Fix warnings
  • Loading branch information
trejjam committed Dec 12, 2022
1 parent 263b490 commit aa2effb
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 72 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
5.0.x
6.0.x
7.0.x
- uses: actions/checkout@v3
- name: Retore
run: dotnet restore --nologo
Expand All @@ -38,9 +38,9 @@ jobs:
DOTNET_CLI_TELEMETRY_OPTOUT: 'true'
steps:
- uses: actions/checkout@v3
- name: Setup .Net 6.0.x
- name: Setup .Net 7.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
dotnet-version: '7.0.x'
- name: .Net Format
run: dotnet format --no-restore --verify-no-changes -v diag
2 changes: 1 addition & 1 deletion .github/workflows/nightly-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
5.0.x
6.0.x
7.0.x
- uses: actions/checkout@v3
- name: Fetch all history for all tags and branches
run: git fetch --prune --unshallow
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
5.0.x
6.0.200
6.0.x
7.0.x
- uses: actions/checkout@v3
- name: Retore
run: dotnet restore --nologo
Expand All @@ -31,9 +31,9 @@ jobs:
DOTNET_CLI_TELEMETRY_OPTOUT: 'true'
steps:
- uses: actions/checkout@v3
- name: Setup .Net 6.0.x
- name: Setup .Net 7.0.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.200'
dotnet-version: '7.0.x'
- name: .Net Format
run: dotnet format --no-restore --verify-no-changes -v diag
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
5.0.x
6.0.x
7.0.x
- uses: actions/checkout@v3
- name: Fetch all history for all tags and branches
run: git fetch --prune --unshallow
Expand Down
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'PayPal.Sdk.Checkout.sln'))\props\PayPal.props" />
</Project>
1 change: 1 addition & 0 deletions PayPal.Sdk.Checkout.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.MD = README.MD
.config\dotnet-tools.json = .config\dotnet-tools.json
GitVersion.yml = GitVersion.yml
props\PayPal.props = props\PayPal.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GithubWorkflows", "GithubWorkflows", "{7DF6DE1B-F6ED-4AC7-8D75-1A95E6EF3390}"
Expand Down
5 changes: 5 additions & 0 deletions props/PayPal.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<IsPackable>false</IsPackable>
Expand All @@ -13,15 +13,6 @@
<ProjectReference Include="..\..\src\PayPal.Sdk.Checkout\PayPal.Sdk.Checkout.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
Expand All @@ -30,6 +21,15 @@
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.json5" CopyToPublishDirectory="Always" CopyToOutputDirectory="Always" />
<Content Update="*.appsettings.json5" CopyToPublishDirectory="Always" CopyToOutputDirectory="Always" />
Expand Down
18 changes: 9 additions & 9 deletions src/PayPal.Sdk.Checkout/PayPal.Sdk.Checkout.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<VersionPrefix>1.0.0</VersionPrefix>
<Owners>PayPal</Owners>
Expand All @@ -24,17 +24,17 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ public Action<HttpMessageHandlerBuilder> Configure(Action<HttpMessageHandlerBuil
next(builder);
var name = builder.Name;
var i = name.IndexOf(',');
if (i > 0)
if (name?.IndexOf(',') is { } commaAt and > 0)
{
name = name.Substring(0, name.IndexOf(','));
name = name[..commaAt];
}
var scopeLogger = _loggerFactory.CreateLogger($"System.Net.Http.HttpClient.{name}.RequestScope");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage

using var log = Log.BeginRequestPipelineScope(_scopeLogger, request);

await log.RequestPipelineStart(_requestLogger, request);
await log.RequestPipelineStart(_requestLogger, request, cancellationToken);
var response = await base.SendAsync(request, cancellationToken);
await log.RequestPipelineEnd(_requestLogger, response);
await log.RequestPipelineEnd(_requestLogger, response, cancellationToken);

return response;
}
Expand All @@ -49,32 +49,34 @@ private static class EventIds
public static readonly EventId PipelineEnd = new(101, "RequestPipelineEnd");
}

private static readonly Func<ILogger, HttpMethod, Uri?, string, IDisposable> BeginRequestPipelineScopeDefine = LoggerMessage.DefineScope<HttpMethod, Uri?, string>(
private static readonly Func<ILogger, HttpMethod, Uri?, string, IDisposable?> BeginRequestPipelineScopeDefine = LoggerMessage.DefineScope<HttpMethod, Uri?, string>(
"HTTP {HttpMethod} {Uri} {CorrelationId}"
);

private static readonly Action<ILogger, HttpMethod, Uri?, string, string?, Exception?> RequestPipelineStartDefine = LoggerMessage.Define<HttpMethod, Uri?, string, string?>(
LogLevel.Trace,
EventIds.PipelineStart,
"Start processing HTTP request {HttpMethod} {Uri} [Correlation: {CorrelationId}]: {HttpContent}"
"Start processing HTTP request {HttpMethod} {Uri} [Correlation: {CorrelationId}]: {HttpContent}",
options: new LogDefineOptions { SkipEnabledCheck = true }
);

private static readonly Action<ILogger, HttpStatusCode, string?, Exception?> RequestPipelineEndDefine = LoggerMessage.Define<HttpStatusCode, string?>(
LogLevel.Trace,
EventIds.PipelineEnd,
"End processing HTTP request - {StatusCode}: {HttpContent}"
"End processing HTTP request - {StatusCode}: {HttpContent}",
options: new LogDefineOptions { SkipEnabledCheck = true }
);

private readonly IDisposable _loggerScope;
private readonly IDisposable? _loggerScope;

private Log(IDisposable loggerScope)
private Log(IDisposable? loggerScope)
{
_loggerScope = loggerScope;
}

public void Dispose()
{
_loggerScope.Dispose();
_loggerScope?.Dispose();
}

public static Log BeginRequestPipelineScope(ILogger logger, HttpRequestMessage request)
Expand All @@ -86,23 +88,29 @@ public static Log BeginRequestPipelineScope(ILogger logger, HttpRequestMessage r
return log;
}

public async Task RequestPipelineStart(ILogger logger, HttpRequestMessage request)
public async Task RequestPipelineStart(ILogger logger, HttpRequestMessage request, CancellationToken cancellationToken)
{
var correlationId = GetCorrelationIdFromRequest(request);
string? content = null;
if (request.Content != null)
if (logger.IsEnabled(LogLevel.Trace))
{
content = await GetContent(request.Content);
}
var correlationId = GetCorrelationIdFromRequest(request);
string? content = null;
if (request.Content != null)
{
content = await GetContent(request.Content, cancellationToken);
}

RequestPipelineStartDefine(logger, request.Method, request.RequestUri, correlationId, content, null);
RequestPipelineStartDefine(logger, request.Method, request.RequestUri, correlationId, content, null);
}
}

public async Task RequestPipelineEnd(ILogger logger, HttpResponseMessage response)
public async Task RequestPipelineEnd(ILogger logger, HttpResponseMessage response, CancellationToken cancellationToken)
{
var content = await GetContent(response.Content);
if (logger.IsEnabled(LogLevel.Trace))
{
var content = await GetContent(response.Content, cancellationToken);

RequestPipelineEndDefine(logger, response.StatusCode, content, null);
RequestPipelineEndDefine(logger, response.StatusCode, content, null);
}
}

private static string GetCorrelationIdFromRequest(HttpRequestMessage request)
Expand All @@ -117,11 +125,12 @@ private static string GetCorrelationIdFromRequest(HttpRequestMessage request)
return correlationId;
}

private async Task<string> GetContent(HttpContent httpContent)
private async Task<string> GetContent(HttpContent httpContent, CancellationToken cancellationToken)
{
if (httpContent.Headers.ContentEncoding.Contains("gzip"))
{
var stream = await httpContent.ReadAsStreamAsync();
await httpContent.LoadIntoBufferAsync();
var stream = await httpContent.ReadAsStreamAsync(cancellationToken);
if (!stream.CanSeek)
{
return "<Stream content unknown - can not seek>";
Expand All @@ -134,7 +143,11 @@ private async Task<string> GetContent(HttpContent httpContent)
using var reader = new StreamReader(
compressionStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: false, bufferSize: -1, leaveOpen: true
);
var content = await reader.ReadToEndAsync();
var content = await reader.ReadToEndAsync(
#if NET7_0_OR_GREATER
cancellationToken
#endif
);

stream.Seek(0, SeekOrigin.Begin);

Expand All @@ -150,7 +163,7 @@ private async Task<string> GetContent(HttpContent httpContent)
sb.Append(contentDisposition);
sb.Append('\t');

var content = await GetContent(innerContent);
var content = await GetContent(innerContent, cancellationToken);

if (!string.IsNullOrEmpty(contentDisposition?.FileName))
{
Expand All @@ -165,7 +178,8 @@ private async Task<string> GetContent(HttpContent httpContent)

if (httpContent is StreamContent streamHttpContent)
{
var streamContent = await streamHttpContent.ReadAsStreamAsync();
await httpContent.LoadIntoBufferAsync();
var streamContent = await streamHttpContent.ReadAsStreamAsync(cancellationToken);

if (streamContent.CanSeek)
{
Expand All @@ -174,15 +188,19 @@ private async Task<string> GetContent(HttpContent httpContent)
using var reader = new StreamReader(
streamContent, Encoding.UTF8, detectEncodingFromByteOrderMarks: false, bufferSize: -1, leaveOpen: true
);
var stringContent = await reader.ReadToEndAsync();
var stringContent = await reader.ReadToEndAsync(
#if NET7_0_OR_GREATER
cancellationToken
#endif
);

streamContent.Seek(0, SeekOrigin.Begin);

return stringContent;
}
}

return await httpContent.ReadAsStringAsync();
return await httpContent.ReadAsStringAsync(cancellationToken);
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions tests/PayPal.Sdk.Checkout.Test/PayPal.Sdk.Checkout.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<VersionPrefix>1.0.0</VersionPrefix>
Expand All @@ -19,19 +19,6 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
Expand All @@ -44,6 +31,19 @@
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.json5" CopyToPublishDirectory="Always" CopyToOutputDirectory="Always" />
<Content Update="*.appsettings.json5" CopyToPublishDirectory="Always" CopyToOutputDirectory="Always" />
Expand Down

0 comments on commit aa2effb

Please sign in to comment.