Exemplo n.º 1
0
        public void StartNew(WinFileSystem win, ClientInfo client, FileFolderInfo selectedFile)
        {
            ControlledClient = client;
            string path = FileSystemDialog.GetSaveFile(null, true, false, selectedFile.Name);

            if (path != null)
            {
                FileTransmissionInfo trans = new FileTransmissionInfo()
                {
                    File = selectedFile
                };
                try
                {
                    download = new DownloadingInfo(win, client, path, trans);
                }
                catch (Exception ex)
                {
                    TaskDialog.ShowException(ex, "建立本地文件失败!");
                    return;
                }
                Telnet.Instance.FileSystemDownloadErrorReceived += FileSystemDownloadErrorReceived;
                Telnet.Instance.FileSystemDownloadPartReceived  += FileSystemDownloadPartReceived;

                Telnet.Instance.Send(new CommandBody(
                                         File_AskForDownloading, Global.CurrentClient.ID, client.ID, trans));

                download.Dialog.ShowDialog();
            }
        }
Exemplo n.º 2
0
        private void FileSystemDownloadPartReceived(object sender, Common.Telnet.DataReceivedEventArgs e)
        {
            FileTransmissionPartInfo part = e.Content.Data as FileTransmissionPartInfo;

            try
            {
                Debug.Assert(download != null);

                if (download.ID != part.ID)
                {
                    return;
                }
                if (download.Canceled)
                {
                    return;
                }

                download.Stream.Position = part.Position;
                download.Stream.Write(part.Content, 0, part.Content.Length);

                download.Dialog.Value   = 1.0 * download.Stream.Position / part.Length;
                download.Dialog.Message = $"正在下载{  download.File.Name}:{Number.ByteToFitString(download.Stream.Position)}/{Number.ByteToFitString(part.Length)}";

                if (part.Position + part.Content.Length == part.Length)
                {
                    download.Dialog.Message = "下载成功";

                    download.Dispose();
                    download = null;
                    DownloadEnd();
                }
                else
                {
                    Telnet.Instance.Send(new CommandBody(File_CanSendNextDownloadPart, Global.CurrentClient.ID, ControlledClient.ID, download.ID));
                }
            }
            catch (ObjectDisposedException ex)
            {
            }
            catch (Exception ex)
            {
                Telnet.Instance.Send(new CommandBody(File_AskForCancelUpload, Global.CurrentClient.ID, ControlledClient.ID, part.ID));

                FileSystemDownloadErrorReceived(null, null);
            }
        }