예제 #1
0
		/// <summary>
		/// Processes the given list of <see cref="RelayMessage"/>.
		/// </summary>
		/// <remarks>
		///     <para>This method is the primary entry point for handling a list of <see cref="RelayMessage"/>.
		///     </para>
		/// </remarks>
		/// <param name="messages">The given list of <see cref="RelayMessage"/>.</param>
		public void HandleMessages(IList<RelayMessage> messages)
		{
			counters.CountMessageList(messages);

			#region Assing SourceZone for each msg
			foreach (RelayMessage message in messages)
			{
				if (message.SourceZone == 0)
				{
					message.SourceZone = MyZone;
				}
			}
			#endregion

			MessageList list = new MessageList(messages);
			
			messageTracer.WriteMessageInfo(messages);
			
			if (list.InMessageCount > 0)
			{
				inMessagesPort.Post(list.InMessages);
			}
			if (list.OutMessageCount > 0)
			{
				HandleOutMessages(list.OutMessages);
			}
		}
예제 #2
0
		public IAsyncResult BeginHandleMessages(IList<RelayMessage> messages, object state, AsyncCallback callback)
		{
			RelayMessageListAsyncResult result;

			MessageList list = new MessageList(messages);
			
			messageTracer.WriteMessageInfo(messages);

			if (list.OutMessageCount > 0)
			{
				result = new RelayMessageListAsyncResult(list.OutMessages, state, callback);
			}
			else
			{
				result = new RelayMessageListAsyncResult(new List<RelayMessage>(0), state, callback);
			}

			try
			{
				counters.CountMessageList(messages);

				#region Assing SourceZone for each msg
				foreach (RelayMessage message in messages)
				{
					if (message.SourceZone == 0)
					{
						message.SourceZone = MyZone;
					}
				}
				#endregion


				if (list.InMessageCount > 0)
				{
					inMessagesPort.Post(list.InMessages);
				}

				if (list.OutMessageCount > 0)
				{
					if (outMessagesPort == null)
					{
						throw new InvalidOperationException("DataRelay is misconfigured.  BeginHandleMessages was called without OutMessagesOnRelayThreads enabled.");
					}
					outMessagesPort.Post(result); 
				}
				else //list.OutMessageCount == 0  // if there were no out messages we're done.
				{
					//we say it's sync because the callback is being called on the same thread
					const bool wasSynchronous = true;
					result.CompleteOperation(wasSynchronous);
				}
			}
			catch (Exception exc)
			{
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat("Exception doing BeginHandleMessages: {0}", exc);
                }                
				result.Exception = exc;
				//we say it's sync because the callback is being called on the same thread
				const bool wasSynchronous = true;
				result.CompleteOperation(wasSynchronous);
			}
			return result;
		}