本文整理汇总了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);
}
}
示例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));
}
示例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);
}
示例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;
}