Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #23 from reisenberger/v201rtm
Browse files Browse the repository at this point in the history
V201rtm
  • Loading branch information
joelhulen authored May 6, 2018
2 parents 2766cea + f6c643a commit 34936cf
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 120 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 2.0.1
- Version 2 RTM, for integration to ASPNET Core 2.1 IHttpClientFactory

## 2.0.0-v2alpha
- Publish as strong-named package only (discontinue non-strong-named versions)
- Add .NetStandard 2.0 target

## 1.0.3
- RTM version

Expand Down
2 changes: 1 addition & 1 deletion GitVersionConfig.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
next-version: 1.0.3
next-version: 2.0.1
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Polly.Extensions.Http is an extensions package containing opinionated convenience methods for configuring [Polly](https://github.com/App-vNext/Polly) policies to handle transient faults typical of calls through HttpClient.

Polly.Extensions.Http targets .NET Standard 1.1.
Polly.Extensions.Http targets .NET Standard 1.1 and .NET Standard 2.0.

[Polly](https://github.com/App-vNext/Polly) is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner.

Expand All @@ -17,11 +17,7 @@ Polly is a member of the [.NET Foundation](https://www.dotnetfoundation.org/abou

Install-Package Polly.Extensions.Http

You can install the Strongly Named version via:

Install-Package Polly.Extensions.Http-Signed

The strongly-named version works with the strongly-named Polly-Signed nuget package.
This package contains a strongly-named DLL.

# Convenience methods for transient faults of HttpClient calls

Expand Down Expand Up @@ -72,9 +68,9 @@ var policy = Policy
.RetryAsync(3);
```

# Using Polly.Extensions.Http with HttpClientFactory
# Using Polly.Extensions.Http with IHttpClientFactory

Polly.Extensions.Http is ideal for creating custom Polly policies for use with HttpClientFactory ([preview1 blog post](https://blogs.msdn.microsoft.com/webdev/2018/02/28/asp-net-core-2-1-preview1-introducing-httpclient-factory/); [preview2 blog post](https://blogs.msdn.microsoft.com/webdev/2018/04/12/asp-net-core-2-1-0-preview2-now-available/)), available from ASP.NET Core 2.1.
Polly.Extensions.Http is ideal for creating custom Polly policies for use with IHttpClientFactory, available from ASP.NET Core 2.1.

```csharp
var retryPolicy = HttpPolicyExtensions
Expand All @@ -89,11 +85,14 @@ serviceCollection.AddHttpClient("example.com", c => c.BaseAddress = new Uri("htt
.AddPolicyHandler(timeoutPolicy);
```

#### TODO: link to public HttpClientFactory documentation and/or expand example, when that documentation is published.
## Official documentation

# For more information on Polly
+ [Microsoft documentation on IHttpClientFactory](https://docs.microsoft.com/en-gb/aspnet/core/fundamentals/http-requests?view=aspnetcore-2.1)
+ [Microsoft documentation on using Polly policies with IHttpClientFactory](https://docs.microsoft.com/en-gb/aspnet/core/fundamentals/http-requests?view=aspnetcore-2.1#use-polly-based-handlers)
+ [Polly documentation on Polly and HttpClientFactory](https://github.com/App-vNext/Polly/wiki/Polly-and-HttpClientFactory)
+ [Main Polly readme](https://github.com/App-vNext/Polly): quickstart details of all Polly policies and features
+ [Polly wiki](https://github.com/App-vNext/Polly/wiki): deep doco on Polly features

For more information on Polly and configuring Polly policies see the [main Polly repository](https://github.com/App-vNext/Polly) and [wiki](https://github.com/App-vNext/Polly/wiki).

# Release notes

Expand Down
141 changes: 61 additions & 80 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,27 @@ var testResultsDir = artifactsDir + Directory("test-results");

// NuGet
var nuspecExtension = ".nuspec";
var signed = "-Signed";
var nuspecFolder = "nuget-package";
var nuspecSrcFile = srcDir + File(projectName + nuspecExtension);
var nuspecDestFile = buildDir + File(projectName + nuspecExtension);
var nuspecSignedDestFile = buildDir + File(projectName + signed + nuspecExtension);
var nupkgDestDir = artifactsDir + Directory(nuspecFolder);
var snkFile = srcDir + File(keyName);

var projectToNugetFolderMap = new Dictionary<string, string[]>() {
{ "NetStandard11", new [] {"netstandard1.1"} },
{ "NetStandard11-Signed", new [] {"netstandard1.1"} },
{ "NetStandard20", new [] {"netstandard2.0"} },
};

// Gitversion
var gitVersionPath = ToolsExePath("GitVersion.exe");
Dictionary<string, object> gitVersionOutput;

// Versioning
string nugetVersion;
string appveyorBuildNumber;
string assemblyVersion;
string assemblySemver;

// StrongNameSigner
var strongNameSignerPath = ToolsExePath("StrongNameSigner.Console.exe");

Expand Down Expand Up @@ -128,37 +132,62 @@ Task("__UpdateAssemblyVersionInformation")
gitVersionOutput = new JsonParser().Parse<Dictionary<string, object>>(output);

Information("Updated GlobalAssemblyInfo");
Information("AssemblyVersion -> {0}", gitVersionOutput["AssemblySemVer"]);
Information("AssemblyFileVersion -> {0}", gitVersionOutput["MajorMinorPatch"]);
Information("AssemblyInformationalVersion -> {0}", gitVersionOutput["InformationalVersion"]);

Information("");
Information("Obtained raw version info for package versioning:");
Information("NuGetVersion -> {0}", gitVersionOutput["NuGetVersion"]);
Information("FullSemVer -> {0}", gitVersionOutput["FullSemVer"]);
Information("AssemblySemVer -> {0}", gitVersionOutput["AssemblySemVer"]);

appveyorBuildNumber = gitVersionOutput["FullSemVer"].ToString();
nugetVersion = gitVersionOutput["NuGetVersion"].ToString();
assemblyVersion = gitVersionOutput["Major"].ToString() + ".0.0.0";
assemblySemver = gitVersionOutput["AssemblySemVer"].ToString();

Information("");
Information("Mapping versioning information to:");
Information("Appveyor build number -> {0}", appveyorBuildNumber);
Information("Nuget package version -> {0}", nugetVersion);
Information("AssemblyVersion -> {0}", assemblyVersion);
Information("AssemblyFileVersion -> {0}", assemblySemver);
Information("AssemblyInformationalVersion -> {0}", assemblySemver);
});

Task("__UpdateDotNetStandardAssemblyVersionNumber")
.Does(() =>
{
// NOTE: TEMPORARY fix only, while GitVersionTask does not support .Net Standard assemblies. See https://github.com/App-vNext/Polly/issues/176.
// This build Task can be removed when GitVersionTask supports .Net Standard assemblies.
var assemblySemVer = gitVersionOutput["AssemblySemVer"].ToString();
Information("Updating NetStandard AssemblyVersions to {0}", assemblySemVer);
Information("Updating Assembly Version Information");

var attributeToValueMap = new Dictionary<string, string>() {
{ "AssemblyVersion", assemblyVersion },
{ "AssemblyFileVersion", assemblySemver },
{ "AssemblyInformationalVersion", assemblySemver },
};

var assemblyInfosToUpdate = GetFiles("./src/**/Properties/AssemblyInfo.cs")
.Select(f => f.FullPath)
.Where(f => !f.Contains("Specs"));

foreach(var assemblyInfo in assemblyInfosToUpdate) {
var replacedFiles = ReplaceRegexInFiles(assemblyInfo, "AssemblyVersion[(]\".*\"[)]", "AssemblyVersion(\"" + assemblySemVer +"\")");
if (!replacedFiles.Any())
{
throw new Exception($"AssemblyVersion could not be updated in {assemblyInfo}.");
foreach(var attributeMap in attributeToValueMap) {
var attribute = attributeMap.Key;
var value = attributeMap.Value;

foreach(var assemblyInfo in assemblyInfosToUpdate) {
var replacedFiles = ReplaceRegexInFiles(assemblyInfo, attribute + "[(]\".*\"[)]", attribute + "(\"" + value +"\")");
if (!replacedFiles.Any())
{
throw new Exception($"{attribute} attribute could not be updated in {assemblyInfo}.");
}
}
}

});

Task("__UpdateAppVeyorBuildNumber")
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
var fullSemVer = gitVersionOutput["FullSemVer"].ToString();
AppVeyor.UpdateBuildVersion(fullSemVer);
AppVeyor.UpdateBuildVersion(appveyorBuildNumber);
});

Task("__BuildSolutions")
Expand Down Expand Up @@ -189,12 +218,10 @@ Task("__RunTests")
}
});

Task("__CopyNonSignedOutputToNugetFolder")
Task("__CopyOutputToNugetFolder")
.Does(() =>
{
foreach(var project in projectToNugetFolderMap.Keys
.Where(p => !p.Contains(signed))
) {
foreach(var project in projectToNugetFolderMap.Keys) {
var sourceDir = srcDir + Directory(projectName + "." + project) + Directory("bin") + Directory(configuration);

foreach(var targetFolder in projectToNugetFolderMap[project]) {
Expand All @@ -208,35 +235,25 @@ Task("__CopyNonSignedOutputToNugetFolder")
CopyFile(nuspecSrcFile, nuspecDestFile);
});

Task("__CopySignedOutputToNugetFolder")
Task("__StronglySignAssemblies")
.Does(() =>
{
foreach(var project in projectToNugetFolderMap.Keys
.Where(p => p.Contains(signed))
) {
var sourceDir = srcDir + Directory(projectName + "." + project) + Directory("bin") + Directory(configuration);

foreach(var targetFolder in projectToNugetFolderMap[project]) {
var destDir = buildDir + Directory("lib");

Information("Copying {0} -> {1}.", sourceDir, destDir);
CopyDirectory(sourceDir, destDir);
}
}
//see: https://github.com/brutaldev/StrongNameSigner
var strongNameSignerSettings = new ProcessSettings()
.WithArguments(args => args
.Append("-in")
.AppendQuoted(buildDir)
.Append("-k")
.AppendQuoted(snkFile)
.Append("-l")
.AppendQuoted("Changes"));

CopyFile(nuspecSrcFile, nuspecSignedDestFile);

var replacedFiles = ReplaceTextInFiles(nuspecSignedDestFile, "dependency id=\"Polly\"", "dependency id=\"Polly-Signed\"");
if (!replacedFiles.Any())
{
throw new Exception("Could not set Polly dependency to Polly-Signed, for -Signed nuget package.");
}
StartProcess(strongNameSignerPath, strongNameSignerSettings);
});

Task("__CreateNonSignedNugetPackage")
Task("__CreateSignedNugetPackage")
.Does(() =>
{
var nugetVersion = gitVersionOutput["NuGetVersion"].ToString();
var packageName = projectName;

Information("Building {0}.{1}.nupkg", packageName, nugetVersion);
Expand All @@ -251,40 +268,6 @@ Task("__CreateNonSignedNugetPackage")
NuGetPack(nuspecDestFile, nuGetPackSettings);
});

Task("__CreateSignedNugetPackage")
.Does(() =>
{
var nugetVersion = gitVersionOutput["NuGetVersion"].ToString();
var packageName = projectName + "-Signed";

Information("Building {0}.{1}.nupkg", packageName, nugetVersion);

var nuGetPackSettings = new NuGetPackSettings {
Id = packageName,
Title = packageName,
Version = nugetVersion,
OutputDirectory = nupkgDestDir
};

NuGetPack(nuspecSignedDestFile, nuGetPackSettings);
});

Task("__StronglySignAssemblies")
.Does(() =>
{
//see: https://github.com/brutaldev/StrongNameSigner
var strongNameSignerSettings = new ProcessSettings()
.WithArguments(args => args
.Append("-in")
.AppendQuoted(buildDir)
.Append("-k")
.AppendQuoted(snkFile)
.Append("-l")
.AppendQuoted("Changes"));

StartProcess(strongNameSignerPath, strongNameSignerSettings);
});

//////////////////////////////////////////////////////////////////////
// BUILD TASKS
//////////////////////////////////////////////////////////////////////
Expand All @@ -297,9 +280,7 @@ Task("Build")
.IsDependentOn("__UpdateAppVeyorBuildNumber")
.IsDependentOn("__BuildSolutions")
.IsDependentOn("__RunTests")
.IsDependentOn("__CopyNonSignedOutputToNugetFolder")
.IsDependentOn("__CreateNonSignedNugetPackage")
.IsDependentOn("__CopySignedOutputToNugetFolder")
.IsDependentOn("__CopyOutputToNugetFolder")
.IsDependentOn("__StronglySignAssemblies")
.IsDependentOn("__CreateSignedNugetPackage");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="Polly" Version="5.9.0" />
<PackageReference Include="Polly" Version="6.0.1" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<DefaultLanguage>en-US</DefaultLanguage>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RootNamespace>PolicyExtensions</RootNamespace>
<RootNamespace>Polly.Extensions.Http</RootNamespace>
<TargetFramework>netstandard1.1</TargetFramework>
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
</PropertyGroup>
Expand All @@ -28,7 +28,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Polly" Version="5.9.0" />
<PackageReference Include="Polly" Version="6.0.1" />
</ItemGroup>
<Import Project="..\Polly.Extensions.Http.Shared\Polly.Extensions.Http.Shared.projitems" Label="Shared" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Runtime.CompilerServices;

[assembly: AssemblyTitle("Polly.Extensions.Http")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: CLSCompliant(true)]

[assembly: InternalsVisibleTo("Polly.Extensions.Http.NetStandard11.Specs")]
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputTypeEx>library</OutputTypeEx>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
<DefineConstants>TRACE;DEBUG;NETCOREAPP1_1</DefineConstants>
<DefineConstants>TRACE;DEBUG;NETCOREAPP2_0</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE;RELEASE;NETCOREAPP1_1</DefineConstants>
<DefineConstants>TRACE;RELEASE;NETCOREAPP2_0</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="Polly-Signed" Version="5.9.0" />
<PackageReference Include="Polly" Version="6.0.1" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
Expand All @@ -27,7 +27,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Polly.Extensions.Http.NetStandard11-Signed\Polly.Extensions.Http.NetStandard11-Signed.csproj" />
<ProjectReference Include="..\Polly.Extensions.Http.NetStandard20\Polly.Extensions.Http.NetStandard20.csproj" />
</ItemGroup>
<Import Project="..\Polly.Extensions.Http.SharedSpecs\Polly.Extensions.Http.SharedSpecs.projitems" Label="Shared" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Polly.Extensions.Http</AssemblyName>
<AssemblyOriginatorKeyFile></AssemblyOriginatorKeyFile>
<DefineConstants>TRACE;PORTABLE</DefineConstants>
<DefaultLanguage>en-US</DefaultLanguage>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RootNamespace>PolicyExtensions</RootNamespace>
<TargetFramework>netstandard1.1</TargetFramework>
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
<RootNamespace>Polly.Extensions.Http</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
Expand All @@ -28,7 +27,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Polly-Signed" Version="5.9.0" />
<PackageReference Include="Polly" Version="6.0.1" />
</ItemGroup>
<Import Project="..\Polly.Extensions.Http.Shared\Polly.Extensions.Http.Shared.projitems" Label="Shared" />
</Project>
Loading

0 comments on commit 34936cf

Please sign in to comment.