-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathLoginWindow.xaml.cs
More file actions
741 lines (661 loc) · 21.6 KB
/
LoginWindow.xaml.cs
File metadata and controls
741 lines (661 loc) · 21.6 KB
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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using Rally.RestApi.Auth;
using Rally.RestApi.Connection;
namespace Rally.RestApi.UiForWpf
{
/// <summary>
/// Interaction logic for LoginWindow.xaml
/// </summary>
internal partial class LoginWindow : Window
{
#region Enum: TabType
private enum TabType
{
Credentials,
Rally,
Proxy
}
#endregion
#region Enum: EditorControlType
private enum EditorControlType
{
Username,
Password,
ConnectionType,
RallyServer,
IdpServer,
TrustAllCertificates,
ProxyServer,
ProxyUsername,
ProxyPassword
}
#endregion
private static int ROW_HEIGHT = 28;
Dictionary<EditorControlType, Control> controls;
Dictionary<Control, Label> controlReadOnlyLabels;
Dictionary<TabType, Control> tabControls;
Dictionary<ConnectionType, string> connectionTypes;
Dictionary<EditorControlType, RowDefinition> controlRowElements;
internal RestApiAuthMgrWpf AuthMgr { get; set; }
Selector tabControl;
HeaderedContentControl rallyTab;
Button loginButton;
Button logoutButton;
Button cancelButton;
#region Constructor
/// <summary>
/// Constructor
/// </summary>
public LoginWindow()
{
InitializeComponent();
RestApiAuthMgrWpf.AllowIdpBasedSso = true;
headerLabel.Content = ApiAuthManager.LoginWindowHeaderLabelText;
controls = new Dictionary<EditorControlType, Control>();
controlReadOnlyLabels = new Dictionary<Control, Label>();
tabControls = new Dictionary<TabType, Control>();
controlRowElements = new Dictionary<EditorControlType, RowDefinition>();
connectionTypes = new Dictionary<ConnectionType, string>();
connectionTypes.Add(ConnectionType.BasicAuth, "Basic Authentication (will try CA Agile Central SSO if it fails)");
connectionTypes.Add(ConnectionType.SpBasedSso, "CA Agile Central based SSO Authentication");
connectionTypes.Add(ConnectionType.IdpBasedSso, "IDP Based SSO Authentication");
}
#endregion
internal void SetLogo(ImageSource logo, ImageSource iconForUi)
{
if (logo != null)
Logo.Source = logo;
if (iconForUi != null)
Icon = iconForUi;
}
#region UpdateLoginState
/// <summary>
/// Updates the login state to show the correct buttons.
/// </summary>
internal void UpdateLoginState()
{
bool isReadOnly = true;
switch (AuthMgr.Api.AuthenticationState)
{
case RallyRestApi.AuthenticationResult.Authenticated:
loginButton.Visibility = Visibility.Hidden;
logoutButton.Visibility = Visibility.Visible;
ShowMessage();
break;
case RallyRestApi.AuthenticationResult.PendingSSO:
loginButton.Visibility = Visibility.Hidden;
logoutButton.Visibility = Visibility.Hidden;
ShowMessage(ApiAuthManager.LoginWindowSsoInProgressText);
break;
case RallyRestApi.AuthenticationResult.NotAuthorized:
loginButton.Visibility = Visibility.Visible;
logoutButton.Visibility = Visibility.Hidden;
isReadOnly = false;
break;
default:
throw new InvalidProgramException("Unknown authentication state.");
}
SetReadOnlyStateForEditors(isReadOnly);
}
#endregion
#region BuildLayout
internal void BuildLayout(RestApiAuthMgrWpf authMgr)
{
Title = ApiAuthManager.LoginWindowTitle;
AuthMgr = authMgr;
tabControl = GetTabControl();
tabControl.Margin = new Thickness(10, 10, 10, 5);
Grid.SetColumn(tabControl, 0);
Grid.SetColumnSpan(tabControl, 3);
Grid.SetRow(tabControl, 1);
layoutGrid.Children.Add(tabControl);
AddTab(tabControl, TabType.Credentials);
AddTab(tabControl, TabType.Rally);
AddTab(tabControl, TabType.Proxy);
AddButtons();
inputRow.Height = new GridLength(tabControl.Height + 20, GridUnitType.Pixel);
inputRow.MinHeight = inputRow.Height.Value;
Height = inputRow.Height.Value + (28 * 2) + 100;
MinHeight = Height;
MaxHeight = Height;
SetDefaultValues();
ConnectionTypeChanged(GetEditor(EditorControlType.ConnectionType), null);
}
#endregion
#region GetTabControl
private Selector GetTabControl()
{
Selector selector;
Type tabControlType = RestApiAuthMgrWpf.GetCustomControlType(CustomWpfControlType.TabControl);
if (tabControlType == null)
selector = new TabControl();
else
selector = (Selector)Activator.CreateInstance(tabControlType);
return selector;
}
#endregion
#region SetDefaultValues
private void SetDefaultValues()
{
Array controlTypes = Enum.GetValues(typeof(EditorControlType));
foreach (EditorControlType editorControlType in controlTypes)
{
Control control = GetEditor(editorControlType);
if (control is TextBox)
{
TextBox textBox = control as TextBox;
if (textBox != null)
{
switch (editorControlType)
{
case EditorControlType.Username:
if (AuthMgr.Api.ConnectionInfo != null)
textBox.Text = AuthMgr.Api.ConnectionInfo.UserName;
else
textBox.Text = AuthMgr.LoginDetails.Username;
break;
case EditorControlType.RallyServer:
if (!String.IsNullOrWhiteSpace(AuthMgr.LoginDetails.RallyServer))
{
textBox.Text = AuthMgr.LoginDetails.RallyServer;
}
else if (ApiAuthManager.LoginWindowDefaultServer != null)
textBox.Text = ApiAuthManager.LoginWindowDefaultServer.ToString();
else
textBox.Text = RallyRestApi.DEFAULT_SERVER;
break;
case EditorControlType.IdpServer:
textBox.Text = AuthMgr.LoginDetails.IdpServer;
break;
case EditorControlType.ProxyServer:
if (AuthMgr.LoginDetails.ProxyServer != null)
textBox.Text = AuthMgr.LoginDetails.ProxyServer;
else if (ApiAuthManager.LoginWindowDefaultProxyServer != null)
textBox.Text = ApiAuthManager.LoginWindowDefaultProxyServer.ToString();
break;
case EditorControlType.ProxyUsername:
textBox.Text = AuthMgr.LoginDetails.ProxyUsername;
break;
default:
throw new InvalidProgramException("The specified editor does not use a text box to set the value.");
}
}
}
else if (control is PasswordBox)
{
PasswordBox passwordBox = control as PasswordBox;
if (passwordBox != null)
{
switch (editorControlType)
{
case EditorControlType.Password:
// Password for user credentials is never sent back to the UI.
break;
case EditorControlType.ProxyPassword:
passwordBox.Password = AuthMgr.LoginDetails.GetProxyPassword();
break;
default:
throw new InvalidProgramException("The specified editor does not use a password box to set the value.");
}
}
}
else if (control is ComboBox)
{
ComboBox comboBox = control as ComboBox;
if (comboBox != null)
{
switch (editorControlType)
{
case EditorControlType.ConnectionType:
// Due to errors in sequencing, we are removing the event listener while we set the value.
comboBox.SelectionChanged -= ConnectionTypeChanged;
comboBox.SelectedValue = AuthMgr.LoginDetails.ConnectionType;
comboBox.SelectionChanged += ConnectionTypeChanged;
// We then trigger the event manually here.
ConnectionTypeChanged(comboBox, null);
break;
default:
throw new InvalidProgramException("The specified editor does not use a password box to set the value.");
}
}
}
else if (control is CheckBox)
{
CheckBox checkBox = control as CheckBox;
if (checkBox != null)
{
switch (editorControlType)
{
case EditorControlType.TrustAllCertificates:
checkBox.IsChecked = AuthMgr.LoginDetails.TrustAllCertificates;
break;
default:
throw new InvalidProgramException("The specified editor does not use a checkbox to set the value.");
}
}
}
else
throw new InvalidProgramException("Unknown handling of control type.");
}
}
#endregion
#region SetReadOnlyStateForEditor
private void SetReadOnlyStateForEditors(bool isReadOnly)
{
Array controlTypes = Enum.GetValues(typeof(EditorControlType));
foreach (EditorControlType editorControlType in controlTypes)
{
Control control = GetEditor(editorControlType);
if (isReadOnly)
{
control.Visibility = Visibility.Hidden;
}
else
control.Visibility = Visibility.Visible;
if (controlReadOnlyLabels.ContainsKey(control))
{
Label label = controlReadOnlyLabels[control];
if (control is TextBox)
{
TextBox textBox = control as TextBox;
if (textBox != null)
label.Content = textBox.Text;
}
else if (control is ComboBox)
{
ComboBox comboBox = control as ComboBox;
if (comboBox != null)
label.Content = comboBox.Text;
}
else if (control is CheckBox)
{
if (editorControlType == EditorControlType.TrustAllCertificates)
label.Content = GetEditorValueAsBool(EditorControlType.TrustAllCertificates).ToString();
}
if (isReadOnly)
label.Visibility = Visibility.Visible;
else
label.Visibility = Visibility.Hidden;
}
}
}
#endregion
#region AddTab
private void AddTab(Selector tabControl, TabType tabType)
{
HeaderedContentControl tab = GetTabItem();
tabControl.Items.Add(tab);
tabControls.Add(tabType, tab);
Grid tabGrid = new Grid();
tab.Content = tabGrid;
tabGrid.HorizontalAlignment = HorizontalAlignment.Stretch;
tabGrid.VerticalAlignment = VerticalAlignment.Top;
AddColumnDefinition(tabGrid, 120);
AddColumnDefinition(tabGrid);
if (tabType == TabType.Credentials)
{
tab.Header = ApiAuthManager.LoginWindowCredentialsTabText;
AddInputToTabGrid(tabGrid, ApiAuthManager.LoginWindowUserNameLabelText, EditorControlType.Username);
AddInputToTabGrid(tabGrid, ApiAuthManager.LoginWindowPwdLabelText, EditorControlType.Password, true);
}
else if (tabType == TabType.Rally)
{
rallyTab = tab;
tab.Header = ApiAuthManager.LoginWindowRallyServerTabText;
AddInputToTabGrid(tabGrid, ApiAuthManager.LoginWindowConnectionTypeText, EditorControlType.ConnectionType);
AddInputToTabGrid(tabGrid, ApiAuthManager.LoginWindowServerLabelText, EditorControlType.RallyServer);
AddInputToTabGrid(tabGrid, ApiAuthManager.LoginWindowServerLabelText, EditorControlType.IdpServer);
AddInputToTabGrid(tabGrid, ApiAuthManager.LoginWindowTrustAllCertificatesText, EditorControlType.TrustAllCertificates);
}
else if (tabType == TabType.Proxy)
{
tab.Header = ApiAuthManager.LoginWindowProxyServerTabText;
AddInputToTabGrid(tabGrid, ApiAuthManager.LoginWindowProxyServerLabelText, EditorControlType.ProxyServer);
AddInputToTabGrid(tabGrid, ApiAuthManager.LoginWindowProxyUserNameLabelText, EditorControlType.ProxyUsername);
AddInputToTabGrid(tabGrid, ApiAuthManager.LoginWindowProxyPwdLabelText, EditorControlType.ProxyPassword, true);
}
else
throw new NotImplementedException();
if ((tabControl.Height.ToString().Equals("NaN", StringComparison.InvariantCultureIgnoreCase)) ||
(tabControl.Height < tabGrid.Height + 20))
{
tabControl.Height = tabGrid.Height + 20;
tabControl.MinHeight = tabControl.Height;
}
}
#endregion
#region GetTabItem
private HeaderedContentControl GetTabItem()
{
HeaderedContentControl tabItem;
Type tabItemType = RestApiAuthMgrWpf.GetCustomControlType(CustomWpfControlType.TabItem);
if (tabItemType == null)
tabItem = new TabItem();
else
tabItem = (HeaderedContentControl)Activator.CreateInstance(tabItemType);
return tabItem;
}
#endregion
#region AddInputToTabGrid
private void AddInputToTabGrid(Grid tabGrid, string labelText, EditorControlType controlType, bool skipReadOnlyLabel = false)
{
Control control = GetEditor(controlType);
int rowIndex = tabGrid.RowDefinitions.Count;
AddRowDefinition(tabGrid, controlType, ROW_HEIGHT);
Label label = new Label();
label.Content = labelText;
label.FontWeight = FontWeights.Bold;
AddControlToGrid(tabGrid, label, rowIndex, 0);
if (control != null)
{
AddControlToGrid(tabGrid, control, rowIndex, 1);
if (!skipReadOnlyLabel)
{
Label readOnlyLabel = new Label();
controlReadOnlyLabels.Add(control, readOnlyLabel);
AddControlToGrid(tabGrid, readOnlyLabel, rowIndex, 1);
}
}
}
#endregion
#region GetEditor
private Control GetEditor(EditorControlType controlType, string defaultValue = null)
{
Control control = null;
if (controls.ContainsKey(controlType))
control = controls[controlType];
else
{
switch (controlType)
{
case EditorControlType.Username:
case EditorControlType.RallyServer:
case EditorControlType.IdpServer:
case EditorControlType.ProxyServer:
case EditorControlType.ProxyUsername:
TextBox textBox = new TextBox();
control = textBox;
break;
case EditorControlType.Password:
case EditorControlType.ProxyPassword:
PasswordBox passwordBox = new PasswordBox();
passwordBox.PasswordChar = '*';
control = passwordBox;
break;
case EditorControlType.ConnectionType:
ComboBox comboBox = new ComboBox();
comboBox.SelectedValuePath = "Key";
comboBox.DisplayMemberPath = "Value";
if ((!RestApiAuthMgrWpf.AllowIdpBasedSso) &&
(connectionTypes.ContainsKey(ConnectionType.IdpBasedSso)))
{
connectionTypes.Remove(ConnectionType.IdpBasedSso);
}
comboBox.ItemsSource = connectionTypes;
comboBox.SelectionChanged += ConnectionTypeChanged;
control = comboBox;
break;
case EditorControlType.TrustAllCertificates:
CheckBox checkBox = new CheckBox();
control = checkBox;
break;
default:
throw new NotImplementedException();
}
control.Margin = new Thickness(0, 0, 10, 0);
control.HorizontalAlignment = HorizontalAlignment.Stretch;
control.MinWidth = 150;
control.Height = 20;
controls.Add(controlType, control);
}
return control;
}
#endregion
#region ConnectionTypeChanged
void ConnectionTypeChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox comboBox = sender as ComboBox;
if (comboBox != null)
{
AuthMgr.LoginDetails.ConnectionType = (ConnectionType)comboBox.SelectedValue;
switch (AuthMgr.LoginDetails.ConnectionType)
{
case ConnectionType.BasicAuth:
SetTabVisibility(TabType.Credentials, true);
SetControlVisibility(EditorControlType.Password, true);
SetControlVisibility(EditorControlType.RallyServer, true);
SetControlVisibility(EditorControlType.IdpServer, false);
break;
case ConnectionType.SpBasedSso:
SetTabVisibility(TabType.Credentials, true);
SetControlVisibility(EditorControlType.Password, false);
SetControlVisibility(EditorControlType.RallyServer, true);
SetControlVisibility(EditorControlType.IdpServer, false);
break;
case ConnectionType.IdpBasedSso:
SetTabVisibility(TabType.Credentials, false);
SetControlVisibility(EditorControlType.RallyServer, false);
SetControlVisibility(EditorControlType.IdpServer, true);
tabControl.SelectedItem = rallyTab;
break;
default:
throw new NotImplementedException();
}
rallyTab.Focus();
}
}
#endregion
#region SetTabVisibility
private void SetTabVisibility(TabType tabType, bool isVisible)
{
if (isVisible)
{
tabControls[tabType].Visibility = Visibility.Visible;
tabControls[tabType].Width = double.NaN;
}
else
{
tabControls[tabType].Visibility = Visibility.Hidden;
tabControls[tabType].Width = 0.0;
}
}
#endregion
#region SetControlVisibility
private void SetControlVisibility(EditorControlType controlType, bool isVisible)
{
if (isVisible)
{
controlRowElements[controlType].Height = new GridLength(ROW_HEIGHT);
}
else
{
controlRowElements[controlType].Height = new GridLength(0.0);
}
}
#endregion
#region GetEditorValue
private string GetEditorValue(EditorControlType controlType)
{
Control control = GetEditor(controlType);
if (control == null)
return null;
TextBox textBox = control as TextBox;
if (textBox != null && controlType == EditorControlType.IdpServer)
return AuthMgr.LoginDetails.RedirectIfIdpPointsAtLoginSso(textBox.Text);
if (textBox != null)
return textBox.Text;
PasswordBox passwordBox = control as PasswordBox;
if (passwordBox != null)
return passwordBox.Password;
return null;
}
#endregion
#region GetEditorValueAsBool
private bool GetEditorValueAsBool(EditorControlType controlType)
{
Control control = GetEditor(controlType);
if (control == null)
return false;
CheckBox checkBox = control as CheckBox;
if (checkBox != null)
{
if (checkBox.IsChecked.HasValue)
return checkBox.IsChecked.Value;
}
return false;
}
#endregion
#region AddButtons
private void AddButtons()
{
Grid buttonGrid = new Grid();
Grid.SetColumn(buttonGrid, 2);
Grid.SetRow(buttonGrid, 3);
layoutGrid.Children.Add(buttonGrid);
AddRowDefinition(buttonGrid, null, 30);
buttonGrid.Height = 100;
AddColumnDefinition(buttonGrid, 70);
AddColumnDefinition(buttonGrid, 70);
AddColumnDefinition(buttonGrid);
loginButton = GetButton();
loginButton.IsDefault = true;
loginButton.Content = ApiAuthManager.LoginWindowLoginText;
loginButton.Click += loginButton_Click;
AddControlToGrid(buttonGrid, loginButton, 1, 0);
logoutButton = GetButton();
logoutButton.Content = ApiAuthManager.LoginWindowLogoutText;
logoutButton.Click += logoutButton_Click;
AddControlToGrid(buttonGrid, logoutButton, 1, 0);
cancelButton = GetButton();
cancelButton.Content = ApiAuthManager.LoginWindowCancelText;
cancelButton.Click += cancelButton_Click;
AddControlToGrid(buttonGrid, cancelButton, 1, 1);
}
#endregion
#region GetButton
private Button GetButton()
{
Button button;
Type buttonType = RestApiAuthMgrWpf.GetCustomControlType(CustomWpfControlType.Buttons);
if (buttonType == null)
button = new Button();
else
button = (Button)Activator.CreateInstance(buttonType);
button.Margin = new Thickness(5, 0, 5, 0);
button.Height = 25;
return button;
}
#endregion
#region AddControlToGrid
private void AddControlToGrid(Grid grid, UIElement control, int row, int column, int rowSpan = 1, int colSpan = 1)
{
if (row >= 0)
Grid.SetRow(control, row);
if (rowSpan > 1)
Grid.SetRowSpan(control, rowSpan);
if (column >= 0)
Grid.SetColumn(control, column);
if (colSpan > 1)
Grid.SetColumnSpan(control, colSpan);
grid.Children.Add(control);
}
#endregion
#region AddRowDefinition
private void AddRowDefinition(Grid grid, EditorControlType? controlType, int pixels = Int32.MaxValue)
{
RowDefinition rowDef = new RowDefinition();
if (pixels == Int32.MaxValue)
rowDef.Height = GridLength.Auto;
else
rowDef.Height = new GridLength(pixels, GridUnitType.Pixel);
grid.RowDefinitions.Add(rowDef);
if (controlType.HasValue)
controlRowElements.Add(controlType.Value, rowDef);
if (pixels != Int32.MaxValue)
{
grid.MinHeight += pixels + 2;
grid.Height = grid.MinHeight;
}
else
grid.Height = double.NaN;
}
#endregion
#region AddColumnDefinition
private void AddColumnDefinition(Grid grid, int pixels = Int32.MaxValue)
{
ColumnDefinition colDef = new ColumnDefinition();
if (pixels != Int32.MaxValue)
colDef.Width = new GridLength(pixels, GridUnitType.Pixel);
grid.ColumnDefinitions.Add(colDef);
}
#endregion
#region loginButton_Click
void loginButton_Click(object sender, RoutedEventArgs e)
{
string errorMessage;
ShowMessage("Logging into CA Agile Central");
AuthMgr.LoginDetails.Username = GetEditorValue(EditorControlType.Username);
AuthMgr.LoginDetails.SetPassword(GetEditorValue(EditorControlType.Password));
AuthMgr.LoginDetails.RallyServer = GetEditorValue(EditorControlType.RallyServer);
AuthMgr.LoginDetails.IdpServer = GetEditorValue(EditorControlType.IdpServer);
AuthMgr.LoginDetails.ProxyServer = GetEditorValue(EditorControlType.ProxyServer);
AuthMgr.LoginDetails.ProxyUsername = GetEditorValue(EditorControlType.ProxyUsername);
AuthMgr.LoginDetails.SetProxyPassword(GetEditorValue(EditorControlType.ProxyPassword));
AuthMgr.LoginDetails.TrustAllCertificates = GetEditorValueAsBool(EditorControlType.TrustAllCertificates);
AuthMgr.PerformAuthenticationCheck(out errorMessage);
ShowMessage(errorMessage);
UpdateLoginState();
if (AuthMgr.Api.AuthenticationState == RallyRestApi.AuthenticationResult.Authenticated)
Close();
}
#endregion
#region logoutButton_Click
void logoutButton_Click(object sender, RoutedEventArgs e)
{
AuthMgr.PerformLogout();
SetDefaultValues();
UpdateLoginState();
}
#endregion
#region cancelButton_Click
void cancelButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
#endregion
#region SsoAuthenticationComplete
internal void SsoAuthenticationComplete(RallyRestApi.AuthenticationResult authenticationResult, RallyRestApi api)
{
if (authenticationResult == RallyRestApi.AuthenticationResult.Authenticated)
Close();
else
{
UpdateLoginState();
}
}
#endregion
#region ShowMessage
private void ShowMessage(string message = "")
{
userMessages.Content = message;
// Sleep to allow UI to update.
Thread.CurrentThread.Join(10);
}
#endregion
#region OnClosing
protected override void OnClosing(CancelEventArgs e)
{
AuthMgr.LoginWindowSsoAuthenticationComplete = null;
base.OnClosing(e);
}
#endregion
}
}