本文整理汇总了C#中TransportContext类的典型用法代码示例。如果您正苦于以下问题:C# TransportContext类的具体用法?C# TransportContext怎么用?C# TransportContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransportContext类属于命名空间,在下文中一共展示了TransportContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
Contract.Assert(stream != null);
// Serialize header
byte[] header = SerializeHeader();
TaskCompletionSource<object> writeTask = new TaskCompletionSource<object>();
try
{
// We don't use TaskFactory.FromAsync as it generates an FxCop CA908 error
Tuple<HttpMessageContent, Stream, TaskCompletionSource<object>> state =
new Tuple<HttpMessageContent, Stream, TaskCompletionSource<object>>(this, stream, writeTask);
IAsyncResult result = stream.BeginWrite(header, 0, header.Length, _onWriteComplete, state);
if (result.CompletedSynchronously)
{
WriteComplete(result, this, stream, writeTask);
}
}
catch (Exception e)
{
writeTask.TrySetException(e);
}
return writeTask.Task;
}
开发者ID:Rhombulus,项目名称:aspnetwebstack,代码行数:26,代码来源:HttpMessageContent.cs
示例2: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
Debug.Assert(stream != null);
if (_contentConsumed)
{
throw new InvalidOperationException(SR.net_http_content_stream_already_read);
}
_contentConsumed = true;
const int BufferSize = 8192;
Task copyTask = _content.CopyToAsync(stream, BufferSize, _cancellationToken);
if (copyTask.IsCompleted)
{
try { _content.Dispose(); } catch { } // same as StreamToStreamCopy behavior
}
else
{
copyTask = copyTask.ContinueWith((t, s) =>
{
try { ((Stream)s).Dispose(); } catch { }
t.GetAwaiter().GetResult();
}, _content, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}
return copyTask;
}
开发者ID:dotnet,项目名称:corefx,代码行数:26,代码来源:NoWriteNoSeekStreamContent.cs
示例3: WriteToStreamAsync
// Sealed because derived classes shouldn't override the async version. Override sync version instead.
public sealed override Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext transportContext)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
if (stream == null)
{
throw new ArgumentNullException("stream");
}
// Underlying stream will do encoding into separate sections. This is just buffering.
return TaskHelpers.RunSynchronously(
() =>
{
Stream bufferedStream = GetBufferStream(stream);
try
{
WriteToStream(type, value, bufferedStream, contentHeaders);
}
finally
{
// Disposing the bufferStream will dispose the underlying stream.
// So Flush any remaining bytes that have been written, but don't actually close the stream.
bufferedStream.Flush();
}
});
}
开发者ID:sanyaade-mobiledev,项目名称:aspnetwebstack-1,代码行数:31,代码来源:BufferedMediaTypeFormatter.cs
示例4: CopyToAsync
public Task CopyToAsync (Stream stream, TransportContext context)
{
if (stream == null)
throw new ArgumentNullException ("stream");
return SerializeToStreamAsync (stream, context);
}
开发者ID:nkuln,项目名称:mono,代码行数:7,代码来源:HttpContent.cs
示例5: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
Debug.Assert(stream != null);
PrepareContent();
// If the stream can't be re-read, make sure that it gets disposed once it is consumed.
return StreamToStreamCopy.CopyAsync(_content, stream, _bufferSize, !_content.CanSeek);
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:8,代码来源:StreamContent.cs
示例6: SerializeToStreamAsync
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
byte[] bytes = new byte[_sizeOfEachWrite];
for (int i = 0; i < _numberOfWrites; i++)
{
await stream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
}
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:8,代码来源:HttpContentTest.cs
示例7: ConnectionRequest
public override bool ConnectionRequest(TransportContext context)
{
TransportContextTCPIP tcpContext = context as TransportContextTCPIP;
IXimuraRQRSEnvelope Env = null;
try
{
Env = context.EnvelopeHelper.GetCallback(context.ServerCommandID.Value);
context.SenderIdentitySet(Env);
Env.DestinationAddress = new EnvelopeAddress(context.ServerCommandID.Value, "ConnRQ");
IXimuraProtocolConnectionRequest Request = Env.Request as IXimuraProtocolConnectionRequest;
IXimuraProtocolConnectionResponse Response = Env.Response as IXimuraProtocolConnectionResponse;
Request.ProtocolContextID = context.SignatureID;
Request.RemoteUri = context.UriRemote;
Request.LocalUri = context.UriLocal;
Request.ConnectionType = TransportConnectionType.Connectionful;
//We want a new server context, so we will not send an ID.
Request.ServerContextID = context.ServerContextID;
context.ContextSession.ProcessRequest(Env);
if (Env.Response.Status != CH.HTTPCodes.OK_200)
{
return false;
}
context.ServerContextID = Response.ServerContextID;
context.MessageTypeIn = Response.MessageRequestType;
//context.FlowControl = Response.FlowControl;
if (Response.MessageResponse != null)
{
context.MessageTransmit(Response.MessageResponse);
}
context.ClosePending = Response.CloseNotify;
context.ConnectionStart();
return true;
}
catch (Exception ex)
{
return false;
}
finally
{
if (Env != null && Env.ObjectPoolCanReturn)
Env.ObjectPoolReturn();
}
return false;
}
开发者ID:mbmccormick,项目名称:Ximura,代码行数:53,代码来源:OpenTCPIPTransportState.cs
示例8: CheckTransportContext
public void CheckTransportContext(TransportContext context)
{
var cbt1 = context.GetChannelBinding(ChannelBindingKind.Endpoint);
var cbt2 = context.GetChannelBinding(ChannelBindingKind.Unique);
var cbt3 = context.GetChannelBinding(ChannelBindingKind.Unknown);
CheckChannelBinding(cbt1);
CheckChannelBinding(cbt2);
CheckChannelBinding(cbt3);
Assert.True(cbt1 != null, "ChannelBindingKind.Endpoint token data should be returned from SCHANNEL.");
Assert.True(cbt2 != null, "ChannelBindingKind.Unique token data should be returned from SCHANNEL.");
Assert.True(cbt3 == null, "ChannelBindingKind.Unknown token data should not be returned from SCHANNEL since it does not map to a defined context attribute.");
}
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:14,代码来源:TransportContextTest.cs
示例9: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
TaskCompletionSource<bool> serializeToStreamTask = new TaskCompletionSource<bool>();
try
{
Stream wrappedStream = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);
_onStreamAvailable(wrappedStream, this, context);
}
catch (Exception e)
{
serializeToStreamTask.TrySetException(e);
}
return serializeToStreamTask.Task;
}
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:15,代码来源:PushStreamContent.cs
示例10: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
if (SerializeToStreamAsyncCallback != null)
{
return SerializeToStreamAsyncCallback(stream, context);
}
else if (InnerContent != null)
{
return InnerContent.CopyToAsync(stream, context);
}
else
{
throw new InvalidOperationException("Construct with inner HttpContent or set SerializeToStreamCallback first.");
}
}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:15,代码来源:MockHttpContent.cs
示例11: SerializeToStream
protected override void SerializeToStream(Stream stream, TransportContext context)
{
Contract.Assert(stream != null);
PrepareContent();
try
{
content.CopyTo(stream, bufferSize);
}
finally
{
// Make sure the source stream gets disposed if it can't be consumed multiple times.
if (!content.CanSeek)
{
content.Dispose();
}
}
}
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:18,代码来源:StreamContent.cs
示例12: WriteToStreamAsync
// Sealed because derived classes shouldn't override the async version. Override sync version instead.
public sealed override Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext transportContext)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
if (stream == null)
{
throw new ArgumentNullException("stream");
}
return TaskHelpers.RunSynchronously(
() =>
{
using (Stream bufferedStream = GetBufferStream(stream, _bufferSizeInBytes))
{
WriteToStream(type, value, bufferedStream, contentHeaders);
}
});
}
开发者ID:sanyaade-mobiledev,项目名称:aspnetwebstack,代码行数:22,代码来源:BufferedMediaTypeFormatter.cs
示例13: WriteToStreamAsync
// Sealed because derived classes shouldn't override the async version. Override sync version instead.
public sealed override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
{
if (type == null)
{
throw Error.ArgumentNull("type");
}
if (writeStream == null)
{
throw Error.ArgumentNull("writeStream");
}
return TaskHelpers.RunSynchronously(
() =>
{
using (Stream bufferedStream = GetBufferStream(writeStream, _bufferSizeInBytes))
{
WriteToStream(type, value, bufferedStream, content);
}
});
}
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:22,代码来源:BufferedMediaTypeFormatter.cs
示例14: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
return SerializeToStreamAsyncDelegate != null ?
SerializeToStreamAsyncDelegate(stream, context) :
Task.CompletedTask;
}
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:6,代码来源:HttpClientHandlerTest.cs
示例15: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context) { throw new NotImplementedException(); }
开发者ID:dotnet,项目名称:corefx,代码行数:1,代码来源:HttpContentHeadersTest.cs
示例16: CopyToAsync
public Task CopyToAsync(Stream stream, TransportContext context)
{
CheckDisposed();
if (stream == null)
{
throw new ArgumentNullException("stream");
}
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
try
{
Task task = null;
if (IsBuffered)
{
byte[] data = this.GetDataBuffer(_bufferedContent);
task = stream.WriteAsync(data, 0, (int)_bufferedContent.Length);
}
else
{
task = SerializeToStreamAsync(stream, context);
CheckTaskNotNull(task);
}
// If the copy operation fails, wrap the exception in an HttpRequestException() if appropriate.
task.ContinueWithStandard(tcs, (copyTask, state) =>
{
var innerTcs = (TaskCompletionSource<object>)state;
if (copyTask.IsFaulted)
{
innerTcs.TrySetException(GetStreamCopyException(copyTask.Exception.GetBaseException()));
}
else if (copyTask.IsCanceled)
{
innerTcs.TrySetCanceled();
}
else
{
innerTcs.TrySetResult(null);
}
});
}
catch (IOException e)
{
tcs.TrySetException(GetStreamCopyException(e));
}
catch (ObjectDisposedException e)
{
tcs.TrySetException(GetStreamCopyException(e));
}
return tcs.Task;
}
开发者ID:brianjsykes,项目名称:corefx,代码行数:52,代码来源:HttpContent.cs
示例17: WriteToStreamAsync
public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content,
TransportContext transportContext, CancellationToken cancellationToken)
{
if (type == null)
{
throw Error.ArgumentNull("type");
}
if (writeStream == null)
{
throw Error.ArgumentNull("writeStream");
}
if (cancellationToken.IsCancellationRequested)
{
return TaskHelpers.Canceled();
}
try
{
WriteToStream(type, value, writeStream, content);
return TaskHelpers.Completed();
}
catch (Exception e)
{
return TaskHelpers.FromError(e);
}
}
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:26,代码来源:BaseJsonMediaTypeFormatter.cs
示例18: SerializeToStreamAsync
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
TaskCompletionSource<bool> serializeToStreamTask = new TaskCompletionSource<bool>();
Stream wrappedStream = new CompleteTaskOnCloseStream(stream, serializeToStreamTask);
await _onStreamAvailable(wrappedStream, this, context);
// wait for wrappedStream.Close/Dispose to get called.
await serializeToStreamTask.Task;
}
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:10,代码来源:PushStreamContent.cs
示例19: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
var formatter = new JsonNetMediaTypeFormatter();
return formatter.WriteToStreamAsync(instance.GetType(), instance, stream, base.Headers, context);
}
开发者ID:netfx,项目名称:extensions,代码行数:5,代码来源:JsonContent.cs
示例20: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
Debug.Assert(stream != null);
return stream.WriteAsync(_content, _offset, _count);
}
开发者ID:noahfalk,项目名称:corefx,代码行数:5,代码来源:ByteArrayContent.cs
注:本文中的TransportContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论