/// <summary> /// Continue to move the event towards your application. /// </summary> /// <param name="channelEvent">Event being processed.</param> public void SendUpstream(IChannelEvent channelEvent) { if (_nextUpstream != null) _nextUpstream.HandleUpstream(_contextCollection.Get(_nextUpstream), channelEvent); else throw new InvalidOperationException("There are no more upstream handlers."); }
protected virtual PostMessageRequest CreatePostMessageRequest( IChannelEvent channelEvent) { if (EventWrapper?.Event == null) { return(CreateDefaultMessage()); } var @event = EventWrapper.Event; var titleSection = new Section(new MarkdownText("Usain Reaction")) { Fields = new List <TextObject> { new MarkdownText($"*Type:*\n{@event.CallbackEventType}"), new MarkdownText( $"*When:*\n{DateTimeOffset.FromUnixTimeSeconds(@event.EventTimestamp.Seconds)}"), }, }; return(new PostMessageRequest { Channel = channelEvent.ChannelId, Blocks = new List <IMessageBlock> { titleSection, }, }); }
/// <summary> /// Process data that was received from the channel. /// </summary> /// <param name="ctx">Context which is used for the currently processed channel</param> /// <param name="e">Event being processed.</param> public void HandleUpstream(IChannelHandlerContext ctx, IChannelEvent e) { if (e is ConnectedEvent) { ctx.State = new Context(); } if (e is ClosedEvent) { Reset(); } else if (e is MessageEvent) { _context = ctx.State.As<Context>(); _context._buffer = e.As<MessageEvent>().Message.As<BufferSlice>(); _context._reader.Assign(_context._buffer); while (_context._parserMethod()) ; if (_context._isComplete) { e.As<MessageEvent>().Message = _context._message; OnComplete(ctx, e); } return; } ctx.SendUpstream(e); }
/// <summary> /// Handle the data that is going to be sent to the remote end point /// </summary> /// <param name="ctx">Context information</param> /// <param name="e">Chennel event.</param> public void HandleDownstream(IChannelHandlerContext ctx, IChannelEvent e) { if (e is CloseEvent && _timer != null) { _timer.Dispose(); _timer = null; } }
void IUpstreamHandler.HandleUpstream(IChannelHandlerContext ctx, IChannelEvent e) { if (e is ExceptionEvent) ExceptionCaught(ctx, e.As<ExceptionEvent>()); else if (e is MessageEvent) HandleMessage(ctx, e.As<MessageEvent>()); else if (e is BoundEvent) HandleBound(ctx, e.As<BoundEvent>()); else if (e is ClosedEvent) HandleClosed(ctx, e.As<ClosedEvent>()); else if (e is ConnectedEvent) HandleConnected(ctx, e.As<ConnectedEvent>()); }
/// <summary> /// Takes a <see cref="Message"/> and converts it into a byte buffer. /// </summary> /// <param name="ctx"></param> /// <param name="e"></param> public void HandleDownstream(IChannelHandlerContext ctx, IChannelEvent e) { if (e is MessageEvent) { var evt = e.As<MessageEvent>(); if (evt.Message is Message) evt.Message = EncodeMessage(evt.Message.As<Message>()); else if (evt.Message is Command) evt.Message = EncodeCommand(evt.Message.As<Command>()); } ctx.SendDownstream(e); }
/// <summary> /// Process data that was received from the channel. /// </summary> /// <param name="ctx">Context which is used for the currently processed channel</param> /// <param name="e">Event being processed.</param> public void HandleUpstream(IChannelHandlerContext ctx, IChannelEvent e) { if (e is ClosedEvent) { _timer = new Timer(OnTryReconnect, ctx, _interval, TimeSpan.Zero); ctx.SendUpstream(e); } else if (e is ConnectedEvent) { _timer.Dispose(); _timer = null; ctx.SendUpstream(e); } }
protected override void DownstreamHandlingComplete(IChannelEvent e) { if (e is BindEvent) { _remoteEndPoint = e.As<BindEvent>().EndPoint; HandlerContexts.SendUpstream(new BoundEvent()); } if (e is ConnectEvent) { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.BeginConnect(_remoteEndPoint, OnConnect, socket); } else base.DownstreamHandlingComplete(e); }
/// <summary> /// Handle the data that is going to be sent to the remote end point /// </summary> /// <param name="ctx">Context information</param> /// <param name="e">Chennel event.</param> public void HandleDownstream(IChannelHandlerContext ctx, IChannelEvent e) { if (e is BindEvent) { if (_listener != null) throw new InvalidOperationException("Listener have already been specified."); _listener = new TcpListener(e.As<BindEvent>().EndPoint.As<IPEndPoint>()); _listener.Start(1000); _listener.BeginAcceptSocket(OnAcceptSocket, null); } else if (e is CloseEvent) { _listener.Stop(); _listener = null; } }
public void HandleUpstream(IChannelHandlerContext ctx, IChannelEvent e) { if (e is ConnectedEvent) { ctx.State = new DecoderContext { ParserMethod = ParseBeforeHeader }; } else if (e is ClosedEvent) { ctx.State = null; } if (!(e is MessageEvent)) { ctx.SendUpstream(e); return; } var evt = e.As<MessageEvent>(); _context = ctx.State.As<DecoderContext>(); var buffer = evt.Message.As<BufferSlice>(); _context.Reader.Assign(buffer); try { while (_context.ParserMethod()) ; } catch (Exception err) { ctx.SendUpstream(new ExceptionEvent(err)); return; } if (!_context.IsComplete) return; // no more processing evt.Message = _context.Message; _context.ParserMethod = ParseBeforeHeader; ctx.SendUpstream(evt); _context.Message.Reset(); }
public void SendUpstream(IChannel source, IChannelEvent channelEvent) { source.HandlerContexts.SendUpstream(channelEvent); /* LinkedListNode<IUpstreamHandler> node = _upstreamHandlers.First; while (node != null) { if (node.Value == source) break; node = node.Next; } if (node == null) throw new InvalidOperationException("Failed to find handler " + node.Value.GetType().FullName + " in the ppeline."); var context = source.HandlerContexts.Get(node.Value); node.Value.HandleDownstream(context, channelEvent); */ }
protected override PostMessageRequest CreatePostMessageRequest( IChannelEvent channelEvent) { if (!(EventWrapper.Event is AppMentionEvent appMentionEvent)) { return(CreateDefaultMessage()); } var titleSection = new Section( new MarkdownText(GetGreetings(appMentionEvent.UserId))); return(new PostMessageRequest { Channel = appMentionEvent.ChannelId, Blocks = new List <IMessageBlock> { titleSection, }, ThreadId = appMentionEvent.ParentMessageId.IsEmpty ? appMentionEvent.MessageId.ToString() : appMentionEvent.ParentMessageId.ToString(), }); }
/// <summary> /// Process data that was received from the channel. /// </summary> /// <param name="ctx">Context which is used for the currently processed channel</param> /// <param name="e">Event being processed.</param> public void HandleUpstream(IChannelHandlerContext ctx, IChannelEvent e) { throw new NotImplementedException(); }
private void SendUpstream(IChannelEvent channelEvent) { HandlerContexts.SendUpstream(channelEvent); }
/// <summary> /// Called when a message has been parsed successfully. /// </summary> /// <param name="ctx"></param> /// <param name="channelEvent"></param> protected virtual void OnComplete(IChannelHandlerContext ctx, IChannelEvent channelEvent) { ctx.SendUpstream(channelEvent); }
/// <summary> /// Process data that was received from the channel. /// </summary> /// <param name="ctx">Context which is used for the currently processed channel</param> /// <param name="e">Event being processed.</param> public void HandleUpstream(IChannelHandlerContext ctx, IChannelEvent e) { }
public void SendDownstream(IChannelEvent channelEvent) { _channel.HandlerContexts.SendDownstream(channelEvent); }
/// <summary> /// Send a message down stream (from application to channel) /// </summary> /// <param name="handler">Handler to start with</param> /// <param name="channelEvent">Event to send</param> /// <remarks> /// All handlers above the specified one will be ignored and not invoked. /// </remarks> public void SendDownstream(IDownstreamHandler handler, IChannelEvent channelEvent) { ChannelHandlerContext ctx = _contexts[handler]; handler.HandleDownstream(ctx, channelEvent); }
/// <summary> /// Send an event upstream (from channels to application) /// </summary> /// <param name="channelEvent">Event to send</param> public void SendUpstream(IChannelEvent channelEvent) { SendUpstream(_channel.Pipeline.UpstreamHandlers.First(), channelEvent); }
protected override void DownstreamHandlingComplete(IChannelEvent e) { if (e is MessageEvent) { var evt = e.As<MessageEvent>(); var buffer = evt.Message.As<BufferSlice>(); Send(buffer); } else if (e is CloseEvent) { Close(SocketError.Success); } }
private void SendUpstream(IChannelEvent evt) { HandlerContexts.SendUpstream(evt); //var ctx = new ChannelHandlerContext(this, _pipeline); //ctx.SendUpstream(evt); }
protected override void UpstreamHandlingComplete(IChannelEvent e) { _readSlice.MoveRemainingBytes(); //var bytesRemaining = _inbufferStream.Length - _inbufferStream.Position; // copy the remaining bytes to the start of buffer //Buffer.BlockCopy(_readArgs.Buffer, (int)_inbufferStream.Position, _readArgs.Buffer, 0, (int)bytesRemaining); //_inbufferStream.SetLength(bytesRemaining); StartRead(); }
/// <summary> /// Send an event upstream (from channels to application) /// </summary> /// <param name="handlerToStartFrom">Handler that should be invoked</param> /// <param name="channelEvent">Event to send</param> public void SendUpstream(IUpstreamHandler handlerToStartFrom, IChannelEvent channelEvent) { ChannelHandlerContext ctx = _contexts[handlerToStartFrom]; handlerToStartFrom.HandleUpstream(ctx, channelEvent); }
public CommonChannelHandler(IChannelEvent channelEvent) { _channelEvent = channelEvent; }