}//窗口随意拖动 #endregion #region 托盘绑定 /// <summary> /// 托盘图标绑定 /// </summary> private void BindNotiyIcon() { //设置托盘的各个属性 notifyIcon = new NotifyIcon { Tag = true,//设置图标闪动标记 BalloonTipText = "微微开始运行", Text = "微微\n" + Applicate.MyAccount.nickname + "(" + Applicate.MyAccount.userId + ")", Visible = true,//显示任务栏图标 Icon = ShikuRec.ShikuIcoBig }; notifyIcon.Visible = true; //设置为可见 notifyIcon.ShowBalloonTip(2000); //设置鼠标悬浮两秒后显示气泡 notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(NotifyIcon_MouseClick); //设置菜单项 ContextMenu cm = new ContextMenu(); MenuItem menuExit = new MenuItem("退出"); MenuItem menuLogout = new MenuItem("切换账号"); menuExit.Click += new EventHandler((s, e) => { ShiKuManager.ApplicationExit(); System.Windows.Application.Current.Shutdown();//退出整个应用程序 }); menuLogout.Click += new EventHandler((s, e) => { ShiKuManager.ApplicationExit(); System.Windows.Forms.Application.Restart(); System.Windows.Application.Current.Shutdown(); }); cm.MenuItems.Add(menuLogout); //注销 cm.MenuItems.Add(menuExit); //注销菜单 notifyIcon.ContextMenu = cm; //绑定右键菜单 }
/// <summary> /// 添加好友事件 /// </summary> /// <param name="sender">控件</param> /// <param name="e">事件源</param> public void userAdd_MouseDown(object sender) { //var web = new WebClient(); string userId = ""; //非空判断 if (userId != "") { //接口添加好友 var client = APIHelper.AddFriendAsync(userId); client.UploadDataCompleted += (sen, res) => { var result = JsonConvert.DeserializeObject <JsonAttention>(Encoding.UTF8.GetString(res.Result));//获取返回值 //var user = ((HttpClient)sender).Tag as DataOfUserDetial; if (result.resultCode == 2 || result.resultCode == 4) { ShiKuManager.SendFriendRequest(userId, true);//发送Xmpp } }; } else { //MessageBox.Show("用户ID无效或获取ID失败", "提示"); } }
/// <summary> /// 同意完成后 /// </summary> /// <param name="sender">事件源</param> /// <param name="e"></param> private void AgreeComplete(object sender, UploadDataCompletedEventArgs e) { var source = (HttpClient)sender; //事件源 var resstr = Encoding.UTF8.GetString(e.Result); //获取字符 var resjson = JsonConvert.DeserializeObject <JsonBase>(resstr); //反序列化 //过滤状态码 switch (resjson.resultCode) { case 1: case 2: ShiKuManager.SendVerifyAgreeXmpp((DataOfFriends)source.Tag); //发送Xmpp消息(通过验证) break; case 3: MessageBox.Show("已经添加该好友, 不能重复添加", "提示", MessageBoxButton.OK); break; case 1100801: MessageBox.Show("对方拒绝被添加", "提示", MessageBoxButton.OK); break; case 1100802: MessageBox.Show("你已经被对方拉黑, 不能添加对方", "提示", MessageBoxButton.OK); break; default: break; } InVerifingWaiting = false; }
/// <summary> /// 截图完成后 /// </summary> /// <param name="sender">控件源</param> /// <param name="e"></param> private void OnScreenCaputred(object sender, RisCaptureLib.ScreenCaputredEventArgs e) { var bmp = e.Bmp; try { Bitmap tmpimg = Helpers.BItmapSourceToBitmap(bmp); string path = Applicate.LocalConfigData.ChatDownloadPath + DateTime.Now.ToFileTime() + ".png"; ConsoleLog.Output("保存截图成功==" + path); LogHelper.log.Info("保存截图成功==" + path); tmpimg.Save(path, ImageFormat.Png); var mainview = this.DataContext as MainViewModel;//获取MainViewModel ShiKuManager.SendMessageFile(new MessageListItem { Jid = mainview.Sess.Jid, ShowTitle = mainview.Sess.NickName, MessageItemContent = mainview.Sess.MyMemberNickname, Avator = Applicate.LocalConfigData.GetDisplayAvatorPath(mainview.Sess.Jid) }, path); //添加至富文本框 //new InlineUIContainer(img, rtb_sendMessage.ThisRichText.Selection.Start); } catch (Exception ex) { ConsoleLog.Output("添加截图失败" + ex.Message); LogHelper.log.Error("添加截图失败", ex); } }
/// <summary> /// 开始创建群聊 /// </summary> public void BeginCreateGroup() { /* if (SelectedMember.Count <= 1) * { * Snackbar.Enqueue("请选择至少两个好友!"); * return; * } * else */ EnableCreate = true; ConfirmEnable = false; //禁用确认 Room room = new Room(); //实例化新的Room对象 //room.IsJoined = true;//我已加入的群 room.name = GroupName; room.desc = GroupDesc; room.jid = Guid.NewGuid().ToString("N"); //随机生成 room.nickname = Applicate.MyAccount.nickname; //建群 room.userSize = SelectedMember.Count + 1; //成员数量 #region 添加群成员 for (int i = 0; i < SelectedMember.Count; i++) { //添加邀请的好友 room.members.Add(new DataofMember() { nickname = (SelectedMember[i]).MessageTitle, userId = (SelectedMember[i]).Jid, groupid = room.id, role = MemberRole.Member }); } //添加自己到群成员中 room.members.Add(new DataofMember() { nickname = Applicate.MyAccount.nickname, userId = Applicate.MyAccount.userId, groupid = room.id, role = MemberRole.Owner }); #endregion List <string> members = new List <string>(); for (int i = 0; i < SelectedMember.Count; i++) { members.Add(SelectedMember[i].Jid.ToString()); //添加成员 } members.Add(Applicate.MyAccount.userId); //添加自己 //异步执行 Task.Run(() => { var client = ShiKuManager.CreateGroup(room, members); client.Tag = room;////设置Tag为本地群组 client.UploadDataCompleted += CreateGroupChatComplete; }); }
private void UserLogin(IHavePassword parameter) { Task.Run(() => { if (IsVisitorLogin == true)//游客登录 { Applicate.URLDATA.data.apiUrl = ConfigurationUtil.GetValue("InitialServer") + "/"; VisitorKey = ConfigurationUtil.GetValue("InitialServer_key"); int index = VisitorKey.LastIndexOf("?"); VisitorKey = VisitorKey.Substring(index + 1); int index2 = VisitorKey.LastIndexOf("="); VisitorKey = VisitorKey.Substring(index2 + 1); VisitorLogin(); return; } //接收用户名和密码 string password; if (IsRememberPwd && TruePasswordWhenRemembered != null && !IsCancelRememberPwdAndTextNewPwd) //如果当前处于记住有效密码 且 不为加载密码后重新输入的密码 { password = TruePasswordWhenRemembered; //使用数据库密码 //parameter.LoginSecurePassword = TruePasswordWhenRemembered.ToSecureString(); } else//没记住密码 或 { password = parameter.LoginSecurePassword.UnSecure();//使用文本框内密码 } EnabledLogin = false;//暂时禁用登录 //获取经纬度 string Longitude = "0"; string Latitude = "0"; if (Location.IsUnknown != true) { Longitude = Location.Longitude.ToString(); Latitude = Location.Latitude.ToString(); } try { var client = ShiKuManager.ShiKuLogin(UserId, password, Latitude, Longitude, GobalAreaList[SelectedCountryCode].prefix.ToString()); client.UploadDataCompleted += LoginComplete; } catch (Exception ex) { SnackBar.Enqueue("登录失败:" + ex.Message, "重试", () => { LoginCommand.Execute(Applicate.GetWindow <IHavePassword>()); }); Console.WriteLine("登录失败:" + ex.Message); EnabledLogin = true;//启用登录 } }); }
/// <summary> /// 注册成功 /// </summary> /// <param name="sender">Client</param> /// <param name="e"></param> private void RegisterComplete(object sender, UploadDataCompletedEventArgs e) { Task.Run(() => { if (e.Error == null) { string result = Encoding.UTF8.GetString(e.Result); var resuser = JsonConvert.DeserializeObject <RegisterModel>(result); Task.Run(() => { var client = ShiKuManager.UploadAvator(resuser.Data.userId, UploadfilePath); client.UploadDataCompleted += (sen, eve) => { if (eve.Error == null) { string restxt = Encoding.UTF8.GetString(eve.Result); var resavator = JsonConvert.DeserializeObject <JsonBase>(restxt); if (resavator.resultCode == 1) { App.Current.Dispatcher.Invoke(() => { LoginPageIndex = 0; SnackBar.Enqueue("注册成功"); UserId = PhoneNumber; InitialRegisterProperties();//重置注册页面 EnabledRegister = true; }); } else { SnackBar.Enqueue(resuser.resultMsg, true); //提示错误信息 App.Current.Dispatcher.Invoke(() => { EnabledRegister = true; }); //启用注册 } } else { SnackBar.Enqueue(eve.Error.Message); App.Current.Dispatcher.Invoke(() => { EnabledRegister = true; });//启用注册 } }; }); } else { SnackBar.Enqueue("注册失败:" + e.Error.Message); App.Current.Dispatcher.Invoke(() => { EnabledRegister = true; }); ConsoleLog.Output("注册失败:" + e.Error.Message); } }); }
private void OK_Click(object sender, RoutedEventArgs e) { //if (this.tb_InitialServer.Text.Trim() != "" && this.tb_InitialServerOfKey.Text.Trim() != "") if (this.tb_InitialServer.Text.Trim() != "") { ConfigurationUtil.SetValue("InitialServer", this.tb_InitialServer.Text); ConfigurationUtil.SetValue("InitialServer_key", this.tb_InitialServerOfKey.Text); } else { Snackbar.Enqueue("请输入地址!"); return; } ShiKuManager.GetConfigAsync(); this.Close(); }
/// <summary> /// 同步基元(进程间通信) /// </summary> //System.Threading.Mutex mutex; #region 应用程序启动时 private void Application_Startup(object sender, StartupEventArgs e) { //Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = 30 });//设置为30帧动画 Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; //设置为但 ShiKuManager.GetConfigAsync(); //获取配置 //mutex = new System.Threading.Mutex(true, "ElectronicNeedleTherapySystem", out ret); /*if (!ret) * { * MessageBox.Show("你已经打开了酷聊,请查看托盘或结束进程重启"); * Environment.Exit(0); * return; * }*/ //Application.Current.MainWindow = new TestingWindow(); Current.MainWindow = new Login(); Current.MainWindow.Show(); //检查目录 CheckOrCreateChatDir(); }
/// <summary> /// 游客登录 /// </summary> private void VisitorLogin() { //获取经纬度 string Longitude = "0"; string Latitude = "0"; if (Location.IsUnknown != true) { Longitude = Location.Longitude.ToString(); Latitude = Location.Latitude.ToString(); } try { var client = ShiKuManager.ShiKuVisitorLogin(VisitorKey, Latitude, Longitude); client.UploadDataCompleted += VisitorLoginComplete; } catch (Exception ex) { SnackBar.Enqueue("登录失败:" + ex.Message, "重试", () => { LoginCommand.Execute(Applicate.GetWindow <IHavePassword>()); }); Console.WriteLine("登录失败:" + ex.Message); EnabledLogin = true;//启用登录 } }
/// <summary> /// 发送已读消息 /// </summary> /// <param name="msgList">消息列表</param> private void SendReadMsgAsync(IList <Messageobject> msgList) { if (msgList != null && msgList.Count > 0) { Task.Run(() => { /*foreach (var msg in msgList) * { * if (msg.isMySend == 0 && msg.isRead == 0)//非自己发送 And 未读消息 * { * ShiKuManager.SendRead(msg.messageId, msg.jid); * } * }*/ for (int a = 0; a < msgList.Count; a++) { if (msgList[a].isMySend == 0 && msgList[a].isRead == 0 && msgList[a].type > kWCMessageType.kWCMessageTypeNone)//非自己发送 And 未读消息 { ShiKuManager.SendRead(msgList[a].messageId, msgList[a].jid); msgList[a].UpdateIsRead(msgList[a].messageId); } } }); } }
public LoginAndRegisterViewModel() { SelectedCountryCode = 6; //默认选中中国 RSelectedCountryCode = 6; EnabledLogin = true; //允许登录 SnackBar = new SnackbarMessageQueue(); #region Initial Commands LoginCommand = new RelayCommand <IHavePassword>(UserLogin); RegisterCommand = new RelayCommand <IHavePassword>(UserRegisterAccount); UsernameTextChangeCommand = new RelayCommand <IHavePassword>(UsernameChanged); UploadAvatorCommand = new RelayCommand(AvatorUpload); FemaleOrMaleCommand = new RelayCommand <object>(FemaleOrMaleChoice); RememberPwdCommand = new RelayCommand <bool>(RememberPassword); RegisterTxtLostFocus = new RelayCommand(CheckPhoneNumber); PasswordChanged = new RelayCommand <RoutedEventArgs>(PasswordChange); visiShowKey = Visibility.Collapsed; IsVisitorLogin = false; #endregion #region Initial Location Lists GPSLocator = new GeoCoordinateWatcher(); Location = new GeoCoordinate(); Task.Run(() => { GPSLocator.TryStart(false, TimeSpan.FromMilliseconds(5000)); ////超过5S则返回False; Location = GPSLocator.Position.Location; //获取位置 }); CountryList = GetLocationList(AreasType.Country).ToObservableCollection(); ProvinceList = new ObservableCollection <Areas>(); ProvinceList.AddRange(new Areas() { parent_id = 1, type = 2 }.GetChildrenList().ToObservableCollection()); CityList = new ObservableCollection <Areas>(); AreaList = new ObservableCollection <Areas>(); //GobalAreaList = new ObservableCollection<Country>(); GobalAreaList = Country.GetCountries().ToObservableCollection();//国家和地区列表 #endregion if (Debugger.IsAttached) { //UserId = "15625294668"; } Messenger.Default.Register <bool>(this, LoginNotifications.InitialAccount, (para) => { InitialAccount(); }); Messenger.Default.Register <string>(this, LoginAndRegisterViewModel.ErrorMessage, (texts) => { SnackBar.Enqueue(texts, "重试", () => { ShiKuManager.GetConfigAsync(); }); }); }
private void InitialCommands() { EditProfileCommand = new RelayCommand(EditProfile); SaveChangedCommand = new RelayCommand(() => { IsUpdating = true;//设置为更新中 editUserDetial.provinceId = ProvinceIndex; editUserDetial.cityId = CityIndex; editUserDetial.areaId = AreaIndex; var client = APIHelper.UpdateUserDetialAsync(EditUserDetial);//开始更新个人详情 client.Tag = EditUserDetial; client.UploadDataCompleted += (sen, res) => { #region res if (res.Error == null) { var source = sen as HttpClient; //获取源对象 var tmpEdit = source.Tag as DataOfUserDetial; //获取自己的详情 string resu = Encoding.UTF8.GetString(res.Result); var result = JsonConvert.DeserializeObject <JsonuserDetial>(resu); //反序列化 if (result.resultCode == 1) { if (!string.IsNullOrEmpty(AvatorPath))//上传头像 { #region 头像 Task.Run(() => { var tClient = ShiKuManager.UploadAvator(Applicate.MyAccount.userId, AvatorPath); tClient.UploadDataCompleted += (send, even) => { LogHelper.log.Debug("======================上传头像完成"); App.Current.Dispatcher.Invoke(() => { if (even.Error == null) { string value = Encoding.UTF8.GetString(even.Result);//上传头像并接收返回值 JsonBase rtnObj = JsonConvert.DeserializeObject <JsonBase>(value); if (rtnObj.resultCode == 1) { Messenger.Default.Send(result.data, CommonNotifications.UpdateMyAccountDetail);//通知更新详情 Snackbar.Enqueue("更新个人信息和头像成功"); ViewUserDetial = new DataOfUserDetial { areaId = result.data.areaId, birthday = result.data.birthday, cityId = result.data.cityId, countryId = result.data.countryId, description = result.data.description, name = result.data.name, nickname = result.data.nickname, remarkName = result.data.remarkName, phone = result.data.phone, sex = result.data.sex, status = result.data.status, provinceId = result.data.provinceId, Telephone = result.data.Telephone, userId = result.data.userId, areaCode = result.data.areaCode, avatarName = result.data.avatarName, };//赋值到编辑时数据 LogHelper.log.Debug("===================更新资料 " + result.data.avatarName); InitialEditProperties(); //重置编辑信息 InitialViewAddress(ViewUserDetial); //刷新地址 Messenger.Default.Send(tmpEdit, MainViewNotifactions.UpdateMyAccount); //更新详情 IsUpdating = false; Transitioner.MovePreviousCommand.Execute(null, null); //返回上一页 } else { Snackbar.Enqueue("更新失败:" + rtnObj.resultMsg);//接口异常 IsUpdating = false; } } else { Snackbar.Enqueue("更新失败:" + even.Error.Message); IsUpdating = false; } }); }; }); #endregion } else { Messenger.Default.Send(result.data, CommonNotifications.UpdateMyAccountDetail);//通知更新详情 ViewUserDetial = new DataOfUserDetial { areaId = result.data.areaId, birthday = result.data.birthday, cityId = result.data.cityId, countryId = result.data.countryId, description = result.data.description, name = result.data.name, nickname = result.data.nickname, remarkName = result.data.remarkName, phone = result.data.phone, sex = result.data.sex, status = result.data.status, provinceId = result.data.provinceId, Telephone = result.data.Telephone, userId = result.data.userId, areaCode = result.data.areaCode, avatarName = result.data.avatarName, }; //赋值到编辑时数据 InitialViewAddress(ViewUserDetial); //刷新地址 Snackbar.Enqueue("更新个人资料成功"); IsUpdating = false; Transitioner.MovePreviousCommand.Execute(null, null); //返回上一页 Messenger.Default.Send(tmpEdit, MainViewNotifactions.UpdateMyAccount); Transitioner.MovePreviousCommand.Execute(null, null); //返回详情显示页面 } } else { Snackbar.Enqueue("更新失败:" + result.resultMsg); IsUpdating = false; } } else { Snackbar.Enqueue("更新失败:" + res.Error.Message); IsUpdating = false; } #endregion }; LoadDetials(); Messenger.Default.Send(ViewUserDetial, CommonNotifications.UpdateMyAccountDetail); }); SelectAvatorCommand = new RelayCommand(SelectAvator); LoadImageLocal = new RelayCommand(SelectAvatorLocal); }
/// <summary> /// 更新密码 /// </summary> private void UpdatePassword() { if (string.IsNullOrEmpty(CurrentPassword)) { Snackbar.Enqueue("请输入密码以修改"); CurrentPassword = ""; CurrentPassword = ""; return; } if (NewPassword == "") { Snackbar.Enqueue("密码不能为空"); NewCheckPassword = ""; NewPassword = ""; return; } if (Pwd_spaces(NewPassword) == false) { Snackbar.Enqueue("密码不能包含空格"); NewCheckPassword = ""; NewPassword = ""; return; } if (NewPassword.Length < 6) { //Password's length Can't be smaller than 6 Snackbar.Enqueue("密码长度不能小于6位"); NewCheckPassword = ""; NewPassword = ""; return; } if (NewPassword != NewCheckPassword) { Snackbar.Enqueue("新密码设置不一致"); NewPassword = ""; NewCheckPassword = ""; return; } else { //No Problem } if (NewCheckPassword == CurrentPassword) { Snackbar.Enqueue("新密码不能与旧密码相同"); NewCheckPassword = ""; NewPassword = ""; return; } var client = APIHelper.ResetPasswordAsync(Helpers.MD5create(CurrentPassword), Helpers.MD5create(NewCheckPassword)); client.UploadDataCompleted += (sen, res) => { var restxt = Encoding.UTF8.GetString(res.Result); var rtn = JsonConvert.DeserializeObject <JsonBase>(restxt); if (rtn.resultCode == 1) { //成功 CurrentPassword = ""; NewPassword = ""; NewCheckPassword = ""; Task.Run(() => { var userObj = new LocalUser() { UserId = Applicate.MyAccount.userId }.GetModel(); if (userObj != null) { userObj.UpdatePwd(Applicate.MyAccount.Telephone, NewCheckPassword, NewCheckPassword.Length); } }); Snackbar.Enqueue("设置成功,请重新登录"); Task.Run(() => { Thread.Sleep(1000); App.Current.Dispatcher.BeginInvoke((Action) delegate() { ShiKuManager.ApplicationExit(); System.Windows.Forms.Application.Restart(); Application.Current.Shutdown(); }); }); } else { //设置失败 Snackbar.Enqueue("设置失败" + rtn.resultMsg); } }; }