예제 #1
0
 /// <summary>
 ///     Handles any message received from server after registration process completes successfully.
 /// </summary>
 /// <param name="message">Message to handle.</param>
 /// <remarks>
 ///     RegisterResponse is handled in base class.
 /// </remarks>
 /// <exception cref="System.InvalidOperationException">Thrown when received not supported message type.</exception>
 protected override void HandleReceivedMessage(Message message)
 {
     switch (message.MessageType)
     {
         case MessageClass.NoOperation:
             NoOperationMessageHandler((NoOperationMessage)message);
             break;
         case MessageClass.SolvePartialProblems:
             PartialProblemsMessageHandler((PartialProblemsMessage)message);
             break;
         case MessageClass.Error:
             ErrorMessageHandler((ErrorMessage)message);
             break;
         default:
             throw new InvalidOperationException("Received not supported message type.");
     }
 }
예제 #2
0
 /// <summary>
 /// Creates a new instance of the MessageEventArgs class using the specified <paramref name="message"/>.
 /// </summary>
 /// <param name="message">The message which is event argument.</param>
 public MessageEventArgs(Message message)
 {
     Message = message;
 }
예제 #3
0
 /// <summary>
 ///     Sends messages and returns messages received. Retruns null if neither primary nor backup servers answered or due to
 ///     other exception.
 /// </summary>
 /// <param name="message">Message to send.</param>
 /// <returns>Messages returned or null.</returns>
 public List<Message> Send(Message message)
 {
     return Send(new List<Message> { message });
 }
예제 #4
0
 /// <summary>
 /// Sends message to server and gets response.
 /// </summary>
 /// <param name="message">Message to be send to server.</param>
 /// <returns>Received messages or null if couldn't get server response.</returns>
 private List<Message> SendMessage(Message message)
 {
     var receivedMessages = _messageSender.Send(message);
     if (receivedMessages == null)
     {
         var exception = new NoResponseException("Server is not responding.");
         RaiseEvent(MessageSendingException, message, exception);
     }
     else
     {
         RaiseEvent(MessageSent, message);
         foreach (var receivedMessage in receivedMessages)
         {
             RaiseEvent(MessageReceived, receivedMessage);
         }
     }
     return receivedMessages;
 }
예제 #5
0
 /// <summary>
 /// Raises event handler if it is not null.
 /// </summary>
 /// <param name="eventHandler">Handler to be raised.</param>
 /// <param name="message">Message to be passed as event event argument.</param>
 /// <param name="exception">Exception to be passed as event event argument.</param>
 private void RaiseEvent(EventHandler<MessageExceptionEventArgs> eventHandler, Message message,
     Exception exception)
 {
     if (eventHandler != null)
     {
         eventHandler(this, new MessageExceptionEventArgs(message, exception));
     }
 }
예제 #6
0
 /// <summary>
 /// Raises event handler if it is not null.
 /// </summary>
 /// <param name="eventHandler">Handler to be raised.</param>
 /// <param name="message">Message to be passed as event event argument.</param>
 private void RaiseEvent(EventHandler<MessageEventArgs> eventHandler, Message message)
 {
     if (eventHandler != null)
     {
         eventHandler(this, new MessageEventArgs(message));
     }
 }
예제 #7
0
 /// <summary>
 /// Creates a new instance of the MessageExceptionEventArgs class using the specified <paramref name="message"/> and
 /// <paramref name="exception"/>.
 /// </summary>
 /// <param name="exception">The exception which is event argument.</param>
 public MessageExceptionEventArgs(Message message, Exception exception)
     : base(message)
 {
     Exception = exception;
 }