public override void ProcessRequest() { GetContentInfoReq req = mSocketTalker.ReceiveObject <GetContentInfoReq>(); GetContentInfoRes res = new GetContentInfoRes(); try { res.InfoList = new List <TextInfo>(); Content content = new Content(req.ContentPath); switch (content.Type) { case Content.TYPE_NOT_FOUND: throw new KnownException("路径 " + content.Path + " 代表的不是一个驱动器、文件或目录,无法获取信息。"); case Content.TYPE_DRIVER: DriveInfo driveInfo = new DriveInfo(content.Path); res.InfoList.Add(new TextInfo("AvailableFreeSpace", driveInfo.AvailableFreeSpace.ToString() + " Bytes")); res.InfoList.Add(new TextInfo("AvailableFreDriveFormateSpace", driveInfo.DriveFormat.ToString())); res.InfoList.Add(new TextInfo("DriveType", driveInfo.DriveType.ToString())); res.InfoList.Add(new TextInfo("IsReady", driveInfo.IsReady.ToString())); res.InfoList.Add(new TextInfo("Name", driveInfo.Name.ToString())); res.InfoList.Add(new TextInfo("RootDirectory", driveInfo.RootDirectory.ToString())); res.InfoList.Add(new TextInfo("TotalFreeSpace", driveInfo.TotalFreeSpace.ToString() + " Bytes")); res.InfoList.Add(new TextInfo("TotalSize", driveInfo.TotalSize.ToString() + " Bytes")); res.InfoList.Add(new TextInfo("VolumeLabel", driveInfo.VolumeLabel.ToString())); break; case Content.TYPE_FILE: FileInfo fileInfo = new FileInfo(content.Path); res.InfoList.Add(new TextInfo("Attributes", fileInfo.Attributes.ToString())); res.InfoList.Add(new TextInfo("CreationTime", fileInfo.CreationTime.ToString())); res.InfoList.Add(new TextInfo("CreationTimeUtc", fileInfo.CreationTimeUtc.ToString())); res.InfoList.Add(new TextInfo("Directory", fileInfo.Directory.ToString())); res.InfoList.Add(new TextInfo("DirectoryName", fileInfo.DirectoryName.ToString())); res.InfoList.Add(new TextInfo("Exists", fileInfo.Exists.ToString())); res.InfoList.Add(new TextInfo("Extension", fileInfo.Extension.ToString())); res.InfoList.Add(new TextInfo("FullName", fileInfo.FullName.ToString())); res.InfoList.Add(new TextInfo("IsReadOnly", fileInfo.IsReadOnly.ToString())); res.InfoList.Add(new TextInfo("LastAccessTime", fileInfo.LastAccessTime.ToString())); res.InfoList.Add(new TextInfo("LastAccessTime", fileInfo.LastAccessTimeUtc.ToString())); res.InfoList.Add(new TextInfo("LastWriteTime", fileInfo.LastWriteTime.ToString())); res.InfoList.Add(new TextInfo("LastWriteTimeUtc", fileInfo.LastWriteTimeUtc.ToString())); res.InfoList.Add(new TextInfo("Length", fileInfo.Length.ToString() + " Bytes")); res.InfoList.Add(new TextInfo("Name", fileInfo.Name.ToString())); break; case Content.TYPE_DIRECTORY: DirectoryInfo directoryInfo = new DirectoryInfo(content.Path); res.InfoList.Add(new TextInfo("Attributes", directoryInfo.Attributes.ToString())); res.InfoList.Add(new TextInfo("CreationTime", directoryInfo.CreationTime.ToString())); res.InfoList.Add(new TextInfo("CreationTimeUtc", directoryInfo.CreationTimeUtc.ToString())); res.InfoList.Add(new TextInfo("Exists", directoryInfo.Exists.ToString())); res.InfoList.Add(new TextInfo("Extension", directoryInfo.Extension.ToString())); res.InfoList.Add(new TextInfo("FullName", directoryInfo.FullName.ToString())); res.InfoList.Add(new TextInfo("LastAccessTime", directoryInfo.LastAccessTime.ToString())); res.InfoList.Add(new TextInfo("LastAccessTime", directoryInfo.LastAccessTimeUtc.ToString())); res.InfoList.Add(new TextInfo("LastWriteTime", directoryInfo.LastWriteTime.ToString())); res.InfoList.Add(new TextInfo("LastWriteTimeUtc", directoryInfo.LastWriteTimeUtc.ToString())); res.InfoList.Add(new TextInfo("Name", directoryInfo.Name.ToString())); res.InfoList.Add(new TextInfo("Parent", directoryInfo.Parent.FullName.ToString())); res.InfoList.Add(new TextInfo("Root", directoryInfo.Root.ToString())); break; } mSocketTalker.SendInt(ProtocolTypes.TYPE_GET_CONTENT_INFO); mSocketTalker.SendObject(res); } catch (Exception e) { res.ErorrOccured = true; res.ErrorMessage = e.Message; mSocketTalker.SendInt(ProtocolTypes.TYPE_GET_CONTENT_INFO); mSocketTalker.SendObject(res); } }
private void OnOutputReceived(object sender, OnResponseReceivedArgs e) { switch (e.ResponseType) { case ProtocolTypes.TYPE_LIST_CONTENTS: { ListContentsRes res = e.GetResponse <ListContentsRes>(); if (res.ErorrOccured) { mErrorLable.Text = res.ErrorMessage; mErrorLable.Show(); mContentList.Items.Clear(); } else { mErrorLable.Text = ""; mErrorLable.Hide(); mContentList.Items.Clear(); if (res.Drivers != null && res.Drivers.Length > 0) { foreach (string driver in res.Drivers) { ListViewItem item = new ListViewItem(); item.ImageKey = "driver.png"; item.Text = driver; mContentList.Items.Add(item); } } if (res.Directories != null && res.Directories.Length > 0) { foreach (string directory in res.Directories) { ListViewItem item = new ListViewItem(); item.ImageKey = "folder.png"; item.Text = Path.GetFileName(directory); mContentList.Items.Add(item); } } if (res.Files != null && res.Files.Length > 0) { foreach (string file in res.Files) { ListViewItem item = new ListViewItem(); item.ImageKey = "file.png"; item.Text = Path.GetFileName(file); mContentList.Items.Add(item); } } } mGoToOrRefreshButton.Text = "刷新"; } break; case ProtocolTypes.TYPE_RENAME_CONTENT: { RenameContentRes res = e.GetResponse <RenameContentRes>(); if (res.ErorrOccured) { MessageBox.Show(res.ErrorMessage, "重命名失败"); } SendListContentsReq(); } break; case ProtocolTypes.TYPE_DELETE_CONTENTS: { DeleteContentsRes res = e.GetResponse <DeleteContentsRes>(); if (res.ErorrOccured) { StringBuilder builder = new StringBuilder(); foreach (string result in res.DeleteResults) { if (result != null) { builder.AppendLine(result); } } MessageBox.Show(builder.ToString(), "删除出现错误"); } SendListContentsReq(); } break; case ProtocolTypes.TYPE_CREATE_DIRECTORY: { CreateDirectoryRes res = e.GetResponse <CreateDirectoryRes>(); if (res.ErorrOccured) { MessageBox.Show(res.ErrorMessage, "新建文件夹失败"); } SendListContentsReq(); } break; case ProtocolTypes.TYPE_START_PROCESS: { StartProcessRes res = e.GetResponse <StartProcessRes>(); if (res.ErorrOccured) { MessageBox.Show(res.ErrorMessage, "打开进程失败"); } } break; case ProtocolTypes.TYPE_GET_CONTENT_INFO: { GetContentInfoRes res = e.GetResponse <GetContentInfoRes>(); if (res.ErorrOccured) { MessageBox.Show(res.ErrorMessage, "获取属性失败"); } else { StringBuilder builder = new StringBuilder(); foreach (TextInfo result in res.InfoList) { builder.AppendLine(result.Name + " : " + result.Value); } MessageBox.Show(builder.ToString(), "数学"); } } break; case ProtocolTypes.TYPE_MOVE_CONTENTS: { MoveContentsRes res = e.GetResponse <MoveContentsRes>(); if (res.ErorrOccured) { MessageBox.Show(res.ErrorMessage, "移动出现错误"); } else { StringBuilder builder = new StringBuilder(); foreach (string result in res.MoveResults) { if (result != null) { builder.AppendLine(result); } } if (builder.Length > 0) { MessageBox.Show(builder.ToString(), "移动出现错误"); } } SendListContentsReq(); } break; case ProtocolTypes.TYPE_COPY_CONTENTS: { CopyContentsRes res = e.GetResponse <CopyContentsRes>(); if (res.ErorrOccured) { MessageBox.Show(res.ErrorMessage, "复制出现错误"); } else { StringBuilder builder = new StringBuilder(); foreach (string result in res.CopyResults) { if (result != null) { builder.AppendLine(result); } } if (builder.Length > 0) { MessageBox.Show(builder.ToString(), "复制出现错误"); } } SendListContentsReq(); } break; } }