async void Find() { string uri = Config.apiUserFind + Word; string response=await HttpGet.HttpGets(uri); if (response != null) { try { JsonArray jsonList = JsonArray.Parse(response); foreach (var item in jsonList) { JsonObject user = item.GetObject(); UserModel userModel = new UserModel(); userModel.uid = user.GetNamedString("phone"); userModel.name = user.GetNamedString("name"); userModel.image = Config.apiFile + user.GetNamedString("image"); userModel.dream = user.GetNamedString("dream"); UserList.Add(userModel); } } catch (Exception ex) { HelpMethods.Msg(ex.Message.ToString()); } } }
async void Load() { string uri = Config.apiPraiseGet + Config.UserPhone; string response =await HttpGet.HttpGets(uri); if (response != null) { try { JsonArray jsonList = JsonArray.Parse(response); foreach (var item in jsonList) { JsonObject user = item.GetObject(); UserModel userModel = new UserModel(); userModel.uid = user.GetNamedString("user_phone"); userModel.name = user.GetNamedString("user_name"); userModel.image = user.GetNamedString("user_image"); userModel.day = user.GetNamedString("post_id"); //文章ID UserList.Add(userModel); } } catch (Exception ex) { HelpMethods.Msg(ex.Message.ToString()); } } }
public void Run(IBackgroundTaskInstance taskInstance) { Windows.Networking.PushNotifications.RawNotification notification = taskInstance.TriggerDetails as Windows.Networking.PushNotifications.RawNotification; if (notification != null) { string message = notification.Content; string[] items = message.Split('|'); int type = int.Parse(items[0]); if (type == 1) { DataContractJsonSerializer ds = new DataContractJsonSerializer(typeof(MessageModel)); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(items[1])); MessageModel messageModel = ds.ReadObject(ms) as MessageModel; UserModel chatUser = new UserModel { uid = messageModel.myPhone, name = messageModel.myName, image = messageModel.myImage, dream = messageModel.myDream, isRead= false }; DbService.Current.InsertOrUpdateFalse(chatUser); if (Config.IsNotify) { switch (messageModel.type) { case 0: ToastUpdate.Update("私信 " + messageModel.myName + ":" + messageModel.msg); break; case 1: ToastUpdate.Update("私信 " + messageModel.myName + "向您发送了一段语音"); break; case 2: ToastUpdate.Update("私信 " + messageModel.myName + "向您发送了一张图片"); break; default: break; } } } } }
void SocketInit() { SocKetHelp.SocketInit(); SocKetHelp.socket.On("chat", (data) => { string str = data.ToString(); MessageModel messageModel = JsonConvert.DeserializeObject<MessageModel>(str); DbService.Current.Add(messageModel); UserModel chatUser = new UserModel { uid = messageModel.myPhone, name = messageModel.myName, image = messageModel.myImage, dream = messageModel.myDream, isRead = false }; DbService.Current.InsertOrUpdateFalse(chatUser); switch (messageModel.type) { case 0: ToastNotify.Notify("私信 " + messageModel.myName + ":" + messageModel.msg); break; case 1: ToastNotify.Notify("私信 " + messageModel.myName + "向您发送一段了语音"); break; case 2: ToastNotify.Notify("私信 " + messageModel.myName + "向您发送了一张图片"); break; default: break; } }); }
public async void DeleteUser(UserModel user) { await connection.DeleteAsync(user); }
public async void Add(UserModel user) { await connection.InsertAsync(user); }
public async void InsertOrUpdateTrue(UserModel User) { var query = from user in connection.Table<UserModel>() where user.uid == User.uid select user; UserModel userQuery = await query.FirstOrDefaultAsync(); if (userQuery != null) { userQuery.isRead = true; await connection.UpdateAsync(userQuery); } else { await connection.InsertAsync(User); } }
public async void Load(string id) { string uri = Config.apiUserInfo+ id; string response = await HttpGet.HttpGets(uri); try { JsonObject user = JsonObject.Parse(response); userId = user.GetNamedString("phone"); UserImage = Config.apiFile+ user.GetNamedString("image"); UserName = user.GetNamedString("name"); UserDay = user.GetNamedString("date"); UserDream = user.GetNamedString("dream"); User = new UserModel { uid = userId, name = UserName, image = UserImage, dream = UserDream, day = UserDay }; } catch (Exception ex) { Debug.WriteLine(ex.Message.ToString()); } string dreamingUri = Config.apiDreamingUserId + id; string dreamingResponse = await HttpGet.HttpGets(dreamingUri); try { DataContractJsonSerializer ds = new DataContractJsonSerializer(typeof(List<DreamingModel>)); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(dreamingResponse)); List<DreamingModel> dreaming = ds.ReadObject(ms) as List<DreamingModel>; DreamingList = dreaming; } catch (Exception ex) { Debug.WriteLine(ex.Message.ToString()); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter != null) { User = e.Parameter as UserModel; textName.Text = User.name; } Init(); SocKetHelp.socket.Off("chat"); SocKetHelp.socket.Emit("get", User.uid + "|" + Config.UserPhone); SocKetHelp.socket.On("new", (data) => { string str = data.ToString(); ObservableCollection<MessageModel> newMessageList = JsonConvert.DeserializeObject<ObservableCollection<MessageModel>>(str); ShowList(newMessageList); }); SocKetHelp.socket.On("chat", (data) => { string str = data.ToString(); MessageModel messageModel = JsonConvert.DeserializeObject<MessageModel>(str); if (messageModel.myPhone == User.uid) { ShowOne(messageModel); } else { DbService.Current.Add(messageModel); UserModel chatUser = new UserModel { uid = messageModel.myPhone, name = messageModel.myName, image = messageModel.myImage, dream = messageModel.myDream, isRead = false }; DbService.Current.InsertOrUpdateFalse(chatUser); switch (messageModel.type) { case 0: ToastNotify.Notify("私信 " + messageModel.myName + ":" + messageModel.msg); break; case 1: ToastNotify.Notify("私信 " + messageModel.myName + "向您发送一段了语音"); break; case 2: ToastNotify.Notify("私信 " + messageModel.myName + "向您发送了一张图片"); break; default: break; } MainViewModel main = new MainViewModel(); } }); DbService.Current.InsertOrUpdateTrue(User); }