コード例 #1
0
ファイル: VForm.cs プロジェクト: windrobin/kumpro
 public Uploader(ConnInfo conn, Control win, INoticeIO nio, WaitHandle cancel)
 {
     this.conn   = conn;
     this.win    = win;
     this.nio    = nio;
     this.cancel = cancel;
 }
コード例 #2
0
ファイル: VForm.cs プロジェクト: windrobin/kumpro
        public static GenRes Upload2(Uri uri, String fp, ConnInfo conn, INoticeIO nio, WaitHandle cancel)
        {
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri ?? conn.Url);

            req.Credentials     = conn.Auth;
            req.UserAgent       = UA;
            req.Method          = "PUT";
            req.PreAuthenticate = true;
            using (FileStream si = File.OpenRead(fp)) {
                req.ContentLength             = si.Length;
                req.ContentType               = "application/octet-stream";
                req.SendChunked               = true;
                req.Pipelined                 = true;
                req.AllowWriteStreamBuffering = true;
                using (Stream os = req.GetRequestStream()) {
                    byte[] bin = new byte[4096];
                    while (true)
                    {
                        nio.Notice(fp, si.Position, si.Length);
                        if (cancel.WaitOne(0, false))
                        {
                            break;
                        }

                        int r = si.Read(bin, 0, bin.Length);
                        if (r < 1)
                        {
                            break;
                        }
                        os.Write(bin, 0, r);
                    }
                }

                GenRes ret = new GenRes();
                ret.baseUri = req.RequestUri;
                try {
                    ret.res = (HttpWebResponse)req.GetResponse();
                }
                catch (WebException err) {
                    ret.err = err;
                }
                return(ret);
            }
        }
コード例 #3
0
ファイル: VForm.cs プロジェクト: windrobin/kumpro
        public static GenRes Upload2(Uri uri, String fp, ConnInfo conn, INoticeIO nio, WaitHandle cancel) {
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri ?? conn.Url);
            req.Credentials = conn.Auth;
            req.UserAgent = UA;
            req.Method = "PUT";
            req.PreAuthenticate = true;
            using (FileStream si = File.OpenRead(fp)) {
                req.ContentLength = si.Length;
                req.ContentType = "application/octet-stream";
                req.SendChunked = true;
                req.Pipelined = true;
                req.AllowWriteStreamBuffering = true;
                using (Stream os = req.GetRequestStream()) {
                    byte[] bin = new byte[4096];
                    while (true) {
                        nio.Notice(fp, si.Position, si.Length);
                        if (cancel.WaitOne(0, false)) break;

                        int r = si.Read(bin, 0, bin.Length);
                        if (r < 1) break;
                        os.Write(bin, 0, r);
                    }
                }

                GenRes ret = new GenRes();
                ret.baseUri = req.RequestUri;
                try {
                    ret.res = (HttpWebResponse)req.GetResponse();
                }
                catch (WebException err) {
                    ret.err = err;
                }
                return ret;
            }
        }
コード例 #4
0
ファイル: VForm.cs プロジェクト: windrobin/kumpro
 public Uploader(ConnInfo conn, Control win, INoticeIO nio, WaitHandle cancel) {
     this.conn = conn;
     this.win = win;
     this.nio = nio;
     this.cancel = cancel;
 }