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


C# MessageBusType类代码示例

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


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

示例1: ReconnectExceedingReconnectWindowDisconnectsWithFastBeatInterval

        public void ReconnectExceedingReconnectWindowDisconnectsWithFastBeatInterval(HostType hostType, TransportType transportType, MessageBusType messageBusType)
        {
            // Test cannot be async because if we do host.ShutDown() after an await the connection stops.

            using (var host = CreateHost(hostType, transportType))
            {
                host.Initialize(keepAlive: 9, messageBusType: messageBusType);
                var connection = CreateHubConnection(host);

                using (connection)
                {
                    var disconnectWh = new ManualResetEventSlim();

                    connection.Closed += () =>
                    {
                        disconnectWh.Set();
                    };

                    SetReconnectDelay(host.Transport, TimeSpan.FromSeconds(15));

                    connection.Start(host.Transport).Wait();                    

                    // Without this the connection start and reconnect can race with eachother resulting in a deadlock.
                    Thread.Sleep(TimeSpan.FromSeconds(3));

                    // Set reconnect window to zero so the second we attempt to reconnect we can ensure that the reconnect window is verified.
                    ((Client.IConnection)connection).ReconnectWindow = TimeSpan.FromSeconds(0);

                    host.Shutdown();

                    Assert.True(disconnectWh.Wait(TimeSpan.FromSeconds(15)), "Closed never fired");
                }
            }
        }
开发者ID:kietnha,项目名称:SignalR,代码行数:34,代码来源:ConnectionFacts.cs

示例2: UseMessageBus

        protected void UseMessageBus(MessageBusType type, IDependencyResolver resolver, int streams = 1)
        {
            IMessageBus bus = null;

            switch (type)
            {
                case MessageBusType.Default:
                    break;
                case MessageBusType.Fake:
                case MessageBusType.FakeMultiStream:
                    bus = new FakeScaleoutBus(resolver, streams);
                    break;
                case MessageBusType.SqlServer:
                    break;
                case MessageBusType.ServiceBus:
                    break;
                case MessageBusType.Redis:
                    break;
                default:
                    break;
            }

            if (bus != null)
            {
                resolver.Register(typeof(IMessageBus), () => bus);
            }
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:27,代码来源:HostedTest.cs

示例3: Initialize

        public void Initialize(int? keepAlive,
                               int? connectionTimeout,
                               int? disconnectTimeout,
                               int? transportConnectTimeout,
                               bool enableAutoRejoiningGroups,
                               MessageBusType type = MessageBusType.Default)
        {
            if (type != MessageBusType.Default)
            {
                throw new NotImplementedException();
            }

            // Use a configuration file to specify values
            string content = String.Format(_webConfigTemplate.Value,
                                           keepAlive,
                                           connectionTimeout,
                                           disconnectTimeout,
                                           transportConnectTimeout,
                                           enableAutoRejoiningGroups,
                                           _logFileName);

            File.WriteAllText(_webConfigPath, content);

            Url = _siteManager.GetSiteUrl(ExtraData);
        }
开发者ID:kabotnik,项目名称:SignalR,代码行数:25,代码来源:IISExpressTestHost.cs

示例4: CanInvokeMethodsAndReceiveMessagesFromValidTypedHub

        public async Task CanInvokeMethodsAndReceiveMessagesFromValidTypedHub(HostType hostType, TransportType transportType, MessageBusType messageBusType)
        {
            using (var host = CreateHost(hostType, transportType))
            {
                host.Initialize(messageBusType: messageBusType);

                using (var connection = CreateHubConnection(host))
                {
                    var hub = connection.CreateHubProxy("ValidTypedHub");
                    var echoTcs = new TaskCompletionSource<string>();
                    var pingWh = new ManualResetEventSlim();

                    hub.On<string>("Echo", message => echoTcs.TrySetResult(message));
                    hub.On("Ping", pingWh.Set);

                    await connection.Start(host.TransportFactory());

                    hub.InvokeWithTimeout("Echo", "arbitrary message");
                    Assert.True(echoTcs.Task.Wait(TimeSpan.FromSeconds(10)));
                    Assert.Equal("arbitrary message", echoTcs.Task.Result);

                    hub.InvokeWithTimeout("Ping");
                    Assert.True(pingWh.Wait(TimeSpan.FromSeconds(10)));
                }
            }
        }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:26,代码来源:TypedHubFacts.cs

示例5: SuccessiveTimeoutTest

        public async Task SuccessiveTimeoutTest(HostType hostType, TransportType transportType, MessageBusType messageBusType)
        {
            using (var host = CreateHost(hostType, transportType))
            {
                // Arrange
                var mre = new AsyncManualResetEvent(false);
                host.Initialize(keepAlive: 5, messageBusType: messageBusType);
                var connection = CreateConnection(host, "/my-reconnect");

                using (connection)
                {
                    connection.Reconnected += () =>
                    {
                        mre.Set();
                    };

                    await connection.Start(host.Transport);

                    ((Client.IConnection)connection).KeepAliveData = new KeepAliveData(TimeSpan.FromMilliseconds(300));

                    // Assert that Reconnected is called
                    Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(15)));

                    // Assert that Reconnected is called again
                    mre.Reset();
                    Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(15)));

                    // Clean-up
                    mre.Dispose();
                }
            }
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:32,代码来源:KeepAliveFacts.cs

示例6: ReconnectionSuccesfulTest

        public void ReconnectionSuccesfulTest(HostType hostType, TransportType transportType, MessageBusType messageBusType)
        {
            using (var host = CreateHost(hostType, transportType))
            {
                // Arrange
                var mre = new ManualResetEventSlim(false);
                host.Initialize(keepAlive: null, messageBusType: messageBusType);
                var connection = CreateConnection(host, "/my-reconnect");

                using (connection)
                {
                    ((Client.IConnection)connection).KeepAliveData = new KeepAliveData(TimeSpan.FromSeconds(2));

                    connection.Reconnected += () =>
                    {
                        mre.Set();
                    };

                    connection.Start(host.Transport).Wait();

                    // Assert
                    Assert.True(mre.Wait(TimeSpan.FromSeconds(10)));

                    // Clean-up
                    mre.Dispose();
                }
            }
        }
开发者ID:RyanChristensen,项目名称:SignalR,代码行数:28,代码来源:KeepAliveFacts.cs

示例7: MarkActiveStopsConnectionIfCalledAfterExtendedPeriod

        public void MarkActiveStopsConnectionIfCalledAfterExtendedPeriod(HostType hostType, TransportType transportType, MessageBusType messageBusType)
        {
            using (var host = CreateHost(hostType, transportType))
            {
                host.Initialize(messageBusType: messageBusType);
                var connection = CreateHubConnection(host);

                using (connection)
                {
                    var disconnectWh = new ManualResetEventSlim();

                    connection.Closed += () =>
                    {
                        disconnectWh.Set();
                    };

                    connection.Start(host.Transport).Wait();

                    // The MarkActive interval should check the reconnect window. Since this is short it should force the connection to disconnect.
                    ((Client.IConnection)connection).ReconnectWindow = TimeSpan.FromSeconds(1);

                    Assert.True(disconnectWh.Wait(TimeSpan.FromSeconds(15)), "Closed never fired");
                }
            }
        }
开发者ID:kietnha,项目名称:SignalR,代码行数:25,代码来源:ConnectionFacts.cs

示例8: TransportTimesOutIfNoInitMessage

        public async Task TransportTimesOutIfNoInitMessage(HostType hostType, TransportType transportType, MessageBusType messageBusType)
        {
            var mre = new AsyncManualResetEvent();

            using (var host = CreateHost(hostType, transportType))
            {
                host.Initialize(transportConnectTimeout: 1, messageBusType: messageBusType);

                HubConnection hubConnection = CreateHubConnection(host, "/no-init");

                IHubProxy proxy = hubConnection.CreateHubProxy("DelayedOnConnectedHub");

                using (hubConnection)
                {
                    try
                    {
                        await hubConnection.Start(host.Transport);
                    }
                    catch
                    {
                        mre.Set();
                    }

                    Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(10)));
                }
            }
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:27,代码来源:HubProxyFacts.cs

示例9: ReconnectionSuccesfulTest

        public async Task ReconnectionSuccesfulTest(HostType hostType, TransportType transportType, MessageBusType messageBusType)
        {
            using (var host = CreateHost(hostType, transportType))
            {
                // Arrange
                var mre = new AsyncManualResetEvent(false);
                host.Initialize(keepAlive: null, messageBusType: messageBusType);
                var connection = CreateConnection(host, "/my-reconnect");

                if (transportType == TransportType.LongPolling)
                {
                    ((Client.Transports.LongPollingTransport)host.Transport).ReconnectDelay = TimeSpan.Zero;
                }

                using (connection)
                {
                    ((Client.IConnection)connection).KeepAliveData = new KeepAliveData(TimeSpan.FromSeconds(2));

                    connection.Reconnected += () =>
                    {
                        mre.Set();
                    };

                    await connection.Start(host.Transport);

                    Assert.True(await mre.WaitAsync(TimeSpan.FromSeconds(10)));

                    // Clean-up
                    mre.Dispose();
                }
            }
        }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:32,代码来源:KeepAliveFacts.cs

示例10: Initialize

 public void Initialize(int? keepAlive = -1,
                        int? connectionTimeout = 110,                               
                        int? disconnectTimeout = 30,
                        int? transportConnectTimeout = 5,
                        bool enableAutoRejoiningGroups = false,
                        MessageBusType type = MessageBusType.Default)
 {
     // nothing to initialize since it is external! 
 }
开发者ID:nirmana,项目名称:SignalR,代码行数:9,代码来源:ExternalTestHost.cs

示例11: ReconnectFiresAfterHostShutdown

        public async Task ReconnectFiresAfterHostShutdown(TransportType transportType, MessageBusType messageBusType)
        {
            var serverRestarts = 0;
            var serverReconnects = 0;

            var host = new ServerRestarter(app =>
            {
                var config = new ConnectionConfiguration
                {
                    Resolver = new DefaultDependencyResolver()
                };

                UseMessageBus(messageBusType, config.Resolver);

                app.MapSignalR<MyReconnect>("/endpoint", config);

                serverRestarts++;
                serverReconnects = 0;
                config.Resolver.Register(typeof(MyReconnect), () => new MyReconnect(() => serverReconnects++));
            });

            using (host)
            {
                using (var connection = CreateConnection("http://foo/endpoint"))
                {
                    var transport = CreateTransport(transportType, host);
                    var pollEvent = new AsyncManualResetEvent();
                    var reconnectedEvent = new AsyncManualResetEvent();

                    host.OnPoll = () =>
                    {
                        pollEvent.Set();
                    };

                    connection.Reconnected += () =>
                    {
                        reconnectedEvent.Set();
                    };

                    await connection.Start(transport);

                    // Wait for the /poll before restarting the server
                    Assert.True(await pollEvent.WaitAsync(TimeSpan.FromSeconds(15)), "Timed out waiting for poll request");

                    host.Restart();

                    Assert.True(await reconnectedEvent.WaitAsync(TimeSpan.FromSeconds(15)), "Timed out waiting for client side reconnect");

                    Assert.Equal(2, serverRestarts);
                    Assert.Equal(1, serverReconnects);
                }
            }
        }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:53,代码来源:ReconnectFacts.cs

示例12: ReconnectFiresAfterHostShutdown

        public void ReconnectFiresAfterHostShutdown(TransportType transportType, MessageBusType messageBusType)
        {
            var persistentConnections = new List<MyReconnect>();
            var host = new ServerRestarter(app =>
            {
                var config = new ConnectionConfiguration
                {
                    Resolver = new DefaultDependencyResolver()
                };

                UseMessageBus(messageBusType, config.Resolver);

                app.MapSignalR<MyReconnect>("/endpoint", config);

                var conn = new MyReconnect();
                config.Resolver.Register(typeof(MyReconnect), () => conn);
                persistentConnections.Add(conn);
            });

            using (host)
            {
                using (var connection = CreateConnection("http://foo/endpoint"))
                {
                    var transport = CreateTransport(transportType, host);
                    var pollEvent = new ManualResetEventSlim();
                    var reconnectedEvent = new ManualResetEventSlim();

                    host.OnPoll = () =>
                    {
                        pollEvent.Set();
                    };

                    connection.Reconnected += () =>
                    {
                        reconnectedEvent.Set();
                    };

                    connection.Start(transport).Wait();

                    // Wait for the /poll before restarting the server
                    Assert.True(pollEvent.Wait(TimeSpan.FromSeconds(15)), "Timed out waiting for poll request");

                    host.Restart();

                    Assert.True(reconnectedEvent.Wait(TimeSpan.FromSeconds(15)), "Timed out waiting for client side reconnect");

                    Assert.Equal(2, persistentConnections.Count);
                    Assert.Equal(1, persistentConnections[1].Reconnects);
                }
            }
        }
开发者ID:RyanChristensen,项目名称:SignalR,代码行数:51,代码来源:ReconnectFacts.cs

示例13: Initialize

        public override void Initialize(int? keepAlive = -1,
                                        int? connectionTimeout = 110,
                                        int? disconnectTimeout = 30,
                                        int? transportConnectTimeout = 5,
                                        bool enableAutoRejoiningGroups = false,
                                        MessageBusType messageBusType = MessageBusType.Default)
        {
            base.Initialize(keepAlive, connectionTimeout, disconnectTimeout, transportConnectTimeout, enableAutoRejoiningGroups, messageBusType);

            _host.Configure(app =>
            {
                Initializer.ConfigureRoutes(app, Resolver);
            });
        }
开发者ID:nirmana,项目名称:SignalR,代码行数:14,代码来源:MemoryTestHost.cs

示例14: HubProgressThrowsInvalidOperationExceptionIfAttemptToReportProgressAfterMethodReturn

        public async Task HubProgressThrowsInvalidOperationExceptionIfAttemptToReportProgressAfterMethodReturn(HostType hostType, TransportType transportType, MessageBusType messageBusType)
        {
            using (var host = CreateHost(hostType, transportType))
            {
                host.Initialize(messageBusType: messageBusType);

                HubConnection hubConnection = CreateHubConnection(host);
                IHubProxy proxy = hubConnection.CreateHubProxy("progress");
                
                proxy.On<bool>("sendProgressAfterMethodReturnResult", result => Assert.True(result));

                using (hubConnection)
                {
                    await hubConnection.Start(host.Transport);

                    await proxy.Invoke<int>("SendProgressAfterMethodReturn", _ => { });
                }
            }
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:19,代码来源:HubProgressFacts.cs

示例15: TryGetMessageBusType

        /// <summary>
        /// Gets a message bus type based on the specified string <paramref name="value"/>.
        /// </summary>
        /// <param name="value">The value to convert to an message bus type (i.e., name, value or unique description).</param>
        /// <param name="result">The message bus type.</param>
        public static Boolean TryGetMessageBusType(String value, out MessageBusType result)
        {
            Int32 parsedValue;
            Object boxedValue = Int32.TryParse(value, out parsedValue) ? parsedValue : (Object)value;

            if (value.IsNullOrWhiteSpace())
            {
                result = MessageBusType.MicrosoftMessageQueuing;
                return true;
            }

            if (Enum.IsDefined(typeof(MessageBusType), boxedValue))
            {
                result = (MessageBusType)Enum.ToObject(typeof(MessageBusType), boxedValue);
                return true;
            }

            return KnownMessageBusTypes.TryGetValue(value, out result);
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:24,代码来源:Program.cs


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