-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65f194c
commit d4eee47
Showing
9 changed files
with
185 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace Microsoft.Azure.SignalR | ||
{ | ||
public class GracefulShutdownOptions | ||
{ | ||
/// <summary> | ||
/// Specifies the timeout of a graceful shutdown process (in seconds). | ||
/// Default value is 30 seconds. | ||
/// </summary> | ||
public TimeSpan Timeout { get; set; } = Constants.Periods.DefaultShutdownTimeout; | ||
private readonly Dictionary<string, List<object>> _dict = new Dictionary<string, List<object>>(); | ||
|
||
/// <summary> | ||
/// Specifies if the client-connection assigned to this server can be migrated to another server. | ||
/// Default value is 0. | ||
/// 1: Migrate client-connection if the server was shutdown gracefully. | ||
/// </summary> | ||
public GracefulShutdownMode Mode { get; set; } = GracefulShutdownMode.Off; | ||
|
||
/// <summary> | ||
/// Specifies the timeout of a graceful shutdown process (in seconds). | ||
/// Default value is 30 seconds. | ||
/// </summary> | ||
public TimeSpan Timeout { get; set; } = Constants.Periods.DefaultShutdownTimeout; | ||
|
||
public void Add<THub>(Func<IHubContext<THub>, Task> func) where THub : Hub | ||
{ | ||
AddMethod<THub>(func); | ||
} | ||
|
||
public void Add<THub>(Action<IHubContext<THub>> action) where THub : Hub | ||
{ | ||
AddMethod<THub>(action); | ||
} | ||
|
||
public void Add<THub>(Func<Task> func) | ||
{ | ||
AddMethod<THub>(func); | ||
} | ||
|
||
public void Add<THub>(Action action) | ||
{ | ||
AddMethod<THub>(action); | ||
} | ||
|
||
internal async Task OnShutdown<THub>(IHubContext<THub> context) where THub : Hub | ||
{ | ||
var name = typeof(THub).Name; | ||
if (_dict.TryGetValue(name, out var methods)) | ||
{ | ||
foreach (var method in methods) | ||
{ | ||
if (method is Action<IHubContext<THub>> action) | ||
{ | ||
action(context); | ||
} | ||
else if (method is Action action2) | ||
{ | ||
action2(); | ||
} | ||
else if (method is Func<IHubContext<THub>, Task> func) | ||
{ | ||
await func(context); | ||
} | ||
else if (method is Func<Task> func2) | ||
{ | ||
await func2(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void AddMethod<THub>(object method) | ||
{ | ||
if (method == null) | ||
{ | ||
return; | ||
} | ||
|
||
var name = typeof(THub).Name; | ||
if (_dict.TryGetValue(name, out var list)) | ||
{ | ||
list.Add(method); | ||
} | ||
else | ||
{ | ||
_dict.Add(name, new List<object>() { method }); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/Microsoft.Azure.SignalR/ServerConnections/ServiceConnectionManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace Microsoft.Azure.SignalR.Tests | ||
{ | ||
internal sealed class TestHubContext<THub> : IHubContext<THub> where THub : Hub | ||
{ | ||
public IHubClients Clients => throw new NotImplementedException(); | ||
|
||
public IGroupManager Groups => throw new NotImplementedException(); | ||
|
||
public static TestHubContext<THub> GetInstance() | ||
{ | ||
return new TestHubContext<THub>(); | ||
} | ||
} | ||
} |