Skip to content

Commit

Permalink
CP-40844: Adds download source action that gets the latest source cod…
Browse files Browse the repository at this point in the history
…e in the production stage (#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]>
  • Loading branch information
CitrixChris and kc284 committed Oct 30, 2023
1 parent ad8ef2e commit 9a80dc9
Show file tree
Hide file tree
Showing 16 changed files with 327 additions and 117 deletions.
49 changes: 43 additions & 6 deletions XenAdmin/Alerts/Types/ClientUpdateAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using XenAdmin.Actions;
using XenAdmin.Actions.GUIActions;
using XenAdmin.Actions.Updates;
using XenAdmin.Core;
using XenAdmin.Dialogs;

using XenAdmin.Dialogs.WarningDialogs;
using XenCenterLib;

namespace XenAdmin.Alerts
{
Expand Down Expand Up @@ -123,28 +125,63 @@ public static void DownloadAndInstallNewClient(ClientUpdateAlert updateAlert, IW

if (currentTasks)
{
if (new Dialogs.WarningDialogs.CloseXenCenterWarningDialog(true).ShowDialog(parent) != DialogResult.OK)
using (var dlg = new CloseXenCenterWarningDialog(true))
{
downloadAndInstallClientAction.ReleaseInstaller();
return;
if (dlg.ShowDialog(parent) != DialogResult.OK)
{
downloadAndInstallClientAction.ReleaseDownloadedContent();
return;
}
}
}

try
{
Process.Start(outputPathAndFileName);
log.DebugFormat("Update {0} found and install started", updateAlert.Name);
downloadAndInstallClientAction.ReleaseInstaller();
downloadAndInstallClientAction.ReleaseDownloadedContent();
Application.Exit();
}
catch (Exception e)
{
log.Error("Exception occurred when starting the installation process.", e);
downloadAndInstallClientAction.ReleaseInstaller(true);
downloadAndInstallClientAction.ReleaseDownloadedContent(true);

using (var dlg = new ErrorDialog(Messages.UPDATE_CLIENT_FAILED_INSTALLER_LAUNCH))
dlg.ShowDialog(parent);
}
}

public static void DownloadSource(IWin32Window parent)
{
// If no update no need to show where to save dialog
var clientVersion = Updates.ClientVersions.FirstOrDefault();

if (clientVersion == null)
{
// There is no XCUpdates.xml so direct to website.
Program.OpenURL(InvisibleMessages.WEBSITE_DOWNLOADS);
}
else
{
string outputPathAndFileName;
using (var saveSourceDialog = new SaveFileDialog())
{
saveSourceDialog.FileName = $"{BrandManager.BrandConsole}-v{clientVersion.Version}-source.zip";
saveSourceDialog.DefaultExt = "zip";
saveSourceDialog.Filter = "(*.zip)|*.zip|All files (*.*)|*.*";
saveSourceDialog.InitialDirectory = Win32.GetKnownFolderPath(Win32.KnownFolders.Downloads);

if (saveSourceDialog.ShowDialog(parent) != DialogResult.OK)
{
return;
}
outputPathAndFileName = saveSourceDialog.FileName;
}

var downloadSourceAction = new DownloadSourceAction(clientVersion.Name, new Uri(clientVersion.SourceUrl), outputPathAndFileName);
downloadSourceAction.RunAsync();
}
}
}
}
2 changes: 1 addition & 1 deletion XenAdmin/Alerts/Types/GuiOldAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public GuiOldAlert()

public override Action FixLinkAction
{
get { return () => Program.OpenURL(InvisibleMessages.OUT_OF_DATE_WEBSITE); }
get { return () => Program.OpenURL(InvisibleMessages.WEBSITE_DOWNLOADS); }
}

public override string FixLinkText => Messages.ALERT_NEW_VERSION_DOWNLOAD;
Expand Down
2 changes: 1 addition & 1 deletion XenAdmin/Core/Updates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class Updates

private static List<XenServerVersion> XenServerVersionsForAutoCheck = new List<XenServerVersion>();
private static List<XenServerPatch> XenServerPatches = new List<XenServerPatch>();
private static List<ClientVersion> ClientVersions = new List<ClientVersion>();
public static List<ClientVersion> ClientVersions = new List<ClientVersion>();
public static List<XenServerVersion> XenServerVersions = new List<XenServerVersion>();

private static readonly List<Alert> updateAlerts = new List<Alert>();
Expand Down
20 changes: 19 additions & 1 deletion XenAdmin/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions XenAdmin/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
using XenAdmin.Controls.GradientPanel;
using XenAdmin.Dialogs.ServerUpdates;
using XenAdmin.Help;
using XenAdmin.Actions.Updates;

namespace XenAdmin
{
Expand Down Expand Up @@ -269,6 +270,7 @@ public MainWindow(string[] args)
statusButtonAlerts.Visible = statusButtonUpdates.Visible = statusButtonCdnUpdates.Visible = statusButtonProgress.Visible = statusButtonErrors.Visible = false;
statusButtonUpdates.ToolTipText = string.Format(statusButtonUpdates.ToolTipText, BrandManager.ProductVersion821);
statusButtonCdnUpdates.ToolTipText = string.Format(statusButtonCdnUpdates.ToolTipText, BrandManager.ProductBrand, BrandManager.ProductVersionPost82);
downloadLatestSourceToolStripMenuItem.Text = Messages.DOWNLOAD_LATEST_SOURCE;
}

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

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

Expand Down Expand Up @@ -2715,7 +2717,14 @@ private void SetClientUpdateAlert()
{
updateAlert = Updates.ClientUpdateAlerts.FirstOrDefault();
if (updateAlert != null)
{
relNotesToolStripMenuItem.Text = string.Format(Messages.MAINWINDOW_UPDATE_RELEASE, updateAlert.NewVersion.Version);
downloadSourceToolStripMenuItem.Text = string.Format(Messages.DOWNLOAD_SOURCE, BrandManager.BrandConsole, updateAlert.NewVersion.Version);
}
var clientVersion = Updates.ClientVersions.FirstOrDefault();
downloadLatestSourceToolStripMenuItem.Text = clientVersion != null
? string.Format(Messages.DOWNLOAD_SOURCE, BrandManager.BrandConsole, clientVersion.Version)
: string.Format(Messages.DOWNLOAD_LATEST_SOURCE, BrandManager.BrandConsole);
updateClientToolStripMenuItem.Visible = updateAlert != null;
}

Expand Down Expand Up @@ -3391,5 +3400,15 @@ private void configureUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
using (var dialog = new ConfigUpdatesDialog())
dialog.ShowDialog(this);
}

private void downloadSourceToolStripMenuItem_Click(object sender, EventArgs e)
{
ClientUpdateAlert.DownloadSource(this);
}

private void downloadLatestSourceToolStripMenuItem_Click(object sender, EventArgs e)
{
ClientUpdateAlert.DownloadSource(this);
}
}
}
25 changes: 23 additions & 2 deletions XenAdmin/MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,9 @@
<data name="pluginItemsPlaceHolderToolStripMenuItem8.Text" xml:space="preserve">
<value>PluginItemsPlaceHolder</value>
</data>
<data name="downloadLatestSourceToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>186, 22</value>
</data>
<data name="aboutXenSourceAdminToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>186, 22</value>
</data>
Expand All @@ -2797,17 +2800,23 @@
<value>Microsoft Sans Serif, 8.25pt</value>
</data>
<data name="downloadInstallToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>173, 22</value>
<value>180, 22</value>
</data>
<data name="downloadInstallToolStripMenuItem.Text" xml:space="preserve">
<value>Download and &amp;Install</value>
</data>
<data name="relNotesToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>173, 22</value>
<value>180, 22</value>
</data>
<data name="relNotesToolStripMenuItem.Text" xml:space="preserve">
<value>v{0} &amp;Release Notes</value>
</data>
<data name="downloadSourceToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 22</value>
</data>
<data name="downloadSourceToolStripMenuItem.Text" xml:space="preserve">
<value>Download v{0} source</value>
</data>
<data name="updateClientToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>87, 20</value>
</data>
Expand Down Expand Up @@ -4143,6 +4152,12 @@
<data name="&gt;&gt;pluginItemsPlaceHolderToolStripMenuItem8.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;downloadLatestSourceToolStripMenuItem.Name" xml:space="preserve">
<value>downloadLatestSourceToolStripMenuItem</value>
</data>
<data name="&gt;&gt;downloadLatestSourceToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;aboutXenSourceAdminToolStripMenuItem.Name" xml:space="preserve">
<value>aboutXenSourceAdminToolStripMenuItem</value>
</data>
Expand All @@ -4167,6 +4182,12 @@
<data name="&gt;&gt;relNotesToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;downloadSourceToolStripMenuItem.Name" xml:space="preserve">
<value>downloadSourceToolStripMenuItem</value>
</data>
<data name="&gt;&gt;downloadSourceToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;securityGroupsToolStripMenuItem.Name" xml:space="preserve">
<value>securityGroupsToolStripMenuItem</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class XenCenterUpdateAlertTests
public void VerifyStoredDataWithDefaultConstructor()
{
var version = new ClientVersion("6.0.2", "xc", true, false, "http://url",
new DateTime(2011, 12, 09).ToString(), "abcde");

new DateTime(2011, 12, 09).ToString(), "abcde", "http://sourceurl");
ClassVerifiers.VerifyGetters(new ClientUpdateAlert(version),
new UpdateAlertClassUnitTestData
{
Expand Down
4 changes: 3 additions & 1 deletion XenModel/Actions/Updates/ClientVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public class ClientVersion
public string Lang;
public DateTime TimeStamp;
public string Checksum;
public string SourceUrl;

public ClientVersion(string version_lang, string name, bool latest, bool latest_cr, string url, string timestamp, string checksum)
public ClientVersion(string version_lang, string name, bool latest, bool latest_cr, string url, string timestamp, string checksum, string sourceUrl)
{
ParseVersion(version_lang);
Name = name;
Expand All @@ -53,6 +54,7 @@ public ClientVersion(string version_lang, string name, bool latest, bool latest_
Url = url;
DateTime.TryParse(timestamp, out TimeStamp);
Checksum = checksum;
SourceUrl = sourceUrl;
}

private void ParseVersion(string version_lang)
Expand Down
Loading

0 comments on commit 9a80dc9

Please sign in to comment.