Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/pnp/pnpframework into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinvanhunen committed Nov 19, 2024
2 parents 33a3682 + eec5fb2 commit 9998d29
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/buildandtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'
include-prerelease: false
- name: Install dependencies
run: dotnet restore
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightlynuget_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'
include-prerelease: false
- name: Create and publish nuget
env:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PnP Framework

**PnP Framework** is a .NET Standard 2.0 / .NET 6.0 / .NET 7.0 / .NET 8.0 library targeting Microsoft 365 containing the PnP Provisioning engine and a ton of other useful extensions. This library is the cross platform successor of the [PnP-Sites-Core](https://github.com/PnP/PnP-Sites-Core) library. The original [PnP-Sites-Core](https://github.com/PnP/PnP-Sites-Core) library only works on Windows (due to the dependency on .Net Framework) and supports SharePoint on-premises and SharePoint Online, while this library will work cross platform but only supports SharePoint Online. Going forward we'll only be **actively maintaining PnP Framework**, the [PnP-Sites-Core](https://github.com/PnP/PnP-Sites-Core) library is retired and archived.
**PnP Framework** is a .NET Standard 2.0 / .NET 8.0 / .NET 9.0 library targeting Microsoft 365 containing the PnP Provisioning engine and a ton of other useful extensions. This library is the cross platform successor of the [PnP-Sites-Core](https://github.com/PnP/PnP-Sites-Core) library. The original [PnP-Sites-Core](https://github.com/PnP/PnP-Sites-Core) library only works on Windows (due to the dependency on .Net Framework) and supports SharePoint on-premises and SharePoint Online, while this library will work cross platform but only supports SharePoint Online. Going forward we'll only be **actively maintaining PnP Framework**, the [PnP-Sites-Core](https://github.com/PnP/PnP-Sites-Core) library is retired and archived.

Next to PnP Framework that will be replacing [PnP-Sites-Core](https://github.com/PnP/PnP-Sites-Core) we're also building a brand new [PnP Core SDK](https://github.com/pnp/pnpcore) that targets modern .NET development and which will work everywhere where .NET will run. This library is the long term evolution of PnP Framework, we'll enable a phased transition from PnP Framework to [PnP Core SDK](https://github.com/pnp/pnpcore) without impacting PnP Framework users.

Expand Down
12 changes: 3 additions & 9 deletions build/build-debug.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,15 @@ $buildCmd = "dotnet build `"$PSScriptRoot/../src/lib/PnP.Framework/PnP.Framework
if ($LocalPnPCore) {
# Check if available
$pnpCoreAssembly = Join-Path $PSScriptRoot -ChildPath "..\..\pnpcore\src\sdk\PnP.Core\bin\Debug\netstandard2.0\PnP.Core.dll"
$pnpCoreAssembly5 = Join-Path $PSScriptRoot -ChildPath "..\..\pnpcore\src\sdk\PnP.Core\bin\Debug\net5.0\PnP.Core.dll"
$pnpCoreAssembly6 = Join-Path $PSScriptRoot -ChildPath "..\..\pnpcore\src\sdk\PnP.Core\bin\Debug\net6.0\PnP.Core.dll"
$pnpCoreAssembly7 = Join-Path $PSScriptRoot -ChildPath "..\..\pnpcore\src\sdk\PnP.Core\bin\Debug\net7.0\PnP.Core.dll"
$pnpCoreAssembly8 = Join-Path $PSScriptRoot -ChildPath "..\..\pnpcore\src\sdk\PnP.Core\bin\Debug\net8.0\PnP.Core.dll"
$pnpCoreAssembly9 = Join-Path $PSScriptRoot -ChildPath "..\..\pnpcore\src\sdk\PnP.Core\bin\Debug\net9.0\PnP.Core.dll"
$pnpCoreAssembly = [System.IO.Path]::GetFullPath($pnpCoreAssembly)
$pnpCoreAssembly5 = [System.IO.Path]::GetFullPath($pnpCoreAssembly5)
$pnpCoreAssembly6 = [System.IO.Path]::GetFullPath($pnpCoreAssembly6)
$pnpCoreAssembly7 = [System.IO.Path]::GetFullPath($pnpCoreAssembly7)
$pnpCoreAssembly8 = [System.IO.Path]::GetFullPath($pnpCoreAssembly8)
$pnpCoreAssembly9 = [System.IO.Path]::GetFullPath($pnpCoreAssembly9)
if (Test-Path $pnpCoreAssembly -PathType Leaf) {
$buildCmd += " -p:PnPCoreSdkPath=`"$pnpCoreAssembly`""
$buildCmd += " -p:PnPCoreSdkPathNet5=`"$pnpCoreAssembly5`""
$buildCmd += " -p:PnPCoreSdkPathNet6=`"$pnpCoreAssembly6`""
$buildCmd += " -p:PnPCoreSdkPathNet7=`"$pnpCoreAssembly7`""
$buildCmd += " -p:PnPCoreSdkPathNet8=`"$pnpCoreAssembly8`""
$buildCmd += " -p:PnPCoreSdkPathNet9=`"$pnpCoreAssembly9`""
}
else {
Write-Error -Message "PnP Core Assembly path $pnpCoreAssembly not found"
Expand Down
2 changes: 1 addition & 1 deletion build/version.debug.increment
Original file line number Diff line number Diff line change
@@ -1 +1 @@
98
101
3 changes: 3 additions & 0 deletions src/lib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Added

- Support for .NET 9.0 [jansenbe - Bert Jansen]
- Support for Rate-Limiting in the PnP Framework + unifiqation of the throttling implementation for all http requests made [jansenbe - Bert Jansen]

### Changed

- Removed references to the PnP Management Shell app (`31359c7f-bd7e-475c-86db-fdb8c937548e`) [jansenbe - Bert Jansen]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>

<IsPackable>false</IsPackable>
<SignAssembly>true</SignAssembly>
Expand All @@ -10,12 +10,12 @@

<ItemGroup>
<PackageReference Include="AngleSharp" Version="0.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Moq" Version="4.15.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.2.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions src/lib/PnP.Framework.Test/Pages/ClientSidePagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PnP.Core.Services;
using PnP.Framework.ALM;
using PnP.Framework.Provisioning.Connectors;
using PnP.Framework.Provisioning.Model;
Expand Down Expand Up @@ -45,6 +46,18 @@ public static void ClassCleanup()
// }
//}

[TestMethod]
public void Bert2()
{
using (var cc = TestCommon.CreateClientContext())
{
cc.Load(cc.Web, p => p.Title);
cc.ExecuteQueryRetry();
//cc.ExecuteQuery();
Assert.IsTrue(cc.Web.Title != null);
}
}

[TestMethod]
public void ExportPagesTest()
{
Expand Down
12 changes: 6 additions & 6 deletions src/lib/PnP.Framework.Test/PnP.Framework.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\pnp.core.snk</AssemblyOriginatorKeyFile>
Expand Down Expand Up @@ -175,17 +175,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.SharePointOnline.CSOM" Version="16.1.*" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="PrivateObjectExtensions" Version="1.4.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.1" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="8.0.2" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.0" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="9.0.0" />
<PackageReference Include="PnP.Core" Version="1.14.*-*" Condition="'$(PnPCoreSdkPath)' == ''" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/PnP.Framework.Test/TestCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private static ClientContext CreateContext(string contextUrl, AzureEnvironment a
}
else
{
using (AuthenticationManager am = new AuthenticationManager(AppId, UserName, Password, null, azureEnvironment))
using (AuthenticationManager am = new AuthenticationManager(AzureADClientId, UserName, Password, null, azureEnvironment))
{

if (azureEnvironment == AzureEnvironment.Custom)
Expand Down
10 changes: 9 additions & 1 deletion src/lib/PnP.Framework/AuthenticationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,10 @@ public static AuthenticationManager CreateWithPnPCoreSdk(PnPContext pnpContext)
/// </summary>
public AuthenticationManager()
{
#if !NET9_0
// Set the TLS preference. Needed on some server os's to work when Office 365 removes support for TLS 1.0
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
#endif
}

private AuthenticationManager(ACSTokenGenerator oAuthAuthenticationProvider) : this()
Expand Down Expand Up @@ -722,7 +724,7 @@ private void ConfigureAuthenticationManagerEnvironmentSettings(PnPContext pnPCon
};
}
}
#endregion
#endregion

#region Access Token Acquisition
/// <summary>
Expand Down Expand Up @@ -1238,6 +1240,8 @@ private ClientContext BuildClientContext(IClientApplicationBase application, str
DisableReturnValueCache = true
};

clientContext.AddWebRequestExecutorFactory();

clientContext.ExecutingWebRequest += (sender, args) =>
{
AuthenticationResult ar = null;
Expand Down Expand Up @@ -1500,6 +1504,8 @@ public ClientContext GetAccessTokenContext(string siteUrl, Func<string, string>
DisableReturnValueCache = true
};

clientContext.AddWebRequestExecutorFactory();

clientContext.ExecutingWebRequest += (sender, args) =>
{
Uri resourceUri = new Uri(siteUrl);
Expand All @@ -1525,6 +1531,8 @@ public ClientContext GetAccessTokenContext(string siteUrl, string accessToken)
DisableReturnValueCache = true
};

clientContext.AddWebRequestExecutorFactory();

clientContext.ExecutingWebRequest += (sender, args) =>
{
args.WebRequestExecutor.RequestHeaders["Authorization"] = "Bearer " + accessToken;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/PnP.Framework/Extensions/ClientContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ private static async Task ExecuteQueryImplementation(ClientRuntimeContext client

await new SynchronizationContextRemover();

#if !NET9_0
// Set the TLS preference. Needed on some server os's to work when Office 365 removes support for TLS 1.0
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
#endif

var clientTag = string.Empty;
if (clientContext is PnPClientContext)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PnP.Framework;
using PnP.Framework.Http;
using PnP.Framework.Utilities.Context;
using System;

Expand All @@ -16,6 +17,11 @@ public static void AddContextSettings(this ClientRuntimeContext clientContext, C
clientContext.StaticObjects[PnPSettingsKey] = contextData;
}

public static void AddWebRequestExecutorFactory(this ClientRuntimeContext clientContext)
{
clientContext.WebRequestExecutorFactory = new HttpClientWebRequestExecutorFactory(PnPHttpClient.Instance.GetHttpClient((ClientContext)clientContext));
}

public static ClientContextSettings GetContextSettings(this ClientRuntimeContext clientContext)
{
if (!clientContext.StaticObjects.TryGetValue(PnPSettingsKey, out object settingsObject))
Expand Down
67 changes: 44 additions & 23 deletions src/lib/PnP.Framework/Http/PnPHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class PnPHttpClient
//private static Configuration configuration;
private const string PnPHttpClientName = "PnPHttpClient";
private static readonly Lazy<PnPHttpClient> _lazyInstance = new Lazy<PnPHttpClient>(() => new PnPHttpClient(), true);
private static readonly SemaphoreSlim semaphoreSlimFactory = new SemaphoreSlim(1);
private ServiceProvider serviceProvider;
private static readonly ConcurrentDictionary<string, HttpClientHandler> credentialsHttpClients = new ConcurrentDictionary<string, HttpClientHandler>();

Expand Down Expand Up @@ -62,7 +63,7 @@ public HttpClient GetHttpClient(ClientContext context)
// Create a new handler, do not dispose it since we're caching it
var handler = new HttpClientHandler
{
Credentials = context.Credentials
Credentials = context.Credentials,
};

credentialsHttpClients.TryAdd(cacheKey, handler);
Expand Down Expand Up @@ -125,35 +126,49 @@ public static void AuthenticateRequest(HttpRequestMessage request, string access

private void BuildServiceFactory()
{
// Use TLS 1.2 as default connection
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
try
{
// Ensure there's only one context factory building happening at any given time
semaphoreSlimFactory.Wait();

// Create container
var serviceCollection = new ServiceCollection();
// Use TLS 1.2 as default connection
#if !NET9_0
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
#endif

// Add http handlers
AddHttpHandlers(serviceCollection);
// Create container
var serviceCollection = new ServiceCollection();

// get User Agent String
string userAgentFromConfig = null;
try
{
userAgentFromConfig = ConfigurationManager.AppSettings["SharePointPnPUserAgent"];
}
catch // throws exception if being called from a .NET Standard 2.0 application
{
// Add http handlers
AddHttpHandlers(serviceCollection);
// Add services
AddPnPServices(serviceCollection);

// get User Agent String
string userAgentFromConfig = null;
try
{
userAgentFromConfig = ConfigurationManager.AppSettings["SharePointPnPUserAgent"];
}
catch // throws exception if being called from a .NET Standard 2.0 application
{

}
if (string.IsNullOrWhiteSpace(userAgentFromConfig))
{
userAgentFromConfig = Environment.GetEnvironmentVariable("SharePointPnPUserAgent", EnvironmentVariableTarget.Process);
}

// Add http clients
AddHttpClients(serviceCollection, userAgentFromConfig);

// Build the container
serviceProvider = serviceCollection.BuildServiceProvider();
}
if (string.IsNullOrWhiteSpace(userAgentFromConfig))
finally
{
userAgentFromConfig = Environment.GetEnvironmentVariable("SharePointPnPUserAgent", EnvironmentVariableTarget.Process);
semaphoreSlimFactory.Release();
}

// Add http clients
AddHttpClients(serviceCollection, userAgentFromConfig);

// Build the container
serviceProvider = serviceCollection.BuildServiceProvider();
}

private static TimeSpan GetHttpTimeout()
Expand Down Expand Up @@ -224,5 +239,11 @@ private static IServiceCollection AddHttpHandlers(IServiceCollection collection)

return collection;
}

private static IServiceCollection AddPnPServices(IServiceCollection collection)
{
return collection
.AddSingleton<RateLimiter>();
}
}
}
Loading

0 comments on commit 9998d29

Please sign in to comment.