This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
/
InstallerControl.cs
189 lines (162 loc) · 7.17 KB
/
InstallerControl.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using CompatCheckAndMigrate.Helpers;
using CompatCheckAndMigrate.ObjectModel;
namespace CompatCheckAndMigrate.Controls
{
public partial class InstallerControl : UserControl, IWizardStep
{
private BackgroundWorker _worker;
private BackgroundWorker _worker2;
private Dictionary<string, InstallerItemControl> _productControlMap;
private InstallHelper _installHelper;
public InstallerControl()
{
InitializeComponent();
_productControlMap = new Dictionary<string, InstallerItemControl>(StringComparer.OrdinalIgnoreCase);
}
public event EventHandler<GoToWizardStepEventArgs> GoTo;
public void SetState(object state, bool isNavigatingBack = false)
{
}
private void FireGoToEvent(WizardSteps step, object state = null)
{
EventHandler<GoToWizardStepEventArgs> _goTo = GoTo;
if (_goTo != null)
{
_goTo(this, new GoToWizardStepEventArgs(step, state));
}
}
public void UpdateInstallStatus(string productName, string status, bool isComplete)
{
try
{
InstallerItemControl installerItem;
if (_productControlMap.TryGetValue(productName, out installerItem))
{
installerItem.UpdateStatus(status, isComplete);
}
}
catch (Exception ex)
{
_installHelper.LogInformation(ex.ToString());
TraceHelper.Tracer.WriteTrace(ex.ToString());
}
}
public void UpdateInstallStatus(string productName, string status)
{
UpdateInstallStatus(productName, status, false);
}
public void MarkAllProductsComplete()
{
if (_installHelper.IsRebootNeeded)
{
Helper.ShowErrorMessageAndExit("Reboot the system and restart the tool");
}
try
{
foreach (var keyvalue in _productControlMap)
{
keyvalue.Value.UpdateStatus("Finished", true);
}
_installHelper.LogInformation("All products installed successfully");
_installHelper.Dispose();
}
catch (Exception ex)
{
TraceHelper.Tracer.WriteTrace(ex.ToString());
_installHelper.LogInformation(ex.ToString());
_installHelper.Dispose();
}
if (Helper.IisVersion < 7)
{
_worker = new BackgroundWorker();
_worker.DoWork += (object doWorkSender, DoWorkEventArgs doWorkEventArgs) =>
{
this.Invoke(new MethodInvoker(delegate()
{
this.busyPictureBox.Visible = this.busyMessageLabel.Visible = true;
this.busyMessageLabel.Text = "Installing DacFx and Upgrading Web Deploy to 3.6. Please wait";
}));
var msiArray = Helper.Is64Bit
? MigrationConstants.DacFxMsiArray64bit
: MigrationConstants.DacFxMsiArray32bit;
foreach (var id in msiArray)
{
string path = Helper.GetMsiFile(string.Format(MigrationConstants.DacfxUrlFormat, id),
id + ".msi");
Helper.ExecuteFile(string.Format(" /q /i \"{0}\"", path));
}
var webDeploy = Helper.Is64Bit
? MigrationConstants.WebDeployMSI64
: MigrationConstants.WebDeployMSI32;
string filepath = Helper.GetMsiFile(webDeploy, "webdeploy3.6beta.msi");
Helper.ExecuteFile(string.Format(" /q /i \"{0}\"", filepath));
};
_worker.RunWorkerCompleted +=
(object runWorkerCompletedSender, RunWorkerCompletedEventArgs runWorkerCompletedEventArgs) =>
{
// Hide busy animation.
this.busyPictureBox.Visible = this.busyMessageLabel.Visible = false;
if (runWorkerCompletedEventArgs.Error != null)
{
Helper.ShowErrorMessageAndExit(runWorkerCompletedEventArgs.Error.Message);
}
this.Invoke(
new MethodInvoker(delegate() { FireGoToEvent(WizardSteps.RemoteComputerInfo, null); }));
};
_worker.RunWorkerAsync();
}
else
{
this.Invoke(new MethodInvoker(delegate() { FireGoToEvent(WizardSteps.RemoteComputerInfo, null); }));
}
}
private void InstallerControl_Load(object sender, EventArgs e)
{
this.busyPictureBox.Visible = this.busyMessageLabel.Visible = true;
_worker = new BackgroundWorker();
_worker2 = new BackgroundWorker();
_worker.DoWork += (object doWorkSender, DoWorkEventArgs doWorkEventArgs) =>
{
string filePath = Helper.GetMsiFile(MigrationConstants.WebPIUrl64, "webpi.msi");
string pathToExecute = string.Format(" /q /i \"{0}\"", filePath);
//MessageBox.Show(pathToExecute);
Helper.ExecuteFile(pathToExecute);
_installHelper = Helper.SetupInstall();
};
_worker.RunWorkerCompleted += (object runWorkerCompletedSender, RunWorkerCompletedEventArgs runWorkerCompletedEventArgs) =>
{
// Hide busy animation.
this.busyPictureBox.Visible = this.busyMessageLabel.Visible = false;
if (runWorkerCompletedEventArgs.Error != null)
{
Helper.ShowErrorMessageAndExit(runWorkerCompletedEventArgs.Error.Message);
}
foreach (var product in _installHelper.ProductList)
{
var installerItem = new InstallerItemControl(product);
installerItem.Dock = DockStyle.Top;
statusPanel.Controls.Add(installerItem);
_productControlMap[product] = installerItem;
}
_worker2.RunWorkerAsync();
};
_worker2.DoWork += (object doWorkSender, DoWorkEventArgs doWorkEventArgs) =>
{
_installHelper.BeginInstall(this);
};
_worker2.RunWorkerCompleted += (object runWorkerCompletedSender, RunWorkerCompletedEventArgs runWorkerCompletedEventArgs) =>
{
if (runWorkerCompletedEventArgs.Error != null)
{
_installHelper.LogInformation(runWorkerCompletedEventArgs.Error.Message);
Helper.ShowErrorMessageAndExit(runWorkerCompletedEventArgs.Error.Message);
}
};
_worker.RunWorkerAsync();
}
}
}