Opc.Ua.Client.MonitoredItem.GetFieldValue C# (CSharp) Метод

GetFieldValue() публичный Метод

Returns value of the field name containing the event type.
public GetFieldValue ( EventFieldList eventFields, NodeId eventTypeId, IList browsePath, uint attributeId ) : object
eventFields EventFieldList
eventTypeId NodeId
browsePath IList
attributeId uint
Результат object
        public object GetFieldValue(
            EventFieldList       eventFields, 
            NodeId               eventTypeId, 
            IList<QualifiedName> browsePath, 
            uint                 attributeId)
        {
            if (eventFields == null)
            {
                return null;
            }
            
            EventFilter filter = m_filter as EventFilter;

            if (filter == null)
            {
                return null;
            }
            
            for (int ii = 0; ii < filter.SelectClauses.Count; ii++)
            {
                if (ii >= eventFields.EventFields.Count)
                {
                    return null;
                }
                
                // check for match.
                SimpleAttributeOperand clause = filter.SelectClauses[ii];

                // attribute id
                if (clause.AttributeId != attributeId)
                {
                    continue;
                }
                
                // match null browse path.
                if (browsePath == null || browsePath.Count == 0)
                {
                    if (clause.BrowsePath != null && clause.BrowsePath.Count > 0)
                    {
                        continue;
                    }
                    
                    // ignore event type id when matching null browse paths.
                    return eventFields.EventFields[ii].Value;
                }

                // match browse path.

                // event type id.
                if (clause.TypeDefinitionId != eventTypeId)
                {
                    continue;
                }

                // match element count.
                if (clause.BrowsePath.Count != browsePath.Count)
                {
                    continue;
                }
            
                // check each element.
                bool match = true;

                for (int jj = 0; jj < clause.BrowsePath.Count; jj++)
                {                    
                    if (clause.BrowsePath[jj] !=  browsePath[jj])
                    {
                        match = false;
                        break;
                    }
                }

                // check of no match.
                if (!match)
                {
                    continue;
                }
            
                // return value.
                return eventFields.EventFields[ii].Value;
            }

            // no event type in event field list.
            return null;
        }
        

Same methods

MonitoredItem::GetFieldValue ( EventFieldList eventFields, NodeId eventTypeId, QualifiedName browseName ) : object
MonitoredItem::GetFieldValue ( EventFieldList eventFields, NodeId eventTypeId, string browsePath, uint attributeId ) : object

Usage Example

Пример #1
0
    /// <summary>
    /// Processes a Publish response from the server.
    /// </summary>
    /// 
    void ItemNotification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
    {
      if (InvokeRequired)
      {
        BeginInvoke(new MonitoredItemNotificationEventHandler(ItemNotification), monitoredItem, e);
        return;
      }
      else if (!IsHandleCreated)
      {
        return;
      }
      try
      {
        if (monitoredItem != null)
        {
          string Key = monitoredItem.StartNodeId.Identifier.ToString() + "." + monitoredItem.RelativePath;
          ListViewItem[] lvis = listView1.Items.Find(Key, true);
          Opc.Ua.MonitoredItemNotification change = e.NotificationValue as Opc.Ua.MonitoredItemNotification;
          if(change != null)
          {
            DataValue dv = change.Value;
            if (lvis.Length == 1)
            {
              ListViewItem lvi = lvis[0];
              int subindex = lvi.SubItems.IndexOfKey(Key);
              ListViewItem.ListViewSubItem si = lvi.SubItems[subindex];
              TypedMonitoredItem mi = si.Tag as TypedMonitoredItem;
              
              if (mi != null)
              {
                if (mi.ClientHandle == monitoredItem.ClientHandle)
                {
                  if (dv != null && dv.Value != null)
                  {
                    if (monitoredItem.Status.Id == StatusCodes.BadNodeIdUnknown)
                    {
                      // Randy said we would get this, but we don't
                      RemoveSessionItem(lvi, true);
                    }
                    else
                    {
                     si.Text = mi.ToString(dv);
                    }
                  }
                  else
                  {
                    // This is what we get
                    RemoveSessionItem(lvi, true);
                  }
                }
                else
                {
                  Utils.Trace("(mi.ClientHandle != monitoredItem.ClientHandle " + MethodBase.GetCurrentMethod());
                }
              }
              else
              {
                Utils.Trace("mi is null " + MethodBase.GetCurrentMethod());
              }
            }
            else
            {
              Utils.Trace("lvis.Length != 1 " + MethodBase.GetCurrentMethod());
            }
          }
          else
          {
            EventFieldList eventFields = e.NotificationValue as EventFieldList;
            if (eventFields != null)
            {

              // get the event fields.
              NodeId eventType      = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.EventType) as NodeId;
              string sourceName     = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.SourceName) as string;
              DateTime? time        = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.Time) as DateTime?;
              ushort? severity      = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.Severity) as ushort?;
              LocalizedText message = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.Message) as LocalizedText;
              NodeId sourceNode     = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.SourceNode) as NodeId;
              //Utils.Trace("eventType: {0}, message: {1}, sourceName: {2} sourceNode: {3}", eventType.ToString(), message.Text.ToString(), sourceName.ToString(), sourceNode.ToString());
              if (eventType == new NodeId(ObjectTypes.AuditActivateSessionEventType))
              {
                Utils.Trace("AuditActivateSessionEventType detected " + MethodBase.GetCurrentMethod());
                AddSessions();
                m_Subscription.ModifyItems();
                m_Subscription.ApplyChanges();
              }
            }
            else
            {
              Utils.Trace("eventFields is null " + MethodBase.GetCurrentMethod());
            }
          }
        }
        else
        {
          Utils.Trace("monitoredItem is null " + MethodBase.GetCurrentMethod());
        }
      }
      catch (Exception exception)
      {
        GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
      }
    }
All Usage Examples Of Opc.Ua.Client.MonitoredItem::GetFieldValue