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 static ModelXmlMapper.MappedType GetMappedType(XElement first) { ModelXmlMapper.MappedType typeInElement = ModelXmlMapper.MappedType.UNDEFINED; if (first != null) { XElement firstElementType = first.Element("Type"); if (firstElementType != null) { if (!ModelXmlMapper.map.TryGetValue(firstElementType.Value, out typeInElement)) { typeInElement = ModelXmlMapper.MappedType.UNDEFINED; } } } return(typeInElement); }
private async void DispatchSingleObjectMsg(XElement xmlObj) { ModelXmlMapper.MappedType typeInElement = GetMappedType(xmlObj); switch (typeInElement) { case ModelXmlMapper.MappedType.MESSAGE: MessageModel msg = new MessageModel(); if (msg.FromXml(xmlObj)) { string message = msg.From + ": " + msg.Content; await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { context.ChatWinodw.MessageReceived(message); } ); } break; case ModelXmlMapper.MappedType.CHAT_REQUEST: ChatRequest req = new ChatRequest(); if (req.FromXml(xmlObj)) { // TODO: check if ongoing chat and return failure from here: await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { context.ContactsWindow.ChatRequestReceived(req); } ); } break; case ModelXmlMapper.MappedType.CHAT_REQUEST_RESPONSE: ChatRequestResponse resp = new ChatRequestResponse(); if (resp.FromXml(xmlObj)) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { context.ContactsWindow.ChatResponseReceived(resp); // context.ChatWinodw.Disconnected(resp); } ); } break; case ModelXmlMapper.MappedType.LOGIN_RESPONSE: LoginResponse loginResp = new LoginResponse(); if (loginResp.FromXml(xmlObj)) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { context.LoginWindow.OnLoginResponseAsync(loginResp); } ); } break; case ModelXmlMapper.MappedType.CONTACT: Contact contact = new Contact(); if (contact.FromXml(xmlObj)) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { if (context.ContactsWindow != null) { context.ContactsWindow.OnContactUpdate(contact); } } ); } break; default: // do nothing break; } }