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


C# RangeCollection.Parse方法代码示例

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


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

示例1: ViaSocketWriter

        public void ViaSocketWriter()
        {
            var ranges = new RangeCollection();

            var fileStream = new FileStream(@"C:\Users\jgauffin\Downloads\AspNetMVC3ToolsUpdateSetup.exe", FileMode.Open,
                                                FileAccess.Read, FileShare.ReadWrite);
            ranges.Parse("bytes=0-50000", (int)fileStream.Length);
            var stream = new ByteRangeStream(ranges, fileStream);
            var job = new StreamSocketWriterJob(stream);

            var buffer = new byte[65535];
            var args = Substitute.For<SocketAsyncEventArgs>();
            args.UserToken.Returns(buffer);
            job.Write(args);
            

            while (true)
            {
                if (job.WriteCompleted(5000))
                {
                    job.Dispose();
                    break;
                }

                job.Write(args);    
            }
            
        }
开发者ID:2594636985,项目名称:griffin.networking,代码行数:28,代码来源:ByteRangeStreamTests.cs

示例2: ReadOneRangePartially

        public void ReadOneRangePartially()
        {
            var stream = CreateTextStream();
            var ranges = new RangeCollection();
            ranges.Parse("bytes=0-99", (int)stream.Length);
            byte[] target = new byte[100];

            var stream2 = new ByteRangeStream(ranges, stream);
            stream2.Read(target, 0, 50);
            stream2.Read(target, 50, 50);

            Assert.Equal(GetString().Substring(0,100), Encoding.ASCII.GetString(target, 0, 100));
        }
开发者ID:2594636985,项目名称:griffin.networking,代码行数:13,代码来源:ByteRangeStreamTests.cs

示例3: HandleRangeRequest

        private void HandleRangeRequest(IRequest request)
        {
            var rangeHeader = request.Headers["Range"];
            var response = request.CreateResponse(HttpStatusCode.PartialContent, "Welcome");

            response.ContentType = "application/octet-stream";
            response.AddHeader("Accept-Ranges", "bytes");
            response.AddHeader("Content-Disposition", @"attachment;filename=""ReallyBigFile.Txt""");

            //var fileStream = new FileStream(Environment.CurrentDirectory + @"\Ranges\ReallyBigFile.Txt", FileMode.Open,
            //                                FileAccess.Read, FileShare.ReadWrite);
            var fileStream = new FileStream(@"C:\Users\jgauffin\Downloads\AspNetMVC3ToolsUpdateSetup.exe", FileMode.Open,
                                                FileAccess.Read, FileShare.ReadWrite);
            var ranges = new RangeCollection();
            ranges.Parse(rangeHeader.Value, (int)fileStream.Length);

            response.AddHeader("Content-Range", ranges.ToHtmlHeaderValue((int)fileStream.Length));
            response.Body = new ByteRangeStream(ranges, fileStream);
            Send(response);
        }
开发者ID:samuraitruong,项目名称:comitdownloader,代码行数:20,代码来源:MyHttpService.cs

示例4: HandleRequest

        /// <summary>
        /// Handle the request.
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <returns><see cref="ModuleResult.Stop"/> will stop all processing except <see cref="IHttpModule.EndRequest"/>.</returns>
        /// <remarks>Invoked in turn for all modules unless you return <see cref="ModuleResult.Stop"/>.</remarks>
        public ModuleResult HandleRequest(IHttpContext context)
        {
            // only handle GET and HEAD
            if (!context.Request.HttpMethod.Equals("GET", StringComparison.OrdinalIgnoreCase)
                && !context.Request.HttpMethod.Equals("HEAD", StringComparison.OrdinalIgnoreCase))
                return ModuleResult.Continue;

            // serve a directory
            if (AllowFileListing)
            {
                if (TryGenerateDirectoryPage(context))
                    return ModuleResult.Stop;
            }

            var header = context.Request.Headers["If-Modified-Since"];
            var time = header != null
                           ? DateTime.ParseExact(header, "R", CultureInfo.InvariantCulture)
                           : DateTime.MinValue;


            var fileContext = new FileContext(context.Request, time);
            _fileService.GetFile(fileContext);
            if (!fileContext.IsFound)
                return ModuleResult.Continue;

            if (!fileContext.IsModified)
            {
                context.Response.StatusCode = (int)HttpStatusCode.NotModified;
                context.Response.ReasonPhrase = "Was last modified " + fileContext.LastModifiedAtUtc.ToString("R");
                return ModuleResult.Stop;
            }

            if (fileContext.IsGzipSubstitute)
            {
                context.Response.AddHeader("Content-Encoding", "gzip");
            }

            var mimeType = MimeTypeProvider.Instance.Get(fileContext.Filename);
            if (mimeType == null)
            {
                context.Response.StatusCode = (int)HttpStatusCode.UnsupportedMediaType;
                context.Response.ReasonPhrase = string.Format("File type '{0}' is not supported.",
                                                                   Path.GetExtension(fileContext.Filename));
                return ModuleResult.Stop;
            }

            context.Response.AddHeader("Last-Modified", fileContext.LastModifiedAtUtc.ToString("R"));
            context.Response.AddHeader("Accept-Ranges", "bytes");
            context.Response.AddHeader("Content-Disposition", "inline;filename=\"" + Path.GetFileName(fileContext.Filename) + "\"");
            context.Response.ContentType = mimeType;
            context.Response.ContentLength = (int)fileContext.FileStream.Length;

            // ranged/partial transfers
            var rangeStr = context.Request.Headers["Range"];
            if (!string.IsNullOrEmpty(rangeStr))
            {
                var ranges = new RangeCollection();
                ranges.Parse(rangeStr, (int)fileContext.FileStream.Length);
                context.Response.AddHeader("Content-Range", ranges.ToHtmlHeaderValue((int)fileContext.FileStream.Length));
                context.Response.Body = new ByteRangeStream(ranges, fileContext.FileStream);
                context.Response.ContentLength = ranges.TotalLength;
                context.Response.StatusCode = 206;
            }
            else
                context.Response.Body = fileContext.FileStream;

            // do not include a body when the client only want's to get content information.
            if (context.Request.HttpMethod.Equals("HEAD", StringComparison.OrdinalIgnoreCase) && context.Response.Body != null)
            {
                context.Response.Body.Dispose();
                context.Response.Body = null;
            }

            return ModuleResult.Stop;
        }
开发者ID:jmptrader,项目名称:Griffin.WebServer,代码行数:81,代码来源:FileModule.cs


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