本文整理汇总了C#中TransportContext类的典型用法代码示例。如果您正苦于以下问题:C# TransportContext类的具体用法?C# TransportContext怎么用?C# TransportContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransportContext类属于命名空间,在下文中一共展示了TransportContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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();
}
});
}
示例4: CopyToAsync
public Task CopyToAsync (Stream stream, TransportContext context)
{
if (stream == null)
throw new ArgumentNullException ("stream");
return SerializeToStreamAsync (stream, context);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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.");
}
示例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;
}
示例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.");
}
}
示例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();
}
}
}
示例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);
}
});
}
示例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);
}
});
}
示例14: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
return SerializeToStreamAsyncDelegate != null ?
SerializeToStreamAsyncDelegate(stream, context) :
Task.CompletedTask;
}
示例15: SerializeToStreamAsync
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context) { throw new NotImplementedException(); }