Beispiel #1
0
        private void RefreshActiveChannels()
        {
            var readedChannels = new List <ActiveChannelsDto>();

            using (var cmd = new MySqlCommand("SELECT * FROM asterisk.ActiveChannels where Application = 'queue' and BridgeId is null", _dbRefreshConnection))
                using (var dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        readedChannels.Add(new ActiveChannelsDto
                        {
                            UniqueId     = dataReader.GetNullableString("UniqueID"),
                            Channel      = dataReader.GetNullableString("Channel"),
                            CallerIdNum  = dataReader.GetNullableString("CallerIDNum"),
                            ChannelState = dataReader.GetNullableString("ChannelState"),
                            AnswerTime   = dataReader.GetNullableDateTime("AnswerTime"),
                            CreateTime   = dataReader.GetNullableDateTime("CreateTime")
                        });
                    }
                    dataReader.Close();
                }
            var remotedChannels = ActiveChannels.Where(n => readedChannels.All(c => c.UniqueId != n.UniqueId)).ToList();
            var newChannels     = readedChannels.Where(n => ActiveChannels.All(c => c.UniqueId != n.UniqueId)).ToList();

            newChannels.ForEach(c => ActiveChannels.Add(c));
            remotedChannels.ForEach(c => ActiveChannels.Remove(c));
        }
Beispiel #2
0
        public void RegisterOperation(Type t)
        {
            var socketOperation = Activator.CreateInstance(t) as ISocketOperation;

            _operationTable.Add(socketOperation.OperationId, socketOperation);
            ActiveChannels.ForEach(ch =>
            {
                var operation = ch.CreateOperation(t);
                ch.OperationTable.Add(operation.OperationId, operation.GetType());
            });
        }
Beispiel #3
0
        public void RegisterOperation <T>() where T : ISocketOperation
        {
            var socketOperation = Activator.CreateInstance <T>();

            _operationTable.Add(socketOperation.OperationId, socketOperation);
            ActiveChannels.ForEach(ch =>
            {
                var operation = ch.CreateOperation <T>();
                ch.OperationTable.Add(operation.OperationId, operation.GetType());
            });
        }
        public async Task JoinChannelAsync(string group, string user)
        {
            if (!IsConnected || ActiveChannels.ContainsKey(group))
            {
                return;
            }

            await hubConnection.SendAsync("AddToGroup", group, user);

            ActiveChannels.Add(group, user);
        }
        public async Task LeaveChannelAsync(string group, string user)
        {
            if (!IsConnected || !ActiveChannels.ContainsKey(group))
            {
                return;
            }

            await hubConnection.SendAsync("RemoveFromGroup", group, user);

            ActiveChannels.Remove(group);
        }
Beispiel #6
0
 /// <summary>
 /// Deactivate a channel to save time in <see cref="Update"/>.
 /// </summary>
 /// <param name="channelName">Channel name.</param>
 protected override void DeactivateChannelImpl(string channelName)
 {
     if (IsConnected)
     {
         multiReader.MultiSourceFrameArrived -= Reader_MultiSourceFrameArrived;
     }
     ActiveChannels.Remove(GetChannelDescriptor(channelName));// manually remove here, because OpenMultiReader uses IsChannelActive
     if (IsConnected)
     {
         OpenMultiReader();
         multiReader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
     }
 }
        public async Task DisconnectAsync()
        {
            if (!IsConnected)
            {
                return;
            }

            try
            {
                await hubConnection.DisposeAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            ActiveChannels.Clear();
            IsConnected = false;
        }
Beispiel #8
0
 internal TcpClientChannel GetMainChannel()
 {
     return((TcpClientChannel)ActiveChannels.First(ch => ch.IsMainChannel));
 }
Beispiel #9
0
 private void IrcClient_OnDisconnected(object sender, EventArgs e)
 {
     ActiveChannels.Clear();
     Console.WriteLine("! Disconnected");
     ErrorLogging.WriteLine("! Disconnected");
 }
Beispiel #10
0
 public void ConnectToChannel(string channelToJoin, Storage.ChannelConfig channelcfg)
 {
     MeebyIrcClient.RfcJoin("#" + channelToJoin);
     this.OnChannelJoining?.Invoke(channelToJoin);
     ActiveChannels.Add("#" + channelToJoin, new SuiBot_ChannelInstance(channelToJoin, BotConnectionConfig.Password, this, channelcfg));
 }
Beispiel #11
0
 private void MeebyIrcClient_OnRawMessage(object sender, IrcEventArgs e)
 {
     try
     {
         if (e.Data.Channel != null && e.Data.Nick != null && e.Data.Message != null && ActiveChannels.ContainsKey(e.Data.Channel))
         {
             LastMessage.Update(GetRoleFromTags(e), e.Data.Nick, e.Data.Message,
                                e.Data.Tags.ContainsKey("msg-id") ? e.Data.Tags["msg-id"] == "highlighted-message" : false,   //if message is highlighted using Twitch points
                                e.Data.Tags.ContainsKey("custom-reward-id") ? e.Data.Tags["custom-reward-id"] : null          //custom reward using viewer points
                                );
             this.OnChatMessageReceived?.Invoke(e.Data.Channel, LastMessage);
             ActiveChannels[e.Data.Channel].DoWork(LastMessage);
         }
     }
     catch (Exception ex)
     {
         ErrorLogging.WriteLine("Exception on raw message " + ex.Message);
     }
 }