Exemplo n.º 1
0
        public void ErrorMessageXmlIsProperlySerializedAndDeserialized()
        {
            var message = new ErrorMessage
            {
                ErrorText = "error text example",
                ErrorType = ErrorType.ExceptionOccured
            };

            var serializedMessage = _serializer.Serialize(message);
            var deserializedMessage = _serializer.Deserialize(serializedMessage);

            Assert.IsInstanceOfType(deserializedMessage, typeof (ErrorMessage));
        }
Exemplo n.º 2
0
        public void MessageSenderSendingMessage()
        {
            var sender = new MessageSender(new IPEndPoint(TestIp, Port));
            Message message = new ErrorMessage
            {
                ErrorText = "TestErrorMessage",
                ErrorType = ErrorType.UnknownSender
            };

            var t = new Task(ListenAndResend);
            t.Start();

            var receivedMessage = sender.Send(new List<Message> {message});

            Assert.AreEqual(1, receivedMessage.Count);
            Assert.AreEqual(message.MessageType, receivedMessage[0].MessageType);
            Assert.AreEqual(message.MessageType, receivedMessage[0].MessageType);
            Assert.AreEqual(((ErrorMessage) message).ErrorText, ((ErrorMessage) receivedMessage[0]).ErrorText);
            Assert.AreEqual(((ErrorMessage) message).ErrorType, ((ErrorMessage) receivedMessage[0]).ErrorType);

            EndConnection();
            t.Wait();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Process item from raw data queue.
        /// </summary>
        /// <param name="data">Dequeued data.</param>
        private void ProcessData(RawDataQueueItem data)
        {
            var messages = _marshaller.Unmarshall(data.Data);
            var responseMessages = new List<Message>();

            foreach (var msg in messages)
            {
                Logger.Trace("Processing " + msg.MessageType + " message.");

                try
                {
                    var metadata = data.Metadata as TcpDataProviderMetadata;
                    var response = HandleMessageGeneric(msg, metadata);
                    responseMessages.AddRange(response);
                }
                catch (RuntimeBinderException e)
                {
                    Logger.Debug(e.Message);
                    Logger.Warn("Unsupported message type received (" + msg.MessageType + ").");
                    var errorMsg = new ErrorMessage
                    {
                        ErrorType = ErrorType.InvalidOperation,
                        ErrorText = "Computational Server doesn't handle " + msg.MessageType + " message."
                    };
                    responseMessages = new List<Message> { errorMsg };
                    break;
                }
            }

            foreach (var msgToSend in responseMessages)
                Logger.Trace("Sending " + msgToSend.MessageType + " message.");

            var marshalledResponse = _marshaller.Marshall(responseMessages);
            data.Callback(marshalledResponse);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Handler for ErrorMessage.
 /// </summary>
 /// <param name="message">An ErrorMessage.</param>
 /// <exception cref="System.InvalidOperationException">
 ///     Thrown when <paramref name="message"/> received from server contains information about server exception.
 /// </exception>
 private void ErrorMessageHandler(ErrorMessage message)
 {
     switch (message.ErrorType)
     {
         case ErrorType.UnknownSender:
             Register();
             break;
         case ErrorType.InvalidOperation:
             // nothing to do
             break;
         case ErrorType.ExceptionOccured:
             throw new InvalidOperationException(
                 "Information about exception on server shouldn't be send to component.");
     }
 }