本文整理汇总了C#中HubConfiguration类的典型用法代码示例。如果您正苦于以下问题:C# HubConfiguration类的具体用法?C# HubConfiguration怎么用?C# HubConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HubConfiguration类属于命名空间,在下文中一共展示了HubConfiguration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SendToGroupFromOutsideOfHub
public async Task SendToGroupFromOutsideOfHub()
{
using (var host = new MemoryHost())
{
IHubContext<IBasicClient> hubContext = null;
host.Configure(app =>
{
var configuration = new HubConfiguration
{
Resolver = new DefaultDependencyResolver()
};
app.MapSignalR(configuration);
hubContext = configuration.Resolver.Resolve<IConnectionManager>().GetHubContext<SendToSome, IBasicClient>();
});
var connection1 = new HubConnection("http://foo/");
using (connection1)
{
var wh1 = new AsyncManualResetEvent(initialState: false);
var hub1 = connection1.CreateHubProxy("SendToSome");
await connection1.Start(host);
hub1.On("send", wh1.Set);
hubContext.Groups.Add(connection1.ConnectionId, "Foo").Wait();
hubContext.Clients.Group("Foo").send();
Assert.True(await wh1.WaitAsync(TimeSpan.FromSeconds(10)));
}
}
}
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:35,代码来源:GetHubContextFacts.cs
示例2: AuthenticatedUserCanReceiveHubMessagesByDefault
public async Task AuthenticatedUserCanReceiveHubMessagesByDefault()
{
using (var host = new MemoryHost())
{
host.Configure(app =>
{
var configuration = new HubConfiguration
{
Resolver = new DefaultDependencyResolver()
};
WithUser(app, new GenericPrincipal(new GenericIdentity("test"), new string[] { }));
app.MapSignalR("/signalr", configuration);
});
var connection = CreateHubConnection("http://foo/");
using (connection)
{
var hub = connection.CreateHubProxy("NoAuthHub");
var wh = new ManualResetEvent(false);
hub.On<string, string, object>("joined", (id, time, authInfo) =>
{
Assert.NotNull(id);
wh.Set();
});
await connection.Start(host);
Assert.True(wh.WaitOne(TimeSpan.FromSeconds(3)));
}
}
}
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:34,代码来源:HubAuthFacts.cs
示例3: AuthenticatedAndAuthorizedUserCanInvokeMethodsInHubsAuthorizedSpecifyingUserAndRole
public void AuthenticatedAndAuthorizedUserCanInvokeMethodsInHubsAuthorizedSpecifyingUserAndRole()
{
using (var host = new MemoryHost())
{
host.Configure(app =>
{
var configuration = new HubConfiguration
{
Resolver = new DefaultDependencyResolver()
};
WithUser(app, new GenericPrincipal(new GenericIdentity("User"), new string[] { "Admin" }));
app.MapHubs("/signalr", configuration);
});
var connection = CreateHubConnection("http://foo/");
var hub = connection.CreateHubProxy("UserAndRoleAuthHub");
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();
}
}
开发者ID:hallco978,项目名称:SignalR,代码行数:33,代码来源:HubAuthFacts.cs
示例4: StressGroups
public static IDisposable StressGroups(int max = 100)
{
var host = new MemoryHost();
host.Configure(app =>
{
var config = new HubConfiguration()
{
Resolver = new DefaultDependencyResolver()
};
app.MapSignalR(config);
var configuration = config.Resolver.Resolve<IConfigurationManager>();
// The below effectively sets the heartbeat interval to five seconds.
configuration.KeepAlive = TimeSpan.FromSeconds(10);
});
var countDown = new CountDownRange<int>(Enumerable.Range(0, max));
var connection = new HubConnection("http://foo");
var proxy = connection.CreateHubProxy("HubWithGroups");
proxy.On<int>("Do", i =>
{
if (!countDown.Mark(i))
{
Debugger.Break();
}
});
try
{
connection.Start(new Client.Transports.LongPollingTransport(host)).Wait();
proxy.Invoke("Join", "foo").Wait();
for (int i = 0; i < max; i++)
{
proxy.Invoke("Send", "foo", i).Wait();
}
proxy.Invoke("Leave", "foo").Wait();
for (int i = max + 1; i < max + 50; i++)
{
proxy.Invoke("Send", "foo", i).Wait();
}
if (!countDown.Wait(TimeSpan.FromSeconds(10)))
{
Console.WriteLine("Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed " + String.Join(",", countDown.Left.Select(i => i.ToString())));
Debugger.Break();
}
}
finally
{
connection.Stop();
}
return host;
}
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:60,代码来源:StressRuns.cs
示例5: Configuration
public void Configuration(IAppBuilder app)
{
app.MapSignalR<SendingConnection>("/sending-connection");
app.MapSignalR<TestConnection>("/test-connection");
app.MapSignalR<RawConnection>("/raw-connection");
app.MapSignalR<StreamingConnection>("/streaming-connection");
app.Use(typeof(ClaimsMiddleware));
ConfigureSignalR(GlobalHost.DependencyResolver, GlobalHost.HubPipeline);
var config = new HubConfiguration()
{
EnableDetailedErrors = true
};
app.MapSignalR(config);
app.Map("/cors", map =>
{
map.UseCors(CorsOptions.AllowAll);
map.MapSignalR<RawConnection>("/raw-connection");
map.MapSignalR();
});
app.Map("/basicauth", map =>
{
map.UseBasicAuthentication(new BasicAuthenticationProvider());
map.MapSignalR<AuthenticatedEchoConnection>("/echo");
map.MapSignalR();
});
BackgroundThread.Start();
}
开发者ID:nirmana,项目名称:SignalR,代码行数:34,代码来源:Startup.cs
示例6: BrodcastFromServer
public static IDisposable BrodcastFromServer()
{
var host = new MemoryHost();
IHubContext context = null;
host.Configure(app =>
{
var config = new HubConfiguration()
{
Resolver = new DefaultDependencyResolver()
};
app.MapHubs(config);
var configuration = config.Resolver.Resolve<IConfigurationManager>();
// The below effectively sets the heartbeat interval to five seconds.
configuration.KeepAlive = TimeSpan.FromSeconds(10);
var connectionManager = config.Resolver.Resolve<IConnectionManager>();
context = connectionManager.GetHubContext("EchoHub");
});
var cancellationTokenSource = new CancellationTokenSource();
var thread = new Thread(() =>
{
while (!cancellationTokenSource.IsCancellationRequested)
{
context.Clients.All.echo();
}
});
thread.Start();
var connection = new Client.Hubs.HubConnection("http://foo");
var proxy = connection.CreateHubProxy("EchoHub");
try
{
connection.Start(host).Wait();
Thread.Sleep(1000);
}
finally
{
connection.Stop();
}
return new DisposableAction(() =>
{
cancellationTokenSource.Cancel();
thread.Join();
host.Dispose();
});
}
开发者ID:armandoramirezdino,项目名称:SignalR,代码行数:57,代码来源:StressRuns.cs
示例7: ConfigureApp
protected override void ConfigureApp(IAppBuilder app)
{
var config = new HubConfiguration
{
Resolver = Resolver
};
app.MapHubs(config);
config.Resolver.Register(typeof(IProtectedData), () => new EmptyProtectedData());
}
开发者ID:hallco978,项目名称:SignalR,代码行数:11,代码来源:MemoryHostHubInvocationRun.cs
示例8: GroupsWorkAfterServerRestart
public async Task GroupsWorkAfterServerRestart()
{
var host = new ServerRestarter(app =>
{
var config = new HubConfiguration
{
Resolver = new DefaultDependencyResolver()
};
app.MapSignalR(config);
});
using (host)
{
using (var connection = CreateHubConnection("http://foo/"))
{
var reconnectedEvent = new AsyncManualResetEvent();
connection.Reconnected += reconnectedEvent.Set;
var hubProxy = connection.CreateHubProxy("groupChat");
var sendEvent = new AsyncManualResetEvent();
string sendMessage = null;
hubProxy.On<string>("send", message =>
{
sendMessage = message;
sendEvent.Set();
});
var groupName = "group$&+,/:;[email protected][]1";
var groupMessage = "hello";
// MemoryHost doesn't support WebSockets, and it is difficult to ensure that
// the reconnected event is reliably fired with the LongPollingTransport.
await connection.Start(new ServerSentEventsTransport(host));
await hubProxy.Invoke("Join", groupName);
host.Restart();
Assert.True(await reconnectedEvent.WaitAsync(TimeSpan.FromSeconds(15)), "Timed out waiting for client side reconnect.");
await hubProxy.Invoke("Send", groupName, groupMessage);
Assert.True(await sendEvent.WaitAsync(TimeSpan.FromSeconds(15)), "Timed out waiting for message.");
Assert.Equal(groupMessage, sendMessage);
}
}
}
开发者ID:ZixiangBoy,项目名称:SignalR-1,代码行数:48,代码来源:ReconnectFacts.cs
示例9: DisconnectFiresForHubsWhenConnectionGoesAway
public void DisconnectFiresForHubsWhenConnectionGoesAway()
{
using (var host = new MemoryHost())
{
var dr = new DefaultDependencyResolver();
var configuration = dr.Resolve<IConfigurationManager>();
var connectWh = new ManualResetEventSlim();
var disconnectWh = new ManualResetEventSlim();
host.Configure(app =>
{
var config = new HubConfiguration
{
Resolver = dr
};
app.MapHubs("/signalr", config);
configuration.DisconnectTimeout = TimeSpan.Zero;
configuration.HeartbeatInterval = TimeSpan.FromSeconds(5);
dr.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(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");
}
}
开发者ID:Jozef89,项目名称:SignalR,代码行数:39,代码来源:DisconnectFacts.cs
示例10: UnauthorizedUserCannotReceiveHubMessagesFromHubsAuthorizedWithRoles
public void UnauthorizedUserCannotReceiveHubMessagesFromHubsAuthorizedWithRoles()
{
using (var host = new MemoryHost())
{
host.Configure(app =>
{
var configuration = new HubConfiguration
{
Resolver = new DefaultDependencyResolver()
};
WithUser(app, new GenericPrincipal(new GenericIdentity("test"), new string[] { "User", "NotAdmin" }));
app.MapSignalR("/signalr", configuration);
});
var connection = CreateHubConnection("http://foo/");
using (connection)
{
var hub = connection.CreateHubProxy("AdminAuthHub");
var wh = new ManualResetEvent(false);
hub.On<string, string, object>("joined", (id, time, authInfo) =>
{
Assert.NotNull(id);
wh.Set();
});
Assert.Throws<AggregateException>(() => connection.Start(host).Wait());
}
}
}
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:31,代码来源:HubAuthFacts.cs
示例11: UnauthenticatedUserCanReceiveHubMessagesFromIncomingAuthorizedHubs
public void UnauthenticatedUserCanReceiveHubMessagesFromIncomingAuthorizedHubs()
{
using (var host = new MemoryHost())
{
host.Configure(app =>
{
var configuration = new HubConfiguration
{
Resolver = new DefaultDependencyResolver()
};
WithUser(app, new GenericPrincipal(new GenericIdentity(""), new string[] { "User", "NotAdmin" }));
app.MapHubs("/signalr", configuration);
});
var connection = CreateHubConnection("http://foo/");
var hub = connection.CreateHubProxy("IncomingAuthHub");
var wh = new ManualResetEvent(false);
hub.On<string, string, object>("joined", (id, time, authInfo) =>
{
Assert.NotNull(id);
wh.Set();
});
connection.Start(host).Wait();
Assert.True(wh.WaitOne(TimeSpan.FromSeconds(3)));
connection.Stop();
}
}
开发者ID:hallco978,项目名称:SignalR,代码行数:31,代码来源:HubAuthFacts.cs
示例12: AuthenticatedUserCanInvokeMethodsWhenAuthenticationRequiredGlobally
public async Task AuthenticatedUserCanInvokeMethodsWhenAuthenticationRequiredGlobally()
{
using (var host = new MemoryHost())
{
host.Configure(app =>
{
var configuration = new HubConfiguration
{
Resolver = new DefaultDependencyResolver()
};
configuration.Resolver.Resolve<IHubPipeline>().RequireAuthentication();
WithUser(app, new GenericPrincipal(new GenericIdentity("test"), new string[] { }));
app.MapSignalR("/signalr", configuration);
});
var connection = CreateHubConnection("http://foo/");
using (connection)
{
var hub = connection.CreateHubProxy("NoAuthHub");
var wh = new ManualResetEvent(false);
hub.On<string, string>("invoked", (id, time) =>
{
Assert.NotNull(id);
wh.Set();
});
await connection.Start(host);
hub.InvokeWithTimeout("InvokedFromClient");
Assert.True(wh.WaitOne(TimeSpan.FromSeconds(3)));
}
}
}
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:37,代码来源:HubAuthFacts.cs
示例13: UnauthenticatedUserCannotInvokeMethodsWhenAuthenticationRequiredGlobally
public void UnauthenticatedUserCannotInvokeMethodsWhenAuthenticationRequiredGlobally()
{
using (var host = new MemoryHost())
{
host.Configure(app =>
{
var configuration = new HubConfiguration
{
Resolver = new DefaultDependencyResolver()
};
configuration.Resolver.Resolve<IHubPipeline>().RequireAuthentication();
WithUser(app, new GenericPrincipal(new GenericIdentity(""), new string[] { }));
app.MapSignalR("/signalr", configuration);
});
var connection = CreateHubConnection("http://foo/");
using (connection)
{
var hub = connection.CreateHubProxy("NoAuthHub");
var wh = new ManualResetEvent(false);
hub.On<string, string>("invoked", (id, time) =>
{
Assert.NotNull(id);
wh.Set();
});
Assert.Throws<AggregateException>(() => connection.Start(host).Wait());
}
}
}
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:33,代码来源:HubAuthFacts.cs
示例14: JoiningGroupMultipleTimesGetsMessageOnce
public void JoiningGroupMultipleTimesGetsMessageOnce(MessageBusType messagebusType)
{
using (var host = new MemoryHost())
{
host.Configure(app =>
{
var config = new HubConfiguration
{
Resolver = new DefaultDependencyResolver()
};
UseMessageBus(messagebusType, config.Resolver);
app.MapHubs(config);
});
var connection = new HubConnection("http://foo");
var hub = connection.CreateHubProxy("SendToSome");
int invocations = 0;
connection.Start(host).Wait();
hub.On("send", () =>
{
invocations++;
});
// Join the group multiple times
hub.InvokeWithTimeout("JoinGroup", "a");
hub.InvokeWithTimeout("JoinGroup", "a");
hub.InvokeWithTimeout("JoinGroup", "a");
hub.InvokeWithTimeout("SendToGroup", "a");
Thread.Sleep(TimeSpan.FromSeconds(3));
Assert.Equal(1, invocations);
connection.Stop();
}
}
开发者ID:hallco978,项目名称:SignalR,代码行数:41,代码来源:HubFacts.cs
示例15: HubDispatcherHandler
public HubDispatcherHandler(AppFunc next, string path, HubConfiguration configuration)
{
_next = next;
_path = path;
_configuration = configuration;
}
开发者ID:Djohnnie,项目名称:Sonarr,代码行数:6,代码来源:HubDispatcherHandler.cs
示例16: ChangeHubUrl
public void ChangeHubUrl()
{
using (var host = new MemoryHost())
{
host.Configure(app =>
{
var config = new HubConfiguration()
{
Resolver = new DefaultDependencyResolver()
};
app.MapHubs("/foo", config);
});
var connection = new Client.Hubs.HubConnection("http://site/foo", useDefaultUrl: false, queryString: new Dictionary<string, string> { { "test", "ChangeHubUrl" } });
var hub = connection.CreateHubProxy("demo");
var wh = new ManualResetEventSlim(false);
hub.On("signal", id =>
{
Assert.NotNull(id);
wh.Set();
});
connection.Start(host).Wait();
hub.InvokeWithTimeout("DynamicTask");
Assert.True(wh.Wait(TimeSpan.FromSeconds(10)));
connection.Stop();
}
}
开发者ID:hallco978,项目名称:SignalR,代码行数:34,代码来源:HubFacts.cs
示例17: ManyUniqueGroups
public static IDisposable ManyUniqueGroups(int concurrency)
{
var host = new MemoryHost();
var threads = new List<Thread>();
var cancellationTokenSource = new CancellationTokenSource();
host.Configure(app =>
{
var config = new HubConfiguration()
{
Resolver = new DefaultDependencyResolver()
};
app.MapHubs(config);
});
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();
});
}
开发者ID:armandoramirezdino,项目名称:SignalR,代码行数:38,代码来源:StressRuns.cs
示例18: ConfigureRoutes
public static void ConfigureRoutes(IAppBuilder app, IDependencyResolver resolver)
{
var hubConfig = new HubConfiguration
{
Resolver = resolver,
EnableDetailedErrors = true
};
app.MapSignalR(hubConfig);
app.MapSignalR("/signalr2/test", new HubConfiguration()
{
Resolver = resolver
});
var config = new ConnectionConfiguration
{
Resolver = resolver
};
app.Map("/multisend", map =>
{
map.UseCors(CorsOptions.AllowAll);
map.RunSignalR<MySendingConnection>(config);
});
app.Map("/autoencodedjson", map =>
{
map.UseCors(CorsOptions.AllowAll);
map.RunSignalR<EchoConnection>(config);
});
app.Map("/redirectionConnection", map =>
{
map.UseCors(CorsOptions.AllowAll);
map.RunSignalR<RedirectionConnection>(config);
});
app.Map("/statusCodeConnection", map =>
{
map.UseCors(CorsOptions.AllowAll);
map.RunSignalR<StatusCodeConnection>(config);
});
app.Map("/jsonp", map =>
{
var jsonpConfig = new ConnectionConfiguration
{
Resolver = resolver,
EnableJSONP = true
};
map.MapSignalR<EchoConnection>("/echo", jsonpConfig);
var jsonpHubsConfig = new HubConfiguration
{
Resolver = resolver,
EnableJSONP = true
};
map.MapSignalR(jsonpHubsConfig);
});
app.MapSignalR<MyBadConnection>("/ErrorsAreFun", config);
app.MapSignalR<MyGroupEchoConnection>("/group-echo", config);
app.MapSignalR<MyReconnect>("/my-reconnect", config);
app.MapSignalR<ExamineHeadersConnection>("/examine-request", config);
app.MapSignalR<ExamineReconnectPath>("/examine-reconnect", config);
app.MapSignalR<MyGroupConnection>("/groups", config);
app.MapSignalR<MyRejoinGroupsConnection>("/rejoin-groups", config);
app.MapSignalR<BroadcastConnection>("/filter", config);
app.MapSignalR<ConnectionThatUsesItems>("/items", config);
app.MapSignalR<SyncErrorConnection>("/sync-error", config);
app.MapSignalR<AddGroupOnConnectedConnection>("/add-group", config);
app.MapSignalR<UnusableProtectedConnection>("/protected", config);
app.MapSignalR<FallbackToLongPollingConnection>("/fall-back", config);
app.MapSignalR<FallbackToLongPollingConnectionThrows>("/fall-back-throws", config);
app.MapSignalR<PreserializedJsonConnection>("/preserialize", config);
// This subpipeline is protected by basic auth
app.Map("/basicauth", map =>
{
map.UseBasicAuthentication(new BasicAuthenticationProvider());
var subConfig = new ConnectionConfiguration
{
Resolver = resolver
};
map.MapSignalR<AuthenticatedEchoConnection>("/echo", subConfig);
var subHubsConfig = new HubConfiguration
{
Resolver = resolver
};
map.MapSignalR(subHubsConfig);
});
app.Map("/force-lp-reconnect", map =>
//.........这里部分代码省略.........
开发者ID:nirmana,项目名称:SignalR,代码行数:101,代码来源:Initializer.cs
示例19: DisconnectFiresForHubsWhenClientCallsStop
public async Task DisconnectFiresForHubsWhenClientCallsStop()
{
using (var host = new MemoryHost())
{
var dr = new DefaultDependencyResolver();
var configuration = dr.Resolve<IConfigurationManager>();
var connectWh = new AsyncManualResetEvent();
var disconnectWh = new AsyncManualResetEvent();
host.Configure(app =>
{
var config = new HubConfiguration
{
Resolver = dr
};
app.MapSignalR("/signalr", config);
configuration.DisconnectTimeout = TimeSpan.FromSeconds(6);
dr.Register(typeof(MyHub), () => new MyHub(connectWh, disconnectWh));
});
var connection = new HubConnection("http://foo/");
connection.CreateHubProxy("MyHub");
// Maximum wait time for disconnect to fire (3 heart beat intervals)
var disconnectWait = TimeSpan.FromTicks(configuration.HeartbeatInterval().Ticks * 3);
await connection.Start(host);
Assert.True(await connectWh.WaitAsync(TimeSpan.FromSeconds(10)), "Connect never fired");
connection.Stop();
Assert.True(await disconnectWh.WaitAsync(disconnectWait), "Disconnect never fired");
}
}
开发者ID:kietnha,项目名称:SignalR,代码行数:38,代码来源:DisconnectFacts.cs
示例20: ConfigureSignalR
public static void ConfigureSignalR(IAppBuilder app, HubConfiguration config)
{
//Changed this method to accept a HubConfiguration parameter
//and pass it off to the MapSignalR method
app.MapSignalR(config);
}
开发者ID:jerodkrone,项目名称:SignalRStructureMapWalkthrough,代码行数:6,代码来源:Startup.cs
注:本文中的HubConfiguration类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论