static void Main() { AppTest a = new AppTest(); Microshaoft.Utils.HttpWebClient x = new Microshaoft.Utils.HttpWebClient(); a._K = 10; //订阅 DataReceive 事件 x.DataReceive += new Microshaoft.Utils.HttpWebClient.DataReceiveEventHandler(a.x_DataReceive); //订阅 ExceptionOccurrs 事件 x.ExceptionOccurrs += new Microshaoft.Utils.HttpWebClient.ExceptionEventHandler(a.x_ExceptionOccurrs); x.ThreadProcessEnd += new Microshaoft.Utils.HttpWebClient.ThreadProcessEventHandler(a.x_ThreadProcessEnd); string F = "http://localhost/download/phpMyAdmin-2.6.1-pl2.zip"; F = "http://down6.flashget.com/flashget182cn.exe"; a._F = F; string f = F.Substring(F.LastIndexOf("/") + 1); //(new System.Threading.Thread(new System.Threading.ThreadStart(new ThreadProcessState(F, @"E:temp" + f, 10, x).StartThreadProcess))).Start(); x.DownloadFile(F, @"d:temp" + f, a._K); // x.DownloadFileChunk(F, @"E:temp" + f,15,34556); System.Console.ReadLine(); // string uploadfile = "e:\test_local.rar"; // string str = x.UploadFileEx("http://localhost/phpmyadmin/uploadaction.php", "POST", uploadfile, "file1"); // System.Console.WriteLine(str); // System.Console.ReadLine(); }
private void x_ExceptionOccurrs(Microshaoft.Utils.HttpWebClient Sender, Microshaoft.Utils.ExceptionEventArgs e) { System.Console.WriteLine(e.Exception.Message); //发生异常重新下载相当于断点续传,你可以自己自行选择处理方式或自行处理 Microshaoft.Utils.HttpWebClient x = new Microshaoft.Utils.HttpWebClient(); x.DownloadFileChunk(this._F, this._f, e.DownloadState.Position, e.DownloadState.Length); e.ExceptionAction = Microshaoft.Utils.ExceptionActions.Ignore; }
private void x_ThreadProcessEnd(Microshaoft.Utils.HttpWebClient Sender, Microshaoft.Utils.ThreadProcessEventArgs e) { //if (e.thread.ThreadState == System.Threading.ThreadState.Stopped) if (this._k++ == this._K - 1) { System.Console.WriteLine("nend"); } }
private void x_DataReceive(Microshaoft.Utils.HttpWebClient Sender, Microshaoft.Utils.DownLoadEventArgs e) { if (!this.b) { lock (_SyncLockObject) { if (!this.b) { System.Console.Write(System.DateTime.Now.ToString() + " 已接收数据: "); //System.Console.Write( System.DateTime.Now.ToString() + " 已接收数据: "); this.b = true; } } } string f = e.DownloadState.FileName; if (e.DownloadState.AttachmentName != null) { f = System.IO.Path.GetDirectoryName(f) + @"\" + e.DownloadState.AttachmentName; } this._f = f; using (System.IO.FileStream sw = new System.IO.FileStream(f, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite)) { sw.Position = e.DownloadState.Position; sw.Write(e.DownloadState.Data, 0, e.DownloadState.Data.Length); sw.Close(); } string s = System.DateTime.Now.ToString(); lock (_SyncLockObject) { this.i += e.DownloadState.Data.Length; System.Console.Write(bs + "\b\b\b\b\b\b\b\b\b\b" + i + " / " + Sender.FileLength + " 字节数据 " + s); //System.Console.Write(bs + i + " 字节数据 " + s); this.bs = new string('\b', Digits(i) + +Digits(Sender.FileLength) + s.Length); } }
static void Main() { AppTest a = new AppTest(); Microshaoft.Utils.HttpWebClient x = new Microshaoft.Utils.HttpWebClient(); //订阅 DataReceive 事件 x.DataReceive += new Microshaoft.Utils.HttpWebClient.DataReceiveEventHandler(a.x_DataReceive); //订阅 ExceptionOccurrs 事件 x.ExceptionOccurrs += new Microshaoft.Utils.HttpWebClient.ExceptionEventHandler(a.x_ExceptionOccurrs); string F = "http://localhost/download/phpMyAdmin-.6.-pl.zip"; a._F = F; F = "http://localhost/download/jdk-__0_0-windows-i86-p.aa.exe"; //F = "http://localhost/download/ReSharper..exe"; //F = "http://localhost/mywebapplications/WebApplication7/WebForm.aspx"; //F = "http://*****:*****@"E:\temp\" + f, 0, x).StartThreadProcess))).Start(); x.DownloadFile(F, @"E:\temp\temp\" + f, 0); // x.DownloadFileChunk(F, @"E:\temp\" + f,,6); System.Console.ReadLine(); // Upload 测试 // string uploadfile = "e:\\test_local.rar"; // string str = x.UploadFileEx("http://localhost/phpmyadmin/uploadaction.php", "POST", uploadfile, "file"); // System.Console.WriteLine(str); // System.Console.ReadLine(); }
private void x_ExceptionOccurrs(Microshaoft.Utils.HttpWebClient Sender, Microshaoft.Utils.ExceptionEventArgs e) { System.Console.WriteLine(e.Exception.Message); //发生异常重新下载相当于断点续传,你可以自己自行选择处理方式或自行处理 Microshaoft.Utils.HttpWebClient x = new Microshaoft.Utils.HttpWebClient(); x.DownloadFileChunk(this._F, this._f, e.DownloadState.Position, e.DownloadState.Length); e.ExceptionAction = Microshaoft.Utils.ExceptionActions.Ignore; }
static void Main() { AppTest a = new AppTest(); Microshaoft.Utils.HttpWebClient x = new Microshaoft.Utils.HttpWebClient(); //订阅 DataReceive 事件 x.DataReceive += new Microshaoft.Utils.HttpWebClient.DataReceiveEventHandler(a.x_DataReceive); //订阅 ExceptionOccurrs 事件 x.ExceptionOccurrs += new Microshaoft.Utils.HttpWebClient.ExceptionEventHandler(a.x_ExceptionOccurrs); string F = "http://localhost/download/phpMyAdmin-.6.-pl.zip"; a._F = F; F = "http://localhost/download/jdk-__0_0-windows-i86-p.aa.exe"; //F = "http://localhost/download/ReSharper..exe"; //F = "http://localhost/mywebapplications/WebApplication7/WebForm.aspx"; //F = "http://*****:*****@"E:\temp\" + f, 0, x).StartThreadProcess))).Start(); x.DownloadFile(F, @"E:\temp\temp\" + f, 0); // x.DownloadFileChunk(F, @"E:\temp\" + f,,6); System.Console.ReadLine(); // Upload 测试 // string uploadfile = "e:\\test_local.rar"; // string str = x.UploadFileEx("http://localhost/phpmyadmin/uploadaction.php", "POST", uploadfile, "file"); // System.Console.WriteLine(str); // System.Console.ReadLine(); }