private void Follow_Users(object sender, EventArgs e) { TJSONArray users = new TJSONArray(); if (listBox1.SelectedItems.Count != 0) { for (int i = 0; i < listBox1.SelectedItems.Count; i++) { int sindex = listBox1.Items.IndexOf(listBox1.SelectedItems[i]); if (sindex > -1) { if (CTConnection.getCurUserID() != UsersArray[sindex].UserID) { users.add(new TJSONString(UsersArray[sindex].UserID)); } //users.add(new TJSONString(listBox1.SelectedItems[i].ToString())); } } CTConnection.getLoginUserInstance().SetUsersToFollow(users, () => { this.Dispatcher.BeginInvoke(() => { this.NavigationService.Navigate(new Uri("/MainTweetPage.xaml", UriKind.Relative)); }); }); } else { this.Dispatcher.BeginInvoke(() => { this.NavigationService.Navigate(new Uri("/MainTweetPage.xaml", UriKind.Relative)); }); } }
private void ApplicationBarIconButton_Click(object sender, EventArgs e) { CTConnection.LogOut(); this.Dispatcher.BeginInvoke(() => { this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); }); }
public static void LogOut() { if (manager != null) { CTConnection.getLoginUserInstance().Logout(); ResetProxy(); } }
// Code to execute when the application is deactivated (sent to background) // This code will not execute when the application is closing private void Application_Deactivated(object sender, DeactivatedEventArgs e) { try { CTConnection.getLoginUserInstance().Logout(); } catch { } }
private void btn_Login(object sender, EventArgs e) { OnLogin LoginDelegate = () => Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/UsersList.xaml", UriKind.Relative))); OnException ExceptionDelegate = (ex) => Dispatcher.BeginInvoke(() => MessageBox.Show(ex.Message)); CTConnection.ResetProxy(); CTConnection.LoginUser(txtName.Text, txtPassword.Password, LoginDelegate, ExceptionDelegate); }
private void UsersList_Loaded(object sender, RoutedEventArgs e) { if (CTConnection.IsNull()) { this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); } else { LoadUsersList(); } }
private void btn_Login(object sender, EventArgs e) { OnLogin LoginDelegate = () => Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/UsersList.xaml", UriKind.Relative))); OnException ExceptionDelegate = (ex) => Dispatcher.BeginInvoke(() => MessageBox.Show(ex.Message)); CTConnection.ResetProxy(); String retmsg = ""; String AccCode = ""; int sindex = lbAccBook.SelectedIndex; if (sindex > -1) { AccCode = AccBookArray[sindex].AccBookID; } CTConnection.LoginUser(txtName.Text, txtPassword.Password, AccCode, retmsg, LoginDelegate, ExceptionDelegate); }
private void LoadUsersList() { CTConnection.getLoginUserInstance().GetUserList(users => { this.Dispatcher.BeginInvoke(() => { listBox1.Items.Clear(); UsersArray.Clear(); int i = 0; for (i = 0; i < users.size(); i++) { TJSONObject userItem = users.getJSONObject(i); UsersArray.Add(new UserRecord(userItem.getString("userid"), userItem.getString("username"))); listBox1.Items.Add(userItem.getString("username")); } //listBox1.DataContext = UsersArray; //listBox1.DisplayMemberPath = "UserName"; }); }, ManageExceptionCallback); }
private void SaveSettings(object sender, EventArgs e) { this.Dispatcher.BeginInvoke(() => { settings["hostname"] = txt_hostname.Text.ToString(); settings["port"] = txt_port.Text.ToString(); settings.Save(); CTConnection.ResetProxy(); try { Convert.ToInt32(txt_port.Text.ToString()); this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); } catch (Exception) { MessageBox.Show("Invalid port number!"); } }); }
private void LoadAccBookList() { CTConnection.getLoginUserInstance().GetAccListJSON(result => { this.Dispatcher.BeginInvoke(() => { lbAccBook.Items.Clear(); AccBookArray.Clear(); TJSONArray accbooks = result.getJSONArray("accbooks"); int i = 0; for (i = 0; i < accbooks.size(); i++) { TJSONObject AccItem = accbooks.getJSONObject(i); AccBookArray.Add(new AccBook(AccItem.getString("syaccbookcode"), AccItem.getString("syaccbookname"))); lbAccBook.Items.Add(AccItem.getString("syaccbookname")); } if (lbAccBook.Items.Count > 0) { lbAccBook.SelectedIndex = 0; } }); }, ManageExceptionCallback); }
// Code to execute when the application is closing (eg, user hit Back) // This code will not execute when the application is deactivated private void Application_Closing(object sender, ClosingEventArgs e) { CTConnection.LogOut(); }
private void btnRing_Click(object sender, RoutedEventArgs e) { CTConnection.getLoginUserInstance().SendCMDToAll("ring"); }
private void btnSendTweet_Click(object sender, RoutedEventArgs e) { CTConnection.getLoginUserInstance().SendMessageToAll(txtMsg.Text.ToString(), OnSendCallback, ManageExceptionCallback); }
private void btnVibrate_Click(object sender, RoutedEventArgs e) { CTConnection.getLoginUserInstance().SendCMDToFollow("vibrate"); }
private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e) { CTConnection.LogOut(); }
public override TJSONValue Execute(TJSONValue value, int JSONType) { TJSONObject obj = TJSONObject.Parse(value.ToString()); Context.Send(new SendOrPostCallback(x => { string notificationtype = obj.getString("notificationType"); string fromusrname = obj.getString("fromusrname"); string datetimestr = obj.getString("datetime"); if (notificationtype == "user_login" || notificationtype == "user_logout") { string userid = obj.getString("from"); string msgText; if (notificationtype == "user_login") { msgText = "登录了!"; } else { msgText = "退出了!"; } if (CTConnection.getCurUserID() == userid) { return; } MessageBox.Show(fromusrname + msgText + datetimestr); PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; PhoneApplicationPage mp = frame.Content as PhoneApplicationPage; if (mp is UsersList) { UsersList userp = (UsersList)mp; userp.RefreshListBox(); } /* SoundEffect.MasterVolume = 1.0f; * SoundEffect sfx = SoundEffect.FromStream(TitleContainer.OpenStream("tweet.wav")); * SoundEffectInstance sfxInstance = sfx.CreateInstance(); * sfxInstance.Play();*/ } else if (notificationtype == "message") { PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; PhoneApplicationPage mp = frame.Content as PhoneApplicationPage; if (mp is MainTweetPage) { System.Windows.Controls.ListBox listbox = ((MainTweetPage)mp).listBox1; listbox.Items.Add(fromusrname + " " + datetimestr); string msgText = obj.getString("message"); int txtPos = 0; int txtLen = 22; if (msgText.Length > txtLen) { while (txtPos < msgText.Length) { string dipTxt = msgText.Substring(txtPos, txtLen); listbox.Items.Add(dipTxt); txtPos = txtPos + txtLen; if (txtPos + txtLen > msgText.Length) { txtLen = msgText.Length - txtPos; } } } else { listbox.Items.Add(msgText); } } } else if (notificationtype == "cmd") { if (obj.getString("cmd") == "vibrate") { PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; PhoneApplicationPage mp = frame.Content as PhoneApplicationPage; if (mp is MainTweetPage) { System.Windows.Controls.ListBox listbox = ((MainTweetPage)mp).listBox1; listbox.Items.Add(fromusrname + " " + datetimestr); listbox.Items.Add("发送:震动"); } Microsoft.Devices.VibrateController.Default.Start(TimeSpan.FromMilliseconds(50)); System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 0, 200); timer.Tick += (tsender, tevt) => { var t = tsender as System.Windows.Threading.DispatcherTimer; t.Stop(); Microsoft.Devices.VibrateController.Default.Stop(); }; timer.Start(); } else if (obj.getString("cmd") == "ring") { PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; PhoneApplicationPage mp = frame.Content as PhoneApplicationPage; if (mp is MainTweetPage) { System.Windows.Controls.ListBox listbox = ((MainTweetPage)mp).listBox1; listbox.Items.Add(fromusrname + " " + datetimestr); listbox.Items.Add("发送:响铃"); } SoundEffect.MasterVolume = 1.0f; SoundEffect sfx = SoundEffect.FromStream(TitleContainer.OpenStream("cmd.wav")); SoundEffectInstance sfxInstance = sfx.CreateInstance(); sfxInstance.Play(); } } }), null); return(null); }