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


C# TransportContext类代码示例

本文整理汇总了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;
        }
开发者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


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