diff options
Diffstat (limited to 'src/test/burn/TestData/WixIuiBaTests/EmbeddedUI/SetupWizard.xaml.cs')
-rw-r--r-- | src/test/burn/TestData/WixIuiBaTests/EmbeddedUI/SetupWizard.xaml.cs | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/src/test/burn/TestData/WixIuiBaTests/EmbeddedUI/SetupWizard.xaml.cs b/src/test/burn/TestData/WixIuiBaTests/EmbeddedUI/SetupWizard.xaml.cs new file mode 100644 index 00000000..a4345481 --- /dev/null +++ b/src/test/burn/TestData/WixIuiBaTests/EmbeddedUI/SetupWizard.xaml.cs | |||
@@ -0,0 +1,154 @@ | |||
1 | namespace WixToolset.Samples.EmbeddedUI | ||
2 | { | ||
3 | using System; | ||
4 | using System.Collections.Generic; | ||
5 | using System.Linq; | ||
6 | using System.Text; | ||
7 | using System.Threading; | ||
8 | using System.Windows; | ||
9 | using System.Windows.Controls; | ||
10 | using System.Windows.Data; | ||
11 | using System.Windows.Documents; | ||
12 | using System.Windows.Input; | ||
13 | using System.Windows.Media; | ||
14 | using System.Windows.Media.Imaging; | ||
15 | using System.Windows.Navigation; | ||
16 | using System.Windows.Shapes; | ||
17 | using WixToolset.Dtf.WindowsInstaller; | ||
18 | |||
19 | public enum SetupOperationType | ||
20 | { | ||
21 | Install, | ||
22 | Repair, | ||
23 | Uninstall | ||
24 | } | ||
25 | |||
26 | /// <summary> | ||
27 | /// Interaction logic for SetupWizard.xaml | ||
28 | /// </summary> | ||
29 | public partial class SetupWizard : Window | ||
30 | { | ||
31 | private bool isMaintenance; | ||
32 | private ManualResetEvent installStartEvent; | ||
33 | private InstallProgressCounter progressCounter; | ||
34 | private bool canceled; | ||
35 | |||
36 | public SetupOperationType Operation { get; private set; } | ||
37 | |||
38 | public SetupWizard(ManualResetEvent installStartEvent, bool isMaintenance) | ||
39 | { | ||
40 | this.installStartEvent = installStartEvent; | ||
41 | this.progressCounter = new InstallProgressCounter(0.5); | ||
42 | this.isMaintenance = isMaintenance; | ||
43 | |||
44 | this.Loaded += this.SetupWizard_Loaded; | ||
45 | } | ||
46 | |||
47 | private void SetupWizard_Loaded(object sender, RoutedEventArgs e) | ||
48 | { | ||
49 | this.Loaded -= this.SetupWizard_Loaded; | ||
50 | |||
51 | if (this.isMaintenance) | ||
52 | { | ||
53 | this.installButton.Visibility = Visibility.Hidden; | ||
54 | this.repairButton.Visibility = Visibility.Visible; | ||
55 | this.uninstallButton.Visibility = Visibility.Visible; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | public MessageResult ProcessMessage(InstallMessage messageType, Record messageRecord, | ||
60 | MessageButtons buttons, MessageIcon icon, MessageDefaultButton defaultButton) | ||
61 | { | ||
62 | try | ||
63 | { | ||
64 | this.progressCounter.ProcessMessage(messageType, messageRecord); | ||
65 | this.progressBar.Value = this.progressBar.Minimum + | ||
66 | this.progressCounter.Progress * (this.progressBar.Maximum - this.progressBar.Minimum); | ||
67 | this.progressLabel.Content = "" + (int) Math.Round(100 * this.progressCounter.Progress) + "%"; | ||
68 | |||
69 | switch (messageType) | ||
70 | { | ||
71 | case InstallMessage.Error: | ||
72 | case InstallMessage.Warning: | ||
73 | case InstallMessage.Info: | ||
74 | string message = String.Format("{0}: {1}", messageType, messageRecord); | ||
75 | this.LogMessage(message); | ||
76 | break; | ||
77 | } | ||
78 | |||
79 | if (this.canceled) | ||
80 | { | ||
81 | this.canceled = false; | ||
82 | return MessageResult.Cancel; | ||
83 | } | ||
84 | } | ||
85 | catch (Exception ex) | ||
86 | { | ||
87 | this.LogMessage(ex.ToString()); | ||
88 | this.LogMessage(ex.StackTrace); | ||
89 | } | ||
90 | |||
91 | return MessageResult.OK; | ||
92 | } | ||
93 | |||
94 | private void LogMessage(string message) | ||
95 | { | ||
96 | this.messagesTextBox.Text += Environment.NewLine + message; | ||
97 | this.messagesTextBox.ScrollToEnd(); | ||
98 | } | ||
99 | |||
100 | internal void EnableExit() | ||
101 | { | ||
102 | this.progressBar.Visibility = Visibility.Hidden; | ||
103 | this.progressLabel.Visibility = Visibility.Hidden; | ||
104 | this.cancelButton.Visibility = Visibility.Hidden; | ||
105 | this.exitButton.Visibility = Visibility.Visible; | ||
106 | } | ||
107 | |||
108 | private void installButton_Click(object sender, RoutedEventArgs e) | ||
109 | { | ||
110 | this.Operation = SetupOperationType.Install; | ||
111 | this.StartInstall(); | ||
112 | } | ||
113 | |||
114 | private void repairButton_Click(object sender, RoutedEventArgs e) | ||
115 | { | ||
116 | this.Operation = SetupOperationType.Repair; | ||
117 | this.StartInstall(); | ||
118 | } | ||
119 | |||
120 | private void uninstallButton_Click(object sender, RoutedEventArgs e) | ||
121 | { | ||
122 | this.Operation = SetupOperationType.Uninstall; | ||
123 | this.StartInstall(); | ||
124 | } | ||
125 | |||
126 | private void StartInstall() | ||
127 | { | ||
128 | this.installButton.Visibility = Visibility.Hidden; | ||
129 | this.repairButton.Visibility = Visibility.Hidden; | ||
130 | this.uninstallButton.Visibility = Visibility.Hidden; | ||
131 | this.progressBar.Visibility = Visibility.Visible; | ||
132 | this.progressLabel.Visibility = Visibility.Visible; | ||
133 | this.installStartEvent.Set(); | ||
134 | } | ||
135 | |||
136 | private void exitButton_Click(object sender, RoutedEventArgs e) | ||
137 | { | ||
138 | this.Close(); | ||
139 | } | ||
140 | |||
141 | private void cancelButton_Click(object sender, RoutedEventArgs e) | ||
142 | { | ||
143 | if (this.installButton.Visibility == Visibility.Visible) | ||
144 | { | ||
145 | this.Close(); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | this.canceled = true; | ||
150 | this.cancelButton.IsEnabled = false; | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | } | ||