public void Accept(Socket socket) { var channel = _channelFactory(); _channels.TryAdd(channel.Id, channel); channel.Closed += (s, e) => { _channels.TryRemove(channel.Id, out var _); ChannelClosed?.Invoke(this, EventArgs.Empty); }; channel.Attach(socket); // ChannelAccepted?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Tries adding new channel into channels' concurrent dictionary /// </summary> /// <param name="webSocket">This goes inside a new channel</param> public void AddConnection(WebSocket webSocket, string uri) { //TODO: IF XML way is added, then implement a factory pattern to make both XML channel or Json channel. var channel = new JsonChannel(); _channels.TryAdd(uri, channel); channel.Closed += (s, e) => { _channels.TryRemove(uri, out var _); ChannelClosed?.Invoke(this, EventArgs.Empty); }; channel.Attach(webSocket); MessageDispatcher.Bind(channel); ChannelAccepted?.Invoke(this, EventArgs.Empty); }
protected virtual void OnChannelClosed(EventArgs e) { ChannelClosed?.Invoke(this, e); }
protected virtual void OnChannelClosed() { ChannelClosed?.Invoke(this, EventArgs.Empty); }
private void SubscribeToEvents() { _subscriptions.Apply(x => x.Dispose()); _subscriptions.Clear(); #region Channel _subscriptions.Add(_connection.On <ChannelSummaryResponse>(ClientEvents.ChannelUpdated, channel => { ChannelUpdated?.Invoke(channel); })); _subscriptions.Add(_connection.On <Guid>(ClientEvents.ChannelClosed, channelId => { ChannelClosed?.Invoke(channelId); })); #endregion #region Message _subscriptions.Add(_connection.On <MessageResponse>(ClientEvents.MessageAdded, message => { MessageAdded?.Invoke(message); })); _subscriptions.Add(_connection.On <MessageResponse>(ClientEvents.MessageUpdated, message => { MessageUpdated?.Invoke(message); })); _subscriptions.Add(_connection.On <Guid, Guid>(ClientEvents.MessageDeleted, (deletedMessageId, channelId) => { MessageDeleted?.Invoke(deletedMessageId, channelId); })); _subscriptions.Add(_connection.On <Guid>(ClientEvents.LastReadMessageChanged, channelId => { LastReadMessageUpdated?.Invoke(channelId); })); #endregion #region Member _subscriptions.Add(_connection.On <ChannelSummaryResponse>(ClientEvents.MemberJoined, (channel) => { MemberJoined?.Invoke(channel); })); _subscriptions.Add(_connection.On <Guid>(ClientEvents.MemberLeft, (channelId) => { MemberLeft?.Invoke(channelId); })); _subscriptions.Add(_connection.On <MemberSummaryResponse, Guid>(ClientEvents.MemberDeleted, (member, channelId) => { MemberDeleted?.Invoke(member, channelId); })); #endregion }
protected void FireClosedEvent() { ChannelClosed?.Invoke(this, new EventArgs()); }
private void OnChannelClosed(object sender, EventArgs e) { HandleDisconnection(sender as IBaseService); ChannelClosed?.Invoke(sender as IBaseService); }