Exemplo n.º 1
0
 public override void Download(ListItem item,
                               Action <ListItem, byte[]> downloaded)
 {
     _client.GetFileAsync(_info.Path,
                          x => downloaded(item, x.RawBytes),
                          OnError);
 }
Exemplo n.º 2
0
        public Task <Stream> GetFile(string path, CancellationToken?ct = null)
        {
            var tcs = new TaskCompletionSource <Stream>();

            if (ct != null)
            {
                ct.Value.Register(tcs.SetCanceled);
            }

            _client.GetFileAsync(path, response => tcs.TrySetResult(new MemoryStream(response.RawBytes)), ex => tcs.TrySetException(ex));

            return(tcs.Task);
        }
        public void download(string filename1)
        {
            _client           = _client = new DropNetClient("b7oxugbxulgsem6", "hczdlsodguxn0jt", "QX-8FEljL0AAAAAAAAAABjTJmnBAjs3-xPcnL7fD2ss_DZWzLlD6NO7YJNLdkv2v");
            _client.UserLogin = new UserLogin {
                Token = "QX-8FEljL0AAAAAAAAAABjTJmnBAjs3-xPcnL7fD2ss_DZWzLlD6NO7YJNLdkv2v", Secret = "hczdlsodguxn0jt"
            };

            string filename = filename1;
            String file2    = "";

            file2 = filename.Replace("\\", "") + "_part1";

            _client.GetFileAsync("/" + file2,
                                 (response) =>
            {
                using (FileStream fs = new FileStream(Application.StartupPath + "\\blockd\\" + file2, FileMode.Create))
                {
                    for (int i = 0; i < response.RawBytes.Length; i++)
                    {
                        fs.WriteByte(response.RawBytes[i]);
                    }
                    fs.Seek(0, SeekOrigin.Begin);
                    for (int i = 0; i < response.RawBytes.Length; i++)
                    {
                        if (response.RawBytes[i] != fs.ReadByte())
                        {
                            MessageBox.Show("Error writing data for " + filename);
                            return;
                        }
                    }
                }
                Cursor.Current = Cursors.Default;
                //  MessageBox.Show("file downloaded");
            },
                                 (error) =>
            {
                // MessageBox.Show("error downloading");
            });

            String file3 = filename.Replace("\\", "") + "_part2";

            _client.GetFileAsync("/" + file3,
                                 (response) =>
            {
                using (FileStream fs = new FileStream(Application.StartupPath + "\\blockd\\" + file3, FileMode.Create))
                {
                    for (int i = 0; i < response.RawBytes.Length; i++)
                    {
                        fs.WriteByte(response.RawBytes[i]);
                    }
                    fs.Seek(0, SeekOrigin.Begin);
                    for (int i = 0; i < response.RawBytes.Length; i++)
                    {
                        if (response.RawBytes[i] != fs.ReadByte())
                        {
                            MessageBox.Show("Error writing data for " + filename);
                            return;
                        }
                    }
                }
                Cursor.Current = Cursors.Default;
                MessageBox.Show("file downloaded");

                merg(filename);
            },
                                 (error) =>
            {
                MessageBox.Show("error downloading");
            });
        }