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; }
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(); }
// Constructor public MainPage() { InitializeComponent(); //Load up database using (ChatRoomDataContext context = new ChatRoomDataContext(Con_String)) { if (!context.DatabaseExists()) { context.CreateDatabase(); } list_chatrooms.ItemsSource = context.ChatRooms.ToList(); updateChatRoomList(); } }
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(); */ }
protected override void OnNavigatedTo(NavigationEventArgs e) { string chatidstring; if (NavigationContext.QueryString.TryGetValue("id", out chatidstring)) { using (ChatRoomDataContext context = new ChatRoomDataContext(MainPage.Con_String)) { IEnumerable<MyChatRoom> queryRooms = from MyChatRoom in context.ChatRooms where MyChatRoom.C_ID_String == chatidstring select MyChatRoom; App.currentRoom = queryRooms.First(); } } chatpage_pivot.Title = App.currentRoom.C_Name.ToUpper(); chat_messages = new ObservableCollection<ChatMessage>(); chat_participants = new ObservableCollection<Participant>(); list_messages.ItemsSource = chat_messages; list_participants.ItemsSource = chat_participants; loadRecentChatHistory(); loadParticipants(); participants_timer = new DispatcherTimer(); participants_timer.Interval = TimeSpan.FromMilliseconds(10000); participants_timer.Tick += new EventHandler(participants_tick); participants_timer.Start(); }
protected void loadRecentChatHistory() { //Show progress indicator progress_history = new ProgressIndicator { IsVisible = true, IsIndeterminate = true, Text = "Updating Chat Room Listing..." }; SystemTray.SetProgressIndicator(this, progress_history); progress_history.IsVisible = true; //Grab recent history from database System.Diagnostics.Debug.WriteLine("Loading recent chat from DB..."); using (ChatRoomDataContext context = new ChatRoomDataContext(MainPage.Con_String)) { IEnumerable<ChatMessage> queryMsgs = from ChatMessage in context.ChatMessages where ChatMessage.chatroom_id == App.currentRoom.C_ID select ChatMessage; foreach (ChatMessage c in queryMsgs) { chat_messages.Add(c); } } Dictionary<String, String> chatvars = new Dictionary<String, String>(); chatvars.Add("chat_id", App.currentRoom.C_ID_String); if (chat_messages.Count <= 0) { System.Diagnostics.Debug.WriteLine("No history stored. Fetching from server instead..."); REST historyREST = new REST("chats/fetch_recent", "GET", chatvars); historyREST.call(rest_load_history_success, rest_load_history_failure); } else { progress_history.IsVisible = false; //Switching to PUSH for this. //chat_timer = new DispatcherTimer(); //chat_timer.Interval = TimeSpan.FromMilliseconds(2000); //chat_timer.Tick += new EventHandler(chat_tick); //chat_timer.Start(); DispatcherTimer scroll_timer = new DispatcherTimer(); scroll_timer.Interval = TimeSpan.FromMilliseconds(100); scroll_timer.Tick += new EventHandler(scrollChatToBottom); scroll_timer.Start(); loadNewChat(); } }
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()); } }
private void updateChatRoomList() { //Show progress indicator progress_chatlist = new ProgressIndicator { IsVisible = true, IsIndeterminate = true, Text = "Updating Chat Room Listing..." }; SystemTray.SetProgressIndicator(this, progress_chatlist); progress_chatlist.IsVisible = true; using (ChatRoomDataContext context = new ChatRoomDataContext(Con_String)) { if (!context.DatabaseExists()) { context.CreateDatabase(); } list_chatrooms.ItemsSource = context.ChatRooms.ToList(); REST chatroomREST = new REST("chats", "GET", null); chatroomREST.call(rest_updateChatRoomList_success,rest_updateChatRoomList_failure); } }