-
Notifications
You must be signed in to change notification settings - Fork 3
/
BrowserWindow.xaml.cs
721 lines (619 loc) · 31 KB
/
BrowserWindow.xaml.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using Newtonsoft.Json;
using System.Reflection;
using System.Diagnostics;
namespace UsosApiBrowser
{
public partial class BrowserWindow : Window
{
/// <summary>
/// This holds cached information on the data user is filling into various
/// inputs. Makes it a bit easier for a user to not get annoyed with this app.
/// </summary>
public VarsCache varsCache = new VarsCache();
/// <summary>
/// Used to connect to USOS API installations.
/// </summary>
private ApiConnector apiConnector;
public BrowserWindow()
{
InitializeComponent();
MessageBox.Show("Please note, that this is a development tool only and it might be a bit buggy. " +
"However, this stands for this client application only, not the USOS API itself!",
"USOS API Browser", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
System.Deployment.Application.ApplicationDeployment ad = System.Deployment.Application.ApplicationDeployment.CurrentDeployment;
this.Title += " (v. " + ad.CurrentVersion.ToString() + ")";
}
this.varsCache.BindWithTextBox("consumer_key", this.consumerKeyTextbox);
this.varsCache.BindWithTextBox("consumer_secret", this.consumerSecretTextbox);
this.varsCache.BindWithTextBox("token", this.tokenTextbox);
this.varsCache.BindWithTextBox("token_secret", this.tokenSecretTextbox);
/* We use a "mother installation" for the first USOS API request. We need to
* get a list of all USOS API installations. */
var motherInstallation = new ApiInstallation
{
base_url = "http://apps.usos.edu.pl/" // will change when out of Beta!
};
this.apiConnector = new ApiConnector(motherInstallation);
this.apiConnector.BeginRequest += new EventHandler(apiConnector_BeginRequest);
this.apiConnector.EndRequest += new EventHandler(apiConnector_EndRequest);
/* Fill up the installations list. */
try
{
this.installationsComboBox.Items.Clear();
var installations = this.apiConnector.GetInstallations();
installations.Add(new ApiInstallation() { base_url = "http://127.0.0.1:8000/" });
foreach (var installation in installations)
{
this.installationsComboBox.Items.Add(new ComboBoxItem
{
Content = installation.base_url,
Tag = installation
});
}
}
catch (WebException)
{
MessageBox.Show("Error occured when trying to access USOS API mother server. Could not populate USOS API installations list.",
"Network error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
if (this.installationsComboBox.Items.Count > 0)
{
/* Now we have a list of all installations in a combo box. We choose
* one of them. */
this.installationsComboBox.SelectedIndex = 0;
this.ReloadInstallation();
}
}
void apiConnector_BeginRequest(object sender, EventArgs e)
{
/* Change a cursor to Wait when API request begins... */
this.Cursor = System.Windows.Input.Cursors.Wait;
}
void apiConnector_EndRequest(object sender, EventArgs e)
{
/* Change a cursor back to Arrow when API request ends. */
this.Cursor = System.Windows.Input.Cursors.Arrow;
}
/// <summary>
/// List of valid scopes (as retrieved from a currently selected API installation).
/// </summary>
public List<ApiScope> scopes;
/// <summary>
/// Refresh the list of valid scopes.
/// </summary>
private void RefreshScopes()
{
this.scopes = this.apiConnector.GetScopes();
}
/// <summary>
/// Refresh the methods tree.
/// </summary>
/// <returns>False if could not connect to the current API installation.</returns>
private bool RefreshTree()
{
/* Retrieving a list of all API methods. */
List<ApiMethod> methods = null;
try
{
methods = this.apiConnector.GetMethods();
}
catch (WebException ex)
{
MessageBox.Show("Could not connect to selected installation.\n" + ex.Message + "\n"
+ ApiConnector.ReadResponse(ex.Response), "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
return false;
}
catch (Exception ex)
{
MessageBox.Show("Could not connect to selected installation.\n" + ex.Message, "Error",
MessageBoxButton.OK, MessageBoxImage.Warning);
return false;
}
/* Building a tree of modules and methods. This is done by analyzing method names. */
foreach (ApiMethod method in methods)
{
string[] path = method.name.Split('/');
TreeViewItem currentnode = null;
for (var i = 1; i < path.Length; i++)
{
string part = path[i];
bool already_present = false;
ItemCollection items = (i == 1) ? this.methodsTreeView.Items : currentnode.Items;
foreach (TreeViewItem item in items)
{
if ((string)item.Header == part) {
already_present = true;
currentnode = item;
}
}
if (!already_present)
{
currentnode = new TreeViewItem { Header = part };
if (i == path.Length - 1)
{
currentnode.Tag = method;
currentnode.ToolTip = method.brief_description;
}
items.Add(currentnode);
}
}
}
/* Expand all nodes of the tree (if the are more than 50 methods in this installation,
* then we skip this step), and select an initial method (request_token). */
foreach (TreeViewItem item in this.methodsTreeView.Items)
{
if (methods.Count < 50)
item.ExpandSubtree();
if ((string)item.Header == "oauth")
{
item.ExpandSubtree();
foreach (TreeViewItem subitem in item.Items)
if ((string)subitem.Header == "request_token")
subitem.IsSelected = true;
}
}
return true;
}
private Dictionary<string, TextBox> methodArgumentsTextboxes = new Dictionary<string,TextBox>();
private CheckBox signWithConsumerSecretCheckbox;
private CheckBox signWithTokenSecretCheckbox;
private TextBox methodResultTextbox;
private CheckBox methodResultHumanReadableCheckbox;
private CheckBox useSslCheckbox;
private void methodsTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
/* User clicked a different method in the tree. We will reset and rebuild
* the right side of the browser window. */
TreeViewItem selected = (TreeViewItem)this.methodsTreeView.SelectedItem;
this.methodArgumentsTextboxes.Clear();
this.mainDockingPanel.Children.Clear();
if (selected == null)
return;
/* The upper panel - for the method call parameters, etc. Docked in the top. */
var formStackPanel = new StackPanel
{
Width = Double.NaN,
Height = Double.NaN,
Orientation = Orientation.Vertical,
};
var scrollViewer = new ScrollViewer
{
Width = Double.NaN,
Height = this.getScrollViewerHeight(),
Margin = new Thickness(0, 0, 0, 10),
};
scrollViewer.Content = formStackPanel;
this.mainDockingPanel.Children.Add(scrollViewer);
DockPanel.SetDock(scrollViewer, Dock.Top);
if (!(selected.Tag is ApiMethod))
return;
var method = this.apiConnector.GetMethod(((ApiMethod)selected.Tag).name);
/* A header with the method's name. */
formStackPanel.Children.Add(new Label
{
Content = method.brief_description.Replace("_", "__"),
FontWeight = FontWeights.Bold,
FontSize = 14
});
/* Hyperlink to method's description page. */
var aBlockWithALink = new TextBlock { Margin = new Thickness(152, 2, 2, 2) };
var methodDescriptionHyperlink = new Hyperlink { Tag = method.ref_url };
methodDescriptionHyperlink.Inlines.Add("view full description of this method");
methodDescriptionHyperlink.Click += new RoutedEventHandler(methodDescriptionLink_Click);
aBlockWithALink.Inlines.Add(methodDescriptionHyperlink);
formStackPanel.Children.Add(aBlockWithALink);
/* Stacking method arguments textboxes... */
var arguments = method.arguments;
if (method.auth_options_token != "ignored")
arguments.Add(new ApiMethodArgument { name = "as_user_id" });
foreach (var arg in method.arguments)
{
var singleArgumentStackPanel = new StackPanel
{
Width = Double.NaN,
Height = Double.NaN,
Orientation = Orientation.Horizontal
};
/* Adding a label with a name of the argument. */
singleArgumentStackPanel.Children.Add(new Label
{
Width = 150,
Height = 28,
Content = arg.name.Replace("_", "__") + ":",
FontStyle = (arg.is_required ? FontStyles.Normal : FontStyles.Italic),
FontWeight = (arg.is_required ? FontWeights.Bold : FontWeights.Normal),
});
/* Adding a textbox for a value. */
var textbox = new TextBox { Width = 280, Height = 23, Tag = arg, BorderBrush = new SolidColorBrush(Colors.Gray) };
singleArgumentStackPanel.Children.Add(textbox);
/* Binding textbox value to cache. This will cause the text to be automatically
* filled with a value that was previously entered to it. */
this.varsCache.BindWithTextBox(method.name + "#" + arg.name, textbox);
/* Saving each textbox instance in a dictionary, in order to easily
* access it later. */
this.methodArgumentsTextboxes.Add(arg.name, textbox);
/* Stacking the entire thing on the form stack panel. */
formStackPanel.Children.Add(singleArgumentStackPanel);
}
/* Just a small margin. */
formStackPanel.Children.Add(new Label { Height = 8 });
/* SSL checkbox. */
this.useSslCheckbox = new CheckBox { Content = "Use SSL" + (method.auth_options_ssl_required == true ? " (required)" : ""),
Margin = new Thickness(150, 0, 0, 0) };
formStackPanel.Children.Add(this.useSslCheckbox);
this.varsCache.BindWithCheckBox("use_ssl", this.useSslCheckbox);
/* "Sign with..." checkboxes. */
this.signWithConsumerSecretCheckbox = new CheckBox { Content = "Sign with Consumer Key (" + method.auth_options_consumer + ")",
Margin = new Thickness(150, 0, 0, 0) };
this.signWithConsumerSecretCheckbox.Checked += new RoutedEventHandler(consumersigncheckbox_Checked);
this.signWithConsumerSecretCheckbox.Unchecked += new RoutedEventHandler(consumersigncheckbox_Unchecked);
formStackPanel.Children.Add(this.signWithConsumerSecretCheckbox);
this.signWithTokenSecretCheckbox = new CheckBox { Content = "Sign with Token (" + method.auth_options_token + ")",
IsEnabled = false, Margin = new Thickness(150, 0, 0, 0) };
formStackPanel.Children.Add(this.signWithTokenSecretCheckbox);
this.varsCache.BindWithCheckBox("sign_with_consumer_key", this.signWithConsumerSecretCheckbox);
this.varsCache.BindWithCheckBox("sign_with_token", this.signWithTokenSecretCheckbox);
/* Execute/Launch buttons. */
var buttonsStack = new StackPanel
{
Width = Double.NaN,
Height = Double.NaN,
Orientation = Orientation.Horizontal,
Margin = new Thickness(150, 0, 0, 0)
};
var theExecuteButton = new Button
{
Content = "Execute!",
Padding = new Thickness(12, 4, 12, 4),
Margin = new Thickness(0, 8, 0, 8)
};
theExecuteButton.Click += new RoutedEventHandler(executeButton_click);
buttonsStack.Children.Add(theExecuteButton);
var launchInBrowserButton = new Button
{
Content = "Launch in Browser",
Padding = new Thickness(12, 4, 12, 4),
Margin = new Thickness(8, 8, 0, 8)
};
launchInBrowserButton.Click += new RoutedEventHandler(browserButton_click);
buttonsStack.Children.Add(launchInBrowserButton);
formStackPanel.Children.Add(buttonsStack);
/* "Try to make it readable" checkbox. */
this.methodResultHumanReadableCheckbox = new CheckBox { Content = "Try to make it more human-readable" };
this.methodResultHumanReadableCheckbox.Click += new RoutedEventHandler(executeButton_click);
this.varsCache.BindWithCheckBox("make_it_readable", this.methodResultHumanReadableCheckbox);
formStackPanel.Children.Add(this.methodResultHumanReadableCheckbox);
/* We fill all the rest of the main docking panel with a single textbox - the results. */
this.methodResultTextbox = new TextBox
{
BorderBrush = new SolidColorBrush(Colors.Gray),
HorizontalScrollBarVisibility = ScrollBarVisibility.Visible,
VerticalScrollBarVisibility = ScrollBarVisibility.Visible,
IsReadOnly = true,
IsReadOnlyCaretVisible = true,
TextWrapping = TextWrapping.Wrap,
FontFamily = new FontFamily("Courier New")
};
this.mainDockingPanel.Children.Add(this.methodResultTextbox);
}
private double getScrollViewerHeight()
{
var parentHeight = this.mainDockingPanel.ActualHeight;
return parentHeight / 2;
}
void consumersigncheckbox_Checked(object sender, RoutedEventArgs e)
{
this.signWithTokenSecretCheckbox.IsEnabled = true;
}
void consumersigncheckbox_Unchecked(object sender, RoutedEventArgs e)
{
/* When a user unchecks the "sign with consumer key" checkbox, we make
* the other one (sign with a token) disabled (you can't sign with only
* a token). */
this.signWithTokenSecretCheckbox.IsChecked = false;
this.signWithTokenSecretCheckbox.IsEnabled = false;
}
void methodDescriptionLink_Click(object sender, RoutedEventArgs e)
{
/* User clicked a hyperlink to a method's description. */
Hyperlink link = (Hyperlink)sender;
string url = (string)link.Tag;
try
{
System.Diagnostics.Process.Start(url);
}
catch (Exception)
{
MessageBox.Show("It appears your system doesn't know in which application to open a http:// protocol. Check your browser settings.\n\n" + url);
return;
}
}
/// <summary>
/// Get a dictionary of currently filled argument values of
/// a currently displayed method.
/// </summary>
Dictionary<string, string> GetMethodArgs()
{
Dictionary<string, string> results = new Dictionary<string, string>();
foreach (var pair in this.methodArgumentsTextboxes)
{
string key = pair.Key;
string value = pair.Value.Text;
if (value.Length > 0)
results.Add(key, value);
}
return results;
}
/// <summary>
/// Get an URL of a currently displayed method, with all the arguments
/// and signatures applied - according to all the textboxes and checkboxes
/// in a form.
/// </summary>
string GetMethodURL()
{
TreeViewItem selected = (TreeViewItem)this.methodsTreeView.SelectedItem;
ApiMethod method = (ApiMethod)selected.Tag;
Dictionary<string, string> args = this.GetMethodArgs();
string url = this.apiConnector.GetURL(method, args,
this.signWithConsumerSecretCheckbox.IsChecked == true ? this.consumerKeyTextbox.Text : "",
this.signWithConsumerSecretCheckbox.IsChecked == true ? this.consumerSecretTextbox.Text : "",
this.signWithTokenSecretCheckbox.IsChecked == true ? this.tokenTextbox.Text : "",
this.signWithTokenSecretCheckbox.IsChecked == true ? this.tokenSecretTextbox.Text : "",
this.useSslCheckbox.IsChecked == true ? true : false);
return url;
}
/// <summary>
/// User clicks the Execute button.
/// </summary>
void executeButton_click(object sender, RoutedEventArgs e)
{
try
{
string probably_json = this.apiConnector.GetResponse(this.GetMethodURL());
if (this.methodResultHumanReadableCheckbox.IsChecked == true)
{
try
{
object obj = JsonConvert.DeserializeObject(probably_json);
if (obj == null)
this.methodResultTextbox.Text = probably_json;
else
this.methodResultTextbox.Text = obj.ToString().Replace("\\t", " ").Replace("\\n", "\n");
}
catch (JsonReaderException)
{
this.methodResultTextbox.Text = probably_json;
}
}
else
{
this.methodResultTextbox.Text = probably_json;
}
}
catch (WebException ex)
{
this.methodResultTextbox.Text = ex.Message + "\n" + ApiConnector.ReadResponse(ex.Response);
}
}
/// <summary>
/// User clicks the "Launch in Browser" button.
/// </summary>
void browserButton_click(object sender, RoutedEventArgs e)
{
try
{
System.Diagnostics.Process.Start(this.GetMethodURL());
}
catch (Exception)
{
MessageBox.Show("It appears your system doesn't know in which application to open a http:// protocol. Check your browser settings.\n\n" + this.GetMethodURL());
return;
}
}
/// <summary>
/// User clicks the "Quick Fill" button.
/// </summary>
private void quickFillButton_Click(object sender, RoutedEventArgs e)
{
if (this.consumerKeyTextbox.Text == "")
{
if (MessageBox.Show("In order to get Access Tokens, you have to register a Consumer Key first. " +
"Would you like to register a new Consumer Key now?", "Consumer Key is missing", MessageBoxButton.OKCancel,
MessageBoxImage.Question) == MessageBoxResult.OK)
{
/* Direct the user to USOS API Developer Center. */
try
{
System.Diagnostics.Process.Start(this.apiConnector.GetURL(new ApiMethod { name = "developers/" }));
}
catch (Exception)
{
MessageBox.Show("It appears your system doesn't know in which application to open a http:// protocol. Check your browser settings.\n\n" + this.apiConnector.GetURL(new ApiMethod { name = "developers/" }));
return;
}
}
return;
}
/* Show initial dialog, user will choose desired scopes. */
var initialDialog = new QuickFillWindow();
initialDialog.Owner = this;
if (initialDialog.ShowDialog() == false)
return; // user cancelled
/* Retrieve a list of selected scopes. */
List<string> scopeKeys = initialDialog.GetSelectedScopeKeys();
/* Build request_token URL. We will use 'oob' as callback, and
* require scopes which the user have selected. */
var request_token_args = new Dictionary<string,string>();
request_token_args.Add("oauth_callback", "oob");
if (scopeKeys.Count > 0)
request_token_args.Add("scopes", string.Join("|", scopeKeys));
try
{
/* Get and parse the request_token response string. */
string tokenstring;
try
{
string request_token_url = this.apiConnector.GetURL(new ApiMethod { name = "services/oauth/request_token" },
request_token_args, this.consumerKeyTextbox.Text, this.consumerSecretTextbox.Text, "", "", true);
tokenstring = this.apiConnector.GetResponse(request_token_url);
}
catch (WebException ex)
{
/* Let's try the same URL, but without SSL. This will allow it to work on
* developer installations (which do not support SSL by default). If it still
* throws exceptions, pass. */
string request_token_url = this.apiConnector.GetURL(new ApiMethod { name = "services/oauth/request_token" },
request_token_args, this.consumerKeyTextbox.Text, this.consumerSecretTextbox.Text, "", "", false);
tokenstring = this.apiConnector.GetResponse(request_token_url);
}
string request_token = null;
string request_token_secret = null;
string[] parts = tokenstring.Split('&');
foreach (string part in parts)
{
if (part.StartsWith("oauth_token="))
request_token = part.Substring("oauth_token=".Length);
if (part.StartsWith("oauth_token_secret="))
request_token_secret = part.Substring("oauth_token_secret=".Length);
}
if (request_token == null || request_token_secret == null)
{
MessageBox.Show("Couldn't parse request token. Try to do this sequence manually!", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
/* Build authorize URL and open it in user's browser. */
var authorize_args = new Dictionary<string, string>();
authorize_args.Add("oauth_token", request_token);
var authorize_url = this.apiConnector.GetURL(new ApiMethod { name = "services/oauth/authorize" }, authorize_args);
try
{
System.Diagnostics.Process.Start(authorize_url);
}
catch (Exception)
{
MessageBox.Show("It appears your system doesn't know in which application to open a http:// protocol. Check your browser settings.\n\n" + authorize_url);
return;
}
/* Open a with PIN request and wait for user's entry. */
var pinWindow = new QuickFillPINWindow();
pinWindow.Owner = this;
pinWindow.ShowDialog();
string verifier = pinWindow.GetPIN();
/* Build the access_token URL. */
var access_token_args = new Dictionary<string, string>();
access_token_args.Add("oauth_verifier", verifier);
try
{
var access_token_url = this.apiConnector.GetURL(new ApiMethod { name = "services/oauth/access_token" }, access_token_args,
this.consumerKeyTextbox.Text, this.consumerSecretTextbox.Text, request_token, request_token_secret, true);
tokenstring = this.apiConnector.GetResponse(access_token_url);
}
catch (WebException ex)
{
/* Let's try the same URL, but without SSL. This will allow it to work on
* developer installations (which do not support SSL by default). If it still
* throws exceptions, pass. */
var access_token_url = this.apiConnector.GetURL(new ApiMethod { name = "services/oauth/access_token" }, access_token_args,
this.consumerKeyTextbox.Text, this.consumerSecretTextbox.Text, request_token, request_token_secret, false);
tokenstring = this.apiConnector.GetResponse(access_token_url);
}
/* Get and parse the access_token response string. */
string access_token = null;
string access_token_secret = null;
parts = tokenstring.Split('&');
foreach (string part in parts)
{
if (part.StartsWith("oauth_token="))
access_token = part.Substring("oauth_token=".Length);
if (part.StartsWith("oauth_token_secret="))
access_token_secret = part.Substring("oauth_token_secret=".Length);
}
if (access_token == null || access_token_secret == null)
{
MessageBox.Show("Couldn't parse access token. Try to do this sequence manually!", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
/* Fill up the token textboxes with an Access Token we received. */
this.tokenTextbox.Text = access_token;
this.tokenSecretTextbox.Text = access_token_secret;
}
catch (WebException ex)
{
MessageBox.Show("A problem occured. Couldn't complete the Quick Fill.\n\n" + ex.Message + "\n"
+ ApiConnector.ReadResponse(ex.Response), "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
private void ReloadInstallation()
{
this.methodsTreeView.Items.Clear();
this.quickFillButton.IsEnabled = false;
/* Checking which installation is selected in a combo box. */
if (this.apiConnector.currentInstallation.base_url != this.installationsComboBox.Text)
{
this.apiConnector.SwitchInstallation(new ApiInstallation { base_url = this.installationsComboBox.Text });
}
if (!this.RefreshTree())
return;
this.RefreshScopes();
/* We did retrieve the list of methods, so the installation URL is OK. If it was
* entered manually (was not on the installation list in a combo box), then we add
* it to the list. */
var onthelist = false;
foreach (object item in this.installationsComboBox.Items)
{
ApiInstallation itemapi = (ApiInstallation)((ComboBoxItem)item).Tag;
if (itemapi.base_url == this.apiConnector.currentInstallation.base_url)
onthelist = true;
}
if (!onthelist)
{
this.installationsComboBox.Items.Add(new ComboBoxItem
{
Content = this.apiConnector.currentInstallation.base_url,
Tag = this.apiConnector.currentInstallation
});
}
this.quickFillButton.IsEnabled = true;
}
private void installationRefreshButton_Click(object sender, RoutedEventArgs e)
{
this.ReloadInstallation();
}
private void installationsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.dropdownopen)
{
//this.ReloadInstallation();
}
}
private bool dropdownopen = false;
private CheckBox runAsUserCheckbox;
private void installationsComboBox_DropDownClosed(object sender, EventArgs e)
{
this.dropdownopen = false;
}
private void installationsComboBox_DropDownOpened(object sender, EventArgs e)
{
this.dropdownopen = true;
}
private void installationsComboBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == System.Windows.Input.Key.Enter)
{
this.ReloadInstallation();
}
}
}
}