private void AddPropertyRefentry(BacnetDeviceObjectPropertyReference bopr, int IdxRemove)
        {
            String newText;

            if (bopr.deviceIndentifier.type != BacnetObjectTypes.OBJECT_DEVICE)
            {
                newText = bopr.objectIdentifier.ToString().Substring(7) + " - " + ((BacnetPropertyIds)bopr.propertyIdentifier).ToString().Substring(5) + " on localDevice";
            }
            else
            {
                newText = bopr.objectIdentifier.ToString().Substring(7) + " - " + ((BacnetPropertyIds)bopr.propertyIdentifier).ToString().Substring(5) + " on DEVICE:" + bopr.deviceIndentifier.instance.ToString();
            }

            if (IdxRemove != -1)
            {
                listReferences.Items.RemoveAt(IdxRemove); // remove an old entry
            }
            ListViewItem lvi = new ListViewItem();

            // add a new one
            lvi.Text       = newText;
            lvi.Tag        = bopr;
            lvi.ImageIndex = YabeMainDialog.GetIconNum(bopr.objectIdentifier.type);
            listReferences.Items.Add(lvi);
        }
Exemplo n.º 2
0
        private void FillTreeNode()
        {
            int icon;

            TAlarmList.Nodes.Clear();

            TAlarmList.BeginUpdate();

            // Only one network read request to get the object name
            int _retries = comm.Retries;

            comm.Retries = 1;

            // fill the Treenode
            foreach (BacnetGetEventInformationData alarm in Alarms)
            {
                if ((alarm.acknowledgedTransitions.ToString() != "111") || (alarm.eventState != BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_NORMAL))
                {
                    TreeNode currentTn;

                    String nameStr = null;

                    lock (DevicesObjectsName)
                        DevicesObjectsName.TryGetValue(new Tuple <String, BacnetObjectId>(adr.FullHashString(), alarm.objectIdentifier), out nameStr);

                    if (nameStr == null)
                    {
                        // Get the property Name, network activity, time consuming
                        IList <BacnetValue> name;
                        bool retcode = comm.ReadPropertyRequest(adr, alarm.objectIdentifier, BacnetPropertyIds.PROP_OBJECT_NAME, out name);

                        if (retcode)
                        {
                            nameStr = name[0].Value.ToString();
                            lock (DevicesObjectsName)
                                DevicesObjectsName.Add(new Tuple <String, BacnetObjectId>(adr.FullHashString(), alarm.objectIdentifier), nameStr);
                        }
                    }

                    icon = YabeMainDialog.GetIconNum(alarm.objectIdentifier.type);
                    if (nameStr != null)
                    {
                        if (!Properties.Settings.Default.DisplayIdWithName)
                        {
                            currentTn = new TreeNode(nameStr, icon, icon);
                        }
                        else
                        {
                            currentTn = new TreeNode(nameStr + " (" + System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(alarm.objectIdentifier.ToString()) + ")", icon, icon);
                        }

                        currentTn.ToolTipText = alarm.objectIdentifier.ToString();
                    }
                    else
                    {
                        currentTn = new TreeNode(alarm.objectIdentifier.ToString(), icon, icon);
                    }

                    currentTn.Tag = alarm;
                    TAlarmList.Nodes.Add(currentTn);

                    if (Properties.Settings.Default.DescriptionInAlarmSummary)
                    {
                        String Descr = "";
                        try
                        {
                            // Get the Description, network activity, time consuming
                            IList <BacnetValue> name;
                            bool retcode = comm.ReadPropertyRequest(adr, alarm.objectIdentifier, BacnetPropertyIds.PROP_DESCRIPTION, out name);

                            if (retcode)
                            {
                                Descr = name[0].Value.ToString();
                            }
                        }
                        catch { }

                        currentTn.Nodes.Add(new TreeNode("Description : " + Descr, Int32.MaxValue, Int32.MaxValue));
                    }

                    icon = Int32.MaxValue; // out bound
                    currentTn.Nodes.Add(new TreeNode("Alarm state : " + GetEventStateNiceName(alarm.eventState.ToString()), icon, icon));


                    TreeNode tn2         = new TreeNode("Ack Required :", icon, icon);
                    bool     ackrequired = false;
                    for (int i = 0; i < 3; i++)
                    {
                        if (alarm.acknowledgedTransitions.ToString()[i] == '0')
                        {
                            BacnetEventNotificationData.BacnetEventEnable bee = (BacnetEventNotificationData.BacnetEventEnable)(1 << i);
                            String text = GetEventEnableNiceName(bee.ToString()) + " since " + alarm.eventTimeStamps[i].Time.ToString();
                            tn2.Nodes.Add(new TreeNode(text, icon, icon));
                            ackrequired = true;
                        }
                    }

                    if (!ackrequired)
                    {
                        tn2 = new TreeNode("No Ack Required, already done", icon, icon);
                    }
                    currentTn.Nodes.Add(tn2);
                }
            }

            // set back the request retries number
            comm.Retries = _retries;

            TAlarmList.EndUpdate();

            TAlarmList.ExpandAll();

            if (TAlarmList.Nodes.Count == 0)
            {
                LblInfo.Visible = true;
                LblInfo.Text    = "Empty event list ... all is OK";
            }
        }