mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-23 20:36:33 +01:00
CA-179502: Reviewed all use of MemorySizeStringMB and came to the conclusion that all its usages must be replaced with MemorySizeStringSuitableUnits.
This commit is contained in:
parent
82ab747bd6
commit
4fadf796ad
@ -189,9 +189,9 @@ namespace XenAdmin.Alerts
|
||||
case AlarmType.Memory:
|
||||
return string.Format(Messages.ALERT_ALARM_MEMORY_DESCRIPTION,
|
||||
Helpers.GetNameAndObject(XenObject),
|
||||
Util.MemorySizeStringMB(CurrentValue * Util.BINARY_KILO),//xapi unit is in kib
|
||||
Util.MemorySizeStringSuitableUnits(CurrentValue * Util.BINARY_KILO, false),//xapi unit is in kib
|
||||
Util.TimeString(TriggerPeriod),
|
||||
Util.MemorySizeStringMB(TriggerLevel * Util.BINARY_KILO));
|
||||
Util.MemorySizeStringSuitableUnits(TriggerLevel * Util.BINARY_KILO, false));
|
||||
case AlarmType.Dom0MemoryDemand:
|
||||
return string.Format(Messages.ALERT_ALARM_DOM0_MEMORY_DEMAND_DESCRIPTION,
|
||||
Helpers.GetNameAndObject(XenObject),
|
||||
|
@ -210,7 +210,7 @@ namespace XenAdmin.Controls.GPU
|
||||
else
|
||||
maxDisplaysColumn.Value = string.Empty;
|
||||
|
||||
videoRamColumn.Value = VGpuType.framebuffer_size != 0 ? Util.MemorySizeStringMB(VGpuType.framebuffer_size) : string.Empty;
|
||||
videoRamColumn.Value = VGpuType.framebuffer_size != 0 ? Util.MemorySizeStringSuitableUnits(VGpuType.framebuffer_size, true) : string.Empty;
|
||||
}
|
||||
|
||||
private void SetupCheckBoxCell()
|
||||
|
@ -90,7 +90,7 @@ namespace XenAdmin.Dialogs.VMDialogs
|
||||
PoolMemoryFree += host.memory_free_calc;
|
||||
}
|
||||
|
||||
return Util.MemorySizeStringMB(PoolMemoryFree);
|
||||
return Util.MemorySizeStringSuitableUnits(PoolMemoryFree, true);
|
||||
}
|
||||
|
||||
private void UpdateRequiredMemory()
|
||||
@ -104,7 +104,7 @@ namespace XenAdmin.Dialogs.VMDialogs
|
||||
required += (long)row.Vm.memory_dynamic_max;
|
||||
}
|
||||
RequiredLabel.ForeColor = required > PoolMemoryFree ? Color.Red : ForeColor;
|
||||
RequiredLabel.Text = Util.MemorySizeStringMB(required);
|
||||
RequiredLabel.Text = Util.MemorySizeStringSuitableUnits(required, true);
|
||||
|
||||
OKButton.Enabled = required == 0 ? true : required < PoolMemoryFree;
|
||||
}
|
||||
@ -206,7 +206,7 @@ namespace XenAdmin.Dialogs.VMDialogs
|
||||
{
|
||||
ImageCell.Value = Images.GetImage16For(Images.GetIconFor(Vm));
|
||||
NameCell.Value = Vm.Name;
|
||||
MemoryCell.Value = Util.MemorySizeStringMB(Vm.memory_dynamic_max);
|
||||
MemoryCell.Value = Util.MemorySizeStringSuitableUnits(Vm.memory_dynamic_max, true);
|
||||
ActionCell.ValueType = typeof(ActionCellItem);
|
||||
ActionCell.ValueMember = "ActionCell";
|
||||
ActionCell.DisplayMember = "Text";
|
||||
|
@ -549,16 +549,16 @@ namespace XenAdmin
|
||||
log.InfoFormat("GDI handles open: {0}", Win32.GetGuiResourcesGDICount(p.Handle));
|
||||
log.InfoFormat("Thread count: {0}", p.Threads.Count);
|
||||
|
||||
log.InfoFormat("Virtual memory size: {0}", Util.MemorySizeStringMB(p.VirtualMemorySize64));
|
||||
log.InfoFormat("Working set: {0}", Util.MemorySizeStringMB(p.WorkingSet64));
|
||||
log.InfoFormat("Private memory size: {0}", Util.MemorySizeStringMB(p.PrivateMemorySize64));
|
||||
log.InfoFormat("Nonpaged system memory size: {0}", Util.MemorySizeStringMB(p.NonpagedSystemMemorySize64));
|
||||
log.InfoFormat("Paged memory size: {0}", Util.MemorySizeStringMB(p.PagedMemorySize64));
|
||||
log.InfoFormat("Paged system memory size: {0}", Util.MemorySizeStringMB(p.PagedSystemMemorySize64));
|
||||
log.InfoFormat("Virtual memory size: {0}", Util.MemorySizeStringSuitableUnits(p.VirtualMemorySize64, false));
|
||||
log.InfoFormat("Working set: {0}", Util.MemorySizeStringSuitableUnits(p.WorkingSet64, false));
|
||||
log.InfoFormat("Private memory size: {0}", Util.MemorySizeStringSuitableUnits(p.PrivateMemorySize64, false));
|
||||
log.InfoFormat("Nonpaged system memory size: {0}", Util.MemorySizeStringSuitableUnits(p.NonpagedSystemMemorySize64, false));
|
||||
log.InfoFormat("Paged memory size: {0}", Util.MemorySizeStringSuitableUnits(p.PagedMemorySize64, false));
|
||||
log.InfoFormat("Paged system memory size: {0}", Util.MemorySizeStringSuitableUnits(p.PagedSystemMemorySize64, false));
|
||||
|
||||
log.InfoFormat("Peak paged memory size: {0}", Util.MemorySizeStringMB(p.PeakPagedMemorySize64));
|
||||
log.InfoFormat("Peak virtual memory size: {0}", Util.MemorySizeStringMB(p.PeakVirtualMemorySize64));
|
||||
log.InfoFormat("Peak working set: {0}", Util.MemorySizeStringMB(p.PeakWorkingSet64));
|
||||
log.InfoFormat("Peak paged memory size: {0}", Util.MemorySizeStringSuitableUnits(p.PeakPagedMemorySize64, false));
|
||||
log.InfoFormat("Peak virtual memory size: {0}", Util.MemorySizeStringSuitableUnits(p.PeakVirtualMemorySize64, false));
|
||||
log.InfoFormat("Peak working set: {0}", Util.MemorySizeStringSuitableUnits(p.PeakWorkingSet64, false));
|
||||
|
||||
log.InfoFormat("Process priority class: {0}", p.PriorityClass.ToString());
|
||||
log.InfoFormat("Privileged processor time: {0}", p.PrivilegedProcessorTime.ToString());
|
||||
|
@ -221,13 +221,13 @@ namespace XenAdmin.Wizards.NewVMWizard
|
||||
sum.Add(new KeyValuePair<string, string>(Messages.NEWVMWIZARD_CPUMEMPAGE_VCPUS, SelectedVcpus.ToString()));
|
||||
sum.Add(new KeyValuePair<string, string>(Messages.NEWVMWIZARD_CPUMEMPAGE_TOPOLOGY, comboBoxTopology.Text));
|
||||
if (memoryMode == 1)
|
||||
sum.Add(new KeyValuePair<string, string>(Messages.MEMORY, Util.MemorySizeStringMB(SelectedMemoryStaticMax)));
|
||||
sum.Add(new KeyValuePair<string, string>(Messages.MEMORY, Util.MemorySizeStringSuitableUnits(SelectedMemoryStaticMax, false)));
|
||||
else
|
||||
{
|
||||
sum.Add(new KeyValuePair<string, string>(Messages.DYNAMIC_MIN, Util.MemorySizeStringMB(SelectedMemoryDynamicMin)));
|
||||
sum.Add(new KeyValuePair<string, string>(Messages.DYNAMIC_MAX, Util.MemorySizeStringMB(SelectedMemoryDynamicMax)));
|
||||
sum.Add(new KeyValuePair<string, string>(Messages.DYNAMIC_MIN, Util.MemorySizeStringSuitableUnits(SelectedMemoryDynamicMin, false)));
|
||||
sum.Add(new KeyValuePair<string, string>(Messages.DYNAMIC_MAX, Util.MemorySizeStringSuitableUnits(SelectedMemoryDynamicMax, false)));
|
||||
if (memoryMode == 3)
|
||||
sum.Add(new KeyValuePair<string, string>(Messages.STATIC_MAX, Util.MemorySizeStringMB(SelectedMemoryStaticMax)));
|
||||
sum.Add(new KeyValuePair<string, string>(Messages.STATIC_MAX, Util.MemorySizeStringSuitableUnits(SelectedMemoryStaticMax, false)));
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
@ -288,12 +288,12 @@ namespace XenAdmin.Wizards.NewVMWizard
|
||||
if (max_mem_total_host != null && SelectedMemoryDynamicMin > max_mem_total)
|
||||
{
|
||||
ErrorPanel.Visible = true;
|
||||
ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN1, Helpers.GetName(max_mem_total_host), Util.MemorySizeStringMB(max_mem_total));
|
||||
ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN1, Helpers.GetName(max_mem_total_host), Util.MemorySizeStringSuitableUnits(max_mem_total, false));
|
||||
}
|
||||
else if (max_mem_free_host != null && SelectedMemoryDynamicMin > max_mem_free)
|
||||
{
|
||||
ErrorPanel.Visible = true;
|
||||
ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN2, Helpers.GetName(max_mem_free_host), Util.MemorySizeStringMB(max_mem_free));
|
||||
ErrorLabel.Text = string.Format(Messages.NEWVMWIZARD_CPUMEMPAGE_MEMORYWARN2, Helpers.GetName(max_mem_free_host), Util.MemorySizeStringSuitableUnits(max_mem_free, false));
|
||||
}
|
||||
else if (max_vcpus_host != null && SelectedVcpus > max_vcpus)
|
||||
{
|
||||
|
@ -121,16 +121,6 @@ namespace XenAdminTests.UnitTests.MiscTests
|
||||
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void TestMemorySizeStringMB()
|
||||
{
|
||||
foreach (var pair in memoryMBpairs)
|
||||
{
|
||||
string expected = string.Format("{0} {1}", pair.Value[0], pair.Value[1]);
|
||||
Assert.AreEqual(expected, Util.MemorySizeStringMB(pair.Key));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMemorySizeStringSuitableUnits()
|
||||
{
|
||||
|
@ -76,7 +76,7 @@ namespace XenAdmin.Actions
|
||||
switch (type)
|
||||
{
|
||||
case HostBackupRestoreType.backup:
|
||||
this.Description = String.Format(Messages.BACKINGUP_HOST_WITH_DATA, Host.Name, Util.MemorySizeStringMB(0));
|
||||
this.Description = String.Format(Messages.BACKINGUP_HOST_WITH_DATA, Host.Name, Util.MemorySizeStringSuitableUnits(0, false));
|
||||
|
||||
LogDescriptionChanges = false;
|
||||
try
|
||||
@ -111,7 +111,7 @@ namespace XenAdmin.Actions
|
||||
|
||||
private void DataReceived(long bytes)
|
||||
{
|
||||
this.Description = String.Format(Messages.BACKINGUP_HOST_WITH_DATA, Host.Name, Util.MemorySizeStringMB(bytes));
|
||||
this.Description = String.Format(Messages.BACKINGUP_HOST_WITH_DATA, Host.Name, Util.MemorySizeStringSuitableUnits(bytes, false));
|
||||
}
|
||||
|
||||
public override void RecomputeCanCancel()
|
||||
|
@ -86,7 +86,7 @@ namespace XenAdmin.Actions
|
||||
case HostStatus.compiling:
|
||||
return Messages.BUGTOOL_HOST_STATUS_COMPILING;
|
||||
case HostStatus.downloading:
|
||||
return string.Format(Messages.BUGTOOL_HOST_STATUS_DOWNLOADING, Util.MemorySizeStringMB(DataTransferred));
|
||||
return string.Format(Messages.BUGTOOL_HOST_STATUS_DOWNLOADING, Util.MemorySizeStringSuitableUnits(DataTransferred, false));
|
||||
default:
|
||||
return Messages.BUGTOOL_HOST_STATUS_PENDING;
|
||||
}
|
||||
|
@ -95,12 +95,7 @@ namespace XenAdmin
|
||||
{
|
||||
return string.Format(Messages.VAL_B, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public static string MemorySizeStringMB(double bytes)
|
||||
{
|
||||
return string.Format(Messages.VAL_MB, Math.Round(bytes / BINARY_MEGA));
|
||||
}
|
||||
}
|
||||
|
||||
public static string DataRateString(double bytesPerSec)
|
||||
{
|
||||
|
@ -1222,8 +1222,8 @@ namespace XenAPI
|
||||
long ServerMBTotal = m.memory_total;
|
||||
|
||||
return string.Format(Messages.GENERAL_MEMORY_SERVER_FREE,
|
||||
Util.MemorySizeStringMB(ServerMBAvail),
|
||||
Util.MemorySizeStringMB(ServerMBTotal));
|
||||
Util.MemorySizeStringSuitableUnits(ServerMBAvail, true),
|
||||
Util.MemorySizeStringSuitableUnits(ServerMBTotal, true));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1237,7 +1237,7 @@ namespace XenAPI
|
||||
if (Connection.Resolve(metrics) == null)
|
||||
return Messages.GENERAL_UNKNOWN;
|
||||
|
||||
return Util.MemorySizeStringMB(xen_memory_calc);
|
||||
return Util.MemorySizeStringSuitableUnits(xen_memory_calc, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1266,7 +1266,7 @@ namespace XenAPI
|
||||
continue;
|
||||
|
||||
string message = string.Format(Messages.GENERAL_MEMORY_VM_USED, vm.Name,
|
||||
Util.MemorySizeStringMB(VMMetrics.memory_actual));
|
||||
Util.MemorySizeStringSuitableUnits(VMMetrics.memory_actual, true));
|
||||
|
||||
lines.Add(message);
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ namespace XenAPI
|
||||
if (IsPassthrough)
|
||||
return Messages.VGPU_PASSTHRU_TOSTRING;
|
||||
|
||||
var videoRam = framebuffer_size != 0 ? Util.MemorySizeStringMB(framebuffer_size): string.Empty;
|
||||
return string.Format(Messages.VGPU_DESCRIPTION, model_name, Capacity, MaxResolution, max_heads);
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ namespace XenAdmin.XenSearch
|
||||
if (total == 0 || Double.IsNaN(total) || Double.IsNaN(free))
|
||||
return Messages.HYPHEN;
|
||||
else
|
||||
return String.Format(Messages.QUERY_MEMORY_USAGE, (used / (free + used) * 100).ToString("0.") + "%", Util.MemorySizeStringMB(free + used));
|
||||
return String.Format(Messages.QUERY_MEMORY_USAGE, (used / (free + used) * 100).ToString("0.") + "%", Util.MemorySizeStringSuitableUnits(free + used, false));
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user