-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
39 lines (29 loc) · 1.29 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// ReSharper disable StringLiteralTypo
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile("appsettings.Development.json", optional: false, reloadOnChange: true)
.Build();
var services = new ServiceCollection();
services.AddLogging(configure => configure.AddConsole());
var graphServiceOptions = new GraphServiceOptions();
configuration.GetRequiredSection("GraphServiceOptions").Bind(graphServiceOptions);
services.AddMicrosoftGraphServices(graphServiceOptions);
var serviceProvider = services.BuildServiceProvider();
var sharepointService = serviceProvider.GetRequiredService<ISharepointGraphService>();
using var cts = new CancellationTokenSource();
var (statusCode, sites) = await sharepointService.GetSites(
selectQueryParameters: ["id", "webUrl", "isPersonalSite"],
cancellationToken: cts.Token);
if (statusCode != HttpStatusCode.OK)
{
Console.WriteLine("Failed to retrieve sites.");
return;
}
foreach (var site in sites)
{
Console.WriteLine($"SiteId: {site.Id}");
Console.WriteLine($"WebUrl: {site.WebUrl}");
Console.WriteLine($"IsPersonalSite: {site.IsPersonalSite}");
Console.WriteLine("--------------------------------------");
}