public void WriteMessage(Message message, bool flush)
        {
            try
            {
                if (_context.TraceEnabled)
                {
                    _context.StartTrace();
                }

                foreach (IMessageHandler t in _handlers)
                {
                    t.HandleMessage(message, _context, _encoder);
                }

                if (_templateHandlers.TryGetValue(message.Template, out IMessageHandler handler))
                {
                    handler.HandleMessage(message, _context, _encoder);
                }

                byte[] data = _encoder.Encode(message);

                if (data == null || data.Length == 0)
                {
                    return;
                }

                byte[] tmp = data;
                _outStream.Write(tmp, 0, tmp.Length);
                if (flush)
                {
                    _outStream.Flush();
                }
            }
            catch (IOException e)
            {
                Global.ErrorHandler.OnError(e, DynError.IoError, "An IO error occurred while writing message {0}", message);
            }
            catch (Exception e)
            {
                Global.ErrorHandler.OnError(e, DynError.GeneralError, "An General error occurred while writing message {0}", message);
            }
        }
Beispiel #2
0
        public void  WriteMessage(Message message, bool flush)
        {
            try
            {
                if (context.TraceEnabled)
                {
                    context.StartTrace();
                }

                if (!(handlers.Count == 0))
                {
                    for (var i = 0; i < handlers.Count; i++)
                    {
                        handlers[i].HandleMessage(message, context, encoder);
                    }
                }
                if (templateHandlers.ContainsKey(message.Template))
                {
                    templateHandlers[message.Template].HandleMessage(message, context, encoder);
                }

                var data = encoder.Encode(message);

                if ((data == null) || (data.Length == 0))
                {
                    return;
                }

                var temp_byteArray = data;
                out_Renamed.Write(temp_byteArray, 0, temp_byteArray.Length);
                if (flush)
                {
                    out_Renamed.Flush();
                }
            }
            catch (System.IO.IOException e)
            {
                Global.HandleError(Error.FastConstants.IO_ERROR, "An IO error occurred while writing message " + message, e);
            }
        }
Beispiel #3
0
        public Message ReadMessage()
        {
            if (context.TraceEnabled)
            {
                context.StartTrace();
            }

            var keepReading = blockReader.ReadBlock(in_Renamed);

            if (!keepReading)
            {
                return(null);
            }

            var message = decoder.ReadMessage();

            if (message == null)
            {
                return(null);
            }

            blockReader.MessageRead(in_Renamed, message);

            if (!(handlers.Count == 0))
            {
                for (var i = 0; i < handlers.Count; i++)
                {
                    handlers[i].HandleMessage(message, context, decoder);
                }
            }
            if (templateHandlers.ContainsKey(message.Template))
            {
                templateHandlers[message.Template].HandleMessage(message, context, decoder);

                return(ReadMessage());
            }

            return(message);
        }
        public Message ReadMessage()
        {
            if (_context.TraceEnabled)
            {
                _context.StartTrace();
            }

            bool keepReading = _blockReader.ReadBlock(_inStream);

            if (!keepReading)
            {
                return(null);
            }

            Message message = _decoder.ReadMessage();

            if (message == null)
            {
                return(null);
            }

            _blockReader.MessageRead(_inStream, message);

            foreach (IMessageHandler t in _handlers)
            {
                t.HandleMessage(message, _context, _decoder);
            }

            IMessageHandler handler;

            if (_templateHandlers.TryGetValue(message.Template, out handler))
            {
                handler.HandleMessage(message, _context, _decoder);

                return(ReadMessage());
            }

            return(message);
        }