-
Notifications
You must be signed in to change notification settings - Fork 5
/
MainForm.cs
156 lines (139 loc) · 5.36 KB
/
MainForm.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using LyncTracker.Logic;
using LyncTracker.Properties;
using Microsoft.Lync.Model;
namespace LyncTracker
{
public partial class MainForm : Form
{
Tracker tracker;
public MainForm()
{
InitializeComponent();
InitializeImageList();
InitializeGroups();
InitializeCheckList();
}
void InitializeCheckList()
{
for(int i = 0; i < clbStatuses.Items.Count;++i)
clbStatuses.Items[i].Checked = true;
}
void InitializeImageList()
{
ImageList il = new ImageList();
il.Images.Add("grey", Resources.grey);
il.Images.Add("yellow", Resources.yellow);
il.Images.Add("red", Resources.red);
il.Images.Add("green", Resources.green);
lvList.SmallImageList = il;
}
void InitializeGroups()
{
//Send mail
ControlsEnabler ctrlEnabler = new ControlsEnabler();
ctrlEnabler.AddControl(tbSendEmail);
cbSendActive.CheckedChanged += ctrlEnabler.CheckedChanged;
//Save to log
ctrlEnabler = new ControlsEnabler();
ctrlEnabler.AddControl(tbLog);
ctrlEnabler.AddControl(bSearch);
cbSaveActive.CheckedChanged += ctrlEnabler.CheckedChanged;
//
cbSendActive.Checked = cbSaveActive.Checked = false;
}
private void bAdd_Click(object sender, EventArgs e)
{
if (tbEmail.Text.Length > 0)
lvList.Items.Add(tbEmail.Text, "grey");
tbEmail.Text = "";
}
private void rbOn_CheckedChanged(object sender, EventArgs e)
{
if (rbOn.Checked)
{
if (cbSendActive.Checked && tbSendEmail.Text.Length == 0)
{
MessageBox.Show("Please input the email to which notifications are to be sent", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (cbSaveActive.Checked && tbLog.Text.Length == 0)
{
MessageBox.Show("Please input the csv log path to which notifications are to be save", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
ChangeAdapter ca = new ChangeAdapter(this);
try
{
tracker = new Tracker(ca);
tracker.Start(ToStringList(lvList.Items), GetStatusList());
}
catch(Exception ex)
{
MessageBox.Show("Lync not turned on", "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
rbOn.Checked = false;
ca.SetStatus("Off");
ca = null;
}
}
else
{
if (tracker != null)
{
tracker.Stop();
tracker = null;
}
tsslStatus.Text = "Off";
}
}
private List<ContactAvailability> GetStatusList()
{
List<ContactAvailability> statusList = new List<ContactAvailability>();
System.Windows.Forms.ListView.CheckedListViewItemCollection s = clbStatuses.CheckedItems;
IEnumerable<ListViewItem> checkedList = (IEnumerable<ListViewItem>)s.Cast<ListViewItem>();
if (checkedList.Any(it=>it.Text=="Available"))
{
statusList.Add(ContactAvailability.Free);
statusList.Add(ContactAvailability.FreeIdle);
}
if (checkedList.Any(it=>it.Text=="Away"))
statusList.Add(ContactAvailability.Away);
if (clbStatuses.CheckedItems.ContainsKey("Busy"))
{
statusList.Add(ContactAvailability.Busy);
statusList.Add(ContactAvailability.BusyIdle);
}
if (clbStatuses.CheckedItems.ContainsKey("Do not disturb"))
statusList.Add(ContactAvailability.DoNotDisturb);
return statusList;
}
List<string> ToStringList(System.Windows.Forms.ListView.ListViewItemCollection oc)
{
List<string> sList = new List<string>();
foreach (ListViewItem lvi in oc)
sList.Add(lvi.Text);
return sList;
}
private void bRemove_Click(object sender, EventArgs e)
{
foreach(ListViewItem lvi in lvList.SelectedItems)
lvList.Items.Remove(lvi);
}
private void bSearch_Click(object sender, EventArgs e)
{
sfdSave.Filter = "CSV (*.csv)|*.*";
if (sfdSave.ShowDialog() == System.Windows.Forms.DialogResult.OK)
tbLog.Text = sfdSave.FileName.Contains(".csv") ? sfdSave.FileName : sfdSave.FileName+".csv";
}
}
}