Skip to content

Commit

Permalink
CA-386317: Use localized value to override data source descriptions
Browse files Browse the repository at this point in the history
Signed-off-by: Danilo Del Busso <[email protected]>
  • Loading branch information
danilo-delbusso committed Dec 4, 2023
1 parent 91a6c25 commit 9866f01
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
15 changes: 5 additions & 10 deletions XenAdmin/Controls/CustomDataGraph/GraphHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,11 @@ public static List<DataSourceItem> BuildList(IXenObject xenObject, List<Data_sou
if (dataSource.name_label == "memory_total_kib" || dataSource.name_label == "memory")
continue;

string friendlyName;
if (dataSource.name_label == "memory_free_kib" && xenObject is Host)
friendlyName = Helpers.GetFriendlyDataSourceName("memory_used_kib", xenObject);
else if (dataSource.name_label == "memory_internal_free" && xenObject is VM)
friendlyName = Helpers.GetFriendlyDataSourceName("memory_internal_used", xenObject);
else
friendlyName = Helpers.GetFriendlyDataSourceName(dataSource.name_label, xenObject);

string itemUuid = Palette.GetUuid(dataSource.name_label, xenObject);
dataSourceItems.Add(new DataSourceItem(dataSource, friendlyName, Palette.GetColour(itemUuid), itemUuid));
var friendlyName = Helpers.GetFriendlyDataSourceName(dataSource.name_label, xenObject) ?? dataSource.name_label;
var friendlyDescription = Helpers.GetFriendlyDataSourceDescription(dataSource.name_label, xenObject) ?? dataSource.name_description;

var itemUuid = Palette.GetUuid(dataSource.name_label, xenObject);
dataSourceItems.Add(new DataSourceItem(dataSource, friendlyName, friendlyDescription, Palette.GetColour(itemUuid), itemUuid));
}

// Filter old datasources only if we have their replacement ones
Expand Down
5 changes: 3 additions & 2 deletions XenModel/FriendlyNameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ public class FriendlyNameManager
/// <summary>
/// Returns null if no match is found.
/// </summary>
public static string GetFriendlyName(string s)
public static string GetFriendlyName(string s, bool ignoreAssert = false)
{
var result = FriendlyNames.GetString(s);
#if DEBUG
Debug.Assert(result != null, $"{s} doesn't exist in FriendlyNames");
if(!ignoreAssert)
Debug.Assert(result != null, $"{s} doesn't exist in FriendlyNames");
#endif
switch (s)
{
Expand Down
18 changes: 18 additions & 0 deletions XenModel/FriendlyNames.Designer.cs

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

6 changes: 6 additions & 0 deletions XenModel/FriendlyNames.resx
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@
<data name="Description-host.system_status-yum" xml:space="preserve">
<value>YUM repository information and RPM package database listing</value>
</data>
<data name="Description-performance.memory_internal_used" xml:space="preserve">
<value>Memory used as reported by the guest agent</value>
</data>
<data name="Description-performance.memory_used_kib" xml:space="preserve">
<value>Total amount of used memory</value>
</data>
<data name="Description-VM.ha_restart_priority.AlwaysRestart" xml:space="preserve">
<value>Always try to restart VM</value>
</data>
Expand Down
28 changes: 25 additions & 3 deletions XenModel/Utils/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,34 @@ public static DataSourceCategory GetDataSourceCategory(string name)
return DataSourceCategory.Custom;
}

private static string GetDataSourceId(string originalId)
{
switch (originalId)
{
case "memory_free_kib":
return "memory_used_kib";
case "memory_internal_free":
return "memory_internal_used";
default:
return originalId;
}
}

public static string GetFriendlyDataSourceDescription(string name, IXenObject iXenObject)
{
var id = GetDataSourceId(name);
// suppressing the assert check since we don't support localization anymore, so there's no need to override all descriptions.
return iXenObject == null ? id : FriendlyNameManager.GetFriendlyName($"Description-performance.{id}", true);
}

public static string GetFriendlyDataSourceName(string name, IXenObject iXenObject)
{
var id = GetDataSourceId(name);
if (iXenObject == null)
return name;
string s = GetFriendlyDataSourceName_(name, iXenObject);
return string.IsNullOrEmpty(s) ? name : s;
return id;

var friendlyDataSourceName = GetFriendlyDataSourceName_(id, iXenObject);
return string.IsNullOrEmpty(friendlyDataSourceName) ? id : friendlyDataSourceName;
}

private static string GetFriendlyDataSourceName_(string name, IXenObject iXenObject)
Expand Down

0 comments on commit 9866f01

Please sign in to comment.