Exemple #1
0
        public void LoginMethod()
        {
            if (!string.IsNullOrEmpty(Username))
            {
                LoginVisibility    = Visibility.Collapsed;
                ChatViewVisibility = Visibility.Visible;

                var request = new User {
                    Name = Username
                };
                Task[] tasks = new Task[2];

                var replies = client.Join(request);
                tasks[0] = ListenAsync(replies.ResponseStream, tokenSource.Token);

                var list = client.GetUserlist(new Google.Protobuf.WellKnownTypes.Empty());
                tasks[1] = ListenUserlistAsync(list.ResponseStream, tokenSource.Token);
            }
        }
Exemple #2
0
        public void Join()
        {
            var response = client.Join(new ChatRequest()
            {
                Name = Name
            });

            System.Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")} [{response.Name}] join {response.Status}");

            cts = new CancellationTokenSource();

            ListenTask = Task.Run(async() =>
            {
                var listen = client.Listen(new ChatRequest()
                {
                    Name = Name
                });

                CancellationTokenSource _cts = null;
                _cts = new CancellationTokenSource();

                do
                {
                    try
                    {
                        await listen.ResponseStream.MoveNext(cts.Token);

                        //if (!ret) continue;
                        if (listen.ResponseStream.Current == null)
                        {
                            continue;
                        }

                        Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}->{listen.ResponseStream.Current.Name}:{listen.ResponseStream.Current.Message}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                } while (!cts.IsCancellationRequested);
            }, cts.Token);
        }