示例#1
0
 /// <summary>
 /// Sends a message to a spesific communicator as a reply to an incoming message.
 /// </summary>
 /// <param name="communicator">Communicator to send message</param>
 /// <param name="message">Message to send</param>
 /// <param name="incomingMessage">Incoming message which is being replied</param>
 private void ReplyMessageToCommunicator(ICommunicator communicator, ControlMessage message, MDSControllerMessage incomingMessage)
 {
     //Create MDSControllerMessage that includes serialized GetApplicationListResponseMessage message
     var outgoingMessage = new MDSControllerMessage
     {
         ControllerMessageTypeId = message.MessageTypeId,
         MessageData = MDSSerializationHelper.SerializeToByteArray(message),
         RepliedMessageId = incomingMessage.MessageId
     };
     //Send message to communicator that sent to message
     SendMessage(outgoingMessage, communicator);
 }
示例#2
0
        /// <summary>
        /// Sends a ControlMessage to all connected MDSController instances.
        /// </summary>
        /// <param name="message">Message to send</param>
        private void SendMessageToAllReceivers(ControlMessage message)
        {
            var outgoingMessage = new MDSControllerMessage
            {
                ControllerMessageTypeId = message.MessageTypeId,
                MessageData = MDSSerializationHelper.SerializeToByteArray(message)
            };

            var receivers = GetAllReceiverCommunicators();
            foreach (var receiver in receivers)
            {
                try
                {
                    SendMessage(outgoingMessage, receiver);
                }
                catch (Exception ex)
                {
                    Logger.Warn(ex.Message, ex);
                }
            }
        }
示例#3
0
 /// <summary>
 /// This methods checks type of message (MessageTypeId) and calls appropriate method to process message.
 /// </summary>
 /// <param name="communicator">Communicator that sent message</param>
 /// <param name="controllerMessage">MDSControllerMessage object that includes controlMessage</param>
 /// <param name="controlMessage">The message to be processed</param>
 private void ProcessControllerMessage(ICommunicator communicator, MDSControllerMessage controllerMessage , ControlMessage controlMessage)
 {
     switch (controlMessage.MessageTypeId)
     {
         case ControlMessageFactory.MessageTypeIdGetApplicationListMessage:
             ProcessGetApplicationListMessage(communicator, controllerMessage);
             break;
         case ControlMessageFactory.MessageTypeIdGetWaitingMessagesOfApplicationMessage:
             ProcessGetWaitingMessagesOfApplicationMessage(communicator, controlMessage as GetWaitingMessagesOfApplicationMessage, controllerMessage);
             break;
         case ControlMessageFactory.MessageTypeIdAddNewApplicationMessage:
             ProcessAddNewApplicationMessage(controlMessage as AddNewApplicationMessage);
             break;
         case ControlMessageFactory.MessageTypeIdRemoveApplicationMessage:
             ProcessRemoveApplicationMessage(communicator, controlMessage as RemoveApplicationMessage, controllerMessage);
             break;
         case ControlMessageFactory.MessageTypeIdGetServerGraphMessage:
             ProcessGetServerGraphMessage(communicator, controllerMessage);
             break;
         case ControlMessageFactory.MessageTypeIdUpdateServerGraphMessage:
             ProcessUpdateServerGraphMessage(communicator, controlMessage as UpdateServerGraphMessage, controllerMessage);
             break;
         case ControlMessageFactory.MessageTypeIdGetApplicationWebServicesMessage:
             ProcessGetApplicationWebServicesMessage(communicator, controlMessage as GetApplicationWebServicesMessage, controllerMessage);
             break;
         case ControlMessageFactory.MessageTypeIdUpdateApplicationWebServicesMessage:
             ProcessUpdateApplicationWebServicesMessage(communicator, controlMessage as UpdateApplicationWebServicesMessage, controllerMessage);
             break;
         default:
             throw new MDSException("Undefined MessageTypeId for ControlMessage: " + controlMessage.MessageTypeId);
     }
 }
示例#4
0
        /// <summary>
        /// Sends a ControlMessage to MDS server and gets it's response message.
        /// </summary>
        /// <param name="message">Message to send</param>
        /// <returns>Response message from server</returns>
        public ControlMessage SendMessageAndGetResponse(ControlMessage message)
        {
            //Create a WaitingMessage to wait and get response message and add it to waiting messages
            var outgoingMessage = new MDSControllerMessage
                                      {
                                          MessageData = MDSSerializationHelper.SerializeToByteArray(message),
                                          ControllerMessageTypeId = message.MessageTypeId
                                      };
            var waitingMessage = new WaitingMessage();
            lock (_waitingMessages)
            {
                _waitingMessages[outgoingMessage.MessageId] = waitingMessage;
            }

            try
            {
                //Send message to the server
                SendMessageInternal(outgoingMessage);

                //Wait until thread is signalled by another thread to get response (Signalled by CommunicationChannel_MessageReceived method)
                waitingMessage.WaitEvent.WaitOne(TimeSpan.FromSeconds(90));

                //Check if response received or timeout occured
                if(waitingMessage.ResponseMessage == null)
                {
                    throw new MDSException("Timeout occured. Response message did not received.");
                }
                
                return DeserializeControlMessage(waitingMessage.ResponseMessage);
            }
            finally
            {
                //Remove message from waiting messages
                lock (_waitingMessages)
                {
                    if (_waitingMessages.ContainsKey(outgoingMessage.MessageId))
                    {
                        _waitingMessages.Remove(outgoingMessage.MessageId);
                    }
                }
            }
        }
示例#5
0
 /// <summary>
 /// Sends a ControlMessage to MDS server.
 /// </summary>
 /// <param name="message">Message to send</param>
 public void SendMessage(ControlMessage message)
 {
     SendMessageInternal(new MDSControllerMessage
                             {
                                 MessageData = MDSSerializationHelper.SerializeToByteArray(message),
                                 ControllerMessageTypeId = message.MessageTypeId
                             });
 }
 /// <summary>
 /// Creates a ControlMessageReceivedEventArgs object.
 /// </summary>
 /// <param name="message">Received message from MDS server</param>
 public ControlMessageReceivedEventArgs(ControlMessage message)
 {
     Message = message;
 }