/// <summary> /// Updates the selected attributes to the dictionary. /// </summary> private void SetSelectedAttributes(TreeNode parent, Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category, Technosoftware.DaAeHdaClient.Ae.TsCAeAttributeDictionary attributes) { foreach (TreeNode child in parent.Nodes) { if (!typeof(TsCAeAttribute).IsInstanceOfType(child.Tag)) { continue; } Technosoftware.DaAeHdaClient.Ae.TsCAeAttribute attribute = (Technosoftware.DaAeHdaClient.Ae.TsCAeAttribute)child.Tag; if (attributes[category.ID].Contains(attribute.ID)) { child.Checked = true; } else { child.Checked = false; } } }
/// <summary> /// Displays the notification in the control. /// </summary> public void ShowNotification(TsCAeSubscription subscription, TsCAeEventNotification notification) { // check for null value. if (notification == null) { sourceTb_.Text = ""; timeTb_.Text = ""; messageTb_.Text = ""; eventTypeTb_.Text = ""; eventCategoryTb_.Text = ""; conditionNameTb_.Text = ""; subConditionNameTb_.Text = ""; newStateTb_.Text = ""; ackRequiredTb_.Text = ""; qualityTb_.Text = ""; activeTimeTb_.Text = ""; actorTb_.Text = ""; attributesLv_.Items.Clear(); return; } // find category. Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category = null; try { Technosoftware.DaAeHdaClient.Ae.TsCAeCategory[] categories = subscription.Server.QueryEventCategories((int)notification.EventType); for (int ii = 0; ii < categories.Length; ii++) { if (categories[ii].ID == notification.EventCategory) { category = categories[ii]; break; } } } catch { category = null; } // find attributes. ArrayList attributes = new ArrayList(); try { // get attribute descriptions. Technosoftware.DaAeHdaClient.Ae.TsCAeAttribute[] descriptions = subscription.Server.QueryEventAttributes(notification.EventCategory); // get selected attributes. int[] attributeIDs = null; if (subscription.Attributes.Contains(notification.EventCategory)) { attributeIDs = subscription.Attributes[notification.EventCategory].ToArray(); } // find decriptions for selected attributes. if (attributeIDs != null) { for (int ii = 0; ii < attributeIDs.Length; ii++) { for (int jj = 0; jj < descriptions.Length; jj++) { if (descriptions[jj].ID == attributeIDs[ii]) { attributes.Add(descriptions[jj]); break; } } } } } catch { // ignore errors. } sourceTb_.Text = notification.SourceID; timeTb_.Text = Technosoftware.DaAeHdaClient.OpcConvert.ToString(notification.Time); messageTb_.Text = notification.Message; eventTypeTb_.Text = Technosoftware.DaAeHdaClient.OpcConvert.ToString(notification.EventType); eventCategoryTb_.Text = (category != null)?category.Name:""; conditionNameTb_.Text = notification.ConditionName; subConditionNameTb_.Text = notification.SubConditionName; newStateTb_.Text = ""; ackRequiredTb_.Text = Technosoftware.DaAeHdaClient.OpcConvert.ToString(notification.AckRequired); qualityTb_.Text = Technosoftware.DaAeHdaClient.OpcConvert.ToString(notification.Quality); activeTimeTb_.Text = Technosoftware.DaAeHdaClient.OpcConvert.ToString(notification.ActiveTime); actorTb_.Text = notification.ActorID; // convert state to a string. if ((notification.NewState & (int)TsCAeConditionState.Active) != 0) { newStateTb_.Text += TsCAeConditionState.Active.ToString(); } if ((notification.NewState & (int)TsCAeConditionState.Enabled) != 0) { if (newStateTb_.Text != "") { newStateTb_.Text += " AND "; } newStateTb_.Text += TsCAeConditionState.Enabled.ToString(); } if ((notification.NewState & (int)TsCAeConditionState.Acknowledged) != 0) { if (newStateTb_.Text != "") { newStateTb_.Text += " AND "; } newStateTb_.Text += TsCAeConditionState.Acknowledged.ToString(); } // fill attributes list. attributesLv_.Items.Clear(); for (int ii = 0; ii < notification.Attributes.Count; ii++) { Technosoftware.DaAeHdaClient.Ae.TsCAeAttribute attribute = (ii < attributes.Count)?(Technosoftware.DaAeHdaClient.Ae.TsCAeAttribute)attributes[ii]:null; ListViewItem item = new ListViewItem((attribute != null)?attribute.Name:"Unknown"); item.SubItems.Add(Technosoftware.DaAeHdaClient.OpcConvert.ToString(notification.Attributes[ii])); attributesLv_.Items.Add(item); } AdjustColumns(attributesLv_); }