Пример #1
0
        /// <summary>
        /// Sends a ControlMessage to NGRID 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 NGRIDControllerMessage
                                      {
                                          MessageData = NGRIDSerializationHelper.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 NGRIDException("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);
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Sends a ControlMessage to NGRID server.
 /// </summary>
 /// <param name="message">Message to send</param>
 public void SendMessage(ControlMessage message)
 {
     SendMessageInternal(new NGRIDControllerMessage
                             {
                                 MessageData = NGRIDSerializationHelper.SerializeToByteArray(message),
                                 ControllerMessageTypeId = message.MessageTypeId
                             });
 }
Пример #3
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, NGRIDControllerMessage incomingMessage)
 {
     //Create NGRIDControllerMessage that includes serialized GetApplicationListResponseMessage message
     var outgoingMessage = new NGRIDControllerMessage
     {
         ControllerMessageTypeId = message.MessageTypeId,
         MessageData = NGRIDSerializationHelper.SerializeToByteArray(message),
         RepliedMessageId = incomingMessage.MessageId
     };
     //Send message to communicator that sent to message
     SendMessage(outgoingMessage, communicator);
 }
Пример #4
0
        /// <summary>
        /// Sends a ControlMessage to all connected NGRIDController instances.
        /// </summary>
        /// <param name="message">Message to send</param>
        private void SendMessageToAllReceivers(ControlMessage message)
        {
            var outgoingMessage = new NGRIDControllerMessage
            {
                ControllerMessageTypeId = message.MessageTypeId,
                MessageData = NGRIDSerializationHelper.SerializeToByteArray(message)
            };

            var receivers = GetAllReceiverCommunicators();
            foreach (var receiver in receivers)
            {
                try
                {
                    SendMessage(outgoingMessage, receiver);
                }
                catch (Exception ex)
                {
                    Logger.Warn(ex.Message, ex);
                }
            }
        }
Пример #5
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">NGRIDControllerMessage object that includes controlMessage</param>
 /// <param name="controlMessage">The message to be processed</param>
 private void ProcessControllerMessage(ICommunicator communicator, NGRIDControllerMessage controllerMessage , ControlMessage controlMessage)
 {
     switch (controlMessage.MessageTypeId)
     {
         case ControlMessageFactory.MessageTypeIdGetApplicationListMessage:
             ProcessGetApplicationListMessage(communicator, 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 NGRIDException("Undefined MessageTypeId for ControlMessage: " + controlMessage.MessageTypeId);
     }
 }
 /// <summary>
 /// Creates a ControlMessageReceivedEventArgs object.
 /// </summary>
 /// <param name="message">Received message from NGRID server</param>
 public ControlMessageReceivedEventArgs(ControlMessage message)
 {
     Message = message;
 }