private Telnet() : base(Config.Instance.ServerIP, Config.Instance.ServerPort, true) { DataReceived += async(s, e) => { var command = e.Content.Command; Debug.WriteLine("客户端接收到:" + command); switch (command) { //以下为通用 case S_ClientsUpdate: ClientInfo[] clients = e.Content.Data as ClientInfo[]; ClientsUpdate?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case S_LoginFeedback: LoginFeedback feedback = e.Content.Data as LoginFeedback; LoginFeedback?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case S_NoSuchClient: NoSuchClient?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; //以下为控制端 case Screen_NewScreen: ReceivedNewImage?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case WMI_Namespace: WMINamespacesReceived?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case WMI_Classes: WMIClassesReceived?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case WMI_Props: WMIPropsReceived?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case File_RootDirectory: FileSystemRootReceived?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case File_DirectoryContent: FileSystemDirectoryContentReceived?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case File_Download: FileSystemDownloadPartReceived?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case File_ReadDownloadingFileError: FileSystemDownloadErrorReceived?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case File_PrepareUploadingFeedback: FileSystemPrepareForUploadingReceived?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case File_CanSendNextUploadPart: Control.FileUploadHelper.CanSendNextPart.Add((Guid)e.Content.Data); break; case File_WriteUploadingFileError: Control.FileUploadHelper.Error.TryAdd((e.Content.Data as FileFolderFeedback).ID, (e.Content.Data as FileFolderFeedback).Message); break; case File_OperationFeedback: FileSystemFileFolderOperationFeedback?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; //以下为被控端 case Screen_AskForStartScreen: await ScreenHelper.StartSendScreen(); break; case Screen_AskForStopScreen: ScreenHelper.StopSendScreen(); break; case Screen_AskForNextScreen: SendNextScreen?.Invoke(this, new DataReceivedEventArgs(e.Content)); break; case WMI_AskForNamespaces: WMIHelper.SendNamespaces(e.Content); break; case WMI_AskForClasses: WMIHelper.SendWMIClasses(e.Content.Data as string, e.Content); break; case WMI_AskForProps: WMIHelper.SendProperties(e.Content.Data as WMIClassInfo, e.Content); break; case File_AskForRootDirectory: FileSystemHelper.SendDiskDrives(e.Content); break; case File_AskForDirectoryContent: FileSystemHelper.SendDirectoryContent(e.Content); break; case File_AskForDownloading: FileSystemHelper.StartDownloadingToA(e.Content); break; case File_CanSendNextDownloadPart: FileSystemHelper.CanSendNextPart.Add((Guid)e.Content.Data); break; case File_AskForCancelDownload: FileSystemHelper.Cancle.Add((Guid)e.Content.Data); break; case File_AskForStartUpload: FileSystemHelper.StartAcceptingUploading(e.Content); break; case File_Upload: FileSystemHelper.AcceptUploadPartFromA(e.Content); break; case File_AskForCancelUpload: FileSystemHelper.CancelUploadFromA(e.Content); break; case File_Operation: FileSystemHelper.FileFolderOperate(e.Content); break; } }; }
private void LoginFeedback(object sender, Common.Telnet.DataReceivedEventArgs e) { LoginFeedback result = e.Content.Data as LoginFeedback; Dispatcher.Invoke(() => { if (result.Success) { Global.CurrentClient = result.Client; #if DEBUG NavigationService.Navigate(new Uri($"UI/{nameof(PageComputerList)}.xaml", UriKind.Relative)); return; #endif //登录界面渐隐 DoubleAnimation ani = new DoubleAnimation(0, TimeSpan.FromSeconds(0.3), FillBehavior.Stop); ani.Completed += (p1, p2) => { grd.Opacity = 0; grd.Children.Clear(); //向grd添加“登陆成功”的标签 TextBlock tbk = new TextBlock() { FontSize = 28, Text = "登录成功", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; grd.Children.Add(tbk); Grid.SetColumnSpan(tbk, 1000); Grid.SetRowSpan(tbk, 1000); //登陆成功渐显 DoubleAnimation ani2 = new DoubleAnimation(1, TimeSpan.FromSeconds(0.3), FillBehavior.Stop); ani2.Completed += async(p3, p4) => { grd.Opacity = 1; await Task.Delay(1000); //登陆成功渐隐 DoubleAnimation ani3 = new DoubleAnimation(0, TimeSpan.FromSeconds(0.3), FillBehavior.HoldEnd); ani3.Completed += (p5, p6) => { User user = result.User; switch (user.Role) { case "用户": NavigationService.Navigate(new Uri($"UI/{nameof(PageComputerList)}.xaml", UriKind.Relative)); break; case "管理员": break; default: TaskDialog.Show("未知角色"); break; } }; grd.BeginAnimation(OpacityProperty, ani3); }; grd.BeginAnimation(OpacityProperty, ani2); }; grd.BeginAnimation(OpacityProperty, ani); } else { //登陆失败,显示错误信息 TaskDialog.ShowError(result.Message); btnLogin.IsEnabled = true; } }); }