本文整理汇总了C#中Microsoft.AspNet.SignalR.Hosting.Memory.MemoryHost.MapHubs方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryHost.MapHubs方法的具体用法?C# MemoryHost.MapHubs怎么用?C# MemoryHost.MapHubs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.SignalR.Hosting.Memory.MemoryHost
的用法示例。
在下文中一共展示了MemoryHost.MapHubs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AuthenticatedAndAuthorizedUserCanInvokeMethodsInHubsAuthorizedWithRoles
public void AuthenticatedAndAuthorizedUserCanInvokeMethodsInHubsAuthorizedWithRoles()
{
using (var host = new MemoryHost())
{
host.MapHubs();
var connection = new Client.Hubs.HubConnection("http://foo/");
host.User = new GenericPrincipal(new GenericIdentity("test"), new string[] { "Admin" });
var hub = connection.CreateHubProxy("AdminAuthHub");
var wh = new ManualResetEvent(false);
hub.On<string, string>("invoked", (id, time) =>
{
Assert.NotNull(id);
wh.Set();
});
connection.Start(host).Wait();
hub.InvokeWithTimeout("InvokedFromClient");
Assert.True(wh.WaitOne(TimeSpan.FromSeconds(3)));
connection.Stop();
}
}
示例2: ManyUniqueGroups
public static IDisposable ManyUniqueGroups(int concurrency)
{
var host = new MemoryHost();
var threads = new List<Thread>();
var cancellationTokenSource = new CancellationTokenSource();
host.MapHubs();
for (int i = 0; i < concurrency; i++)
{
var thread = new Thread(_ =>
{
while (!cancellationTokenSource.IsCancellationRequested)
{
RunOne(host);
}
});
threads.Add(thread);
thread.Start();
}
return new DisposableAction(() =>
{
cancellationTokenSource.Cancel();
threads.ForEach(t => t.Join());
host.Dispose();
});
}
示例3: ChangeHubUrl
public void ChangeHubUrl()
{
using (var host = new MemoryHost())
{
host.MapHubs("/foo");
var connection = new Client.Hubs.HubConnection("http://site/foo", useDefaultUrl: false);
var hub = connection.CreateHubProxy("demo");
var wh = new ManualResetEventSlim(false);
hub.On("signal", id =>
{
Assert.NotNull(id);
wh.Set();
});
connection.Start(host).Wait();
hub.Invoke("DynamicTask").Wait();
Assert.True(wh.Wait(TimeSpan.FromSeconds(10)));
connection.Stop();
}
}
示例4: AddingToMultipleGroups
public void AddingToMultipleGroups()
{
var host = new MemoryHost();
host.MapHubs();
int max = 10;
var countDown = new CountDownRange<int>(Enumerable.Range(0, max));
var connection = new Client.Hubs.HubConnection("http://foo");
var proxy = connection.CreateProxy("MultGroupHub");
proxy.On<User>("onRoomJoin", user =>
{
Assert.True(countDown.Mark(user.Index));
});
connection.Start(host).Wait();
for (int i = 0; i < max; i++)
{
var user = new User { Index = i, Name = "tester", Room = "test" + i };
proxy.Invoke("login", user).Wait();
proxy.Invoke("joinRoom", user).Wait();
}
Assert.True(countDown.Wait(TimeSpan.FromSeconds(30)), "Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed " + String.Join(",", countDown.Left.Select(i => i.ToString())));
connection.Stop();
}
示例5: DisconnectFiresForHubsWhenConnectionGoesAway
public void DisconnectFiresForHubsWhenConnectionGoesAway()
{
using (var host = new MemoryHost())
{
host.MapHubs();
host.Configuration.DisconnectTimeout = TimeSpan.Zero;
host.Configuration.HeartbeatInterval = TimeSpan.FromSeconds(5);
var connectWh = new ManualResetEventSlim();
var disconnectWh = new ManualResetEventSlim();
host.DependencyResolver.Register(typeof(MyHub), () => new MyHub(connectWh, disconnectWh));
var connection = new Client.Hubs.HubConnection("http://foo/");
connection.CreateHubProxy("MyHub");
// Maximum wait time for disconnect to fire (3 heart beat intervals)
var disconnectWait = TimeSpan.FromTicks(host.Configuration.HeartbeatInterval.Ticks * 3);
connection.Start(host).Wait();
Assert.True(connectWh.Wait(TimeSpan.FromSeconds(10)), "Connect never fired");
connection.Stop();
Assert.True(disconnectWh.Wait(disconnectWait), "Disconnect never fired");
}
}
示例6: RunConnectDisconnect
public static IDisposable RunConnectDisconnect(int connections)
{
var host = new MemoryHost();
host.MapHubs();
for (int i = 0; i < connections; i++)
{
var connection = new Client.Hubs.HubConnection("http://foo");
var proxy = connection.CreateHubProxy("EchoHub");
var wh = new ManualResetEventSlim(false);
proxy.On("echo", _ => wh.Set());
try
{
connection.Start(host).Wait();
proxy.Invoke("Echo", "foo").Wait();
if (!wh.Wait(TimeSpan.FromSeconds(10)))
{
Debugger.Break();
}
}
finally
{
connection.Stop();
}
}
return host;
}
示例7: UnableToCreateHubThrowsError
public void UnableToCreateHubThrowsError()
{
using (var host = new MemoryHost())
{
host.MapHubs();
var hubConnection = new HubConnection("http://fake");
IHubProxy proxy = hubConnection.CreateHubProxy("MyHub2");
hubConnection.Start(host).Wait();
Assert.Throws<MissingMethodException>(() => proxy.Invoke("Send", "hello").Wait());
}
}
示例8: ComplexPersonState
public void ComplexPersonState()
{
var host = new MemoryHost();
host.MapHubs();
var connection = new Client.Hubs.HubConnection("http://site/");
var hub = connection.CreateProxy("demo");
var wh = new ManualResetEvent(false);
connection.Start(host).Wait();
var person = new SignalR.Samples.Hubs.DemoHub.DemoHub.Person
{
Address = new SignalR.Samples.Hubs.DemoHub.DemoHub.Address
{
Street = "Redmond",
Zip = "98052"
},
Age = 25,
Name = "David"
};
var person1 = hub.Invoke<SignalR.Samples.Hubs.DemoHub.DemoHub.Person>("ComplexType", person).Result;
var person2 = hub.GetValue<SignalR.Samples.Hubs.DemoHub.DemoHub.Person>("person");
JObject obj = ((dynamic)hub).person;
var person3 = obj.ToObject<SignalR.Samples.Hubs.DemoHub.DemoHub.Person>();
Assert.NotNull(person1);
Assert.NotNull(person2);
Assert.NotNull(person3);
Assert.Equal("David", person1.Name);
Assert.Equal("David", person2.Name);
Assert.Equal("David", person3.Name);
Assert.Equal(25, person1.Age);
Assert.Equal(25, person2.Age);
Assert.Equal(25, person3.Age);
Assert.Equal("Redmond", person1.Address.Street);
Assert.Equal("Redmond", person2.Address.Street);
Assert.Equal("Redmond", person3.Address.Street);
Assert.Equal("98052", person1.Address.Zip);
Assert.Equal("98052", person2.Address.Zip);
Assert.Equal("98052", person3.Address.Zip);
connection.Stop();
}
示例9: HubNamesAreNotCaseSensitive
public void HubNamesAreNotCaseSensitive()
{
var host = new MemoryHost();
host.MapHubs();
var hubConnection = new HubConnection("http://fake");
IHubProxy proxy = hubConnection.CreateProxy("chatHub");
var wh = new ManualResetEvent(false);
proxy.On("addMessage", data =>
{
Assert.Equal("hello", data);
wh.Set();
});
hubConnection.Start(host).Wait();
proxy.Invoke("Send", "hello").Wait();
Assert.True(wh.WaitOne(TimeSpan.FromSeconds(5)));
}
示例10: SendToSelf
public void SendToSelf()
{
var host = new MemoryHost();
host.MapHubs();
var connection1 = new Client.Hubs.HubConnection("http://foo/");
var connection2 = new Client.Hubs.HubConnection("http://foo/");
var wh1 = new ManualResetEventSlim(initialState: false);
var wh2 = new ManualResetEventSlim(initialState: false);
var hub1 = connection1.CreateProxy("SendToSome");
var hub2 = connection2.CreateProxy("SendToSome");
connection1.Start(host).Wait();
connection2.Start(host).Wait();
hub1.On("send", wh1.Set);
hub2.On("send", wh2.Set);
hub1.Invoke("SendToSelf").Wait();
Assert.True(wh1.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));
Assert.False(wh2.WaitHandle.WaitOne(TimeSpan.FromSeconds(5)));
connection1.Stop();
connection2.Stop();
}
示例11: SettingState
public void SettingState()
{
var host = new MemoryHost();
host.MapHubs();
var connection = new Client.Hubs.HubConnection("http://foo/");
var hub = connection.CreateProxy("demo");
connection.Start(host).Wait();
var result = hub.Invoke<string>("SetStateValue", "test").Result;
Assert.Equal("test", result);
Assert.Equal("test", hub["Company"]);
connection.Stop();
}
示例12: RejoiningGroupsOnlyReceivesGroupsBelongingToHub
public void RejoiningGroupsOnlyReceivesGroupsBelongingToHub()
{
var host = new MemoryHost();
var groupsRequestedToBeRejoined = new List<string>();
var groupsRequestedToBeRejoined2 = new List<string>();
host.DependencyResolver.Register(typeof(RejoinMultGroupHub), () => new RejoinMultGroupHub(groupsRequestedToBeRejoined));
host.DependencyResolver.Register(typeof(RejoinMultGroupHub2), () => new RejoinMultGroupHub2(groupsRequestedToBeRejoined2));
host.Configuration.KeepAlive = null;
host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
host.MapHubs();
var connection = new Client.Hubs.HubConnection("http://foo");
var proxy = connection.CreateProxy("RejoinMultGroupHub");
var proxy2 = connection.CreateProxy("RejoinMultGroupHub2");
connection.Start(host).Wait();
var user = new User { Name = "tester" };
proxy.Invoke("login", user).Wait();
proxy2.Invoke("login", user).Wait();
// Force Reconnect
Thread.Sleep(TimeSpan.FromSeconds(3));
proxy.Invoke("joinRoom", user).Wait();
proxy2.Invoke("joinRoom", user).Wait();
Thread.Sleep(TimeSpan.FromSeconds(3));
Assert.True(groupsRequestedToBeRejoined.Contains("foo"));
Assert.True(groupsRequestedToBeRejoined.Contains("tester"));
Assert.False(groupsRequestedToBeRejoined.Contains("foo2"));
Assert.False(groupsRequestedToBeRejoined.Contains("tester2"));
Assert.True(groupsRequestedToBeRejoined2.Contains("foo2"));
Assert.True(groupsRequestedToBeRejoined2.Contains("tester2"));
Assert.False(groupsRequestedToBeRejoined2.Contains("foo"));
Assert.False(groupsRequestedToBeRejoined2.Contains("tester"));
connection.Stop();
}
示例13: ReturningNullFromReconnectAccepted
public void ReturningNullFromReconnectAccepted()
{
var mockHub = new Mock<SomeHub>() { CallBase = true };
mockHub.Setup(h => h.OnReconnected()).Returns<Task>(null).Verifiable();
var host = new MemoryHost();
host.HubPipeline.EnableAutoRejoiningGroups();
host.Configuration.KeepAlive = null;
host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(1);
host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(1);
host.DependencyResolver.Register(typeof(SomeHub), () => mockHub.Object);
host.MapHubs();
var connection = new Client.Hubs.HubConnection("http://foo");
var hub = connection.CreateProxy("SomeHub");
connection.Start(host).Wait();
// Force Reconnect
Thread.Sleep(TimeSpan.FromSeconds(3));
hub.Invoke("AllFoo").Wait();
Thread.Sleep(TimeSpan.FromSeconds(3));
connection.Stop();
mockHub.Verify();
}
示例14: Overloads
public void Overloads()
{
var host = new MemoryHost();
host.MapHubs();
var connection = new Client.Hubs.HubConnection("http://foo/");
var hub = connection.CreateProxy("demo");
connection.Start(host).Wait();
hub.Invoke("Overload").Wait();
int n = hub.Invoke<int>("Overload", 1).Result;
Assert.Equal(1, n);
connection.Stop();
}
示例15: ReadingState
public void ReadingState()
{
var host = new MemoryHost();
host.MapHubs();
var connection = new Client.Hubs.HubConnection("http://foo/");
var hub = connection.CreateProxy("demo");
hub["name"] = "test";
connection.Start(host).Wait();
var result = hub.Invoke<string>("ReadStateValue").Result;
Assert.Equal("test", result);
connection.Stop();
}