Skip to content

Commit

Permalink
Merge pull request #3047 from danilo-delbusso/improvement/lcm/RPU_CP-…
Browse files Browse the repository at this point in the history
…39929

(Stockholm) CP-39929: Improvements on the RPU/Updates wizard
  • Loading branch information
kc284 authored Aug 30, 2022
2 parents a623678 + e30137d commit d6f2099
Show file tree
Hide file tree
Showing 62 changed files with 575 additions and 732 deletions.
124 changes: 92 additions & 32 deletions XenAdmin/Core/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,33 @@
* SUCH DAMAGE.
*/

using System.Drawing;
using System;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace XenAdmin.Core
{
internal static class ExtensionMethods
{
/// <summary>
/// Internationalization of True/False
/// </summary>
public static string ToStringI18n(this bool value)
{
return value ? Messages.TRUE : Messages.FALSE;
}
internal static class ExtensionMethods
{
private const int DEFAULT_STRING_INDENTATION = 2;
/// <summary>
/// Internationalization of True/False
/// </summary>
public static string ToStringI18n(this bool value)
{
return value ? Messages.TRUE : Messages.FALSE;
}

/// <summary>
/// Turns a bool to internationalized Yes/No (on occasion it's user friendlier than True/False)
/// </summary>
public static string ToYesNoStringI18n(this bool value)
{
return value ? Messages.YES : Messages.NO;
}
/// <summary>
/// Turns a bool to internationalized Yes/No (on occasion it's user friendlier than True/False)
/// </summary>
public static string ToYesNoStringI18n(this bool value)
{
return value ? Messages.YES : Messages.NO;
}

/// <summary>
/// This has the same bahvoiur as the standard ellipsise extension but this uses graphics
Expand Down Expand Up @@ -88,24 +91,81 @@ public static string Ellipsise(this string text, Rectangle rectangle, Font font)
return text.Ellipsise(c);
}

public static StringBuilder AppendIndented(this StringBuilder builder, string value, int indent = 2)
/// <summary>
/// Append the input value after it's been prepended with the specified amount of spaces.
/// If the value spans multiple lines, each line will be indented.
/// </summary>
/// <param name="builder">The <see cref="StringBuilder"/> to which the modified value will be appended.</param>
/// <param name="value">The value to prepend with spaces and then append.</param>
/// <param name="indent">The amount of spaces to prepend to each line in the input value.</param>
/// <returns>The input <see cref="StringBuilder"/> after the operation has been completed.</returns>
public static StringBuilder AppendIndented(this StringBuilder builder, string value, int indent = DEFAULT_STRING_INDENTATION)
{
var indentString = "";
var i = 0;
while (i++ < indent)
indentString += " ";
var newvalue = value.Replace(System.Environment.NewLine, string.Format("{0}{1}", System.Environment.NewLine, indentString));
return builder.Append(string.Format("{0}{1}", indentString, newvalue));
return builder.Append(PrependIndentation(value, indent));
}

public static StringBuilder AppendIndented(this StringBuilder builder, StringBuilder value, int indent = 2)
/// <summary>
/// Add a new line to the input <see cref="StringBuilder"/>, with options to format the input value before it's appended.
/// timestamps and indentation will be ignored if the input value is an null or whitespace
/// </summary>
/// <param name="builder">The <see cref="StringBuilder"/> to which the modified value will be appended.</param>
/// <param name="value">The value to format before appending.</param>
/// <param name="timestamp">The timestamp to prepend to each line. If null, no timestamp will be added.</param>
/// <param name="showTimestamp">Override for the timestamp. If set to false, no timestamp will be shown even if the value is null.</param>
/// <param name="indent">true if each line should be prepended with indentation. Uses the default indentation defined in <see cref="ExtensionMethods"/>: <see cref="DEFAULT_STRING_INDENTATION"/></param>
/// <param name="addExtraLine">true to append an extra line.</param>
/// <returns>The input <see cref="StringBuilder"/> after the operation has been completed.</returns>
public static StringBuilder AppendFormattedLine(this StringBuilder builder, string value, DateTime? timestamp, bool showTimestamp = true, bool indent = false, bool addExtraLine = false)
{
var formattedValue = value;
if (!string.IsNullOrWhiteSpace(value))
{
if (indent)
{
formattedValue = PrependIndentation(formattedValue);
}
if (timestamp != null && showTimestamp)
{
formattedValue = PrependTimestamps(formattedValue, (DateTime) timestamp);
}
}

builder.AppendLine(formattedValue);

if (addExtraLine)
{
builder.AppendLine();
}

return builder;
}

/// <summary>
/// Prepend every line in the input value with the specified indentation level.
/// </summary>
/// <param name="value">The value to which indentation will be applied</param>
/// <param name="indent">The level of indentation, i.e. the number of spaces to prepend to every line in the value.</param>
/// <returns>The input value with prepended indentation./</returns>
private static string PrependIndentation(string value, int indent = DEFAULT_STRING_INDENTATION)
{
var indentString = new string(' ', indent);
var newValue = value.Replace(Environment.NewLine, $"{Environment.NewLine}{indentString}");
return $"{indentString}{newValue}";
}

/// <summary>
/// Prepend every line in the input value with a formatted string of <see cref="DateTime.Now"/>.
/// </summary>
/// <param name="value">The input value</param>
/// <param name="timestamp">The timestamp to show</param>
/// <param name="localize">true to format the string with the user's locale</param>
/// <returns>The input value with prepended timestamps/</returns>
public static string PrependTimestamps(string value, DateTime timestamp, bool localize = true)
{
var indentString = "";
var i = 0;
while (i++ < indent)
indentString += " ";
var newvalue = value.Replace(System.Environment.NewLine, string.Format("{0}{1}", System.Environment.NewLine, indentString));
return builder.Append(string.Format("{0}{1}", indentString, newvalue));
var timestampString = HelpersGUI.DateTimeToString(timestamp, Messages.DATEFORMAT_DM_HMS, localize);
// normalise all line endings before splitting
var lines = value.Replace(Environment.NewLine, "\n").Split('\n');
return string.Join(Environment.NewLine, lines.Select(line => $"{timestampString} | {line}"));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,8 @@ public ConflictingUpdatePresent(Check check, string conflictingUpdates, Host hos
this.conflictingUpdates = conflictingUpdates;
}

public override string Description
{
get
{
return string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED_CONFLICTING_UPDATE, ServerName, conflictingUpdates);
}
}
public override string Description => string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED_CONFLICTING_UPDATE, ServerName, conflictingUpdates);

public override string HelpMessage
{
get { return string.Empty; }
}
public override string HelpMessage => string.Empty;
}
}
14 changes: 4 additions & 10 deletions XenAdmin/Diagnostics/Problems/HostProblem/HostMaintenanceMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ namespace XenAdmin.Diagnostics.Problems.HostProblem
{
public class HostMaintenanceMode : HostProblem
{
public HostMaintenanceMode(Check check, Host host)
: base(check, host)
public HostMaintenanceMode(Check check, Host host)
: base(check, host)
{
}

public override string Description
{
get { return string.Format(Messages.UPDATES_WIZARD_HOST_MAINTENANCE_MODE, ServerName); }
}
public override string Description => string.Format(Messages.UPDATES_WIZARD_HOST_MAINTENANCE_MODE, ServerName);

protected override AsyncAction CreateAction(out bool cancelled)
{
Expand All @@ -56,10 +53,7 @@ protected override AsyncAction CreateAction(out bool cancelled)
return new EnableHostAction(Server, false, AddHostToPoolCommand.EnableNtolDialog);
}

public override string HelpMessage
{
get { return Messages.ENABLE_PLAIN; }
}
public override string HelpMessage => Messages.ENABLE_PLAIN;

public override AsyncAction CreateUnwindChangesAction()
{
Expand Down
4 changes: 2 additions & 2 deletions XenAdmin/Diagnostics/Problems/HostProblem/HostNeedsReboot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public HostNeedsReboot(Check check, Host host, bool livePatchingRestricted = fal

public override string Description => livePatchingRestricted
? string.Format(Messages.UPDATES_WIZARD_REBOOT_NEEDED_LIVEPATCH_RESTRICTED, host.name_label)
: livePatchingDisabled
? string.Format(Messages.UPDATES_WIZARD_REBOOT_NEEDED_LIVEPATCH_DISABLED, host.name_label)
: livePatchingDisabled
? string.Format(Messages.UPDATES_WIZARD_REBOOT_NEEDED_LIVEPATCH_DISABLED, host.name_label)
: string.Format(Messages.UPDATES_WIZARD_REBOOT_NEEDED, host.name_label);
}
}
23 changes: 4 additions & 19 deletions XenAdmin/Diagnostics/Problems/HostProblem/HostNotLive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,9 @@ public HostNotLive(Check check, Host host)
{
}

public override string Description
{
get { return string.Format(Messages.UPDATES_WIZARD_HOST_NOT_LIVE, ServerName); }
}
public override string Description => string.Format(Messages.UPDATES_WIZARD_HOST_NOT_LIVE, ServerName);

public override string HelpMessage
{
get { return CanStartHost() ? Messages.START_HOST : string.Empty; }
}
public override string HelpMessage => CanStartHost() ? Messages.START_HOST : string.Empty;

protected override AsyncAction CreateAction(out bool cancelled)
{
Expand Down Expand Up @@ -85,17 +79,8 @@ public HostNotLiveWarning(Check check, Host host)
this.host = host;
}

public override string Title
{
get { return Check.Description; }
}
public override string Title => Check.Description;

public override string Description
{
get
{
return string.Format(Messages.UPDATES_WIZARD_HOST_NOT_LIVE_WARNING, host);
}
}
public override string Description => string.Format(Messages.UPDATES_WIZARD_HOST_NOT_LIVE_WARNING, host);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public override string Message
{
switch (reason)
{
case HostNotSafeToUpgradeReason.NotEnoughSpace :
return string.Format(Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE_LONG, BrandManager.ProductVersion70);
case HostNotSafeToUpgradeReason.NotEnoughSpace:
return string.Format(Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE_LONG, BrandManager.ProductVersion70);

default:
return string.Format(Messages.NOT_SAFE_TO_UPGRADE_DEFAULT_WARNING_LONG, BrandManager.ProductVersion70);
}
Expand Down
39 changes: 15 additions & 24 deletions XenAdmin/Diagnostics/Problems/HostProblem/HostOutOfSpaceProblem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class HostOutOfSpaceProblem : HostProblem
private readonly Pool_update update;

public HostOutOfSpaceProblem(Check check, Host host, Pool_patch patch, DiskSpaceRequirements diskSpaceReq)
: base(check, host)
: base(check, host)
{
this.patch = patch;
this.diskSpaceReq = diskSpaceReq;
Expand Down Expand Up @@ -82,13 +82,13 @@ public override string Description

switch (diskSpaceReq.Operation)
{
case DiskSpaceRequirements.OperationTypes.install :
return string.Format(Messages.NOT_ENOUGH_SPACE_MESSAGE_INSTALL, ServerName, name);
case DiskSpaceRequirements.OperationTypes.upload :
return string.Format(Messages.NOT_ENOUGH_SPACE_MESSAGE_UPLOAD, ServerName, name);
case DiskSpaceRequirements.OperationTypes.automatedUpdates :
case DiskSpaceRequirements.OperationTypes.install:
return string.Format(Messages.NOT_ENOUGH_SPACE_MESSAGE_INSTALL, ServerName, name);

case DiskSpaceRequirements.OperationTypes.upload:
return string.Format(Messages.NOT_ENOUGH_SPACE_MESSAGE_UPLOAD, ServerName, name);

case DiskSpaceRequirements.OperationTypes.automatedUpdates:
return string.Format(Messages.NOT_ENOUGH_SPACE_MESSAGE_AUTO_UPDATE, ServerName);

case DiskSpaceRequirements.OperationTypes.automatedUpdatesUploadOne:
Expand All @@ -108,7 +108,7 @@ protected override AsyncAction CreateAction(out bool cancelled)

if (patch != null && diskSpaceReq.CanCleanup)
{
Program.Invoke(Program.MainWindow, delegate()
Program.Invoke(Program.MainWindow, delegate ()
{
using (var dlg = new WarningDialog(diskSpaceReq.GetSpaceRequirementsMessage(),
new ThreeButtonDialog.TBDButton(Messages.YES, DialogResult.Yes, selected: true),
Expand All @@ -122,30 +122,21 @@ protected override AsyncAction CreateAction(out bool cancelled)
});
}
else
{
Program.Invoke(Program.MainWindow, delegate()
{
Program.Invoke(Program.MainWindow, delegate ()
{
using (var dlg = new WarningDialog(diskSpaceReq.GetSpaceRequirementsMessage()))
dlg.ShowDialog();
});
}
cancelled = action == null;
cancelled = action == null;

return action;
}

public override string HelpMessage
{
get { return diskSpaceReq.GetMessageForActionLink(); }
}
public override string HelpMessage => diskSpaceReq.GetMessageForActionLink();

public override bool IsFixable
{
get
{
return false;
}
}
public override bool IsFixable => false;

public override bool Equals(object obj)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public HostPrepareToUpgradeProblem(Check check, Host host, string friendlyErrorK
public override bool IsFixable => false;

public override string Description => _shortMessage;

public override string HelpMessage => Messages.MORE_INFO;

protected override Actions.AsyncAction CreateAction(out bool cancelled)
Expand Down
2 changes: 1 addition & 1 deletion XenAdmin/Diagnostics/Problems/HostProblem/HostProblem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace XenAdmin.Diagnostics.Problems.HostProblem
{
public abstract class HostProblem : Problem
{
protected HostProblem(Check check, Host server)
protected HostProblem(Check check, Host server)
: base(check)
{
Server = server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,14 @@ public LicenseRestrictionProblem(Check check, Host host)
this.host = host;
}

public override string Description
{
get { return string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED, Helpers.GetName(host).Ellipsise(30), FriendlyErrorNames.LICENCE_RESTRICTION); }
}
public override string Description => string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED, Helpers.GetName(host).Ellipsise(30), FriendlyErrorNames.LICENCE_RESTRICTION);

public override string Title
{
get { return Description; }
}
public override string Title => Description;

public override string LinkText
{
get { return Messages.LICENSE_MANAGER_BUY_LICENSE_LINK_TEXT; }
}
public override string LinkText => Messages.LICENSE_MANAGER_BUY_LICENSE_LINK_TEXT;

public override string HelpMessage
{
get { return LinkText; }
}
public override string HelpMessage => LinkText;

public override Uri UriToLaunch
{
get { return new Uri(InvisibleMessages.UPSELL_SA); }
}
public override Uri UriToLaunch => new Uri(InvisibleMessages.UPSELL_SA);
}
}
Loading

0 comments on commit d6f2099

Please sign in to comment.