public override void ProcessRequest() { GetContentReq req = mSocketTalker.ReceiveObject <GetContentReq>(); GetContentRes res = new GetContentRes(); Content content = new Content(req.ContentPath); try { switch (content.Type) { case Content.TYPE_NOT_FOUND: throw new KnownException("找不到路径 " + content.Path + " 所代表的内容。"); case Content.TYPE_DRIVER: throw new KnownException("路径 " + content.Path + " 代表的是一个驱动器,无法下载。"); } mSocketTalker.SendInt(ProtocolTypes.TYPE_GET_CONTENT); mSocketTalker.SendObject(res); switch (content.Type) { case Content.TYPE_FILE: SendFile(content, new Content(GetFileContainer(content.Path))); mSocketTalker.SendString(" "); break; case Content.TYPE_DIRECTORY: SendDirectory(content, new Content(GetDirectoryContainer(content.Path))); mSocketTalker.SendString(" "); break; } } catch (SocketException e) { throw e; } catch (Exception e) { res.ErorrOccured = true; res.ErrorMessage = e.Message; mSocketTalker.SendInt(ProtocolTypes.TYPE_GET_CONTENT); mSocketTalker.SendObject(res); } }
private void OnOutputReceived(object sender, OnResponseReceivedArgs e) { switch (e.ResponseType) { case ProtocolTypes.TYPE_GET_CONTENT: { GetContentRes res = e.GetResponse <GetContentRes>(); if (res.ErorrOccured) { LogEvent("请求下载文件失败,请关闭窗口并重试。"); } else { LogEvent("请求下载文件成功。正在接收文件..."); mReceiveFilesThread = new Thread(ReceiveFiles); mReceiveFilesThread.IsBackground = true; mReceiveFilesThread.Start(); } } break; } }