From 046476cd6e2f65ad25a8bec370467009eb259f4b Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Tue, 15 Aug 2023 01:20:31 +0100 Subject: [PATCH] Show a different alert message if the user has never synchronized. Signed-off-by: Konstantina Chremmou --- .../Alerts/Types/OutOfSyncWithCdnAlert.cs | 28 +++++++++++++------ XenModel/Messages.Designer.cs | 9 ++++++ XenModel/Messages.resx | 3 ++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/XenAdmin/Alerts/Types/OutOfSyncWithCdnAlert.cs b/XenAdmin/Alerts/Types/OutOfSyncWithCdnAlert.cs index a08aadfc9..383664687 100644 --- a/XenAdmin/Alerts/Types/OutOfSyncWithCdnAlert.cs +++ b/XenAdmin/Alerts/Types/OutOfSyncWithCdnAlert.cs @@ -40,7 +40,7 @@ namespace XenAdmin.Alerts { public class OutOfSyncWithCdnAlert : Alert { - private readonly TimeSpan _outOfSyncSpan; + private readonly TimeSpan _outOfSyncSpan = TimeSpan.Zero; private readonly Pool _pool; private OutOfSyncWithCdnAlert(Pool pool, DateTime timestamp) @@ -49,12 +49,19 @@ namespace XenAdmin.Alerts _pool = pool; Connection = _pool.Connection; - _outOfSyncSpan = _timestamp - _pool.last_update_sync; + if (pool.last_update_sync > Util.GetUnixMinDateTime()) + { + _outOfSyncSpan = _timestamp - _pool.last_update_sync; - if (_outOfSyncSpan >= TimeSpan.FromDays(180)) - Priority = AlertPriority.Priority1; - else if (_outOfSyncSpan >= TimeSpan.FromDays(90)) - Priority = AlertPriority.Priority2; + if (_outOfSyncSpan >= TimeSpan.FromDays(180)) + Priority = AlertPriority.Priority1; + else if (_outOfSyncSpan >= TimeSpan.FromDays(90)) + Priority = AlertPriority.Priority2; + } + else + { + Priority = AlertPriority.Priority3; + } } public static bool TryCreate(IXenConnection connection, out Alert alert) @@ -79,8 +86,9 @@ namespace XenAdmin.Alerts public override string AppliesTo => Helpers.GetName(_pool); - public override string Description => string.Format(Messages.ALERT_CDN_OUT_OF_SYNC_DESCRIPTION, - AlertExtensions.GetGuiDate(_pool.last_update_sync)); + public override string Description => _outOfSyncSpan == TimeSpan.Zero + ? Messages.ALERT_CDN_NEVER_SYNC_TITLE + : string.Format(Messages.ALERT_CDN_OUT_OF_SYNC_DESCRIPTION, AlertExtensions.GetGuiDate(_pool.last_update_sync)); public override Action FixLinkAction { @@ -99,7 +107,9 @@ namespace XenAdmin.Alerts public override string HelpID => "TODO"; - public override string Title => string.Format(Messages.ALERT_CDN_OUT_OF_SYNC_TITLE, _outOfSyncSpan.Days); + public override string Title => _outOfSyncSpan == TimeSpan.Zero + ? Messages.ALERT_CDN_NEVER_SYNC_TITLE + : string.Format(Messages.ALERT_CDN_OUT_OF_SYNC_TITLE, _outOfSyncSpan.Days); } diff --git a/XenModel/Messages.Designer.cs b/XenModel/Messages.Designer.cs index 248164ed1..1ab43b090 100755 --- a/XenModel/Messages.Designer.cs +++ b/XenModel/Messages.Designer.cs @@ -4993,6 +4993,15 @@ namespace XenAdmin { } } + /// + /// Looks up a localized string similar to You have never synchronized with the update channel.. + /// + public static string ALERT_CDN_NEVER_SYNC_TITLE { + get { + return ResourceManager.GetString("ALERT_CDN_NEVER_SYNC_TITLE", resourceCulture); + } + } + /// /// Looks up a localized string similar to The last synchronization with the update channel took place on {0}.. /// diff --git a/XenModel/Messages.resx b/XenModel/Messages.resx index d25392cab..e9fbc0b3f 100755 --- a/XenModel/Messages.resx +++ b/XenModel/Messages.resx @@ -1834,6 +1834,9 @@ This alarm is set to be triggered when the total throughput exceeds {4}. (Showing first {0} entries) + + You have never synchronized with the update channel. + The last synchronization with the update channel took place on {0}.