public void pushRawChannel_HttpNotificationReceived(object sender, Microsoft.Phone.Notification.HttpNotificationEventArgs e) { string content; using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body)) { content = reader.ReadToEnd(); } dynamic m = JsonConvert.DeserializeObject<dynamic>(content); if (!((String)(m.chat_id)).Equals(App.currentRoom.C_ID_String)) //If this isn't for our current room, ignore it. return; ChatMessage msg = new ChatMessage { msg_id = (int)(m.message_id), sender_id = (int)(m.user_id), sender_name = (String)(m.display_name), msg_string = (String)(m.message_string), chatroom_id = App.currentRoom.C_ID }; Dispatcher.BeginInvoke(() => addMessage(msg)); using (ChatRoomDataContext context = new ChatRoomDataContext(MainPage.Con_String)) { context.ChatMessages.InsertOnSubmit(msg); context.SubmitChanges(); } //throw new NotImplementedException(); }
public void rest_load_history_success(System.Net.HttpStatusCode code, dynamic data) { if (data != null) { foreach (dynamic item in data) { ChatMessage msg = new ChatMessage { msg_id = (int)(item.id), sender_id = (int)(item.user_id), sender_name = (String)(item.display_name), msg_string = (String)(item.message_string), chatroom_id = App.currentRoom.C_ID }; chat_messages.Add(msg); using (ChatRoomDataContext context = new ChatRoomDataContext(MainPage.Con_String)) { context.ChatMessages.InsertOnSubmit(msg); context.SubmitChanges(); } } list_messages.ScrollTo(chat_messages.Last()); } progress_history.IsVisible = false; /* chat_timer = new DispatcherTimer(); chat_timer.Interval = TimeSpan.FromMilliseconds(2000); chat_timer.Tick += new EventHandler(chat_tick); chat_timer.Start(); */ }
public void rest_load_new_chat_success(System.Net.HttpStatusCode code, dynamic data) { if (data != null) { foreach (dynamic item in data) { ChatMessage msg = new ChatMessage { msg_id = (int)(item.id), sender_id = (int)(item.user_id), sender_name = (String)(item.display_name), msg_string = (String)(item.message_string), chatroom_id = (int)(App.currentRoom.C_ID) }; chat_messages.Add(msg); using (ChatRoomDataContext context = new ChatRoomDataContext(MainPage.Con_String)) { context.ChatMessages.InsertOnSubmit(msg); context.SubmitChanges(); } } list_messages.ScrollTo(chat_messages.Last()); } }
public void rest_updateChatRoomList_success(System.Net.HttpStatusCode code, dynamic data) { using (ChatRoomDataContext context = new ChatRoomDataContext(Con_String)) { if (!context.DatabaseExists()) { context.CreateDatabase(); } foreach (dynamic item in data) { MyChatRoom room = new MyChatRoom { C_Name = (String)(item.name), C_ID_String = (String)(item.class_id_string), C_Course_Number = (int)(item.course_number), C_Subject_Code = (String)(item.subject_code) }; String room_string_id = (String)(item.class_id_string); IEnumerable<MyChatRoom> queryRooms = from MyChatRoom in context.ChatRooms where MyChatRoom.C_ID_String == room_string_id select MyChatRoom; if (queryRooms.Count() <= 0) //If we don't have this room in the database, add it. context.ChatRooms.InsertOnSubmit(room); } context.SubmitChanges(); list_chatrooms.ItemsSource = context.ChatRooms.ToList(); } progress_chatlist.IsVisible = false; }