/// <summary> /// Force a refresh for all active conditions and inactive, unacknowledged conditions whose event notifications match the filter of the event subscription. /// </summary> /// <param name="dwConnection">The OLE Connection number returned from IConnectionPoint::Advise. This is passed to help the server determine which OPC event sink to call when the request completes.</param> public void Refresh(int dwConnection) { try { if (m_RefreshID != 0 || m_RefreshQ.Count != 0) { throw ComUtils.CreateComException("Refresh", ResultIds.E_BUSY); } m_RefreshID = dwConnection; // Foe each source walk through all associated conditions. If the condition is "refreshable", i.e. Active or // inactive/unacknowledged, then create an event and push it on to the subscription's refresh queue SourceMap sourceMap = SourceMap.TheSourceMap; foreach (KeyValuePair <string, ConditionMap> kvp in sourceMap) { string sourceName = kvp.Key; ConditionMap conditionMap = kvp.Value; foreach (KeyValuePair <string, OPCCondition> kvpCond in conditionMap) { string conditionName = kvpCond.Key; OPCCondition cond = kvpCond.Value; if (cond.IsEnabled() && (cond.IsActive() || !cond.IsAcked())) { OnEventClass OEClass = new OnEventClass(sourceName, conditionName, cond); if (MatchesFilter(OEClass)) { m_RefreshQ.Enqueue(OEClass); } } } } if (m_RefreshQ.Count > 0) { ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadWork), null); } else { CancelRefresh(dwConnection); } } catch (Exception e) { Utils.Trace(e, "Unexpected error in Refresh"); throw ComUtils.CreateComException(e); } }
/// <summary> /// If the event type is CONDITION_EVENT then update any existing record of the condition and adjust /// state and change mask. /// </summary> /// <param name="EventNotification"></param> /// <param name="areas"></param> public void ProcessEventNotificationList(EventNotification EventNotification, string[] areas) { SourceMap sourceMap = SourceMap.TheSourceMap; try { lock (sourceMap) { OPCCondition cond; if (EventNotification.EventType == OpcRcw.Ae.Constants.CONDITION_EVENT) { ConditionMap conditionMap; if (sourceMap.TryGetValue(EventNotification.SourceID, out conditionMap) == false) { conditionMap = new ConditionMap(); sourceMap.Add(EventNotification.SourceID, conditionMap); } if (conditionMap.TryGetValue(EventNotification.ConditionName, out cond) == false) { cond = new OPCCondition(); cond.EventType = EventNotification.EventType; conditionMap.Add(EventNotification.ConditionName, cond); } ProcessCondition(EventNotification, areas, cond); // When the condition has transitioned to Acked (if ack required) and inactive or disabled // then remove it from the condition source/condition database if ((!cond.IsActive() || !cond.IsEnabled()) && (cond.IsAcked() || !cond.AckRequired)) { conditionMap.Remove(EventNotification.ConditionName); } } else // a tracking or simple event { cond = new OPCCondition(); cond.EventType = EventNotification.EventType; ProcessCondition(EventNotification, areas, cond); } } } catch (Exception e) { Utils.Trace(e, "Unexpected error in ProcessEventNotificationList"); } }