diff options
Diffstat (limited to '')
-rw-r--r-- | src/samples/Dtf/EmbeddedUI/SetupWizard.xaml | 17 | ||||
-rw-r--r-- | src/samples/Dtf/EmbeddedUI/SetupWizard.xaml.cs | 111 |
2 files changed, 128 insertions, 0 deletions
diff --git a/src/samples/Dtf/EmbeddedUI/SetupWizard.xaml b/src/samples/Dtf/EmbeddedUI/SetupWizard.xaml new file mode 100644 index 00000000..a43059e8 --- /dev/null +++ b/src/samples/Dtf/EmbeddedUI/SetupWizard.xaml | |||
@@ -0,0 +1,17 @@ | |||
1 | |||
2 | <!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. --> | ||
3 | |||
4 | |||
5 | <Window x:Class="WixToolset.Dtf.Samples.EmbeddedUI.SetupWizard" | ||
6 | xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
7 | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
8 | Title="Sample Embedded UI" Height="400" Width="540" Visibility="Visible"> | ||
9 | <Grid> | ||
10 | <TextBox Margin="8,8,8,63" Name="messagesTextBox" IsReadOnly="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" FontFamily="Lucida Console" FontSize="10" /> | ||
11 | <Button Height="23" HorizontalAlignment="Right" Name="installButton" VerticalAlignment="Bottom" Width="75" Click="installButton_Click" Margin="0,0,91,8">Install</Button> | ||
12 | <Button Height="23" HorizontalAlignment="Right" Name="exitButton" VerticalAlignment="Bottom" Width="75" Visibility="Hidden" Click="exitButton_Click" Margin="0,0,8,8">Exit</Button> | ||
13 | <Button Height="23" Margin="0,0,8,8" Name="cancelButton" VerticalAlignment="Bottom" Width="75" HorizontalAlignment="Right" Click="cancelButton_Click">Cancel</Button> | ||
14 | <ProgressBar Height="16" Margin="8,0,8,39" Name="progressBar" VerticalAlignment="Bottom" Visibility="Hidden" IsIndeterminate="False" /> | ||
15 | <Label Height="28" HorizontalAlignment="Left" Margin="8,0,0,4.48" Name="progressLabel" VerticalAlignment="Bottom" Width="120" Visibility="Hidden">0%</Label> | ||
16 | </Grid> | ||
17 | </Window> | ||
diff --git a/src/samples/Dtf/EmbeddedUI/SetupWizard.xaml.cs b/src/samples/Dtf/EmbeddedUI/SetupWizard.xaml.cs new file mode 100644 index 00000000..b25b8a9e --- /dev/null +++ b/src/samples/Dtf/EmbeddedUI/SetupWizard.xaml.cs | |||
@@ -0,0 +1,111 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolset.Dtf.Samples.EmbeddedUI | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Linq; | ||
8 | using System.Text; | ||
9 | using System.Threading; | ||
10 | using System.Windows; | ||
11 | using System.Windows.Controls; | ||
12 | using System.Windows.Data; | ||
13 | using System.Windows.Documents; | ||
14 | using System.Windows.Input; | ||
15 | using System.Windows.Media; | ||
16 | using System.Windows.Media.Imaging; | ||
17 | using System.Windows.Navigation; | ||
18 | using System.Windows.Shapes; | ||
19 | using WixToolset.Dtf.WindowsInstaller; | ||
20 | |||
21 | /// <summary> | ||
22 | /// Interaction logic for SetupWizard.xaml | ||
23 | /// </summary> | ||
24 | public partial class SetupWizard : Window | ||
25 | { | ||
26 | private ManualResetEvent installStartEvent; | ||
27 | private InstallProgressCounter progressCounter; | ||
28 | private bool canceled; | ||
29 | |||
30 | public SetupWizard(ManualResetEvent installStartEvent) | ||
31 | { | ||
32 | this.installStartEvent = installStartEvent; | ||
33 | this.progressCounter = new InstallProgressCounter(0.5); | ||
34 | } | ||
35 | |||
36 | public MessageResult ProcessMessage(InstallMessage messageType, Record messageRecord, | ||
37 | MessageButtons buttons, MessageIcon icon, MessageDefaultButton defaultButton) | ||
38 | { | ||
39 | try | ||
40 | { | ||
41 | this.progressCounter.ProcessMessage(messageType, messageRecord); | ||
42 | this.progressBar.Value = this.progressBar.Minimum + | ||
43 | this.progressCounter.Progress * (this.progressBar.Maximum - this.progressBar.Minimum); | ||
44 | this.progressLabel.Content = "" + (int) Math.Round(100 * this.progressCounter.Progress) + "%"; | ||
45 | |||
46 | switch (messageType) | ||
47 | { | ||
48 | case InstallMessage.Error: | ||
49 | case InstallMessage.Warning: | ||
50 | case InstallMessage.Info: | ||
51 | string message = String.Format("{0}: {1}", messageType, messageRecord); | ||
52 | this.LogMessage(message); | ||
53 | break; | ||
54 | } | ||
55 | |||
56 | if (this.canceled) | ||
57 | { | ||
58 | this.canceled = false; | ||
59 | return MessageResult.Cancel; | ||
60 | } | ||
61 | } | ||
62 | catch (Exception ex) | ||
63 | { | ||
64 | this.LogMessage(ex.ToString()); | ||
65 | this.LogMessage(ex.StackTrace); | ||
66 | } | ||
67 | |||
68 | return MessageResult.OK; | ||
69 | } | ||
70 | |||
71 | private void LogMessage(string message) | ||
72 | { | ||
73 | this.messagesTextBox.Text += Environment.NewLine + message; | ||
74 | this.messagesTextBox.ScrollToEnd(); | ||
75 | } | ||
76 | |||
77 | internal void EnableExit() | ||
78 | { | ||
79 | this.progressBar.Visibility = Visibility.Hidden; | ||
80 | this.progressLabel.Visibility = Visibility.Hidden; | ||
81 | this.cancelButton.Visibility = Visibility.Hidden; | ||
82 | this.exitButton.Visibility = Visibility.Visible; | ||
83 | } | ||
84 | |||
85 | private void installButton_Click(object sender, RoutedEventArgs e) | ||
86 | { | ||
87 | this.installButton.Visibility = Visibility.Hidden; | ||
88 | this.progressBar.Visibility = Visibility.Visible; | ||
89 | this.progressLabel.Visibility = Visibility.Visible; | ||
90 | this.installStartEvent.Set(); | ||
91 | } | ||
92 | |||
93 | private void exitButton_Click(object sender, RoutedEventArgs e) | ||
94 | { | ||
95 | this.Close(); | ||
96 | } | ||
97 | |||
98 | private void cancelButton_Click(object sender, RoutedEventArgs e) | ||
99 | { | ||
100 | if (this.installButton.Visibility == Visibility.Visible) | ||
101 | { | ||
102 | this.Close(); | ||
103 | } | ||
104 | else | ||
105 | { | ||
106 | this.canceled = true; | ||
107 | this.cancelButton.IsEnabled = false; | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | } | ||