Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit d6f2099

Browse files
authored
Merge pull request #3047 from danilo-delbusso/improvement/lcm/RPU_CP-39929
(Stockholm) CP-39929: Improvements on the RPU/Updates wizard
2 parents a623678 + e30137d commit d6f2099

File tree

62 files changed

+575
-732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+575
-732
lines changed

XenAdmin/Core/ExtensionMethods.cs

+92-32
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,33 @@
2929
* SUCH DAMAGE.
3030
*/
3131

32-
using System.Drawing;
32+
using System;
33+
using System.Drawing;
34+
using System.Linq;
3335
using System.Text;
3436
using System.Windows.Forms;
3537

3638

3739
namespace XenAdmin.Core
3840
{
39-
internal static class ExtensionMethods
40-
{
41-
/// <summary>
42-
/// Internationalization of True/False
43-
/// </summary>
44-
public static string ToStringI18n(this bool value)
45-
{
46-
return value ? Messages.TRUE : Messages.FALSE;
47-
}
41+
internal static class ExtensionMethods
42+
{
43+
private const int DEFAULT_STRING_INDENTATION = 2;
44+
/// <summary>
45+
/// Internationalization of True/False
46+
/// </summary>
47+
public static string ToStringI18n(this bool value)
48+
{
49+
return value ? Messages.TRUE : Messages.FALSE;
50+
}
4851

49-
/// <summary>
50-
/// Turns a bool to internationalized Yes/No (on occasion it's user friendlier than True/False)
51-
/// </summary>
52-
public static string ToYesNoStringI18n(this bool value)
53-
{
54-
return value ? Messages.YES : Messages.NO;
55-
}
52+
/// <summary>
53+
/// Turns a bool to internationalized Yes/No (on occasion it's user friendlier than True/False)
54+
/// </summary>
55+
public static string ToYesNoStringI18n(this bool value)
56+
{
57+
return value ? Messages.YES : Messages.NO;
58+
}
5659

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

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

101-
public static StringBuilder AppendIndented(this StringBuilder builder, StringBuilder value, int indent = 2)
107+
/// <summary>
108+
/// Add a new line to the input <see cref="StringBuilder"/>, with options to format the input value before it's appended.
109+
/// timestamps and indentation will be ignored if the input value is an null or whitespace
110+
/// </summary>
111+
/// <param name="builder">The <see cref="StringBuilder"/> to which the modified value will be appended.</param>
112+
/// <param name="value">The value to format before appending.</param>
113+
/// <param name="timestamp">The timestamp to prepend to each line. If null, no timestamp will be added.</param>
114+
/// <param name="showTimestamp">Override for the timestamp. If set to false, no timestamp will be shown even if the value is null.</param>
115+
/// <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>
116+
/// <param name="addExtraLine">true to append an extra line.</param>
117+
/// <returns>The input <see cref="StringBuilder"/> after the operation has been completed.</returns>
118+
public static StringBuilder AppendFormattedLine(this StringBuilder builder, string value, DateTime? timestamp, bool showTimestamp = true, bool indent = false, bool addExtraLine = false)
119+
{
120+
var formattedValue = value;
121+
if (!string.IsNullOrWhiteSpace(value))
122+
{
123+
if (indent)
124+
{
125+
formattedValue = PrependIndentation(formattedValue);
126+
}
127+
if (timestamp != null && showTimestamp)
128+
{
129+
formattedValue = PrependTimestamps(formattedValue, (DateTime) timestamp);
130+
}
131+
}
132+
133+
builder.AppendLine(formattedValue);
134+
135+
if (addExtraLine)
136+
{
137+
builder.AppendLine();
138+
}
139+
140+
return builder;
141+
}
142+
143+
/// <summary>
144+
/// Prepend every line in the input value with the specified indentation level.
145+
/// </summary>
146+
/// <param name="value">The value to which indentation will be applied</param>
147+
/// <param name="indent">The level of indentation, i.e. the number of spaces to prepend to every line in the value.</param>
148+
/// <returns>The input value with prepended indentation./</returns>
149+
private static string PrependIndentation(string value, int indent = DEFAULT_STRING_INDENTATION)
150+
{
151+
var indentString = new string(' ', indent);
152+
var newValue = value.Replace(Environment.NewLine, $"{Environment.NewLine}{indentString}");
153+
return $"{indentString}{newValue}";
154+
}
155+
156+
/// <summary>
157+
/// Prepend every line in the input value with a formatted string of <see cref="DateTime.Now"/>.
158+
/// </summary>
159+
/// <param name="value">The input value</param>
160+
/// <param name="timestamp">The timestamp to show</param>
161+
/// <param name="localize">true to format the string with the user's locale</param>
162+
/// <returns>The input value with prepended timestamps/</returns>
163+
public static string PrependTimestamps(string value, DateTime timestamp, bool localize = true)
102164
{
103-
var indentString = "";
104-
var i = 0;
105-
while (i++ < indent)
106-
indentString += " ";
107-
var newvalue = value.Replace(System.Environment.NewLine, string.Format("{0}{1}", System.Environment.NewLine, indentString));
108-
return builder.Append(string.Format("{0}{1}", indentString, newvalue));
165+
var timestampString = HelpersGUI.DateTimeToString(timestamp, Messages.DATEFORMAT_DM_HMS, localize);
166+
// normalise all line endings before splitting
167+
var lines = value.Replace(Environment.NewLine, "\n").Split('\n');
168+
return string.Join(Environment.NewLine, lines.Select(line => $"{timestampString} | {line}"));
109169
}
110-
}
170+
}
111171
}

XenAdmin/Diagnostics/Problems/HostProblem/ConflictingUpdatePresent.cs

+2-11
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,8 @@ public ConflictingUpdatePresent(Check check, string conflictingUpdates, Host hos
4545
this.conflictingUpdates = conflictingUpdates;
4646
}
4747

48-
public override string Description
49-
{
50-
get
51-
{
52-
return string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED_CONFLICTING_UPDATE, ServerName, conflictingUpdates);
53-
}
54-
}
48+
public override string Description => string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED_CONFLICTING_UPDATE, ServerName, conflictingUpdates);
5549

56-
public override string HelpMessage
57-
{
58-
get { return string.Empty; }
59-
}
50+
public override string HelpMessage => string.Empty;
6051
}
6152
}

XenAdmin/Diagnostics/Problems/HostProblem/HostMaintenanceMode.cs

+4-10
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,12 @@ namespace XenAdmin.Diagnostics.Problems.HostProblem
3939
{
4040
public class HostMaintenanceMode : HostProblem
4141
{
42-
public HostMaintenanceMode(Check check, Host host)
43-
: base(check, host)
42+
public HostMaintenanceMode(Check check, Host host)
43+
: base(check, host)
4444
{
4545
}
4646

47-
public override string Description
48-
{
49-
get { return string.Format(Messages.UPDATES_WIZARD_HOST_MAINTENANCE_MODE, ServerName); }
50-
}
47+
public override string Description => string.Format(Messages.UPDATES_WIZARD_HOST_MAINTENANCE_MODE, ServerName);
5148

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

59-
public override string HelpMessage
60-
{
61-
get { return Messages.ENABLE_PLAIN; }
62-
}
56+
public override string HelpMessage => Messages.ENABLE_PLAIN;
6357

6458
public override AsyncAction CreateUnwindChangesAction()
6559
{

XenAdmin/Diagnostics/Problems/HostProblem/HostNeedsReboot.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public HostNeedsReboot(Check check, Host host, bool livePatchingRestricted = fal
5252

5353
public override string Description => livePatchingRestricted
5454
? string.Format(Messages.UPDATES_WIZARD_REBOOT_NEEDED_LIVEPATCH_RESTRICTED, host.name_label)
55-
: livePatchingDisabled
56-
? string.Format(Messages.UPDATES_WIZARD_REBOOT_NEEDED_LIVEPATCH_DISABLED, host.name_label)
55+
: livePatchingDisabled
56+
? string.Format(Messages.UPDATES_WIZARD_REBOOT_NEEDED_LIVEPATCH_DISABLED, host.name_label)
5757
: string.Format(Messages.UPDATES_WIZARD_REBOOT_NEEDED, host.name_label);
5858
}
5959
}

XenAdmin/Diagnostics/Problems/HostProblem/HostNotLive.cs

+4-19
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,9 @@ public HostNotLive(Check check, Host host)
4545
{
4646
}
4747

48-
public override string Description
49-
{
50-
get { return string.Format(Messages.UPDATES_WIZARD_HOST_NOT_LIVE, ServerName); }
51-
}
48+
public override string Description => string.Format(Messages.UPDATES_WIZARD_HOST_NOT_LIVE, ServerName);
5249

53-
public override string HelpMessage
54-
{
55-
get { return CanStartHost() ? Messages.START_HOST : string.Empty; }
56-
}
50+
public override string HelpMessage => CanStartHost() ? Messages.START_HOST : string.Empty;
5751

5852
protected override AsyncAction CreateAction(out bool cancelled)
5953
{
@@ -85,17 +79,8 @@ public HostNotLiveWarning(Check check, Host host)
8579
this.host = host;
8680
}
8781

88-
public override string Title
89-
{
90-
get { return Check.Description; }
91-
}
82+
public override string Title => Check.Description;
9283

93-
public override string Description
94-
{
95-
get
96-
{
97-
return string.Format(Messages.UPDATES_WIZARD_HOST_NOT_LIVE_WARNING, host);
98-
}
99-
}
84+
public override string Description => string.Format(Messages.UPDATES_WIZARD_HOST_NOT_LIVE_WARNING, host);
10085
}
10186
}

XenAdmin/Diagnostics/Problems/HostProblem/HostNotSafeToUpgradeWarning.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public override string Message
6060
{
6161
switch (reason)
6262
{
63-
case HostNotSafeToUpgradeReason.NotEnoughSpace :
64-
return string.Format(Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE_LONG, BrandManager.ProductVersion70);
65-
63+
case HostNotSafeToUpgradeReason.NotEnoughSpace:
64+
return string.Format(Messages.NOT_SAFE_TO_UPGRADE_NOT_ENOUGH_SPACE_LONG, BrandManager.ProductVersion70);
65+
6666
default:
6767
return string.Format(Messages.NOT_SAFE_TO_UPGRADE_DEFAULT_WARNING_LONG, BrandManager.ProductVersion70);
6868
}

XenAdmin/Diagnostics/Problems/HostProblem/HostOutOfSpaceProblem.cs

+15-24
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class HostOutOfSpaceProblem : HostProblem
4646
private readonly Pool_update update;
4747

4848
public HostOutOfSpaceProblem(Check check, Host host, Pool_patch patch, DiskSpaceRequirements diskSpaceReq)
49-
: base(check, host)
49+
: base(check, host)
5050
{
5151
this.patch = patch;
5252
this.diskSpaceReq = diskSpaceReq;
@@ -82,13 +82,13 @@ public override string Description
8282

8383
switch (diskSpaceReq.Operation)
8484
{
85-
case DiskSpaceRequirements.OperationTypes.install :
86-
return string.Format(Messages.NOT_ENOUGH_SPACE_MESSAGE_INSTALL, ServerName, name);
87-
88-
case DiskSpaceRequirements.OperationTypes.upload :
89-
return string.Format(Messages.NOT_ENOUGH_SPACE_MESSAGE_UPLOAD, ServerName, name);
90-
91-
case DiskSpaceRequirements.OperationTypes.automatedUpdates :
85+
case DiskSpaceRequirements.OperationTypes.install:
86+
return string.Format(Messages.NOT_ENOUGH_SPACE_MESSAGE_INSTALL, ServerName, name);
87+
88+
case DiskSpaceRequirements.OperationTypes.upload:
89+
return string.Format(Messages.NOT_ENOUGH_SPACE_MESSAGE_UPLOAD, ServerName, name);
90+
91+
case DiskSpaceRequirements.OperationTypes.automatedUpdates:
9292
return string.Format(Messages.NOT_ENOUGH_SPACE_MESSAGE_AUTO_UPDATE, ServerName);
9393

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

109109
if (patch != null && diskSpaceReq.CanCleanup)
110110
{
111-
Program.Invoke(Program.MainWindow, delegate()
111+
Program.Invoke(Program.MainWindow, delegate ()
112112
{
113113
using (var dlg = new WarningDialog(diskSpaceReq.GetSpaceRequirementsMessage(),
114114
new ThreeButtonDialog.TBDButton(Messages.YES, DialogResult.Yes, selected: true),
@@ -122,30 +122,21 @@ protected override AsyncAction CreateAction(out bool cancelled)
122122
});
123123
}
124124
else
125-
{
126-
Program.Invoke(Program.MainWindow, delegate()
125+
{
126+
Program.Invoke(Program.MainWindow, delegate ()
127127
{
128128
using (var dlg = new WarningDialog(diskSpaceReq.GetSpaceRequirementsMessage()))
129129
dlg.ShowDialog();
130130
});
131131
}
132-
cancelled = action == null;
133-
132+
cancelled = action == null;
133+
134134
return action;
135135
}
136136

137-
public override string HelpMessage
138-
{
139-
get { return diskSpaceReq.GetMessageForActionLink(); }
140-
}
137+
public override string HelpMessage => diskSpaceReq.GetMessageForActionLink();
141138

142-
public override bool IsFixable
143-
{
144-
get
145-
{
146-
return false;
147-
}
148-
}
139+
public override bool IsFixable => false;
149140

150141
public override bool Equals(object obj)
151142
{

XenAdmin/Diagnostics/Problems/HostProblem/HostPrepareToUpgradeProblem.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public HostPrepareToUpgradeProblem(Check check, Host host, string friendlyErrorK
5151
public override bool IsFixable => false;
5252

5353
public override string Description => _shortMessage;
54-
54+
5555
public override string HelpMessage => Messages.MORE_INFO;
5656

5757
protected override Actions.AsyncAction CreateAction(out bool cancelled)

XenAdmin/Diagnostics/Problems/HostProblem/HostProblem.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace XenAdmin.Diagnostics.Problems.HostProblem
3838
{
3939
public abstract class HostProblem : Problem
4040
{
41-
protected HostProblem(Check check, Host server)
41+
protected HostProblem(Check check, Host server)
4242
: base(check)
4343
{
4444
Server = server;

XenAdmin/Diagnostics/Problems/HostProblem/LicenseRestrictionProblem.cs

+5-20
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,14 @@ public LicenseRestrictionProblem(Check check, Host host)
4646
this.host = host;
4747
}
4848

49-
public override string Description
50-
{
51-
get { return string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED, Helpers.GetName(host).Ellipsise(30), FriendlyErrorNames.LICENCE_RESTRICTION); }
52-
}
49+
public override string Description => string.Format(Messages.UPDATES_WIZARD_PRECHECK_FAILED, Helpers.GetName(host).Ellipsise(30), FriendlyErrorNames.LICENCE_RESTRICTION);
5350

54-
public override string Title
55-
{
56-
get { return Description; }
57-
}
51+
public override string Title => Description;
5852

59-
public override string LinkText
60-
{
61-
get { return Messages.LICENSE_MANAGER_BUY_LICENSE_LINK_TEXT; }
62-
}
53+
public override string LinkText => Messages.LICENSE_MANAGER_BUY_LICENSE_LINK_TEXT;
6354

64-
public override string HelpMessage
65-
{
66-
get { return LinkText; }
67-
}
55+
public override string HelpMessage => LinkText;
6856

69-
public override Uri UriToLaunch
70-
{
71-
get { return new Uri(InvisibleMessages.UPSELL_SA); }
72-
}
57+
public override Uri UriToLaunch => new Uri(InvisibleMessages.UPSELL_SA);
7358
}
7459
}

0 commit comments

Comments
 (0)