Esempio n. 1
0
 private void Clear()
 {
     _stream.Dispose();
     _stream     = null;
     _packetType = null;
     _header     = null;
 }
Esempio n. 2
0
        /// <summary>
        /// Handle an message
        /// </summary>
        /// <param name="context">Context unique for this handler instance</param>
        /// <param name="message">Message to process</param>
        /// <remarks>
        /// All messages that can't be handled MUST be send up the chain using <see cref="IPipelineHandlerContext.SendUpstream"/>.
        /// </remarks>
        public void HandleUpstream(IPipelineHandlerContext context, IPipelineMessage message)
        {
            var msg = message as Received;

            if (msg == null)
            {
                context.SendUpstream(message);
                return;
            }

            // byte + byte + int
            if (msg.BufferSlice.RemainingLength < 6)
            {
                return;
            }

            var header = new SimpleHeader
            {
                Version       = msg.BufferSlice.Buffer[msg.BufferSlice.Position++],
                ContentId     = msg.BufferSlice.Buffer[msg.BufferSlice.Position++],
                ContentLength = BitConverter.ToInt32(msg.BufferSlice.Buffer, msg.BufferSlice.Position)
            };

            msg.BufferSlice.Position += 4;
            context.SendUpstream(new ReceivedHeader(header));

            if (msg.BufferSlice.RemainingLength > 0)
            {
                context.SendUpstream(msg);
            }
        }
        /// <summary>
        /// Handle an message
        /// </summary>
        /// <param name="context">Context unique for this handler instance</param>
        /// <param name="message">Message to process</param>
        public void HandleUpstream(IPipelineHandlerContext context, IPipelineMessage message)
        {
            var msg = message as Received;
            if (msg == null)
            {
                context.SendUpstream(message);
                return;
            }

            var bytesToCopy = Math.Min(msg.BufferReader.Count, _bytesLeft);
            msg.BufferReader.Read(_header, _position, bytesToCopy);
            _position += bytesToCopy;
            _bytesLeft -= bytesToCopy;

            if (_bytesLeft > 0)
            {
                return;
            }

            var header = new SimpleHeader
                {
                    Version = _header[0],
                    Length = BitConverter.ToInt32(_header, 1)
                };

            _bytesLeft = 5;
            _position = 0;
            context.SendUpstream(new ReceivedHeader(header));

            if (msg.BufferReader.Position < msg.BufferReader.Count)
                context.SendUpstream(msg);
        }
Esempio n. 4
0
        private void HandleHeader(IPipelineHandlerContext context, IPipelineMessage message, ReceivedHeader headerMsg)
        {
            _packetType = _mapper.GetPacketType(_header.ContentId);
            if (_packetType == null)
            {
                // not supported, let the rest of the pipeline
                // handle the packet.
                context.SendUpstream(message);
            }
            else
            {
                _header = headerMsg.Header;
                var buffer = _bufferPool.PopSlice();
                if (_header.ContentLength > buffer.Capacity)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  "Buffer ({0} bytes) is less than the packet content ({1} bytes). Sorry, that's not possible in the current version.",
                                  buffer.Capacity, _header.ContentLength));
                }

                _bytesLeft = _header.ContentLength;
                _stream    = new BufferPoolStream(_bufferPool, buffer);
            }
        }
        /// <summary>
        /// Handle an message
        /// </summary>
        /// <param name="context">Context unique for this handler instance</param>
        /// <param name="message">Message to process</param>
        /// <remarks>
        /// All messages that can't be handled MUST be send up the chain using <see cref="IPipelineHandlerContext.SendUpstream"/>.
        /// </remarks>
        public void HandleUpstream(IPipelineHandlerContext context, IPipelineMessage message)
        {
            var msg = message as Received;
            if (msg == null)
            {
                context.SendUpstream(message);
                return;
            }

            // byte + byte + int
            if (msg.BufferSlice.RemainingLength < 6)
            {
                return;
            }

            var header = new SimpleHeader
            {
                Version = msg.BufferSlice.Buffer[msg.BufferSlice.Position++],
                ContentId = msg.BufferSlice.Buffer[msg.BufferSlice.Position++],
                ContentLength = BitConverter.ToInt32(msg.BufferSlice.Buffer, msg.BufferSlice.Position)
            };
            msg.BufferSlice.Position += 4;
            context.SendUpstream(new ReceivedHeader(header));

            if (msg.BufferSlice.RemainingLength > 0)
                context.SendUpstream(msg);            
        }
Esempio n. 6
0
 public ReceivedHeader(SimpleHeader header)
 {
     if (header == null)
     {
         throw new ArgumentNullException("header");
     }
     Header = header;
 }
Esempio n. 7
0
        /// <summary>
        /// Handle an message
        /// </summary>
        /// <param name="context">Context unique for this handler instance</param>
        /// <param name="message">Message to process</param>
        public void HandleUpstream(IPipelineHandlerContext context, IPipelineMessage message)
        {
            var headerMsg = message as ReceivedHeader;

            if (headerMsg != null)
            {
                _header = headerMsg.Header;
                if (_header.Length > 65535)
                {
                    var error = new ErrorResponse("-9999", new RpcError
                    {
                        Code    = RpcErrorCode.InvalidRequest,
                        Message =
                            "Support requests which is at most 655355 bytes.",
                    });
                    context.SendDownstream(new SendResponse(error));
                }

                return;
            }

            var received = message as Received;

            if (received != null)
            {
                var count = Math.Min(received.BufferSlice.RemainingLength, _header.Length);
                _stream.Write(received.BufferSlice.Buffer, received.BufferSlice.Position, count);
                received.BufferSlice.Position += count;

                if (_stream.Length == _header.Length)
                {
                    _stream.Position = 0;
                    var request = DeserializeRequest(_stream);
                    context.SendUpstream(new ReceivedRequest(request));
                }

                return;
            }

            context.SendUpstream(message);
        }
        /// <summary>
        /// Handle an message
        /// </summary>
        /// <param name="context">Context unique for this handler instance</param>
        /// <param name="message">Message to process</param>
        public void HandleUpstream(IPipelineHandlerContext context, IPipelineMessage message)
        {
            var headerMsg = message as ReceivedHeader;
            if (headerMsg != null)
            {
                _header = headerMsg.Header;
                if (_header.Length > 65535)
                {
                    var error = new ErrorResponse("-9999", new RpcError
                        {
                            Code = RpcErrorCode.InvalidRequest,
                            Message =
                                "Support requests which is at most 655355 bytes.",
                        });
                    context.SendDownstream(new SendResponse(error));
                }

                return;
            }

            var received = message as Received;
            if (received != null)
            {
                var count = Math.Min(received.BufferReader.Count, _header.Length);
                received.BufferReader.CopyTo(_stream, count);
                if (_stream.Length == _header.Length)
                {
                    _stream.Position = 0;
                    var request = DeserializeRequest(_stream);
                    context.SendUpstream(new ReceivedRequest(request));
                }

                return;
            }

            context.SendUpstream(message);
        }
Esempio n. 9
0
        /// <summary>
        /// Handle an message
        /// </summary>
        /// <param name="context">Context unique for this handler instance</param>
        /// <param name="message">Message to process</param>
        public void HandleUpstream(IPipelineHandlerContext context, IPipelineMessage message)
        {
            var msg = message as Received;

            if (msg == null)
            {
                context.SendUpstream(message);
                return;
            }

            var bytesToCopy = Math.Min(msg.BufferReader.Count, _bytesLeft);

            msg.BufferReader.Read(_header, _position, bytesToCopy);
            _position  += bytesToCopy;
            _bytesLeft -= bytesToCopy;

            if (_bytesLeft > 0)
            {
                return;
            }

            var header = new SimpleHeader
            {
                Version = _header[0],
                Length  = BitConverter.ToInt32(_header, 1)
            };

            _bytesLeft = 5;
            _position  = 0;
            context.SendUpstream(new ReceivedHeader(header));

            if (msg.BufferReader.Position < msg.BufferReader.Count)
            {
                context.SendUpstream(msg);
            }
        }
        private void HandleHeader(IPipelineHandlerContext context, IPipelineMessage message, ReceivedHeader headerMsg)
        {
            _packetType = _mapper.GetPacketType(_header.ContentId);
            if (_packetType == null)
            {
                // not supported, let the rest of the pipeline
                // handle the packet.
                context.SendUpstream(message);
            }
            else
            {
                _header = headerMsg.Header;
                var buffer = _bufferPool.PopSlice();
                if (_header.ContentLength > buffer.Capacity)
                    throw new InvalidOperationException(
                        string.Format(
                            "Buffer ({0} bytes) is less than the packet content ({1} bytes). Sorry, that's not possible in the current version.",
                            buffer.Capacity, _header.ContentLength));

                _bytesLeft = _header.ContentLength;
                _stream = new BufferPoolStream(_bufferPool, buffer);
            }
        }
 private void Clear()
 {
     _stream.Dispose();
     _stream = null;
     _packetType = null;
     _header = null;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ReceivedHeader"/> class.
 /// </summary>
 /// <param name="header">The header.</param>
 public ReceivedHeader(SimpleHeader header)
 {
     if (header == null) throw new ArgumentNullException("header");
     Header = header;
 }
Esempio n. 13
0
        /// <summary>
        /// Converts the xml documentation string into a description object.
        /// </summary>
        public static Description GetDescription(IEntity entity)
        {
            IHeader header = null;

            var method = entity as IMethod;

            if (method != null)
            {
                header = new MethodHeader(method);
            }
            var field = entity as IField;

            if (field != null)
            {
                header = new FieldHeader(field);
            }

            var property = entity as IProperty;

            if (property != null)
            {
                header = new PropertyHeader(property);
            }

            if (header == null)
            {
                header = new SimpleHeader(AmbienceService.GetCurrentAmbience().Convert(entity));
            }


            var    description      = new Description(header);
            string xmlDocumentation = entity.Documentation;

            if (string.IsNullOrEmpty(xmlDocumentation))
            {
                return(description);
            }

            try
            {
                // original pattern without escape symbols: \<see cref=\"[^\"]+\.([^\"]+)\"\ /\>
                const string seeCrefPattern = "\\<see cref=\\\"[^\\\"]+\\.([^\\\"]+)\\\"\\ /\\>";
                xmlDocumentation = Regex.Replace(xmlDocumentation, seeCrefPattern, "$1");

                XDocument xml = XDocument.Parse("<docroot>" + xmlDocumentation + "</docroot>");

                foreach (XElement element in xml.Root.Elements())
                {
                    Test[element.Name.LocalName] = element.ToString();
                }

                XElement summary = xml.Descendants("summary").FirstOrDefault();
                if (summary != null)
                {
                    description.Summary = summary.Value.Trim();
                }

                XElement[] xmlParameters = xml.Descendants("param").ToArray();
                foreach (XElement node in xmlParameters)
                {
                    string    name = node.Attribute("name").Value;
                    string    parameterDescription = node.Value;
                    Parameter parameterObject      =
                        description.Parameters.FirstOrDefault(parameter => parameter.Name == name);
                    if (parameterObject != null)
                    {
                        parameterObject.Description = parameterDescription;
                    }
                }
            }
            catch (Exception)
            {
                return(new SimpleDescription(xmlDocumentation));
            }
            return(description);
        }