Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (_isByeClicked == false)
            {
                var message = textBox1.Text;
                textBox1.Clear();

                if (string.IsNullOrWhiteSpace(message))
                {
                    return;
                }

                if (string.Compare(message, "bye", true) == 0)
                {
                    _isByeClicked = true;
                }

                ButtonSendClicked?.Invoke(message, false);
            }
        }
Ejemplo n.º 2
0
        private void listBox3_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (_isByeClicked == false)
            {
                var index = listBox3.SelectedIndex;

                if (index < 1)
                {
                    return;
                }

                var command = listBox3.SelectedItem.ToString();

                if (string.Compare(command, "bye", true) == 0)
                {
                    _isByeClicked = true;
                }

                ChatCommandClicked?.Invoke(command, false);
            }
        }
        private async Task Reader()
        {
            using (HttpClient client = new HttpClient {
                Timeout = Timeout.InfiniteTimeSpan
            })
            {
                for (int i = 1; AutoReconnect && (RetryLimit == -1 || i <= RetryLimit); i++)
                {
                    try
                    {
                        using (var response = await client.GetAsync($"https://stream.lobi.co/2/group/{GroupID}?token={AccessToken}", HttpCompletionOption.ResponseHeadersRead))
                            using (var reader = new System.IO.StreamReader(await response.Content.ReadAsStreamAsync()))
                            {
                                i         = 0;    //カウンタ初期化
                                Connected = true; //Connected!!
                                ConnectedEvent?.Invoke(GroupID);
                                while (!reader.EndOfStream)
                                {
                                    token = new CancellationTokenSource();       //トークン初期化
                                    var jobj = await _Read(reader, token.Token); //Jsonデータ読み取り

                                    var ev = jobj["event"]?.ToString();
                                    if (ev == "chat")
                                    {
                                        ChatEvent?.Invoke(GroupID, JsonConvert.DeserializeObject <Chat>(jobj["chat"].ToString()));
                                    }
                                    else if (ev == "chat_deleted")
                                    {
                                        ChatDeletedEvent?.Invoke(GroupID, jobj["id"].ToString());
                                    }
                                    else if (ev == "part")
                                    {
                                        PartEvent?.Invoke(GroupID, JsonConvert.DeserializeObject <UserMinimal>(jobj["user"].ToString()));
                                    }
                                    else if (ev == "archive")
                                    {
                                        ArchiveEvent?.Invoke(GroupID);
                                    }
                                }
                            }
                        token     = null;
                        Connected = false;
                        DisconnectedEvent?.Invoke(GroupID);
                    }
                    catch (OperationCanceledException)
                    {
                        token     = null;
                        Connected = false;
                        DisconnectedEvent?.Invoke(GroupID);
                        return;
                    }
                    catch (Exception ex)
                    {
                        if (Connected)
                        {
                            token     = null;
                            Connected = false;
                            DisconnectedEvent?.Invoke(GroupID);//必要かな??
                        }
                        else
                        {
                            token     = null;
                            Connected = false;//一応ね
                        }
                        FailConnectEvent?.Invoke(GroupID, ex);
                    }
                    await Task.Delay(RetryCoolTimeMilliseconds);//クールタイム
                }
            }
        }