当前位置: 首页>>代码示例>>C#>>正文


C# HttpWorkerRequest.GetTotalEntityBodyLength方法代码示例

本文整理汇总了C#中System.Web.HttpWorkerRequest.GetTotalEntityBodyLength方法的典型用法代码示例。如果您正苦于以下问题:C# HttpWorkerRequest.GetTotalEntityBodyLength方法的具体用法?C# HttpWorkerRequest.GetTotalEntityBodyLength怎么用?C# HttpWorkerRequest.GetTotalEntityBodyLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpWorkerRequest的用法示例。


在下文中一共展示了HttpWorkerRequest.GetTotalEntityBodyLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateStream

        public static RequestBufferlessStream CreateStream(HttpWorkerRequest workerRequest)
        {
            if (workerRequest == null)
                throw new ArgumentNullException("workerRequest");

            long totalBytes = (long)workerRequest.GetTotalEntityBodyLength();
            return new RequestBufferlessStream(workerRequest, totalBytes);
        }
开发者ID:cloudguy,项目名称:Storage-Monster,代码行数:8,代码来源:RequestBufferlessStream.cs

示例2: AsyncUpload

        public AsyncUpload(HttpWorkerRequest wRquest)
        {
            if (wRquest == null) throw new ArgumentNullException("wRquest");
            this.uploadProcess = new UploadProcess(delegate(float f) { });
            workerRequest = wRquest;

            //当前读到的流长度
            this.preLen = workerRequest.GetPreloadedEntityBodyLength();
            //请求流的总长度
            this.totLen = workerRequest.GetTotalEntityBodyLength();
            //内容分隔符 如: -----------------------------152733254716788
            if (preLen == 0 && workerRequest.IsClientConnected() && workerRequest.HasEntityBody())
            {
                byte[] buffer = new byte[8192];
                preLen = workerRequest.ReadEntityBody(buffer, buffer.Length);
                byte[] buf = new byte[preLen];
                for (int i = 0; i < buf.Length; i++) buf[i] = buffer[i];
                this.perBodyBytes = buf;
            }
            else
                this.perBodyBytes = workerRequest.GetPreloadedEntityBody();

            this.headerBytes = this.GetBoundaryBytes(Encoding.UTF8.GetBytes(workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentType)));
            //请求流尾部分隔符 如: -----------------------------152733254716788--
            this.contentEnd = new byte[this.headerBytes.Length + 2];
            this.headerBytes.CopyTo(this.contentEnd, 0);
            this.contentEnd[this.headerBytes.Length] = 45;
            this.contentEnd[this.headerBytes.Length + 1] = 45;

            //当前流中第一个文件分隔符的位置
            int fHeaderPosition = perBodyBytes.Indexof(fileNameHeader);
            //尝试在已读取到的流中找文件尾位置
            this.fEndPosition = perBodyBytes.Indexof(contentEnd);
            if (fHeaderPosition > -1)
            {
                //先找到文件名
                IList<byte> bufList = new List<byte>();
                int i = fHeaderPosition + fileNameHeader.Length;
                while (i < perBodyBytes.Length)
                {
                    if (perBodyBytes[i] == 34) break;
                    bufList.Add(perBodyBytes[i]);
                    i++;
                }

                this.FileName = Encoding.UTF8.GetString(bufList.ToArray());//file name
                this.fPosition = perBodyBytes.Indexof(wrapBytes, i) + 4;//当前流中此文件的开始位置
                this.FileLength = this.totLen - this.fPosition;
            }
        }
开发者ID:hanwest00,项目名称:MYTestWeb,代码行数:50,代码来源:AsyncUpload.cs

示例3: ParseRequest

 /// <summary>
 /// Parses the request into files then parses the files into form fields and uploaded files.
 /// </summary>
 /// <param name="r">The r.</param>
 /// <returns></returns>
 Mapper ParseRequest(HttpWorkerRequest r)
 {
     // get the ID of the upload from the querystring if any
     var qid = r.GetQueryString();
     Guid id;
     if(!Guid.TryParse(qid, out id)) {
         throw new HttpParseException("Upload contains no ID.");
     }
     var d = new HttpUploadStatusEventArgs() {
         Id = id,
         StartedOn = DateTime.Now,
         LastUpdated = DateTime.Now,
         Message = "Beginning Upload."
     };
     var isIdFound = false;
     var isMapFound = false;
     var e = new UTF8Encoding();
     // bytes for "Content-Disposition: form-data; "
     var mapSig = new byte[] {
     67,111,110,116,101,110,116,45,68,105,115,112,111,
     115,105,116,105,111,110,58,32,102,111,114,109,
     45,100,97,116,97,59,32,110,97,109,101,61,
     34,109,97,112,34,13,10,13,10
     };
     var idSig = new byte[] {
     67,111,110,116,101,110,116,45,68,105,115,112,111,115,105,116,105,
     111,110,58,32,102,111,114,109,45,100,97,116,97,59,32,110,
     97,109,101,61,34,105,100,34,13,10,13,10};
     var m = new Mapper();
     // first 46 bytes = boundary signature
     const int f = 131072; // 128kb = 131072b
     var l = r.GetTotalEntityBodyLength();
     d.BytesTotal = l;
     var p = r.GetPreloadedEntityBody();
     var b = GetBoundary(p);
     updateUploadStatus(ref d,l,"Uploading preloaded entity body.");
     // load stream into temp file
     var fst = Path.GetTempFileName();
     using (var fs = new FileStream(fst, FileMode.OpenOrCreate)) {
         // write preloaded body to file
         Debug.Assert(p != null, "GetPreloadedEntityBody != null");
         fs.Write(p, 0, p.Length);
         var c = p.Length;
         var q = 0;
         var u = new byte[f];
         updateUploadStatus(ref d, l, "Uploading.");
         while (l - c > q) {
             q = r.ReadEntityBody(u, 0, f);
             fs.Write(u, 0, q);
             c += q;
             updateUploadStatus(ref d, c, "Uploading.");
         }
         if (l - c > 0) {
             var ux = new byte[l - c];
             q = r.ReadEntityBody(ux, 0, l - c);
             fs.Write(ux, 0, q);
         }
         fs.Flush();
         fs.Position = 0;
         updateUploadStatus(ref d, c, "Upload Complete, Parsing upload.");
         // read the entire file finding all boundaries
         var s = new List<long>();
         while (fs.Position < fs.Length) {
             s.Add(FindPosition(fs, b, fs.Position));
         }
         fs.Position = 0;
         // the last boundary is the eof
         for (var i = 0; s.Count - 1 > i; i++) {
             // indexes between boundaries - this is the new file size in bytes
             if (s[i + 1] == -1) {
                 break;
             }
             var z = s[i + 1] - s[i];
             // this is the size of the object between the boundaries (including current boundary)
             var g = (z) < f ? z : f;
             // chunk size (g) = 131072 (f) or next boundary pos - current boundary pos (z)
             var n = Path.GetTempFileName();
             fs.Position = s[i]; // start reading from the beginning position of the object (including boundary)
             using (var a = new FileStream(n, FileMode.OpenOrCreate)) {
                 q = 0;
                 c = 0;
                 while (z - c > q) {
                     //read blocks while position - mod block size  is less than end position
                     q = fs.Read(u, 0, (int)g);
                     a.Write(u, 0, q);
                     c += q;
                 }
                 q = fs.Read(u, 0, (int)z - c);
                 a.Write(u, 0, q);
                 a.Position = 0;
                 // read in form data
                 if (!isMapFound) {
                     if (FindPosition(a, mapSig, 0) > -1) {
                         // this is the map field
                         var mapBytes = new byte[a.Length - a.Position - 2]; // -2 to drop the \r\n
//.........这里部分代码省略.........
开发者ID:CorbinDallas,项目名称:Oda,代码行数:101,代码来源:ParseRequest.cs


注:本文中的System.Web.HttpWorkerRequest.GetTotalEntityBodyLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。