-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
290 lines (253 loc) · 11.7 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Xml;
using System.IO;
using System.Xml.Linq;
namespace Microsoft.LiveMeeting.RecordingExporter
{
public partial class MainForm : Form
{
public SortableBindingList<Recording> _recordings;
string _outputPath;
public List<string> _report;
public Timer _initTimer;
private ListSortDirection _sortDir = ListSortDirection.Ascending;
private int _sortColumn = 0;
public MainForm()
{
InitializeComponent();
_recordings = new SortableBindingList<Recording>();
_report = new List<string>();
_initTimer = new Timer();
_initTimer.Interval = 150;
_initTimer.Tick += OnInitTimerTick;
_initTimer.Start();
}
private void OnInitTimerTick(object sender, EventArgs e)
{
_initTimer.Stop();
Invoke((Action)delegate () {
Initialize();
});
}
void Initialize()
{
Config.LoadSettings();
if (!Config.IsConfigValid())
{
GetSettings();
}
if (!Config.IsConfigValid())
{
MessageBox.Show("Expected valid conference center name, username and password. Exiting...", "Settings error", MessageBoxButtons.OK);
Application.Exit();
}
if (Config.IsConfigValid())
RefreshRecordingList();
}
void GetSettings()
{
SettingsForm settings = new SettingsForm();
DialogResult result = settings.ShowDialog();
}
void RefreshRecordingList()
{
XDocument requestDoc = new XDocument(
new XElement("PlaceWareConfCenter", new XAttribute("authUser", Properties.Settings.Default.Username), new XAttribute("authPassword", Config.Password),
new XElement("ListRecordingsRequest", new XAttribute("listDeleted", false),
new XElement("TimeIntervalQuery", new XAttribute("fieldName", "startTime"),
new XElement("TimeInterval", new XAttribute("startTime", "2015-01-01T00:00:00Z"), new XAttribute("endTime", "2016-10-26T00:00:00Z"))),
new XElement("FieldList",
new XElement("Name", "title"),
new XElement("Name", "createTime"),
new XElement("Name", "duration"),
new XElement("Name", "owner"),
new XElement("Name", "name"),
new XElement("Name", "registration"),
new XElement("Name", "size"),
new XElement("Name", "startTime"),
new XElement("Name", "timeZone"),
new XElement("Name", "reid")))));
XmlDocument doc = new XmlDocument();
doc.Load(requestDoc.CreateReader());
XmlDocument resp = XmlApiClient.PostMessageRequest(doc);
XmlNodeList list = resp.SelectNodes("//Recording");
_recordings.Clear();
foreach (XmlNode node in list)
{
Recording recording = new Recording(node);
_recordings.Add(recording);
}
Debug.WriteLine(_recordings.Count.ToString());
dataGridView1.DataSource = _recordings;
foreach (DataGridViewColumn column in dataGridView1.Columns)
dataGridView1.Columns[column.Name].SortMode = DataGridViewColumnSortMode.Automatic;
}
private string GetRecordingURL(string recID)
{
XDocument requestDoc = new XDocument(
new XElement("PlaceWareConfCenter", new XAttribute("authUser", Properties.Settings.Default.Username), new XAttribute("authPassword", Config.Password),
new XElement("GetURLRequest",
new XElement("StringQuery", new XAttribute("fieldName", "reid"), new XAttribute("operator", "="), new XAttribute("value", recID)),
new XElement("OptionList",
new XElement("StringOption", new XAttribute("name", "recViewerCompany"), new XAttribute("value", Config.RecViewerCompany)),
new XElement("StringOption", new XAttribute("name", "recViewerName"), new XAttribute("value", Config.RecViewerName)),
new XElement("StringOption", new XAttribute("name", "recViewerEmail"), new XAttribute("value", Config.RecViewerEmail)),
new XElement("EnumerationOption", new XAttribute("name", "resourceType"), new XAttribute("value", "WindowsMediaMovieRecordingDownload"),
new XElement("String", "ESS"),
new XElement("String", "PWP"),
new XElement("String", "HighFidelityPresentation"),
new XElement("String", "HighFidelityPresentationDownload"),
new XElement("String", "WindowsMediaMovieRecording"),
new XElement("String", "WindowsMediaMovieRecordingDownload"),
new XElement("String", "BasicRecording"))))));
XmlDocument doc = new XmlDocument();
doc.Load(requestDoc.CreateReader());
XmlDocument response = XmlApiClient.PostMessageRequest(doc);
XmlNode node = response.SelectSingleNode("//GetURLReply");
if (node == null)
{
Debug.WriteLine("GetURLReply missing, response=" + response.OuterXml);
return null;
}
string url = node.Attributes["url"].Value;
return url;
}
private async void OnDownloadButtonClick(object sender, EventArgs e)
{
buttonDownload.Enabled = false;
if (dataGridView1.SelectedRows.Count <= 0)
return;
FolderBrowserDialog picker = new FolderBrowserDialog();
if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.FolderPath))
picker.SelectedPath = Properties.Settings.Default.FolderPath;
DialogResult r = picker.ShowDialog();
if (r != DialogResult.OK)
{
return;
}
_outputPath = picker.SelectedPath;
Properties.Settings.Default.FolderPath = _outputPath;
Properties.Settings.Default.Save();
progressBarOverall.Value = 0;
progressBarOverall.Visible = true;
progressBarSingle.Visible = true;
dataGridView1.Enabled = false;
progressBarOverall.Maximum = dataGridView1.SelectedRows.Count - 1;
IProgress<int> progress = new Progress<int>(value => {
if (value == -1)
{
progressBarOverall.Value = 0;
progressBarOverall.Visible = false;
progressBarSingle.Visible = false;
dataGridView1.Enabled = true;
buttonDownload.Enabled = true;
labelCurrentFile.Text = "Done!";
}
else
{
progressBarOverall.Value = value;
}
});
IProgress<string> updateFilename = new Progress<string>(value => { labelCurrentFile.Text = value; });
await Task.Run(() =>
{
int progIndex = 0;
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
string url = GetRecordingURL(row.Cells[0].Value.ToString());
if (string.IsNullOrWhiteSpace(url))
{
progIndex = progIndex + 1;
_report.Add("FAILURE: (no valid download URL)" + row.Cells[0]);
continue;
}
string name = DateTime.Parse(row.Cells["StartTime"].Value.ToString()).ToString("yy-MM-dd") + "_" + row.Cells["Title"].Value.ToString() + " (" + row.Cells["RecordingID"].Value.ToString() + ")";
name = name.Replace(":", "");
name = name.Replace("\\", "");
name = name.Replace("//", "");
name = name.Replace(".", "");
string path = _outputPath + "\\" + name + ".wmv";
updateFilename.Report(name);
progress.Report(progIndex);
progIndex = progIndex + 1;
try
{
DownloadResource(url, path);
_report.Add("SUCCESS: " + row.Cells[0]);
}
catch (Exception ex)
{
_report.Add("FAILURE: (" + ex.Message + ") " + row.Cells[0]);
}
}
progress.Report(-1);
});
}
public Stream GetResourceStream(string url)
{
// Get resource using HTTP GET with the url of a resource;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
Stream responseStream = null;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.ContentType == "application/octet-stream")
{
responseStream = response.GetResponseStream();
}
return responseStream;
}
public void DownloadResource(string url, string filePath)
{
using (Stream res = GetResourceStream(url))
{
if (res == null)
return;
using (FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate))
{
int length = 1024 * 1024;
Byte[] buffer = new Byte[length];
int bytesRead = res.Read(buffer, 0, length);
while (bytesRead > 0)
{
fileStream.Write(buffer, 0, bytesRead);
bytesRead = res.Read(buffer, 0, length);
}
fileStream.Close();
}
res.Close();
}
}
private void toolStripMenuItemExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void toolStripMenuItemSettings_Click(object sender, EventArgs e)
{
GetSettings();
}
private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{
RefreshRecordingList();
}
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
labelSelected.Text = "Download " + dataGridView1.SelectedRows.Count.ToString() + " recordings. This process may take a long time to complete.";
else
labelSelected.Text = "Select one or more recordings from the list to download.";
}
private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (_sortColumn == e.ColumnIndex)
_sortDir = (_sortDir == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending);
_sortColumn = e.ColumnIndex;
dataGridView1.Sort(dataGridView1.Columns[_sortColumn], _sortDir);
}
}
}