private void RaiseDataMessageReceivedEvent(DataMessage dataMessage) { _logger.Trace("Raising DataMessageReceived event"); var handlers = DataMessageReceived; if (handlers != null) { handlers(this, new DataMessageEventArgs(dataMessage)); } }
private void RaiseDataAcquiredEvent(DataMessage message) { // check if this data type is paused or not active lock (_locker) { if (_pausedDataTypes.Contains(message.DataType)) { // do not report data that is currently paused return; } if (!_activeDataTypes.Contains(message.DataType)) { // do not report data that is currently not active // (this case indicates a small overlap between data acquisition and a stop control message, // or an inconsistency if it happens permanently - but by ignoring it we at least keep the // server in a consistent state and provide expected behavior). return; } } _logger.Trace("Raising event DataAcquired for {0}", message.DataType); // this is not synchronized to the context of the creator (e.g UI thread) automatically; // however, what we do ensure is that no more than one of these events are raised // at the same time to allow easier/safer sequential processing lock (_dataAcquiredEventLocker) { var handlers = DataAcquired; if (handlers != null) { handlers(this, new DataMessageEventArgs(message)); } } }
/// <summary> /// Manually adds new data to the data source to be reported to consumers. /// This is mandatory for certain data types like <c>Text</c> which cannot be acquired automatically. /// </summary> /// <param name="dataMessage">The data message to be reported to consumers of the data source.</param> public void AddData(DataMessage dataMessage) { try { _logger.Trace("Manually adding data of type {0} using AddData", dataMessage.DataType); // no synchronization needed here, because it is done // when the DataAcquired event is raised if (dataMessage.DataType == DataType.Text) { // we need to specially prepare text due to the message size constraints var textMessage = dataMessage as TextData; if (textMessage != null) { AddData(textMessage.Text); } } else { // for all other types of data, we simply pass through what we get RaiseDataAcquiredEvent(dataMessage); } } catch (Exception ex) { throw new PhoneControllerException(string.Format("Error while adding data {0}: {1}", dataMessage.DataType, ex.Message), ex); } }