Example #1
0
        private void OnDownload(object state)
        {
            FrmProgress frm = (FrmProgress)state;

            using (FileHelper fh = new FileHelper(mSaveFileName, false))
            {
                while (true)
                {
                    FileBlock fb = mClient.Read <FileBlock>();
                    fh.Write(fb.Data, 0, fb.Data.Length);

                    Invoke(new Action <FrmProgress>(o =>
                    {
                        frm.ChangeProgress(fb.Data.Length);
                        if (fb.Eof)
                        {
                            frm.Hide();
                            cmdDownload.Enabled = true;
                        }
                    }), frm);
                    if (fb.Eof)
                    {
                        break;
                    }
                }
            }
        }
Example #2
0
        private void cmdDownload_Click(object sender, EventArgs e)
        {
            ResourceItem ri = (ResourceItem)listView1.SelectedItems[0];

            saveFileDialog1.FileName = ri.Data.Name;
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                mSaveFileName = saveFileDialog1.FileName;
                object result = mClient.Send(new Download {
                    File = ri.Data.Name
                });
                if (result is Error)
                {
                    MessageBox.Show(((Error)result).Message);
                    return;
                }
                FrmProgress frm = new FrmProgress();
                frm.ChangeProgress(((FileInfo)result).Size, 0);
                frm.Show(this);
                cmdDownload.Enabled = false;
                System.Threading.ThreadPool.QueueUserWorkItem(OnDownload, frm);
            }
        }
Example #3
0
        private void cmdDownload_Click(object sender, EventArgs e)
        {
            ResourceItem ri = (ResourceItem)listView1.SelectedItems[0];
            saveFileDialog1.FileName = ri.Data.Name;
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                mSaveFileName = saveFileDialog1.FileName;
                object result = mClient.Send(new Download { File = ri.Data.Name });
                if (result is Error)
                {
                    MessageBox.Show(((Error)result).Message);
                    return;
                }
                FrmProgress frm = new FrmProgress();
                frm.ChangeProgress(((FileInfo)result).Size, 0);
                frm.Show(this);
                cmdDownload.Enabled = false;
                System.Threading.ThreadPool.QueueUserWorkItem(OnDownload, frm);
            }

        }