-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
59 lines (52 loc) · 1.29 KB
/
Form1.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
using System;
using System.Collections.Async;
using System.Windows.Forms;
using SyncWhole.Common;
using SyncWhole.Google;
using SyncWhole.Outlook;
namespace SyncWhole
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var googleFactory = new GoogleCalendarAdapterFactory("token.json");
var outlookFactory = new OutlookAdapterFactory();
_cmbCalendars.Items.Add(googleFactory);
_cmbCalendars.Items.Add(outlookFactory);
}
private async void ButtonClick(object sender, EventArgs e)
{
_btnLoad.Enabled = false;
try
{
listBox1.Items.Clear();
if (!(_cmbCalendars.SelectedItem is IAppointmentSourceFactory factory))
{
return;
}
using (IAppointmentSource source = await factory.ConnectSourceAsync())
{
await source.LoadAllAppointments()
.ForEachAsync(a => BeginInvoke((Action) (() => listBox1.Items.Add(a))));
}
}
finally
{
_btnLoad.Enabled = true;
}
}
private void ListBoxSelectionChanged(object sender, EventArgs e)
{
if (!(listBox1.SelectedItem is ILoadedAppointment apt))
{
return;
}
_lblDetails.Text = apt.ToLongString();
}
private void Form1Closing(object sender, FormClosingEventArgs e)
{
}
}
}