當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。