private void OnReceice(IAsyncResult ar) { try { int count = Server.EndReceive(ar); if (Datagram.DatagramDataHead <= count) { Action <byte[]> action = OnProcess; byte[] buffer = new byte[count]; Array.Copy(Buffer, 0, buffer, 0, count); action.BeginInvoke(buffer, null, null); } } catch { } try { if (IsConnect) { Server.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, OnReceice, null); } } catch { if (IsConnect) { Disconnect(); RunningDatas.ErrorNotify("程序错误 无法接收网络消息 请重新启动软件后重试"); } } }
private void CacheFresh_Trigger(object sender, System.Timers.ElapsedEventArgs args) { if (0 < FileCache.Count) { foreach (var item in FileCache) { item.Value.Flush(); if (item.Value.Invaild) { item.Value.Close(); FileCache.TryRemove(item.Key, out _); RunningDatas.ErrorNotify ( string.Format ( " {0}超时 \n\r 文件:{1} ", item.Value.GetStreamType() == StreamType.Download ? "下载" : "上传", item.Value.GetName() ) ); } else if ((DateTime.Now - item.Value.Time).TotalMilliseconds > CacheVaildTime) { item.Value.Invaild = true; } } } CacheTimer.Start(); }
private void SearchButton_Click(object sender, RoutedEventArgs e) { FriendAndGroupList.Items.Clear(); if (0 == SearchBox.Text.Length) { RunningDatas.ErrorNotify("查询条件不能为空!"); return; } KXTNetStruct.SearchReq req = new KXTNetStruct.SearchReq { SearchString = SearchBox.Text }; if ((bool)FriendRadioButton.IsChecked) { req.SearchType = KXTNetStruct.SearchReq.SearchType_User; } else if ((bool)GroupRadioButton.IsChecked) { req.SearchType = KXTNetStruct.SearchReq.SearchType_Group; } RunningDatas.DataSender.SearchReq(RequestID, req); }
public void RequestCallback(object response) { OperationTimer.Stop(); UserIDBox.IsEnabled = true; UserPassword.IsEnabled = true; OKButton.IsEnabled = true; CancelButton.IsEnabled = true; ProgressWaitBar.Visibility = Visibility.Collapsed; ProgressWaitBar.IsIndeterminate = false; ProgressWaitBar.ShowPaused = false; ProgressWaitBar.ShowError = false; LoginResponse res = response as LoginResponse; if (LoginResult.Success != res.LoginResult) { RunningDatas.ErrorNotify("用户无法验证登录"); return; } LocalDB.AddAccount(Request.UserID, Request.UserPW, Request.UserIDType); _ = Dispatcher.RunAsync ( Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { Hide(); } )); }
private void ContentDialog_OKButtonClick(object sender, RoutedEventArgs args) { if (0 == UserIDBox.Text.Length || 0 == UserPassword.Password.Length) { RunningDatas.ErrorNotify("用户名与密码不能为空"); return; } if (!Utils.Utils.LoginUserCheck(UserIDBox.Text, out KXTNetStruct.Struct.LoginType type)) { RunningDatas.ErrorNotify("无法识别的用户名"); return; } Request.UserID = UserIDBox.Text; Request.UserPW = Utils.Security.SHA1Encode(UserPassword.Password); Request.UserIDType = type; RunningDatas.RequestTable.TryAdd(RequestID, this); RunningDatas.DataSender.Login(RequestID, Request); OperationTimer.Start(); UserIDBox.IsEnabled = false; UserPassword.IsEnabled = false; OKButton.IsEnabled = false; CancelButton.IsEnabled = false; ProgressWaitBar.Visibility = Visibility.Visible; ProgressWaitBar.IsIndeterminate = true; ProgressWaitBar.ShowPaused = false; ProgressWaitBar.ShowError = false; }
private void EmailNext() { if (0 == EmailBox.Text.Length) { RunningDatas.ErrorNotify("注册邮箱不能为空"); return; } if (!Utils.Utils.IsEmail(EmailBox.Text)) { RunningDatas.ErrorNotify("注册邮箱无效"); return; } RunningDatas.RequestTable.TryAdd(RequestID, this); if (RunningDatas.DataSender.RegistEmailReq ( RequestID, new KXTNetStruct.RegistEmailReq { Email = EmailBox.Text } )) { NextButton.Visibility = Visibility.Collapsed; RingControl.Visibility = Visibility.Visible; RingControl.IsActive = true; OperationTimer.Start(); } else { RunningDatas.InfoNotify("无法连接到网络"); } }
public void CreateDownload(Guid stream_id, StorageFolder path, string name, int length) { Download download; try { download = new Download(path, name, length); } catch { RunningDatas.ErrorNotify ( string.Format ( " 创建下载任务失败:{0} \n\r 无法写入到文件", name ) ); return; } if (!FileCache.TryAdd(stream_id, download)) { download.Clear(); RunningDatas.ErrorNotify ( string.Format ( " 创建下载任务失败:{0} ", name ) ); } }
private void OnMain_HeartRequest(Datagram datagram) { datagram.DataType = DatagramType.Client; datagram.MessageType = MainMessageType.HeartResponse; if (!Send(datagram)) { Disconnect(); RunningDatas.ErrorNotify("网络连接失败 请重启软件后重试"); } }
private void Operation_Trigger(object sender, ElapsedEventArgs args) { _ = Dispatcher.RunAsync ( Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { OperationWaiting.IsIndeterminate = false; })); RunningDatas.InfoNotify("数据请求超时"); }
void IDataSender.CreateFolder(CreateFolder create) { Datagram datagram = new Datagram { DataType = DatagramType.Cloud, MessageType = CloudDatagramDefine.CreateFolder, Datas = create.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
void IDataSender.ApplyUserRes(ApplyResponse response) { Datagram datagram = new Datagram { DataType = DatagramType.Login, MessageType = LoginMessageType.ApplyUserRes, Datas = response.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
private void Trigger(object sender, ElapsedEventArgs args) { _ = Dispatcher.RunAsync ( Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { WaitingBar.IsIndeterminate = false; WaitingBar.Visibility = Visibility.Collapsed; Next.Visibility = Visibility.Visible; })); RunningDatas.InfoNotify("请求超时"); }
void IDataSender.DeleteFile(DeleteFolderFile delete) { Datagram datagram = new Datagram { DataType = DatagramType.Cloud, MessageType = CloudDatagramDefine.DeleteFile, Datas = delete.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
void IDataSender.DropGroup(DeleteUser delete) { Datagram datagram = new Datagram { DataType = DatagramType.Login, MessageType = LoginMessageType.DropGroup, Datas = delete.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
void IDataSender.UpdateGroupDescribe(UpdateGroupDescribe update) { Datagram datagram = new Datagram { DataType = DatagramType.Login, MessageType = LoginMessageType.UpdateGroupDescribe, Datas = update.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
void IDataSender.ChatsFinish(ChatsFinishPackage finish) { Datagram datagram = new Datagram { DataType = DatagramType.Chat, MessageType = ChatDatagramDefine.GroupChat, Datas = finish.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
void IDataSender.FileUploadCancel(FileUploadCancel cancel) { Datagram datagram = new Datagram { DataType = DatagramType.Cloud, MessageType = CloudDatagramDefine.FileUploadCancel, Datas = cancel.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
void IDataSender.FileDownloadFinish(FileDownloadFinish finish) { Datagram datagram = new Datagram { DataType = DatagramType.Cloud, MessageType = CloudDatagramDefine.FileDownloadFinish, Datas = finish.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
void IDataSender.FileStreamRes(StreamRes res) { Datagram datagram = new Datagram { DataType = DatagramType.Cloud, MessageType = CloudDatagramDefine.StreamRes, Datas = res.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
void IDataSender.FileDownload(Guid request_id, FileDownloadReq req) { Datagram datagram = new Datagram { DataType = DatagramType.Cloud, MessageType = CloudDatagramDefine.FileDownloadReq, RequestID = request_id, Datas = req.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
void IDataSender.GroupChatReq(Guid request_id, GroupChatsReq req) { Datagram datagram = new Datagram { DataType = DatagramType.Chat, MessageType = ChatDatagramDefine.GroupChatsReq, RequestID = request_id, Datas = req.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
private void LoginTimer_Tigger(object sender, System.Timers.ElapsedEventArgs args) { _ = Dispatcher.RunAsync (Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { FlushFriendAndGroup.Visibility = Visibility.Visible; FlushFriendAndGroupRing.IsActive = false; FlushFriendAndGroupRing.Visibility = Visibility.Collapsed; })); RunningDatas.RequestTable.TryRemove(RequestID, out _); RunningDatas.InfoNotify("请求超时"); }
private void VerificationNext() { if (0 == VerificationBox.Text.Length) { RunningDatas.ErrorNotify("验证码不能为空"); return; } if (8 > VerificationBox.Text.Length) { RunningDatas.ErrorNotify("验证码无效"); return; } if (!Utils.Utils.ConvertVerifyCode(VerificationBox.Text, out byte[] value))
void IDataSender.GroupMemberReq(Guid request_id, GroupMemberReq req) { Datagram datagram = new Datagram { DataType = DatagramType.Login, MessageType = LoginMessageType.GroupMemberReq, RequestID = request_id, Datas = req.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
void IDataSender.AppliesRequest(Guid request_id, FriendGroupApplyRequest request) { Datagram datagram = new Datagram { DataType = DatagramType.Login, MessageType = LoginMessageType.AppliesRequest, RequestID = request_id, Datas = request.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
public void CreateUpload(Guid stream_id, StorageFile file) { Upload upload = new Upload(file); if (!FileCache.TryAdd(stream_id, upload)) { upload.Close(); RunningDatas.ErrorNotify ( string.Format ( " 创建上传任务失败:{0} ", file.Path + "\\" + file.Name ) ); } }
void IDataSender.Regist(Guid request_id) { Datagram datagram = new Datagram { DataType = DatagramType.Main, MessageType = MainMessageType.RegistReq, RequestID = request_id, Datas = new MainRegistReq { UserID = IKXTServer.DataConvert.GetGuid(RunningDatas.UserID) }.ToByteArray() }; if (!Send(datagram)) { RunningDatas.InfoNotify("网络连接失败 请重启软件后重试"); } }
private void OperationTimer_Trigger(object sender, System.Timers.ElapsedEventArgs args) { _ = Dispatcher.RunAsync (Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => { UserIDBox.IsEnabled = true; UserPassword.IsEnabled = true; OKButton.IsEnabled = true; CancelButton.IsEnabled = true; ProgressWaitBar.Visibility = Visibility.Collapsed; ProgressWaitBar.IsIndeterminate = false; ProgressWaitBar.ShowPaused = false; ProgressWaitBar.ShowError = false; })); RunningDatas.RequestTable.TryRemove(RequestID, out _); RunningDatas.ErrorNotify("登录超时 请重试"); }
private void SenderButton_Tapped(object sender, TappedRoutedEventArgs e) { MessageEnter.TextDocument.GetText(Windows.UI.Text.TextGetOptions.None, out string message); if (RunningDatas.DataSender.FriendChat(new ChatMessage { Message = message, Sender = RunningDatas.UserID, Target = FriendID })) { MessageEnter.TextDocument.SetText(Windows.UI.Text.TextSetOptions.None, ""); ChatPanel.Items.Add(new UserMessageMagnets { Text = message, Time = DateTime.Now.ToString(), HorizontalAlignment = HorizontalAlignment.Right, Photo = Utils.Utils.GetPhoto(RunningDatas.UserPhoto) }); } else { RunningDatas.InfoNotify("发送失败 网络错误"); } }
private void OnChat_GroupChat(Datagram datagram) { ChatMessage message = datagram.UnSerialData <ChatMessage>(); RunningDatas.ReceiveMessage(ChatPackageType.Group, message); }