public RChatViewModel(IStorage <MessageViewModel> storage) : base() { Title = "NBS群聊"; initSelf(); BindingOperations.EnableCollectionSynchronization(_collection, _lockObject); PubSubTask.PubSubTaskClient cli = new PubSubTask.PubSubTaskClient(GrpcBaseHelper.Instance().Channel); serviceClient = new PubSubServiceClient <MessageViewModel>(cli, _collection, SELF, SELF.UID, true); StartRecving(); this.AssignCommands(); loadLocalHistory(storage, 1); }
public PubSubServiceClient( PubSubTask.PubSubTaskClient client, ObservableCollection <T> collection, T self, string acid, bool debug) { this.pubsubClient = client; this.collection = collection; this.Self = self; this.selfID = acid; DEBUG = debug; }
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; } }