public async Task ReceiveAsync(int bufferSize = 1024 * 4)
        {
            OnConnect?.Invoke(this, ws.State == WebSocketState.Open);

            try
            {
                while (true)
                {
                    var buffer = new byte[bufferSize];
                    var result = await ws.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None);

                    if (result.MessageType == WebSocketMessageType.Close ||
                        !result.CloseStatus.HasValue)
                    {
                        break;
                    }

                    OnMessageReceive?.Invoke(this, new Message {
                        Client = this, MessageType = result.MessageType, Data = buffer
                    });
                }
            }
            catch { }

            Close();
        }
Esempio n. 2
0
        public void MessageReceiveHandler(MessageModel model)
        {
            OnMessageReceive?.Invoke(model);
            switch (model.MessageType)
            {
            case MessageType.CreatePlayList:
                break;

            case MessageType.UploadPlayList:
                break;

            case MessageType.UploadFile:
                break;

            case MessageType.PlayRandomVideo:
                break;

            case MessageType.Query:
                break;

            case MessageType.MiddlewareCommand:
                break;

            case MessageType.ServerList:
                var d = model.Data as ServerListModel;
                Servers = d.ClientIPs;
                break;

            default:
                break;
            }
        }
Esempio n. 3
0
        public async Task ReceiveAsync(int bufferSize = 1024 * 4)
        {
            OnConnect?.Invoke(this, ws.State == WebSocketState.Open);
            var buffer = new byte[bufferSize];

            try
            {
                while (true)
                {
                    var array  = new ArraySegment <byte>(buffer);
                    var result = await ws.ReceiveAsync(array, CancellationToken.None);

                    // FIXME result.CloseStatus or !result.CloseStatus
                    // if (result.MessageType == WebSocketMessageType.Close || !result.CloseStatus.HasValue)
                    if (result.MessageType == WebSocketMessageType.Close || result.CloseStatus.HasValue)
                    {
                        break;
                    }
                    var data = array.Slice(0, result.Count).ToArray();
                    OnMessageReceive?.Invoke(this, new Message {
                        Client = this, MessageType = result.MessageType, Data = data
                    });
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Close();
        }
Esempio n. 4
0
        public override async Task StartAsync()
        {
            Connection = await Client.Connect(_key);

            Connection.OnMessageReceived += async message =>
            {
                await OnMessageReceive.Invoke(new SlackMessageObject(message));
            };
            await base.StartAsync();
        }
Esempio n. 5
0
        public DiscordBotClient(DiscordProviderConfigurations config)
        {
            client.MessageReceived += async(msg) =>
            {
                await OnMessageReceive.Invoke(new DiscordMessageObject(msg));
            };

            client.MessageUpdated += async(msgCached, newMsg, channel) =>
            {
                await OnMessageEdit.Invoke(new DiscordMessageObject(newMsg), new DiscordChannelObject(channel));
            };
        }
Esempio n. 6
0
        public DiscordBotProvider(DiscordProviderConfigurations config)
        {
            this.config = config;

            client = new DiscordShardedClient(
                new DiscordSocketConfig
            {
                TotalShards = config.ShardCount
            });

            client.MessageReceived += async message =>
            {
                await OnMessageReceive.Invoke(new DiscordMessageObject(message));
            };
        }
Esempio n. 7
0
File: Bot.cs Progetto: binn/Meru
        public void AddProvider(IBotProvider provider)
        {
            provider.OnMessageReceive += async(m) =>
            {
                await OnMessageReceive.Invoke(m);
            };

            provider.OnMessageEdit += async(m) =>
            {
                await OnMessageEdit.Invoke(m);
            };

            provider.OnMessageDelete += async(m) =>
            {
                await OnMessageDelete.Invoke(m);
            };

            providers.Add(provider);
        }
Esempio n. 8
0
 protected void OnMessageReceiveEvent(string message)
 {
     OnMessageReceive?.Invoke(this, new MessageEventArgs(message));
 }
Esempio n. 9
0
 public static void MessageReceived(IMessage message) => OnMessageReceive?.Invoke(message);
Esempio n. 10
0
 public void Message(string message)
 {
     Messages.Add(message);
     OnMessageReceive.Invoke();
 }
Esempio n. 11
0
        /*================================*\
        |*   Protected Member Functions   *|
        \*================================*/

        /*===============*\
        |*   Overrides   *|
        \*===============*/

        protected override void ReceiveMessage(RosPose2D message)
        {
            CustomRosConverter.Pose2DToPose2D(pose2D, message);
            OnMessageReceive.Invoke();
        }
Esempio n. 12
0
 private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
 {
     errorMessage.Add(e.Data);
     OnMessageReceive?.Invoke(e.Data);
 }
Esempio n. 13
0
 private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
 {
     this.message.Add(e.Data);
     OnMessageReceive?.Invoke(e.Data);
 }
Esempio n. 14
0
 private static void MessageReceive(string name, string message)
 {
     OnMessageReceive?.Invoke(name, message);
 }
 virtual protected void WshOnMessageReceive(object sender, Message message)
 {
     OnMessageReceive?.Invoke(this, message);
 }
Esempio n. 16
0
 internal static void MessageReceive(int id, IMessage message) => OnMessageReceive?.Invoke(message, id);