This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFirstTimeWizard.xaml.cs
111 lines (93 loc) · 4.54 KB
/
FirstTimeWizard.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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using NgrokSharp;
namespace ngrokGUI
{
/// <summary>
/// Interaction logic for FirstTimeWizard.xaml
/// </summary>
public partial class FirstTimeWizard : Window
{
private List<ComboBoxTunnelDataTemplate> comboBoxTunnelDataTemplates = new List<ComboBoxTunnelDataTemplate>(6);
private readonly INgrokManager _ngrokManager;
public FirstTimeWizard(INgrokManager ngrokManager)
{
InitializeComponent();
foreach (var tabItem in tabcl.Items)
{
((TabItem)tabItem).IsEnabled = false;
}
comboBoxTunnelDataTemplates.Add(new ComboBoxTunnelDataTemplate() { Country = "Usa", Flag = "/Assets/Locations/icons8-usa-48.png", Region = NgrokManager.Region.UnitedStates});
comboBoxTunnelDataTemplates.Add(new ComboBoxTunnelDataTemplate() { Country = "Germany", Flag = "/Assets/Locations/icons8-germany-48.png", Region = NgrokManager.Region.Europe});
comboBoxTunnelDataTemplates.Add(new ComboBoxTunnelDataTemplate() { Country = "Singapore", Flag = "/Assets/Locations/icons8-singapore-48.png", Region = NgrokManager.Region.AsiaPacific});
comboBoxTunnelDataTemplates.Add(new ComboBoxTunnelDataTemplate() { Country = "Australia", Flag = "/Assets/Locations/icons8-australia-48.png", Region = NgrokManager.Region.Australia});
comboBoxTunnelDataTemplates.Add(new ComboBoxTunnelDataTemplate() { Country = "Brazil", Flag = "/Assets/Locations/icons8-brazil-48.png", Region = NgrokManager.Region.SouthAmerica});
comboBoxTunnelDataTemplates.Add(new ComboBoxTunnelDataTemplate() { Country = "Japan", Flag = "/Assets/Locations/icons8-japan-48.png", Region = NgrokManager.Region.Japan});
comboBoxTunnelDataTemplates.Add(new ComboBoxTunnelDataTemplate() { Country = "India", Flag = "/Assets/Locations/icons8-india-48.png", Region = NgrokManager.Region.India});
cmbTunnelExit.ItemsSource = comboBoxTunnelDataTemplates;
cmbTunnelExit.SelectedIndex = 0;
_ngrokManager = ngrokManager;
}
private async void BtnDownload_OnClick(object sender, RoutedEventArgs e)
{
if ((string)btnDownload.Content == "Next")
{
tabcl.SelectedIndex = 1;
return;
}
txtbkDownloadInstruction.Text = "Please wait while ngrok is downloading";
pbprogress.IsIndeterminate = true;
btnDownload.IsEnabled = false;
await _ngrokManager.DownloadAndUnzipNgrokAsync();
DownloadAndUnZipDone();
}
private void DownloadAndUnZipDone()
{
btnDownload.Content = "Next";
txtbkDownloadInstruction.Text = "Download completed successfully! Please click next.";
btnDownload.IsEnabled = true;
pbprogress.IsIndeterminate = false;
pbprogress.Value = 100;
}
private void BtnSelectDataCenter_OnClick(object sender, RoutedEventArgs e)
{
tabcl.SelectedIndex = 2;
}
private async void BtnAuth_OnClick(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(txtbxAuthToken.Text))
{
var dialogResult = MessageBox.Show("There is no authtoken, without one the sessions are limited to 2 hours. Are you okay with that?", "Do you want the 2 hour limit ?", MessageBoxButton.YesNo);
if (dialogResult == MessageBoxResult.No)
{
return;
}
}
if ((bool)cbxPaidAccount.IsChecked && !string.IsNullOrWhiteSpace(txtbxAuthToken.Text))
{
var dialogResult = MessageBox.Show("Are you sure have a paid Ngrok account?", "Are you sure have a paid account?", MessageBoxButton.YesNo);
if (dialogResult == MessageBoxResult.No)
{
return;
}
}
await _ngrokManager.RegisterAuthTokenAsync(txtbxAuthToken.Text);
DialogResult = true;
Close();
}
private void TxtbxAuthToken_OnTextChanged(object sender, TextChangedEventArgs e)
{
if (string.IsNullOrWhiteSpace(txtbxAuthToken.Text))
{
cbxPaidAccount.IsEnabled = false;
}
else
{
cbxPaidAccount.IsEnabled = true;
}
}
}
}