-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
38 lines (32 loc) · 1.26 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
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((_, config) => config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true))
.ConfigureServices((context, services) => services.ConfigureGraphClient(context.Configuration))
.ConfigureServices((_, services) =>
{
services.AddScoped<IOperations, Operations>();
services.AddScoped<IDateTimes, DateTimes>();
})
.ConfigureLogging((context, logging) => logging.AddConfiguration(context.Configuration.GetSection("Logging")))
.Build();
var operations = host.Services.GetRequiredService<IOperations>();
var dateTimes = host.Services.GetRequiredService<IDateTimes>();
var user = await operations.GetUserAsync();
if (user is not null)
{
try
{
Console.WriteLine($"User {user.DisplayName} found");
var result = await operations.GetAllOneNotesAsync();
Console.WriteLine($"Notebooks {JsonSerializer.Serialize(result)}");
Console.WriteLine($"Notebook {result.OdataCount} created at {result.Value[0].CreatedDateTime}");
}
catch (ApiException error)
{
GraphModel.PrintApiException(error);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}