Пример #1
0
        /// <summary>
        /// TODO
        /// </summary>
        private void CreateAccount()
        {
            try
            {
                Channel channel     = GrpcBase.NewChannel();
                var     accountTask = new AccountTask.AccountTaskClient(channel);

                accountTask.CreateAccount(new CreateAccountRequest {
                    Password = "******"
                });
                Console.WriteLine(">>>>>>create success.");
            }catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
        public async Task TaskReciver(ObservableCollection <MessageViewModel> c)
        {
            if (c == null)
            {
                c = new ObservableCollection <MessageViewModel>();
            }
            try
            {
                channel = baseHelper.NewChannel();
                client  = new PubSubTask.PubSubTaskClient(channel);
                using (var call = client.Subscribe(
                           new SubscribeRequest {
                    Topics = NBSTopic.NBSWorld.ToString()
                }))
                {
                    var responseStream = call.ResponseStream;
                    while (await responseStream.MoveNext <SubscribeResponse>())
                    {
                        SubscribeResponse resp = responseStream.Current;
                        Console.WriteLine("--------------------------------->");
                        string ts = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        Console.WriteLine("Time:" + ts);
                        Console.WriteLine("Content:" + resp.MsgData.ToString());
                        Console.WriteLine("<---------------------------------");
                        MessageViewModel m = new MessageViewModel
                        {
                            UID          = resp.From,
                            Nickname     = resp.From,
                            AvatarName   = "/avatars/other.gif",
                            IsSelf       = false,
                            MessageTime  = ts,
                            MessageState = MessageState.Normal,
                            MsgType      = MessageType.text,
                            Content      = resp.MsgData.ToString()
                        };

                        c.Add(m);
                    }
                }
            }
            catch
            {
                throw;
            }
        }