-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul Schaeflein
committed
Jan 13, 2025
1 parent
52c0025
commit c967102
Showing
13 changed files
with
537 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
using Azure.Identity; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Graph.Community.SPClient.Sample | ||
{ | ||
internal class SiteDesign | ||
{ | ||
private readonly AzureAdSettings azureAdSettings; | ||
private readonly SharePointSettings sharePointSettings; | ||
|
||
public SiteDesign( | ||
IOptions<AzureAdSettings> azureAdOptions, | ||
IOptions<SharePointSettings> sharePointOptions) | ||
{ | ||
this.azureAdSettings = azureAdOptions.Value; | ||
this.sharePointSettings = sharePointOptions.Value; | ||
} | ||
|
||
public async Task Run() | ||
Check warning on line 25 in sample/SiteDesign.cs GitHub Actions / build
|
||
{ | ||
//////////////////////////////////////// | ||
// | ||
// Capture diagnostic information | ||
// | ||
/////////////////////////////////////// | ||
|
||
var logger = new StringBuilderHttpMessageLogger(); | ||
|
||
////////////////////// | ||
// | ||
// TokenCredential | ||
// | ||
////////////////////// | ||
|
||
var credential = new ChainedTokenCredential( | ||
new SharedTokenCacheCredential(new SharedTokenCacheCredentialOptions() { TenantId = azureAdSettings.TenantId, ClientId = azureAdSettings.ClientId }), | ||
new InteractiveBrowserCredential(new InteractiveBrowserCredentialOptions { TenantId = azureAdSettings.TenantId, ClientId = azureAdSettings.ClientId }) | ||
); | ||
|
||
|
||
//////////////////////////////////////////////////////////// | ||
// | ||
// SharePoint REST Client with Logger and SharePoint service handler | ||
// | ||
//////////////////////////////////////////////////////////// | ||
|
||
// Configure our client | ||
SPClientOptions clientOptions = new() | ||
{ | ||
// use the default user agent | ||
|
||
//UserAgentInfo = new SharePointThrottlingDecoration() | ||
//{ | ||
// CompanyName = "Company", | ||
// AppName = "Application", | ||
// AppVersion = "0.0.0", | ||
// ISV = false | ||
//}, | ||
|
||
// use our logger | ||
MessageLogger = logger | ||
}; | ||
|
||
var spClient = SPClientFactory.Create(sharePointSettings.SpoTenantUrl, credential, clientOptions); | ||
|
||
/////////////////////////////////////// | ||
// | ||
// Setup is complete, run the sample | ||
// | ||
////////////////////////////////////// | ||
|
||
var scopes = new string[] { $"{sharePointSettings.SpoTenantUrl}/AllSites.FullControl" }; | ||
var WebUrl = $"{sharePointSettings.SpoTenantUrl}{sharePointSettings.ServerRelativeSiteUrl}"; | ||
|
||
//var siteScript = new SiteScriptMetadata() | ||
//{ | ||
// Title = "Green Theme", | ||
// Description = "Apply the Green Theme", | ||
// Content = "{\"$schema\": \"schema.json\",\"actions\": [{\"verb\": \"applyTheme\",\"themeName\": \"Green\"}],\"bindata\": { },\"version\": 1}", | ||
//}; | ||
|
||
//try | ||
//{ | ||
|
||
|
||
// var createdScript = await graphServiceClient | ||
// .SharePointAPI(WebUrl) | ||
// .SiteScripts | ||
// .Request() | ||
// .WithScopes(scopes) | ||
// .CreateAsync(siteScript); | ||
|
||
// var siteDesign = new SiteDesignMetadata() | ||
// { | ||
// Title = "Green Theme", | ||
// Description = "Apply the Green theme", | ||
// SiteScriptIds = new System.Collections.Generic.List<Guid>() { new Guid(createdScript.Id) }, | ||
// WebTemplate = "64" // 64 = Team Site, 68 = Communication Site, 1 = Groupless Team Site | ||
// }; | ||
|
||
// var createdDesign = await graphServiceClient | ||
// .SharePointAPI(WebUrl) | ||
// .SiteDesigns | ||
// .Request() | ||
// .WithScopes(scopes) | ||
// .CreateAsync(siteDesign); | ||
|
||
// var applySiteDesignRequest = new ApplySiteDesignRequest | ||
// { | ||
// SiteDesignId = createdDesign.Id, | ||
// WebUrl = WebUrl | ||
// }; | ||
|
||
// var applySiteDesignResponse = await graphServiceClient | ||
// .SharePointAPI(WebUrl) | ||
// .SiteDesigns | ||
// .Request() | ||
// .WithScopes(scopes) | ||
// .ApplyAsync(applySiteDesignRequest); | ||
|
||
// foreach (var outcome in applySiteDesignResponse.CurrentPage) | ||
// { | ||
// Console.WriteLine(outcome.OutcomeText); | ||
// } | ||
|
||
//} | ||
//catch (Exception ex) | ||
//{ | ||
|
||
// Console.WriteLine(ex.Message); | ||
//} | ||
|
||
|
||
Console.WriteLine("Press enter to show log"); | ||
Console.ReadLine(); | ||
Console.WriteLine(); | ||
var log = logger.GetLog(); | ||
Console.WriteLine(log); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using Azure.Identity; | ||
using Microsoft.Extensions.Options; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Graph.Community.SPClient.Sample | ||
{ | ||
internal class SitePages | ||
{ | ||
private readonly AzureAdSettings azureAdSettings; | ||
private readonly SharePointSettings sharePointSettings; | ||
|
||
public SitePages( | ||
IOptions<AzureAdSettings> azureAdOptions, | ||
IOptions<SharePointSettings> sharePointOptions) | ||
{ | ||
this.azureAdSettings = azureAdOptions.Value; | ||
this.sharePointSettings = sharePointOptions.Value; | ||
} | ||
|
||
|
||
public async Task Run() | ||
{ | ||
//////////////////////////////////////// | ||
// | ||
// Capture diagnostic information | ||
// | ||
/////////////////////////////////////// | ||
|
||
var logger = new StringBuilderHttpMessageLogger(); | ||
|
||
////////////////////// | ||
// | ||
// TokenCredential | ||
// | ||
////////////////////// | ||
|
||
var credential = new ChainedTokenCredential( | ||
new SharedTokenCacheCredential(new SharedTokenCacheCredentialOptions() { TenantId = azureAdSettings.TenantId, ClientId = azureAdSettings.ClientId }), | ||
new InteractiveBrowserCredential(new InteractiveBrowserCredentialOptions { TenantId = azureAdSettings.TenantId, ClientId = azureAdSettings.ClientId }) | ||
); | ||
|
||
|
||
//////////////////////////////////////////////////////////// | ||
// | ||
// SharePoint REST Client with Logger and SharePoint service handler | ||
// | ||
//////////////////////////////////////////////////////////// | ||
|
||
// Configure our client | ||
SPClientOptions clientOptions = new() | ||
{ | ||
// use the default user agent | ||
|
||
//UserAgentInfo = new SharePointThrottlingDecoration() | ||
//{ | ||
// CompanyName = "Company", | ||
// AppName = "Application", | ||
// AppVersion = "0.0.0", | ||
// ISV = false | ||
//}, | ||
|
||
// use our logger | ||
MessageLogger = logger | ||
}; | ||
|
||
var spClient = SPClientFactory.Create(sharePointSettings.SpoTenantUrl, credential, clientOptions); | ||
|
||
/////////////////////////////////////// | ||
// | ||
// Setup is complete, run the sample | ||
// | ||
////////////////////////////////////// | ||
|
||
var scopes = new string[] { $"{sharePointSettings.SpoTenantUrl}/AllSites.FullControl" }; | ||
var WebUrl = $"{sharePointSettings.SpoTenantUrl}{sharePointSettings.ServerRelativeSiteUrl}"; | ||
|
||
try | ||
{ | ||
var sitePages = await spClient[sharePointSettings.ServerRelativeSiteUrl]._api.Sitepages.Pages.GetAsync(); | ||
|
||
Console.WriteLine($"Site Pages for {WebUrl}"); | ||
Console.WriteLine($" count: {sitePages?.Value?.Count.ToString() ?? "<null>" }"); | ||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
await logger.WriteLine(""); | ||
await logger.WriteLine("================== Exception caught =================="); | ||
await logger.WriteLine(ex.ToString()); | ||
} | ||
|
||
|
||
Console.WriteLine("Press enter to show log"); | ||
Console.ReadLine(); | ||
Console.WriteLine(); | ||
var log = logger.GetLog(); | ||
Console.WriteLine(log); | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.