/// <summary> /// Populates the tree with the event attributes supported by the category. /// </summary> private void ShowEventAttributes(TreeNodeCollection nodes, Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category) { Technosoftware.DaAeHdaClient.Ae.TsCAeAttribute[] attributes = null; // fetch attributes. try { attributes = mServer_.QueryEventAttributes(category.ID); } catch (Exception e) { MessageBox.Show(e.Message); return; } // add attributes to tree. foreach (Technosoftware.DaAeHdaClient.Ae.TsCAeAttribute attribute in attributes) { // create node. TreeNode node = new TreeNode(attribute.Name) { ImageIndex = Resources.IMAGE_EXPLODING_BOX, SelectedImageIndex = Resources.IMAGE_EXPLODING_BOX, Tag = attribute }; // add to tree. nodes.Add(node); } }
/// <summary> /// Updates categories with selected attributes to dictionary. /// </summary> private void SetSelectedCategories(TreeNode parent, Technosoftware.DaAeHdaClient.Ae.TsCAeAttributeDictionary attributes) { foreach (TreeNode child in parent.Nodes) { if (!typeof(Technosoftware.DaAeHdaClient.Ae.TsCAeCategory).IsInstanceOfType(child.Tag)) { continue; } // check if category exists. Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category = (Technosoftware.DaAeHdaClient.Ae.TsCAeCategory)child.Tag; if (!attributes.Contains(category.ID)) { child.Checked = false; continue; } // check if attributes need to be fetched. if (child.Nodes.Count == 1 && child.Nodes[0].Text.Length == 0) { child.Nodes.Clear(); ShowEventAttributes(child.Nodes, category); } // update individual attributes. SetSelectedAttributes(child, category, attributes); } }
/// <summary> /// Sets the currently selected categories. /// </summary> public void SetSelectedCategories(int[] categoryIDs) { foreach (ListViewItem item in categoriesLv_.Items) { item.Checked = false; Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category = (Technosoftware.DaAeHdaClient.Ae.TsCAeCategory)item.Tag; for (int ii = 0; ii < categoryIDs.Length; ii++) { if (categoryIDs[ii] == category.ID) { item.Checked = true; break; } } } }
/// <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> /// Checks or unchecks all attributes for the specified category id. /// </summary> public void SelectCategory(TreeNode parent, int categoryId, bool picked) { foreach (TreeNode child in parent.Nodes) { if (!typeof(Technosoftware.DaAeHdaClient.Ae.TsCAeCategory).IsInstanceOfType(child.Tag)) { continue; } // find the matching category id. Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category = (Technosoftware.DaAeHdaClient.Ae.TsCAeCategory)child.Tag; if (categoryId == category.ID) { // ensure node is visible if state changes. if (child.Checked != picked) { // fetch attributes if a dummy mode exists. if (child.Nodes.Count == 1 && child.Nodes[0].Text.Length == 0) { child.Nodes.Clear(); ShowEventAttributes(child.Nodes, category); } child.EnsureVisible(); } if (picked) { child.Checked = true; } else { child.Checked = false; } } } }
/// <summary> /// Populates the tree with the conditions for the category. /// </summary> private void BrowseCategory(TreeNodeCollection nodes, Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category) { // fetch conditions. string[] conditions = mServer_.QueryConditionNames(category.ID); // add conditions to tree. for (int ii = 0; ii < conditions.Length; ii++) { // create node. TreeNode node = new TreeNode(conditions[ii]) { ImageIndex = Resources.IMAGE_EXPLODING_BOX, SelectedImageIndex = Resources.IMAGE_EXPLODING_BOX, Tag = new Condition(conditions[ii]) }; // add dummy child to ensure '+' sign is visible. node.Nodes.Add(new TreeNode()); // add to tree. nodes.Add(node); } }
/// <summary> /// Adds selected attributes to the dictionary. /// </summary> private void GetSelectedAttributes(TreeNode parent, Technosoftware.DaAeHdaClient.Ae.TsCAeCategory category, Technosoftware.DaAeHdaClient.Ae.TsCAeAttributeDictionary attributes) { foreach (TreeNode child in parent.Nodes) { if (!typeof(Technosoftware.DaAeHdaClient.Ae.TsCAeAttribute).IsInstanceOfType(child.Tag)) { continue; } if (child.Checked) { Technosoftware.DaAeHdaClient.Ae.TsCAeAttributeCollection collection = attributes[category.ID]; if (collection == null) { attributes.Add(category.ID, null); collection = attributes[category.ID]; } collection.Add(((Technosoftware.DaAeHdaClient.Ae.TsCAeAttribute)child.Tag).ID); } } }
/// <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_); }