Skip to content

Commit 9a80dc9

Browse files
CitrixChrisKonstantina Chremmou
andauthored
CP-40844: Adds download source action that gets the latest source code in the production stage (xenserver#3153)
* CP-40844 adds download source action that gets the latest source code in the production stage. Signed-off-by: Chris Lancaster <[email protected]> CP-40844 refactors download file actions Signed-off-by: Chris Lancaster <[email protected]> Adds source url to branding.sh Signed-off-by: Chris Lancaster <[email protected]> CP40844 refactors code and implements reviewers comments, aswell as better message handeling Signed-off-by: Chris Lancaster <[email protected]> CP-40844 Sorts messages Signed-off-by: Chris Lancaster <[email protected]> CP-40844 removes stray console logging Signed-off-by: Chris Lancaster <[email protected]> CP-40844 Changes to use FirstOrDefault to avoid null exceptions/errors Signed-off-by: Chris Lancaster <[email protected]> CP-40844 removes unessessary usings Signed-off-by: Chris Lancaster <[email protected]> CP-40844 code tidy up Signed-off-by: Chris Lancaster <[email protected]> CP-40844 Removes erroneous root tag from merge conflict resolution Signed-off-by: Chris Lancaster <[email protected]> CP-40844 sorts messages Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 fixes misnamed method and adds sourceurl parameter to brandmanager Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 Source url now uses XCUpdates url and just substitues the name of the file Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 Adds source url to xenadmin-build.ps1 Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 defines log4net in each class not just inherited Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 removes unused class variable Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 removes unneeded class variable and uses parent property instead. Simplifies messages for source download and client update. Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 reduces public exposure of member variables/properties Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 merges download x file actions into single file. Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 overide ReleaseDownloadedContent in DownloadAndUpdateClientAction to handle disposal of FileStream Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 minor fixes/tidy up Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 defaults the download latest source button to be invisible. Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 if there is no client update detected then we shouldnt show a where to save dialog Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 Directs user to xenserver website to download source if automatic update checks are turned off. Renames message OUT_OF_DATE_WEBSITE to WEBSITE_DOWNLOADS Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 updates source param to sourceUrl in XCUpdates.xml Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 moves strings to Messages and applys source name string to relevant places Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 removes sourceurl from brand manager Signed-off-by: Chris Lancaster <[email protected]> * CP-40844 uses string literal rather than string join Signed-off-by: Chris Lancaster <[email protected]> * Some more corrections. Signed-off-by: Konstantina Chremmou <[email protected]> --------- Signed-off-by: Chris Lancaster <[email protected]> Signed-off-by: Konstantina Chremmou <[email protected]> Co-authored-by: Konstantina Chremmou <[email protected]>
1 parent ad8ef2e commit 9a80dc9

File tree

16 files changed

+327
-117
lines changed

16 files changed

+327
-117
lines changed

XenAdmin/Alerts/Types/ClientUpdateAlert.cs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
using System;
3232
using System.Diagnostics;
3333
using System.IO;
34+
using System.Linq;
3435
using System.Windows.Forms;
3536
using XenAdmin.Actions;
3637
using XenAdmin.Actions.GUIActions;
3738
using XenAdmin.Actions.Updates;
3839
using XenAdmin.Core;
3940
using XenAdmin.Dialogs;
40-
41+
using XenAdmin.Dialogs.WarningDialogs;
42+
using XenCenterLib;
4143

4244
namespace XenAdmin.Alerts
4345
{
@@ -123,28 +125,63 @@ public static void DownloadAndInstallNewClient(ClientUpdateAlert updateAlert, IW
123125

124126
if (currentTasks)
125127
{
126-
if (new Dialogs.WarningDialogs.CloseXenCenterWarningDialog(true).ShowDialog(parent) != DialogResult.OK)
128+
using (var dlg = new CloseXenCenterWarningDialog(true))
127129
{
128-
downloadAndInstallClientAction.ReleaseInstaller();
129-
return;
130+
if (dlg.ShowDialog(parent) != DialogResult.OK)
131+
{
132+
downloadAndInstallClientAction.ReleaseDownloadedContent();
133+
return;
134+
}
130135
}
131136
}
132137

133138
try
134139
{
135140
Process.Start(outputPathAndFileName);
136141
log.DebugFormat("Update {0} found and install started", updateAlert.Name);
137-
downloadAndInstallClientAction.ReleaseInstaller();
142+
downloadAndInstallClientAction.ReleaseDownloadedContent();
138143
Application.Exit();
139144
}
140145
catch (Exception e)
141146
{
142147
log.Error("Exception occurred when starting the installation process.", e);
143-
downloadAndInstallClientAction.ReleaseInstaller(true);
148+
downloadAndInstallClientAction.ReleaseDownloadedContent(true);
144149

145150
using (var dlg = new ErrorDialog(Messages.UPDATE_CLIENT_FAILED_INSTALLER_LAUNCH))
146151
dlg.ShowDialog(parent);
147152
}
148153
}
154+
155+
public static void DownloadSource(IWin32Window parent)
156+
{
157+
// If no update no need to show where to save dialog
158+
var clientVersion = Updates.ClientVersions.FirstOrDefault();
159+
160+
if (clientVersion == null)
161+
{
162+
// There is no XCUpdates.xml so direct to website.
163+
Program.OpenURL(InvisibleMessages.WEBSITE_DOWNLOADS);
164+
}
165+
else
166+
{
167+
string outputPathAndFileName;
168+
using (var saveSourceDialog = new SaveFileDialog())
169+
{
170+
saveSourceDialog.FileName = $"{BrandManager.BrandConsole}-v{clientVersion.Version}-source.zip";
171+
saveSourceDialog.DefaultExt = "zip";
172+
saveSourceDialog.Filter = "(*.zip)|*.zip|All files (*.*)|*.*";
173+
saveSourceDialog.InitialDirectory = Win32.GetKnownFolderPath(Win32.KnownFolders.Downloads);
174+
175+
if (saveSourceDialog.ShowDialog(parent) != DialogResult.OK)
176+
{
177+
return;
178+
}
179+
outputPathAndFileName = saveSourceDialog.FileName;
180+
}
181+
182+
var downloadSourceAction = new DownloadSourceAction(clientVersion.Name, new Uri(clientVersion.SourceUrl), outputPathAndFileName);
183+
downloadSourceAction.RunAsync();
184+
}
185+
}
149186
}
150187
}

XenAdmin/Alerts/Types/GuiOldAlert.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public GuiOldAlert()
4949

5050
public override Action FixLinkAction
5151
{
52-
get { return () => Program.OpenURL(InvisibleMessages.OUT_OF_DATE_WEBSITE); }
52+
get { return () => Program.OpenURL(InvisibleMessages.WEBSITE_DOWNLOADS); }
5353
}
5454

5555
public override string FixLinkText => Messages.ALERT_NEW_VERSION_DOWNLOAD;

XenAdmin/Core/Updates.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class Updates
6767

6868
private static List<XenServerVersion> XenServerVersionsForAutoCheck = new List<XenServerVersion>();
6969
private static List<XenServerPatch> XenServerPatches = new List<XenServerPatch>();
70-
private static List<ClientVersion> ClientVersions = new List<ClientVersion>();
70+
public static List<ClientVersion> ClientVersions = new List<ClientVersion>();
7171
public static List<XenServerVersion> XenServerVersions = new List<XenServerVersion>();
7272

7373
private static readonly List<Alert> updateAlerts = new List<Alert>();

XenAdmin/MainWindow.Designer.cs

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

XenAdmin/MainWindow.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
using XenAdmin.Controls.GradientPanel;
6363
using XenAdmin.Dialogs.ServerUpdates;
6464
using XenAdmin.Help;
65+
using XenAdmin.Actions.Updates;
6566

6667
namespace XenAdmin
6768
{
@@ -269,6 +270,7 @@ public MainWindow(string[] args)
269270
statusButtonAlerts.Visible = statusButtonUpdates.Visible = statusButtonCdnUpdates.Visible = statusButtonProgress.Visible = statusButtonErrors.Visible = false;
270271
statusButtonUpdates.ToolTipText = string.Format(statusButtonUpdates.ToolTipText, BrandManager.ProductVersion821);
271272
statusButtonCdnUpdates.ToolTipText = string.Format(statusButtonCdnUpdates.ToolTipText, BrandManager.ProductBrand, BrandManager.ProductVersionPost82);
273+
downloadLatestSourceToolStripMenuItem.Text = Messages.DOWNLOAD_LATEST_SOURCE;
272274
}
273275

274276
private void RegisterEvents()
@@ -966,7 +968,7 @@ private void connection_CachePopulated(IXenConnection connection)
966968
Program.Invoke(Program.MainWindow, delegate
967969
{
968970
var msg = string.Format(Messages.GUI_OUT_OF_DATE, BrandManager.BrandConsole, Helpers.GetName(coordinator));
969-
var url = InvisibleMessages.OUT_OF_DATE_WEBSITE;
971+
var url = InvisibleMessages.WEBSITE_DOWNLOADS;
970972
var title = string.Format(Messages.CONNECTION_REFUSED_TITLE, Helpers.GetName(coordinator).Ellipsise(80));
971973
var error = $"{msg}\n{url}";
972974

@@ -994,7 +996,7 @@ private void connection_CachePopulated(IXenConnection connection)
994996
{
995997
var msg = string.Format(Messages.GUI_NOT_COMPATIBLE, BrandManager.BrandConsole, BrandManager.ProductVersion712,
996998
BrandManager.ProductVersion80, Helpers.GetName(coordinator));
997-
var url = InvisibleMessages.OUT_OF_DATE_WEBSITE;
999+
var url = InvisibleMessages.WEBSITE_DOWNLOADS;
9981000
var title = string.Format(Messages.CONNECTION_REFUSED_TITLE, Helpers.GetName(coordinator).Ellipsise(80));
9991001
var error = $"{msg}\n{url}";
10001002

@@ -2715,7 +2717,14 @@ private void SetClientUpdateAlert()
27152717
{
27162718
updateAlert = Updates.ClientUpdateAlerts.FirstOrDefault();
27172719
if (updateAlert != null)
2720+
{
27182721
relNotesToolStripMenuItem.Text = string.Format(Messages.MAINWINDOW_UPDATE_RELEASE, updateAlert.NewVersion.Version);
2722+
downloadSourceToolStripMenuItem.Text = string.Format(Messages.DOWNLOAD_SOURCE, BrandManager.BrandConsole, updateAlert.NewVersion.Version);
2723+
}
2724+
var clientVersion = Updates.ClientVersions.FirstOrDefault();
2725+
downloadLatestSourceToolStripMenuItem.Text = clientVersion != null
2726+
? string.Format(Messages.DOWNLOAD_SOURCE, BrandManager.BrandConsole, clientVersion.Version)
2727+
: string.Format(Messages.DOWNLOAD_LATEST_SOURCE, BrandManager.BrandConsole);
27192728
updateClientToolStripMenuItem.Visible = updateAlert != null;
27202729
}
27212730

@@ -3391,5 +3400,15 @@ private void configureUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
33913400
using (var dialog = new ConfigUpdatesDialog())
33923401
dialog.ShowDialog(this);
33933402
}
3403+
3404+
private void downloadSourceToolStripMenuItem_Click(object sender, EventArgs e)
3405+
{
3406+
ClientUpdateAlert.DownloadSource(this);
3407+
}
3408+
3409+
private void downloadLatestSourceToolStripMenuItem_Click(object sender, EventArgs e)
3410+
{
3411+
ClientUpdateAlert.DownloadSource(this);
3412+
}
33943413
}
33953414
}

XenAdmin/MainWindow.resx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,6 +2772,9 @@
27722772
<data name="pluginItemsPlaceHolderToolStripMenuItem8.Text" xml:space="preserve">
27732773
<value>PluginItemsPlaceHolder</value>
27742774
</data>
2775+
<data name="downloadLatestSourceToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
2776+
<value>186, 22</value>
2777+
</data>
27752778
<data name="aboutXenSourceAdminToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
27762779
<value>186, 22</value>
27772780
</data>
@@ -2797,17 +2800,23 @@
27972800
<value>Microsoft Sans Serif, 8.25pt</value>
27982801
</data>
27992802
<data name="downloadInstallToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
2800-
<value>173, 22</value>
2803+
<value>180, 22</value>
28012804
</data>
28022805
<data name="downloadInstallToolStripMenuItem.Text" xml:space="preserve">
28032806
<value>Download and &amp;Install</value>
28042807
</data>
28052808
<data name="relNotesToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
2806-
<value>173, 22</value>
2809+
<value>180, 22</value>
28072810
</data>
28082811
<data name="relNotesToolStripMenuItem.Text" xml:space="preserve">
28092812
<value>v{0} &amp;Release Notes</value>
28102813
</data>
2814+
<data name="downloadSourceToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
2815+
<value>180, 22</value>
2816+
</data>
2817+
<data name="downloadSourceToolStripMenuItem.Text" xml:space="preserve">
2818+
<value>Download v{0} source</value>
2819+
</data>
28112820
<data name="updateClientToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
28122821
<value>87, 20</value>
28132822
</data>
@@ -4143,6 +4152,12 @@
41434152
<data name="&gt;&gt;pluginItemsPlaceHolderToolStripMenuItem8.Type" xml:space="preserve">
41444153
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
41454154
</data>
4155+
<data name="&gt;&gt;downloadLatestSourceToolStripMenuItem.Name" xml:space="preserve">
4156+
<value>downloadLatestSourceToolStripMenuItem</value>
4157+
</data>
4158+
<data name="&gt;&gt;downloadLatestSourceToolStripMenuItem.Type" xml:space="preserve">
4159+
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
4160+
</data>
41464161
<data name="&gt;&gt;aboutXenSourceAdminToolStripMenuItem.Name" xml:space="preserve">
41474162
<value>aboutXenSourceAdminToolStripMenuItem</value>
41484163
</data>
@@ -4167,6 +4182,12 @@
41674182
<data name="&gt;&gt;relNotesToolStripMenuItem.Type" xml:space="preserve">
41684183
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
41694184
</data>
4185+
<data name="&gt;&gt;downloadSourceToolStripMenuItem.Name" xml:space="preserve">
4186+
<value>downloadSourceToolStripMenuItem</value>
4187+
</data>
4188+
<data name="&gt;&gt;downloadSourceToolStripMenuItem.Type" xml:space="preserve">
4189+
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
4190+
</data>
41704191
<data name="&gt;&gt;securityGroupsToolStripMenuItem.Name" xml:space="preserve">
41714192
<value>securityGroupsToolStripMenuItem</value>
41724193
</data>

XenAdminTests/UnitTests/AlertTests/XenCenterUpdateAlertTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class XenCenterUpdateAlertTests
4343
public void VerifyStoredDataWithDefaultConstructor()
4444
{
4545
var version = new ClientVersion("6.0.2", "xc", true, false, "http://url",
46-
new DateTime(2011, 12, 09).ToString(), "abcde");
47-
46+
new DateTime(2011, 12, 09).ToString(), "abcde", "http://sourceurl");
47+
4848
ClassVerifiers.VerifyGetters(new ClientUpdateAlert(version),
4949
new UpdateAlertClassUnitTestData
5050
{

XenModel/Actions/Updates/ClientVersion.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ public class ClientVersion
4343
public string Lang;
4444
public DateTime TimeStamp;
4545
public string Checksum;
46+
public string SourceUrl;
4647

47-
public ClientVersion(string version_lang, string name, bool latest, bool latest_cr, string url, string timestamp, string checksum)
48+
public ClientVersion(string version_lang, string name, bool latest, bool latest_cr, string url, string timestamp, string checksum, string sourceUrl)
4849
{
4950
ParseVersion(version_lang);
5051
Name = name;
@@ -53,6 +54,7 @@ public ClientVersion(string version_lang, string name, bool latest, bool latest_
5354
Url = url;
5455
DateTime.TryParse(timestamp, out TimeStamp);
5556
Checksum = checksum;
57+
SourceUrl = sourceUrl;
5658
}
5759

5860
private void ParseVersion(string version_lang)

0 commit comments

Comments
 (0)