Skip to content

Commit

Permalink
CP40844 refactors code and implements reviewers comments, aswell as b…
Browse files Browse the repository at this point in the history
…etter message handeling

Signed-off-by: Chris Lancaster <[email protected]>
  • Loading branch information
CitrixChris committed Aug 29, 2023
1 parent 63842d1 commit b7fd83a
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 53 deletions.
40 changes: 23 additions & 17 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.Web.UI.WebControls;
using System.Windows.Forms;
using XenAdmin.Actions;
using XenAdmin.Actions.GUIActions;
using XenAdmin.Actions.Updates;
using XenAdmin.Core;
using XenAdmin.Dialogs;

using XenCenterLib;

namespace XenAdmin.Alerts
{
Expand Down Expand Up @@ -149,19 +151,26 @@ public static void DownloadAndInstallNewClient(ClientUpdateAlert updateAlert, IW

public static void DownloadSource(IWin32Window parent)
{
var saveSourceDialog = new SaveFileDialog();
saveSourceDialog.FileName = "XenCenter-source";
saveSourceDialog.DefaultExt = "zip";
saveSourceDialog.Filter = "Zip files (*.zip)|*.zip|All files (*.*)|*.*";
saveSourceDialog.InitialDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),"Downloads");

if (saveSourceDialog.ShowDialog() != DialogResult.OK)
var outputPathAndFileName = string.Empty;
using (var saveSourceDialog = new SaveFileDialog())
{
return;
saveSourceDialog.FileName = BrandManager.BrandConsoleNoSpace + "-source.zip";
saveSourceDialog.DefaultExt = "zip";
saveSourceDialog.Filter = "(*.zip)|*.zip|All files (*.*)|*.*";
saveSourceDialog.InitialDirectory = Win32.GetKnownFolderPath(Win32.KnownFolders.Downloads);

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

var outputPathAndFileName = saveSourceDialog.FileName;
var downloadSourceAction = new DownloadSourceAction("Source", new Uri(BrandManager.SourceUrl), outputPathAndFileName);
Console.WriteLine(Updates.ClientVersions.Count);
var clientVersion = Updates.ClientVersions.First();
if (clientVersion == null) { return; }
var sourceUrl = clientVersion.SourceUrl;
var downloadSourceAction = new DownloadSourceAction(clientVersion.Name, clientVersion.Version, new Uri(sourceUrl), outputPathAndFileName);

using (var dlg = new ActionProgressDialog(downloadSourceAction, ProgressBarStyle.Continuous))
{
Expand All @@ -182,13 +191,10 @@ public static void DownloadSource(IWin32Window parent)
break;
}

if (currentTasks)
if (currentTasks && new Dialogs.WarningDialogs.CloseXenCenterWarningDialog(true).ShowDialog(parent) != DialogResult.OK)
{
if (new Dialogs.WarningDialogs.CloseXenCenterWarningDialog(true).ShowDialog(parent) != DialogResult.OK)
{
downloadSourceAction.ReleaseDownloadedContent();
return;
}
downloadSourceAction.ReleaseDownloadedContent();
return;
}
}
}
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
6 changes: 6 additions & 0 deletions XenAdmin/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,13 @@ private void SetClientUpdateAlert()
{
updateAlert = Updates.ClientUpdateAlerts.FirstOrDefault();
if (updateAlert != null)
{
relNotesToolStripMenuItem.Text = string.Format(Messages.MAINWINDOW_UPDATE_RELEASE, updateAlert.NewVersion.Version);
downloadLatestSourceToolStripMenuItem.Text = string.Format(Messages.DOWNLOAD_SOURCE, updateAlert.NewVersion.Version);
}
var clientVersion = Updates.ClientVersions.First();
downloadSourceToolStripMenuItem.Visible = clientVersion != null;
downloadSourceToolStripMenuItem.Text = string.Format(Messages.DOWNLOAD_SOURCE, clientVersion.Version);
updateClientToolStripMenuItem.Visible = updateAlert != null;
}

Expand Down
34 changes: 17 additions & 17 deletions XenAdmin/MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3130,7 +3130,7 @@
<value>&amp;Help</value>
</data>
<data name="helpTopicsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 22</value>
<value>186, 22</value>
</data>
<data name="helpTopicsToolStripMenuItem.Text" xml:space="preserve">
<value>Help &amp;Contents</value>
Expand All @@ -3139,58 +3139,58 @@
<value>F1</value>
</data>
<data name="helpContextMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 22</value>
<value>186, 22</value>
</data>
<data name="helpContextMenuItem.Text" xml:space="preserve">
<value>Conte&amp;xt Help</value>
</data>
<data name="toolStripMenuItem15.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 6</value>
<value>183, 6</value>
</data>
<data name="viewApplicationLogToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 22</value>
<value>186, 22</value>
</data>
<data name="viewApplicationLogToolStripMenuItem.Text" xml:space="preserve">
<value>View {0} &amp;Log Files</value>
</data>
<data name="toolStripMenuItem17.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 6</value>
<value>183, 6</value>
</data>
<data name="toolStripMenuItemCfu.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 22</value>
<value>186, 22</value>
</data>
<data name="toolStripMenuItemCfu.Text" xml:space="preserve">
<value>Check for {0} &amp;Updates</value>
</data>
<data name="xenSourceOnTheWebToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 22</value>
<value>186, 22</value>
</data>
<data name="xenSourceOnTheWebToolStripMenuItem.Text" xml:space="preserve">
<value>{0} on the &amp;Web</value>
</data>
<data name="xenCenterPluginsOnlineToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 22</value>
<value>186, 22</value>
</data>
<data name="xenCenterPluginsOnlineToolStripMenuItem.Text" xml:space="preserve">
<value>{0} &amp;Plugins online</value>
</data>
<data name="toolStripSeparator7.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 6</value>
<value>183, 6</value>
</data>
<data name="pluginItemsPlaceHolderToolStripMenuItem8.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 22</value>
<value>186, 22</value>
</data>
<data name="pluginItemsPlaceHolderToolStripMenuItem8.Text" xml:space="preserve">
<value>PluginItemsPlaceHolder</value>
</data>
<data name="downloadLatestSourceToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 22</value>
<value>186, 22</value>
</data>
<data name="downloadLatestSourceToolStripMenuItem.Text" xml:space="preserve">
<value>Download Latest Source</value>
<value>Download v{0} source.</value>
</data>
<data name="aboutXenSourceAdminToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 22</value>
<value>186, 22</value>
</data>
<data name="aboutXenSourceAdminToolStripMenuItem.Text" xml:space="preserve">
<value>&amp;About {0}</value>
Expand All @@ -3208,22 +3208,22 @@
<value>Microsoft Sans Serif, 8.25pt</value>
</data>
<data name="downloadInstallToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 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>188, 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>188, 22</value>
<value>180, 22</value>
</data>
<data name="downloadSourceToolStripMenuItem.Text" xml:space="preserve">
<value>Download latest source </value>
<value>Download v{0} source</value>
</data>
<data name="updateClientToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>87, 20</value>
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
2 changes: 1 addition & 1 deletion XenAdminTests/XenAdminTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\XenAdmin\XenAdmin.csproj">
<Project>{70BDA4BC-F062-4302-8ACD-A15D8BF31D65}</Project>
<Project>{70bda4bc-f062-4302-8acd-a15d8bf31d65}</Project>
<Name>XenAdmin</Name>
</ProjectReference>
<ProjectReference Include="..\XenCenterLib\XenCenterLib.csproj">
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
7 changes: 6 additions & 1 deletion XenModel/Actions/Updates/DownloadAndUpdateClientAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ public class DownloadAndUpdateClientAction : DownloadFileAction, IByteProgressAc
private FileStream _msiStream;

public DownloadAndUpdateClientAction(string updateName, Uri uri, string outputFileName, string checksum)
: base(updateName, uri, outputFileName, string.Format(Messages.DOWNLOAD_CLIENT_INSTALLER_ACTION_TITLE, updateName), true)
: base(updateName,
uri,
outputFileName,
string.Format(Messages.DOWNLOAD_CLIENT_INSTALLER_ACTION_TITLE, updateName),
string.Format(Messages.DOWNLOAD_CLIENT_INSTALLER_ACTION_DESCRIPTION, updateName),
true)
{
_checksum = checksum;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,24 @@ public class DownloadFileAction : AsyncAction, IByteProgressAction
private Exception _downloadError;
private readonly string _authToken;
private WebClient _client;
private string _title;
private string _description;


public string ByteProgressDescription { get; set; }



public DownloadFileAction(string fileName, Uri uri, string outputFileName, string title, bool suppressHistory)
public DownloadFileAction(string fileName, Uri uri, string outputFileName, string title, string description, bool suppressHistory)
: base(null, title, fileName, suppressHistory)
{
_fileName = fileName;
_address = uri;
_canDownloadFile = _address != null;
_outputPathAndFileName = outputFileName;
_authToken = XenAdminConfigManager.Provider.GetInternalStageAuthToken();
_title = title;
_description = description;
}

protected void DownloadFile()
Expand Down Expand Up @@ -193,8 +198,8 @@ protected override void Run()
if (!_canDownloadFile)
return;

log.InfoFormat("Downloading '{0}' source (from '{1}') to '{2}'", FileName, _address, _outputPathAndFileName);
Description = string.Format(Messages.DOWNLOAD_CLIENT_INSTALLER_ACTION_DESCRIPTION, FileName);
log.InfoFormat("Downloading '{0}' (from '{1}') to '{2}'", FileName, _address, _outputPathAndFileName);
Description = string.Format(_description, FileName);
LogDescriptionChanges = false;
DownloadFile();
LogDescriptionChanges = true;
Expand All @@ -206,7 +211,7 @@ protected override void Run()
throw new CancelledException();

if (!File.Exists(_outputPathAndFileName))
throw new Exception(Messages.DOWNLOAD_CLIENT_INSTALLER_MSI_NOT_FOUND);
throw new Exception(Messages.DOWNLOAD_FILE_NOT_FOUND);

Description = Messages.COMPLETED;
}
Expand Down Expand Up @@ -235,7 +240,8 @@ public void ReleaseDownloadedContent(bool deleteDownloadedContent = false)
private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
int pc = (int)(95.0 * e.BytesReceived / e.TotalBytesToReceive);
var descr = string.Format(Messages.DOWNLOAD_CLIENT_INSTALLER_ACTION_PROGRESS_DESCRIPTION, FileName,

var descr = string.Format(Messages.DOWNLOAD_FILE_ACTION_PROGRESS_DESCRIPTION, FileName,
Util.DiskSizeString(e.BytesReceived, "F1"),
Util.DiskSizeString(e.TotalBytesToReceive));
ByteProgressDescription = descr;
Expand Down
14 changes: 10 additions & 4 deletions XenModel/Actions/Updates/DownloadSourceAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@
namespace XenAdmin.Actions.Updates
{
public class DownloadSourceAction : DownloadFileAction, IByteProgressAction
{
public DownloadSourceAction(string sourceName, Uri uri, string outputFileName)
: base(sourceName, uri, outputFileName, Messages.DOWNLOAD_SOURCE_ACTION, false) // TODO: Get proper title.
{
public DownloadSourceAction(string sourceName, Version version, Uri uri, string outputFileName)
: base(sourceName + " source",
uri,
outputFileName,
string.Format(Messages.DOWNLOAD_SOURCE_ACTION_TITLE, version.ToString()),
Messages.DOWNLOAD_SOURCE_ACTION_DESCRIPTION,
false)
{
}

}
}
}

5 changes: 4 additions & 1 deletion XenModel/Actions/Updates/DownloadUpdatesXmlAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private void GetXenCenterVersions(XmlDocument xdoc)
bool latest = false;
bool latestCr = false;
string url = string.Empty;
string sourceUrl = string.Empty;
string timestamp = string.Empty;
string checksum = string.Empty;

Expand All @@ -120,13 +121,15 @@ private void GetXenCenterVersions(XmlDocument xdoc)
latestCr = attrib.Value.ToUpperInvariant() == bool.TrueString.ToUpperInvariant();
else if (attrib.Name == "url")
url = attrib.Value;
else if (attrib.Name == "source")
sourceUrl = attrib.Value;
else if (attrib.Name == "timestamp")
timestamp = attrib.Value;
else if (attrib.Name == "checksum")
checksum = attrib.Value;
}

ClientVersions.Add(new ClientVersion(versionLang, name, latest, latestCr, url, timestamp, checksum));
ClientVersions.Add(new ClientVersion(versionLang, name, latest, latestCr, url, timestamp, checksum, sourceUrl));
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions XenModel/BrandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ static BrandManager()

public static readonly string CfuUrl;

public static readonly string SourceUrl;

public static readonly string VmTools;

public static readonly string XenHost;
Expand Down
Loading

0 comments on commit b7fd83a

Please sign in to comment.