/// <summary>
 /// Raise MetaDataReceived event
 /// </summary>
 /// <param name="e"></param>
 internal void RaiseMetaDataReceivedEvent(SubscribedDataEventArgs e)
 {
     try
     {
         if (MetaDataReceived != null)
         {
             MetaDataReceived(this, e);
         }
     }
     catch (Exception ex)
     {
         Utils.Trace(ex, "UaPubSubApplication.RaiseMetaDataReceivedEvent");
     }
 }
Example #2
0
        /// <summary>
        /// Raises the <see cref="UaPubSubApplication.DataReceived"/> event.
        /// </summary>
        /// <param name="networkMessage">The network message that was received.</param>
        /// <param name="source">The source of the received event.</param>
        protected void RaiseNetworkMessageDataReceivedEvent(UaNetworkMessage networkMessage, string source)
        {
            if (networkMessage.DataSetMessages != null && networkMessage.DataSetMessages.Count > 0)
            {
                SubscribedDataEventArgs subscribedDataEventArgs = new SubscribedDataEventArgs() {
                    NetworkMessage = networkMessage,
                    Source = source
                };

                //trigger notification for received subscribed data set
                Application.RaiseDataReceivedEvent(subscribedDataEventArgs);
                Utils.Trace("Connection '{0}' - RaiseNetworkMessageDataReceivedEvent() from source={0}, with {1} DataSets",
                    source, subscribedDataEventArgs.NetworkMessage.DataSetMessages.Count);
            }
            else
            {
                Utils.Trace("Connection '{0}' - RaiseNetworkMessageDataReceivedEvent() message from source={0} cannot be decoded.", source);
            }
        }
Example #3
0
        /// <summary>
        /// Processes the decoded <see cref="UaNetworkMessage"/> and
        /// raises the <see cref="UaPubSubApplication.DataReceived"/> or <see cref="UaPubSubApplication.MetaDataReceived"/> event.
        /// </summary>
        /// <param name="networkMessage">The network message that was received.</param>
        /// <param name="source">The source of the received event.</param>
        protected void ProcessDecodedNetworkMessage(UaNetworkMessage networkMessage, string source)
        {
            if (networkMessage.IsMetaDataMessage)
            {
                // update configuration of the corresponding reader objects found in this connection configuration
                List <DataSetReaderDataType> allReaders = GetAllDataSetReaders();
                foreach (DataSetReaderDataType reader in allReaders)
                {
                    bool raiseChangedEvent = false;

                    lock (m_lock)
                    {
                        // check if reader's MetaData shall be updated
                        if (reader.DataSetWriterId != 0 &&
                            reader.DataSetWriterId == networkMessage.DataSetWriterId &&
                            (reader.DataSetMetaData == null ||
                             !Utils.IsEqual(reader.DataSetMetaData.ConfigurationVersion, networkMessage.DataSetMetaData.ConfigurationVersion)))
                        {
                            raiseChangedEvent = true;
                        }
                    }

                    if (raiseChangedEvent)
                    {
                        // raise event
                        ConfigurationUpdatingEventArgs metaDataUpdatedEventArgs = new ConfigurationUpdatingEventArgs()
                        {
                            ChangedProperty = ConfigurationProperty.DataSetMetaData,
                            Parent          = reader,
                            NewValue        = networkMessage.DataSetMetaData,
                            Cancel          = false
                        };

                        // raise the ConfigurationUpdating event and see if configuration shall be changed
                        m_uaPubSubApplication.RaiseConfigurationUpdatingEvent(metaDataUpdatedEventArgs);

                        // check to see if the event handler canceled the save of new MetaData
                        if (!metaDataUpdatedEventArgs.Cancel)
                        {
                            Utils.Trace("Connection '{0}' - The MetaData is updated for DataSetReader '{1}' with DataSetWriterId={2}",
                                        source, reader.Name, networkMessage.DataSetWriterId);

                            lock (m_lock)
                            {
                                reader.DataSetMetaData = networkMessage.DataSetMetaData;
                            }
                        }
                    }
                }

                SubscribedDataEventArgs subscribedDataEventArgs = new SubscribedDataEventArgs()
                {
                    NetworkMessage = networkMessage,
                    Source         = source
                };

                // trigger notification for received DataSet MetaData
                Application.RaiseMetaDataReceivedEvent(subscribedDataEventArgs);

                Utils.Trace(
                    "Connection '{0}' - RaiseMetaDataReceivedEvent() from source={0}",
                    source,
                    subscribedDataEventArgs.NetworkMessage.DataSetMessages.Count);
            }
            else if (networkMessage.DataSetMessages != null && networkMessage.DataSetMessages.Count > 0)
            {
                SubscribedDataEventArgs subscribedDataEventArgs = new SubscribedDataEventArgs()
                {
                    NetworkMessage = networkMessage,
                    Source         = source
                };

                //trigger notification for received subscribed DataSet
                Application.RaiseDataReceivedEvent(subscribedDataEventArgs);

                Utils.Trace(
                    "Connection '{0}' - RaiseNetworkMessageDataReceivedEvent() from source={0}, with {1} DataSets",
                    source,
                    subscribedDataEventArgs.NetworkMessage.DataSetMessages.Count);
            }
            else
            {
                Utils.Trace("Connection '{0}' - RaiseNetworkMessageDataReceivedEvent() message from source={0} cannot be decoded.", source);
            }
        }