Esempio n. 1
0
        private void DispatchEvent()
        {
            if (_eventBuffer.Count == 0) return;

            _eventBuffer.RemoveAll(item => item.Equals("\n"));

            var message = new MessageEvent(string.Concat(_eventBuffer), _lastEventId, _configuration.Uri);
            _logger.DebugFormat("Received event \"{0}\"", _eventName);

            OnMessageReceived(new MessageReceivedEventArgs(message, _eventName));

            _eventBuffer.Clear();
            _eventName = Constants.MessageField;
        }
Esempio n. 2
0
        private void DispatchEvent()
        {
            var name = _eventName ?? Constants.MessageField;

            _eventName = null;
            MessageEvent message;

            if (_eventDataStringBuffer != null)
            {
                if (_eventDataStringBuffer.Count == 0)
                {
                    return;
                }
                // remove last item which is always a trailing newline
                _eventDataStringBuffer.RemoveAt(_eventDataStringBuffer.Count - 1);
                var dataString = string.Concat(_eventDataStringBuffer);
                message = new MessageEvent(name, dataString, _lastEventId, _configuration.Uri);

                _eventDataStringBuffer.Clear();
            }
            else
            {
                if (_eventDataUtf8ByteBuffer is null || _eventDataUtf8ByteBuffer.Length == 0)
                {
                    return;
                }
                var dataSpan = new Utf8ByteSpan(_eventDataUtf8ByteBuffer.GetBuffer(), 0,
                                                (int)_eventDataUtf8ByteBuffer.Length - 1); // remove trailing newline
                message = new MessageEvent(name, dataSpan, _lastEventId, _configuration.Uri);

                // We've now taken ownership of the original buffer; null out the previous
                // reference to it so a new one will be created next time
                _eventDataUtf8ByteBuffer = null;
            }

            _logger.Debug("Received event \"{0}\"", name);
            OnMessageReceived(new MessageReceivedEventArgs(message));
        }
Esempio n. 3
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            MessageEvent that = (MessageEvent)obj;

            if (!_data?.Equals(that._data) ?? that._data != null)
            {
                return(false);
            }
            if (!_lastEventId?.Equals(that._lastEventId) ?? that._lastEventId != null)
            {
                return(false);
            }
            return(!(_origin != null ? !_origin.Equals(that._origin) : that._origin != null));
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="message">the <see cref="MessageEvent"/> received from the stream</param>
 public MessageReceivedEventArgs(MessageEvent message)
 {
     Message = message;
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageReceivedEventArgs"/> class.
 /// </summary>
 /// <param name="message">The <see cref="MessageEvent"/> data recieved by the Server Sent Event.</param>
 /// <param name="eventName">Name of the event type received by the Server Sent Event.</param>
 public MessageReceivedEventArgs(MessageEvent message, string eventName)
 {
     Message   = message;
     EventName = eventName;
 }