From 6730bbf64a06ad38a0bcefe55a2d3b1feabfcd31 Mon Sep 17 00:00:00 2001 From: Wanpeng Li <38236089+realwanpengli@users.noreply.github.com> Date: Mon, 24 Dec 2018 15:00:59 +0800 Subject: [PATCH] Add project and interfaces for SignalR Service SDK (#289) * Add project and interfaces * Change parameter name for IUserGroupManager * Remove unnecessary interface * Remove unnecessary libraries * stage file * typo * Make it async * Change name * Modify interface for GenerateAccessToken * Remove unnecessary package * Change package name * Update sln * Change namespace * Change comment style * change using order * typo * add interface for ServiceHubContext * do not package for now * Remove take access token as input * Change name from ServiceHubContextBackend to ServiceTransportType * Only generate client access token * Make interface * Comment * COMMENT UPDATE --- AzureSignalR.sln | 9 +++++- .../IServiceHubContext.cs | 13 +++++++++ .../IServiceManager.cs | 17 +++++++++++ .../IServiceManagerBuilder.cs | 10 +++++++ .../IUserGroupManager.cs | 14 ++++++++++ .../Microsoft.Azure.SignalRService.csproj | 13 +++++++++ .../ServiceHubContext.cs | 28 +++++++++++++++++++ .../ServiceManager.cs | 23 +++++++++++++++ .../ServiceManagerBuilder.cs | 26 +++++++++++++++++ .../ServiceManagerOptions.cs | 10 +++++++ .../ServiceTransportType.cs | 11 ++++++++ 11 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.Azure.SignalRService/IServiceHubContext.cs create mode 100644 src/Microsoft.Azure.SignalRService/IServiceManager.cs create mode 100644 src/Microsoft.Azure.SignalRService/IServiceManagerBuilder.cs create mode 100644 src/Microsoft.Azure.SignalRService/IUserGroupManager.cs create mode 100644 src/Microsoft.Azure.SignalRService/Microsoft.Azure.SignalRService.csproj create mode 100644 src/Microsoft.Azure.SignalRService/ServiceHubContext.cs create mode 100644 src/Microsoft.Azure.SignalRService/ServiceManager.cs create mode 100644 src/Microsoft.Azure.SignalRService/ServiceManagerBuilder.cs create mode 100644 src/Microsoft.Azure.SignalRService/ServiceManagerOptions.cs create mode 100644 src/Microsoft.Azure.SignalRService/ServiceTransportType.cs diff --git a/AzureSignalR.sln b/AzureSignalR.sln index ee6af7cc8..6660b1d40 100644 --- a/AzureSignalR.sln +++ b/AzureSignalR.sln @@ -48,7 +48,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.ChatSample.SelfHostS EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.ChatSample.CSharpClient", "samples\AspNet.ChatSample\AspNet.ChatSample.CSharpClient\AspNet.ChatSample.CSharpClient.csproj", "{38522915-6EA5-4F1D-B6EC-7FE4B178F579}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNet.ChatSample.JavaScriptClient", "samples\AspNet.ChatSample\AspNet.ChatSample.JavaScriptClient\AspNet.ChatSample.JavaScriptClient.csproj", "{5C5D6C13-61BA-48B8-803A-E6A03D31499E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.ChatSample.JavaScriptClient", "samples\AspNet.ChatSample\AspNet.ChatSample.JavaScriptClient\AspNet.ChatSample.JavaScriptClient.csproj", "{5C5D6C13-61BA-48B8-803A-E6A03D31499E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.SignalRService", "src\Microsoft.Azure.SignalRService\Microsoft.Azure.SignalRService.csproj", "{46D902F1-555F-4D82-8D2A-332AA5C0D287}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -104,6 +106,10 @@ Global {5C5D6C13-61BA-48B8-803A-E6A03D31499E}.Debug|Any CPU.Build.0 = Debug|Any CPU {5C5D6C13-61BA-48B8-803A-E6A03D31499E}.Release|Any CPU.ActiveCfg = Release|Any CPU {5C5D6C13-61BA-48B8-803A-E6A03D31499E}.Release|Any CPU.Build.0 = Release|Any CPU + {46D902F1-555F-4D82-8D2A-332AA5C0D287}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46D902F1-555F-4D82-8D2A-332AA5C0D287}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46D902F1-555F-4D82-8D2A-332AA5C0D287}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46D902F1-555F-4D82-8D2A-332AA5C0D287}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -122,6 +128,7 @@ Global {CA7F8B59-F1DA-400C-A114-467664C715ED} = {6E50C30D-3ECB-4C66-A579-2528C56924BB} {38522915-6EA5-4F1D-B6EC-7FE4B178F579} = {6E50C30D-3ECB-4C66-A579-2528C56924BB} {5C5D6C13-61BA-48B8-803A-E6A03D31499E} = {6E50C30D-3ECB-4C66-A579-2528C56924BB} + {46D902F1-555F-4D82-8D2A-332AA5C0D287} = {DA69F624-5398-4884-87E4-B816698CDE65} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7945A4E4-ACDB-4F6E-95CA-6AC6E7C2CD59} diff --git a/src/Microsoft.Azure.SignalRService/IServiceHubContext.cs b/src/Microsoft.Azure.SignalRService/IServiceHubContext.cs new file mode 100644 index 000000000..e48231c4a --- /dev/null +++ b/src/Microsoft.Azure.SignalRService/IServiceHubContext.cs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.AspNetCore.SignalR; + +namespace Microsoft.Azure.SignalRService +{ + public interface IServiceHubContext: IDisposable, IHubContext + { + IUserGroupManager UserGroups { get; } + } +} diff --git a/src/Microsoft.Azure.SignalRService/IServiceManager.cs b/src/Microsoft.Azure.SignalRService/IServiceManager.cs new file mode 100644 index 000000000..9383e7954 --- /dev/null +++ b/src/Microsoft.Azure.SignalRService/IServiceManager.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.Security.Claims; +using System.Threading.Tasks; + +namespace Microsoft.Azure.SignalRService +{ + public interface IServiceManager + { + Task CreateHubContextAsync(string hubName); + + string GenerateClientAccessToken(IList claims, TimeSpan? lifeTime = null); + } +} diff --git a/src/Microsoft.Azure.SignalRService/IServiceManagerBuilder.cs b/src/Microsoft.Azure.SignalRService/IServiceManagerBuilder.cs new file mode 100644 index 000000000..773abdfec --- /dev/null +++ b/src/Microsoft.Azure.SignalRService/IServiceManagerBuilder.cs @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.Azure.SignalRService +{ + public interface IServiceManagerBuilder + { + IServiceManager Build(); + } +} diff --git a/src/Microsoft.Azure.SignalRService/IUserGroupManager.cs b/src/Microsoft.Azure.SignalRService/IUserGroupManager.cs new file mode 100644 index 000000000..b1e0c0397 --- /dev/null +++ b/src/Microsoft.Azure.SignalRService/IUserGroupManager.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.Azure.SignalRService +{ + public interface IUserGroupManager + { + Task AddToGroupAsync(string userId, string groupName, CancellationToken cancellationToken = default); + Task RemoveFromGroupAsync(string userId, string groupName, CancellationToken cancellationToken = default); + } +} \ No newline at end of file diff --git a/src/Microsoft.Azure.SignalRService/Microsoft.Azure.SignalRService.csproj b/src/Microsoft.Azure.SignalRService/Microsoft.Azure.SignalRService.csproj new file mode 100644 index 000000000..b5cfcedfa --- /dev/null +++ b/src/Microsoft.Azure.SignalRService/Microsoft.Azure.SignalRService.csproj @@ -0,0 +1,13 @@ + + + + netstandard2.0 + + false + + + + + + + diff --git a/src/Microsoft.Azure.SignalRService/ServiceHubContext.cs b/src/Microsoft.Azure.SignalRService/ServiceHubContext.cs new file mode 100644 index 000000000..2224c4691 --- /dev/null +++ b/src/Microsoft.Azure.SignalRService/ServiceHubContext.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.SignalR; + +namespace Microsoft.Azure.SignalRService +{ + internal class ServiceHubContext : IServiceHubContext + { + public IUserGroupManager UserGroups => throw new NotImplementedException(); + + public IHubClients Clients => throw new NotImplementedException(); + + public IGroupManager Groups => throw new NotImplementedException(); + + public void Dispose() + { + throw new NotImplementedException(); + } + + public Task DisposeAsync() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Microsoft.Azure.SignalRService/ServiceManager.cs b/src/Microsoft.Azure.SignalRService/ServiceManager.cs new file mode 100644 index 000000000..b2416d1e4 --- /dev/null +++ b/src/Microsoft.Azure.SignalRService/ServiceManager.cs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.Security.Claims; +using System.Threading.Tasks; + +namespace Microsoft.Azure.SignalRService +{ + public class ServiceManager : IServiceManager + { + public Task CreateHubContextAsync(string hubName) + { + throw new NotImplementedException(); + } + + public string GenerateClientAccessToken(IList claims, TimeSpan? lifeTime = null) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Microsoft.Azure.SignalRService/ServiceManagerBuilder.cs b/src/Microsoft.Azure.SignalRService/ServiceManagerBuilder.cs new file mode 100644 index 000000000..5c6cfb70e --- /dev/null +++ b/src/Microsoft.Azure.SignalRService/ServiceManagerBuilder.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; + +namespace Microsoft.Azure.SignalRService +{ + public class ServiceManagerBuilder : IServiceManagerBuilder + { + public ServiceManagerBuilder WithCredentials(string connectionString) + { + throw new NotImplementedException(); + } + + public ServiceManagerBuilder WithOptions(Action options) + { + throw new NotImplementedException(); + } + + public IServiceManager Build() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Microsoft.Azure.SignalRService/ServiceManagerOptions.cs b/src/Microsoft.Azure.SignalRService/ServiceManagerOptions.cs new file mode 100644 index 000000000..4eab2ae4a --- /dev/null +++ b/src/Microsoft.Azure.SignalRService/ServiceManagerOptions.cs @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.Azure.SignalRService +{ + public class ServiceManagerOptions + { + public ServiceTransportType ServiceTransportType { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.Azure.SignalRService/ServiceTransportType.cs b/src/Microsoft.Azure.SignalRService/ServiceTransportType.cs new file mode 100644 index 000000000..453b1324f --- /dev/null +++ b/src/Microsoft.Azure.SignalRService/ServiceTransportType.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.Azure.SignalRService +{ + public enum ServiceTransportType + { + Transient, + Persistent + } +} \ No newline at end of file