diff --git a/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs b/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs index 3d9c067f6..6ebd5ba19 100644 --- a/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs +++ b/XenAdmin/Dialogs/VMProtectionRecovery/VMProtectionPoliciesDialog.cs @@ -201,43 +201,54 @@ namespace XenAdmin.Dialogs.VMPolicies dataGridView1.SuspendLayout(); var selectedPolicy = currentSelected; dataGridView1.Rows.Clear(); + var policyList = VMGroup.VMPolicies(Pool.Connection.Cache); + + /* creating a dictionary to hold (policy_uuid, message list) */ + + Dictionary> policyMessage = new Dictionary>(); + + /* populate the dictionary with policy uuid */ + + foreach (var policy in policyList) + { + policy.PolicyAlerts.Clear(); + List messageList = new List(); + policyMessage.Add(policy.uuid, messageList); + } + + /* iterate through all messages and populate the dictionary with message list */ - /* filter out the messages for VMSS as the VMSS does not have recent alerts and that need to be populated below*/ - List vmssMessages = new List(); if (!VMGroup.isVMPolicyVMPP) { var messages = Pool.Connection.Cache.Messages; + List value = new List(); + foreach (var message in messages) { if (message.cls == cls.VMSS) { - vmssMessages.Add(message); - } - } - } - foreach (var policy in VMGroup.VMPolicies(Pool.Connection.Cache)) - { - if (!VMGroup.isVMPolicyVMPP) - { - policy.PolicyAlerts.Clear(); - List processedMessages = new List(); - /*for VMSS: Populate the alerts from Messages by filtering out the alerts for this schedule - This is not required in VMPP as the VMPP record itself has the recentAlerts */ - foreach (var message in vmssMessages) - { - if (message.obj_uuid == policy.uuid) + if (policyMessage.TryGetValue(message.obj_uuid, out value)) { - policy.PolicyAlerts.Add(new PolicyAlert(message.priority, message.name, message.timestamp)); - processedMessages.Add(message); + value.Add(message); } - } - vmssMessages.RemoveAll(message => processedMessages.Contains(message)); - } - if (dataGridView1.ColumnCount > 0) - dataGridView1.Rows.Add(new PolicyRow(policy)); + } + } } - RefreshButtons(); + + /* add only 10 messages for each policy and referesh the rows*/ + + foreach (var policy in policyList) + { + for (int messageCount = 0; messageCount < 10 && messageCount < policyMessage[policy.uuid].Count; messageCount++) + { + policy.PolicyAlerts.Add(new PolicyAlert(policyMessage[policy.uuid][messageCount].priority, policyMessage[policy.uuid][messageCount].name, policyMessage[policy.uuid][messageCount].timestamp)); + } + if (dataGridView1.ColumnCount > 0) + dataGridView1.Rows.Add(new PolicyRow(policy)); + } + + RefreshButtons(); if (selectedPolicy != null) { foreach (PolicyRow row in dataGridView1.Rows)