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


C# Hosting.HostContext类代码示例

本文整理汇总了C#中Microsoft.AspNet.SignalR.Hosting.HostContext的典型用法代码示例。如果您正苦于以下问题:C# HostContext类的具体用法?C# HostContext怎么用?C# HostContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HostContext类属于Microsoft.AspNet.SignalR.Hosting命名空间,在下文中一共展示了HostContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendUrlTriggersReceivedEvent

        public void SendUrlTriggersReceivedEvent()
        {
            var tcs = new TaskCompletionSource<string>();
            var request = new Mock<IRequest>();
            var form = new NameValueCollection();
            form["data"] = "This is my data";
            var qs = new NameValueCollection();
            qs["connectionId"] = "1";
            request.Setup(m => m.QueryString).Returns(new NameValueCollectionWrapper(qs));
            request.Setup(m => m.ReadForm()).Returns(Task.FromResult<INameValueCollection>(new NameValueCollectionWrapper(form)));
            request.Setup(m => m.LocalPath).Returns("/test/echo/send");
            var counters = new Mock<IPerformanceCounterManager>();
            var heartBeat = new Mock<ITransportHeartbeat>();
            var json = JsonUtility.CreateDefaultSerializer();
            var hostContext = new HostContext(request.Object, null);
            var transportConnection = new Mock<ITransportConnection>();
            var traceManager = new Mock<ITraceManager>();
            counters.SetupGet(m => m.ConnectionsConnected).Returns(new NoOpPerformanceCounter());
            traceManager.Setup(m => m[It.IsAny<string>()]).Returns(new System.Diagnostics.TraceSource("foo"));
            var transport = new Mock<ForeverTransport>(hostContext, json, heartBeat.Object, counters.Object, traceManager.Object)
            {
                CallBase = true
            };

            transport.Object.Received = data =>
            {
                tcs.TrySetResult(data);
                return TaskAsyncHelper.Empty;
            };

            transport.Object.ProcessRequest(transportConnection.Object).Wait();

            Assert.Equal("This is my data", tcs.Task.Result);
        }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:34,代码来源:ForeverTransportFacts.cs

示例2: AbortUrlTriggersConnectionAbort

        public void AbortUrlTriggersConnectionAbort()
        {
            var request = new Mock<IRequest>();
            var qs = new NameValueCollection();
            request.Setup(m => m.QueryString).Returns(qs);
            request.Setup(m => m.Url).Returns(new Uri("http://test/echo/abort"));
            string abortedConnectionId = null;
            var counters = new Mock<IPerformanceCounterManager>();
            var heartBeat = new Mock<ITransportHeartbeat>();
            var json = new JsonNetSerializer();
            var hostContext = new HostContext(request.Object, null);
            var transportConnection = new Mock<ITransportConnection>();
            var traceManager = new Mock<ITraceManager>();
            traceManager.Setup(m => m[It.IsAny<string>()]).Returns(new System.Diagnostics.TraceSource("foo"));
            transportConnection.Setup(m => m.Send(It.IsAny<ConnectionMessage>()))
                               .Callback<ConnectionMessage>(m =>
                               {
                                   abortedConnectionId = m.Signal;
                                   var command = m.Value as Command;
                                   Assert.NotNull(command);
                                   Assert.Equal(CommandType.Abort, command.CommandType);
                               })
                               .Returns(TaskAsyncHelper.Empty);

            var transport = new Mock<ForeverTransport>(hostContext, json, heartBeat.Object, counters.Object, traceManager.Object)
            {
                CallBase = true
            };

            transport.Object.ConnectionId = "1";
            transport.Object.ProcessRequest(transportConnection.Object).Wait();

            Assert.Equal("c-1", abortedConnectionId);
        }
开发者ID:belanger-simon,项目名称:SignalR,代码行数:34,代码来源:ForeverTransportFacts.cs

示例3: Invoke

        public Task Invoke(IDictionary<string, object> environment)
        {
            var serverRequest = new ServerRequest(environment);
            var serverResponse = new ServerResponse(environment);
            var hostContext = new HostContext(serverRequest, serverResponse);

            // Add CORS support
            var origins = serverRequest.RequestHeaders.GetHeaders("Origin");
            if (origins != null && origins.Any(origin => !String.IsNullOrEmpty(origin)))
            {
                serverResponse.ResponseHeaders["Access-Control-Allow-Origin"] = origins;
                serverResponse.ResponseHeaders["Access-Control-Allow-Credentials"] = AllowCredentialsTrue;
            }

            hostContext.Items[HostConstants.SupportsWebSockets] = LazyInitializer.EnsureInitialized(
                ref _supportWebSockets,
                ref _supportWebSocketsInitialized,
                ref _supportWebSocketsLock,
                () => environment.SupportsWebSockets());

            hostContext.Items[HostConstants.ShutdownToken] = environment.GetShutdownToken();
            hostContext.Items[HostConstants.DebugMode] = environment.GetIsDebugEnabled();

            serverRequest.DisableRequestBuffering();
            serverResponse.DisableResponseBuffering();

            _connection.Initialize(_resolver, hostContext);

            return _connection.ProcessRequest(hostContext);
        }
开发者ID:Jozef89,项目名称:SignalR,代码行数:30,代码来源:CallHandler.cs

示例4: TransportDisconnectBase

        protected TransportDisconnectBase(HostContext context, ITransportHeartbeat heartbeat, IPerformanceCounterManager performanceCounterManager, ITraceManager traceManager)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (heartbeat == null)
            {
                throw new ArgumentNullException("heartbeat");
            }

            if (performanceCounterManager == null)
            {
                throw new ArgumentNullException("performanceCounterManager");
            }

            if (traceManager == null)
            {
                throw new ArgumentNullException("traceManager");
            }

            _context = context;
            _heartbeat = heartbeat;
            _counters = performanceCounterManager;

            // Queue to protect against overlapping writes to the underlying response stream
            WriteQueue = new TaskQueue();

            _trace = traceManager["SignalR.Transports." + GetType().Name];
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:31,代码来源:TransportDisconnectBase.cs

示例5: ProcessRequest

        public override Task ProcessRequest(HostContext context)
        {
            string alterWhen = "____Never____";
            int statusCode = 200;

            if (!String.IsNullOrEmpty(context.Request.QueryString["alterWhen"]))
            {
                alterWhen = context.Request.QueryString["alterWhen"];
            }

            if (!String.IsNullOrEmpty(context.Request.QueryString["statusCode"]))
            {
                statusCode = Int32.Parse(context.Request.QueryString["statusCode"]);
            }

            var owinRequest = new OwinRequest(context.Environment);

            if (owinRequest.Path.Value.Contains("/" + alterWhen))
            {
                var response = new OwinResponse(context.Environment);

                // Alter status code
                response.StatusCode = statusCode;

                using (var sw = new StreamWriter(response.Body))
                {
                    sw.WriteLine("Hello world");
                    sw.Flush();
                }

                return TaskAsyncHelper.Empty;
            }

            return base.ProcessRequest(context);
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:35,代码来源:StatusCodeConnection.cs

示例6: Invoke

        public Task Invoke(IDictionary<string, object> environment)
        {
            var serverRequest = new ServerRequest(environment);
            var serverResponse = new ServerResponse(environment);
            var hostContext = new HostContext(serverRequest, serverResponse);

            string origin = serverRequest.RequestHeaders.GetHeader("Origin");

            if (_configuration.EnableCrossDomain)
            {
                // Add CORS response headers support
                if (!String.IsNullOrEmpty(origin))
                {
                    serverResponse.ResponseHeaders.SetHeader("Access-Control-Allow-Origin", origin);
                    serverResponse.ResponseHeaders.SetHeader("Access-Control-Allow-Credentials", "true");
                }
            }
            else
            {
                string callback = serverRequest.QueryString["callback"];

                // If it's a JSONP request and we're not allowing cross domain requests then block it
                // If there's an origin header and it's not a same origin request then block it.

                if (!String.IsNullOrEmpty(callback) ||
                    (!String.IsNullOrEmpty(origin) && !IsSameOrigin(serverRequest.Url, origin)))
                {
                    return EndResponse(environment, 403, "Forbidden");
                }
            }

            // Add the nosniff header for all responses to prevent IE from trying to sniff mime type from contents
            serverResponse.ResponseHeaders.SetHeader("X-Content-Type-Options", "nosniff");

            hostContext.Items[HostConstants.SupportsWebSockets] = LazyInitializer.EnsureInitialized(
                ref _supportWebSockets,
                ref _supportWebSocketsInitialized,
                ref _supportWebSocketsLock,
                () => environment.SupportsWebSockets());

            hostContext.Items[HostConstants.ShutdownToken] = environment.GetShutdownToken();
            hostContext.Items[HostConstants.DebugMode] = environment.GetIsDebugEnabled();

            serverRequest.DisableRequestCompression();
            serverResponse.DisableResponseBuffering();

            _connection.Initialize(_configuration.Resolver, hostContext);

            if (!_connection.Authorize(serverRequest))
            {
                // If we failed to authorize the request then return a 403 since the request
                // can't do anything
                return EndResponse(environment, 403, "Forbidden");
            }
            else
            {
                return _connection.ProcessRequest(hostContext);
            }
        }
开发者ID:stirno,项目名称:SignalR,代码行数:59,代码来源:CallHandler.cs

示例7: LongPollingTransport

 public LongPollingTransport(HostContext context, IDependencyResolver resolver)
     : this(context,
            resolver.Resolve<IJsonSerializer>(),
            resolver.Resolve<ITransportHeartbeat>(),
            resolver.Resolve<IPerformanceCounterManager>(),
            resolver.Resolve<ITraceManager>())
 {
 }
开发者ID:bjarteskogoy,项目名称:SignalR,代码行数:8,代码来源:LongPollingTransport.cs

示例8: ForeverTransport

 protected ForeverTransport(HostContext context, IDependencyResolver resolver)
     : this(context,
            resolver.Resolve<IJsonSerializer>(),
            resolver.Resolve<ITransportHeartbeat>(),
            resolver.Resolve<IPerformanceCounterManager>(),
            resolver.Resolve<ITraceManager>())
 {
 }
开发者ID:Jozef89,项目名称:SignalR,代码行数:8,代码来源:ForeverTransport.cs

示例9: ForeverFrameTransportEscapesTagsWithPersistentResponse

        public void ForeverFrameTransportEscapesTagsWithPersistentResponse(string data, string expected)
        {
            var request = MockRequest();
            var response = new CustomResponse();
            var context = new HostContext(request.Object, response);
            var fft = new ForeverFrameTransport(context, new DefaultDependencyResolver());

            AssertEscaped(fft, response, GetWrappedResponse(data), expected);
        }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:9,代码来源:ForeverFrameTransportFacts.cs

示例10: WebSocketTransport

 public WebSocketTransport(HostContext context,
                           IJsonSerializer serializer,
                           ITransportHeartbeat heartbeat,
                           IPerformanceCounterManager performanceCounterWriter,
                           ITraceManager traceManager)
     : base(context, serializer, heartbeat, performanceCounterWriter, traceManager)
 {
     _context = context;
 }
开发者ID:Jozef89,项目名称:SignalR,代码行数:9,代码来源:WebSocketTransport.cs

示例11: ForeverFrameTransportEscapesTags

        public void ForeverFrameTransportEscapesTags(string data, string expected)
        {
            var request = new Mock<IRequest>();
            var response = new CustomResponse();
            var context = new HostContext(request.Object, response);
            var fft = new ForeverFrameTransport(context, new DefaultDependencyResolver());

            AssertEscaped(fft, response, data, expected);
        }
开发者ID:RyanChristensen,项目名称:SignalR,代码行数:9,代码来源:ForeverFrameTransportFacts.cs

示例12: AvoidDeadlockIfCancellationTokenTriggeredBeforeSubscribing

        public void AvoidDeadlockIfCancellationTokenTriggeredBeforeSubscribing()
        {
            var response = new Mock<IResponse>();
            response.Setup(m => m.CancellationToken).Returns(CancellationToken.None);
            var request = new Mock<IRequest>();
            var qs = new NameValueCollection();
            qs["connectionId"] = "1";
            request.Setup(m => m.QueryString).Returns(qs);
            request.Setup(m => m.Url).Returns(new Uri("http://test/echo/connect"));
            var counters = new Mock<IPerformanceCounterManager>();
            var heartBeat = new Mock<ITransportHeartbeat>();
            var json = new JsonNetSerializer();
            var hostContext = new HostContext(request.Object, response.Object);
            var transportConnection = new Mock<ITransportConnection>();
            var traceManager = new Mock<ITraceManager>();
            traceManager.Setup(m => m[It.IsAny<string>()]).Returns(new System.Diagnostics.TraceSource("foo"));

            Func<PersistentResponse, object, Task<bool>> callback = null;
            object state = null;

            var disposable = new DisposableAction(() =>
            {
                callback(new PersistentResponse() { Terminal = true }, state);
            });

            transportConnection.Setup(m => m.Receive(It.IsAny<string>(),
                                                     It.IsAny<Func<PersistentResponse, object, Task<bool>>>(),
                                                     It.IsAny<int>(),
                                                     It.IsAny<object>())).Callback<string, Func<PersistentResponse, object, Task<bool>>, int, object>((id, cb, max, st) =>
                                                     {
                                                         callback = cb;
                                                         state = st;
                                                     })
                                                     .Returns(disposable);

            var transport = new Mock<ForeverTransport>(hostContext, json, heartBeat.Object, counters.Object, traceManager.Object)
            {
                CallBase = true
            };

            var wh = new ManualResetEventSlim();

            transport.Object.BeforeCancellationTokenCallbackRegistered = () =>
            {
                // Trip the cancellation token
                transport.Object.End();
            };

            // Act
            Task.Factory.StartNew(() =>
            {
                transport.Object.ProcessRequest(transportConnection.Object);
                wh.Set();
            });

            Assert.True(wh.Wait(TimeSpan.FromSeconds(2)), "Dead lock!");
        }
开发者ID:armandoramirezdino,项目名称:SignalR,代码行数:57,代码来源:ForeverTransportFacts.cs

示例13: WebSocketTransport

 public WebSocketTransport(HostContext context,
                           IDependencyResolver resolver)
     : this(context,
            resolver.Resolve<JsonSerializer>(),
            resolver.Resolve<ITransportHeartbeat>(),
            resolver.Resolve<IPerformanceCounterManager>(),
            resolver.Resolve<ITraceManager>(),
            resolver.Resolve<IConfigurationManager>().MaxIncomingWebSocketMessageSize)
 {
 }
开发者ID:ZixiangBoy,项目名称:SignalR-1,代码行数:10,代码来源:WebSocketTransport.cs

示例14: LongPollingTransport

 public LongPollingTransport(HostContext context,
                             JsonSerializer jsonSerializer,
                             ITransportHeartbeat heartbeat,
                             IPerformanceCounterManager performanceCounterManager,
                             ITraceManager traceManager,
                             IConfigurationManager configurationManager)
     : base(context, jsonSerializer, heartbeat, performanceCounterManager, traceManager)
 {
     _configurationManager = configurationManager;
 }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:10,代码来源:LongPollingTransport.cs

示例15: TestLongPollingTransport

 private TestLongPollingTransport(
     HostContext context,
     JsonSerializer json,
     ITransportHeartbeat heartBeat,
     IPerformanceCounterManager counters,
     ITraceManager traceManager,
     IConfigurationManager configuarionManager)
     : base(context, json, heartBeat, counters, traceManager, configuarionManager)
 {
 }
开发者ID:GondhiDinesh,项目名称:SignalR,代码行数:10,代码来源:LongPollingTransportFacts.cs


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