-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
85 lines (74 loc) · 2.18 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Console.WriteLine("Hi, Welcome to our Interview Scheduler");
Console.WriteLine("Make sure you have a CSV file with the following columns: Name, Email, InterviewTime, Interviewer, InterviewerMail");
Console.WriteLine("Just log in to your Microsoft account and we will take care of the rest!");
var settings = Settings.LoadSettings();
// Initialize Graph
InitializeGraph(settings);
// Greet the user by name
await GreetUserAsync();
int choice = -1;
while (choice != 0)
{
Console.WriteLine("Please choose one of the following options:");
Console.WriteLine("0. Exit");
Console.WriteLine("1. Schedule Interviews");
try
{
choice = int.Parse(Console.ReadLine() ?? string.Empty);
}
catch (System.FormatException)
{
choice = -1;
}
switch (choice)
{
case 0:
Console.WriteLine("Thank you for using our Interview Scheduler!");
break;
case 1:
await SendInterviewInvitationsAsync();
break;
default:
Console.WriteLine("Invalid choice! Please try again.");
break;
}
}
void InitializeGraph(Settings settings)
{
GraphHelper.InitializeGraphForUserAuth(settings,
(info, cancel) =>
{
// Display the device code message to
// the user. This tells them
// where to go to sign in and provides the
// code to use.
Console.WriteLine(info.Message);
return Task.FromResult(0);
});
}
async Task GreetUserAsync()
{
try
{
var user = await GraphHelper.GetUserAsync();
Console.WriteLine($"Hello, {user?.DisplayName}!");
// For Work/school accounts, email is in Mail property
// Personal accounts, email is in UserPrincipalName
Console.WriteLine($"Email: {user?.Mail ?? user?.UserPrincipalName ?? ""}");
}
catch (Exception ex)
{
Console.WriteLine($"Error getting user: {ex.Message}");
}
}
async Task SendInterviewInvitationsAsync()
{
try
{
await GraphHelper.SendInterviewInvitationsAsync();
}
catch (Exception ex)
{
Console.WriteLine($"Error while creating a meet: {ex.Message}");
}
}