Exemple #1
0
 public void auth_success(System.Net.HttpStatusCode code, dynamic data)
 {
     progress.IsVisible = false;
     REST.auth_token = data.authentication.token;
     REST.auth_pass = SHA1.CalculateSHA1(input_password.Password);
     //Let's verify our password
     REST verify = new REST("auth/verify", "GET", null);
     verify.call(verify_success, verify_failure);
 }
Exemple #2
0
        private void button_login_Click(object sender, RoutedEventArgs e)
        {
            //Disable form
            input_login.IsEnabled = false;
            input_password.IsEnabled = false;
            button_login.IsEnabled = false;
            button_register.IsEnabled = false;

            //Show progress indicator
            progress = new ProgressIndicator
            {
                IsVisible = true,
                IsIndeterminate = true,
                Text = "Authenticating..."
            };
            SystemTray.SetProgressIndicator(this, progress);
            progress.IsVisible = true;
            //Make a rest call to get an authentication token
            Dictionary<String,String> authvars = new Dictionary<String,String>();
            authvars.Add("email", input_login.Text);
            authvars.Add("device", "2");

            REST auth = new REST("auth", "GET", authvars);
            auth.call(auth_success, auth_failure);
        }
Exemple #3
0
        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();
            }
        }
Exemple #4
0
 private void Send_Click(object sender, EventArgs e)
 {
     input_chat_text.IsEnabled = false;
     Dictionary<String, String> sendvars = new Dictionary<String, String>();
     sendvars.Add("chat_id", App.currentRoom.C_ID_String);
     sendvars.Add("message", input_chat_text.Text);
     REST sendREST = new REST("chats/send", "POST", sendvars);
     sendREST.call(rest_send_success, rest_send_failure);
 }
Exemple #5
0
 protected void loadParticipants()
 {
     //Show progress indicator
     /*
     progress_participants = new ProgressIndicator
     {
         IsVisible = true,
         IsIndeterminate = true,
         Text = "Updating Chat Room Participants..."
     };
     SystemTray.SetProgressIndicator(this, progress_participants);
     progress_participants.IsVisible = true;
     */
     Dictionary<String, String> participantvars = new Dictionary<String, String>();
     participantvars.Add("id", App.currentRoom.C_ID_String);
     REST historyREST = new REST("chats/get_participants", "GET", participantvars);
     historyREST.call(rest_load_participants_success, rest_load_history_failure);
 }
Exemple #6
0
 protected void loadNewChat()
 {
     if (chat_messages.Count <= 0)
         return;
     //Show progress indicator
     /*
     progress_history = new ProgressIndicator
     {
         IsVisible = true,
         IsIndeterminate = true,
         Text = "Updating Chat Room..."
     };
     SystemTray.SetProgressIndicator(this, progress_history);
     progress_history.IsVisible = true;
      */
     Dictionary<String, String> chatvars = new Dictionary<String, String>();
     chatvars.Add("chat_id", App.currentRoom.C_ID_String);
     chatvars.Add("msg_id", chat_messages.Last().msg_id.ToString());
     REST historyREST = new REST("chats/fetch_since", "GET", chatvars);
     historyREST.call(rest_load_new_chat_success, rest_load_new_chat_failure);
 }
        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);
            }
        }
        /**
         * Signs out of LiveCourse, deleting the database and authentication information from the device.
         */
        private void SignOut_Click(object sender, EventArgs e)
        {
            //Show progress bar
            progress_chatlist = new ProgressIndicator
            {
                IsVisible = true,
                IsIndeterminate = true,
                Text = "Signing Out..."
            };
            SystemTray.SetProgressIndicator(this, progress_chatlist);
            progress_chatlist.IsVisible = true;

            //Stop the push notifications.
            //Get device ID
            byte[] myDeviceID = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
            string DeviceIDAsString = Convert.ToBase64String(myDeviceID);

            Dictionary<String, String> pushvars = new Dictionary<String, String>();
            pushvars.Add("dev_id", DeviceIDAsString);
            pushvars.Add("channel", "0");
            REST push = new REST("users/wp_remove", "POST", pushvars);
            push.call(rest_signout_success, rest_signout_failure);
        }
Exemple #9
0
        void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
        {
            //Dispatcher.BeginInvoke(() =>
            //{
                byte[] myDeviceID = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
                string DeviceIDAsString = Convert.ToBase64String(myDeviceID);
                System.Diagnostics.Debug.WriteLine("Device ID: '" + DeviceIDAsString + "'");
                System.Diagnostics.Debug.WriteLine("PUSH URI: '" + e.ChannelUri.ToString() + "'");

                Dictionary<String, String> wpvars = new Dictionary<String, String>();
                wpvars.Add("dev_id", DeviceIDAsString);
                wpvars.Add("url", e.ChannelUri.ToString());
                wpvars.Add("channel", "0");
                REST chatroomREST = new REST("users/wp_add", "POST", wpvars);
                chatroomREST.call(null, null);
            //});
        }