private async void DispatchListMsg(XElement xmlList) { XElement first = (XElement)xmlList.FirstNode; ModelXmlMapper.MappedType typeInList = GetMappedType(first); IList <AbstractXmlSerializable> list = ModelXmlMapper.FromArrayXml(xmlList); switch (typeInList) { case ModelXmlMapper.MappedType.UNDEFINED: case ModelXmlMapper.MappedType.CONTACT: await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { context.LoginWindow.OnContactsListReceived(list); } ); break; default: // do nothing break; } }
private void HandleLoginMsg(Login login, TalkBackDBContext dbContext) { UsersRepository repo = new UsersRepository(dbContext); // check if User Exists: if (repo.IsUserExist(login.Name)) { // check password: if (!repo.IsPasswordCorrect(login.Name, login.Password)) { LoginResponse response = new LoginResponse { Success = false, ErrorMessage = "Wrong password, please try again" }; WebSocketMiddleware.SendStringAsync(_webSocket, response.ToXml().ToString()); return; } } else { // new user: add it to repo repo.AddNewUser(new UserModel { Name = login.Name, Password = login.Password }); } // login successfully: // 1. record UserName for this handler UserName = login.Name; // 2. add to the websocket dictionary WebSocketMiddleware._sockets.TryAdd(UserName, _webSocket); // 3. inform all online users about the new/updated contact, // create a Set<string> of online users: ISet <string> online = new HashSet <string>(); Contact me = new Contact { Name = UserName, IsOnline = true }; string contactUpdate = me.ToXml().ToString(); online = Broadcast(contactUpdate); // 4. send the client the list of contacts: IList <AbstractXmlSerializable> contacts = repo.GetContactsList(UserName, online); string contactsList = ModelXmlMapper.GetAsXmlString(contacts); WebSocketMiddleware.SendStringAsync(_webSocket, contactsList); }
public async void SendListAsync(IList <AbstractXmlSerializable> list) { string serialized = ModelXmlMapper.GetAsXmlString(list); await connectTask.ContinueWith(_ => SendMessageUsingMessageWebSocketAsync(serialized)); }
public async void SendObjectAsync(AbstractXmlSerializable obj) { string serialized = ModelXmlMapper.GetAsXmlString(obj); await connectTask.ContinueWith(_ => SendMessageUsingMessageWebSocketAsync(serialized)); }