├── .gitignore ├── LICENSE ├── README.md ├── assets └── icon │ └── rx.png ├── nuget └── pack.bat └── src ├── .editorconfig ├── ReactiveSignalR.sln └── ReactiveSignalR ├── HubConnectionExtensions.cs └── ReactiveSignalR.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Takaaki Suzuki 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ReactiveSignalR 2 | 3 | ReactiveSignalR provides reactive programming for ASP.NET Core SignalR client application (*NOT* supports ASP.NET SignalR). 4 | 5 | 6 | 7 | ## Feature 8 | 9 | - Provides `HubConnection.On` method as `IObservable` 10 | - Provides `HubConnection` event as `IObservable` 11 | 12 | 13 | 14 | ## How to use 15 | 16 | ```cs 17 | //--- Create connection 18 | var url = "http://localhost:5000/chathub"; 19 | var connection = new HubConnectionBuilder().WithUrl(url).Build(); 20 | 21 | //--- Fluently coding using Rx 22 | var subscription 23 | = connection 24 | .On("Receive") // ReactiveSignalR provides this line 25 | .Subscribe(message => /* do something */); 26 | 27 | //--- Unsubscribe 28 | subscription.Dispose(); 29 | ``` 30 | 31 | 32 | ## Installation 33 | Getting started from downloading NuGet package. 34 | 35 | ```text 36 | PM> Install-Package ReactiveSignalR 37 | ``` 38 | 39 | 40 | ## License 41 | 42 | This library is provided under [MIT License](http://opensource.org/licenses/MIT). 43 | 44 | 45 | ## Author 46 | 47 | Takaaki Suzuki (a.k.a [@xin9le](https://twitter.com/xin9le)) is software developer in Japan who awarded Microsoft MVP for Developer Technologies (C#) since July 2012. -------------------------------------------------------------------------------- /assets/icon/rx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xin9le/ReactiveSignalR/4952249c4ad7bbc2db14b3174e3afc7d77027e9e/assets/icon/rx.png -------------------------------------------------------------------------------- /nuget/pack.bat: -------------------------------------------------------------------------------- 1 | dotnet pack ../src/ReactiveSignalR/ReactiveSignalR.csproj -c Release -o ./packages -------------------------------------------------------------------------------- /src/.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig style reference 2 | # https://docs.microsoft.com/ja-jp/visualstudio/ide/editorconfig-code-style-settings-reference 3 | 4 | 5 | 6 | # top-most EditorConfig file 7 | root = true 8 | 9 | # Don't use tabs for indentation. 10 | [*] 11 | indent_style = space 12 | end_of_line = crlf 13 | # (Please don't specify an indent_size here; that has too many unintended consequences.) 14 | 15 | # Code files 16 | [*.{cs,csx,vb,vbx,ts,js,css,less}] 17 | indent_size = 4 18 | insert_final_newline = true 19 | charset = utf-8-bom 20 | 21 | # Xml project files 22 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] 23 | indent_size = 4 24 | 25 | # Xml config files 26 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] 27 | indent_size = 4 28 | 29 | # JSON files 30 | [*.json] 31 | indent_size = 4 32 | 33 | # CSharp 34 | [*.cs] 35 | dotnet_sort_system_directives_first = true 36 | dotnet_style_qualification_for_field = true 37 | dotnet_style_qualification_for_property = true 38 | dotnet_style_qualification_for_method = true 39 | dotnet_style_qualification_for_event = true 40 | 41 | csharp_style_deconstructed_variable_declaration = false:none 42 | csharp_style_pattern_matching_over_as_with_null_check = false:none 43 | -------------------------------------------------------------------------------- /src/ReactiveSignalR.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29001.49 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveSignalR", "ReactiveSignalR\ReactiveSignalR.csproj", "{26EB156E-CAED-45EA-A1E7-A4C999D9F4C2}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{D70E7405-ECEE-4BDC-BBF7-DDD0918A1141}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Config", "Config", "{15B4169C-BC87-403B-94A7-E27240556F6A}" 11 | ProjectSection(SolutionItems) = preProject 12 | .editorconfig = .editorconfig 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {26EB156E-CAED-45EA-A1E7-A4C999D9F4C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {26EB156E-CAED-45EA-A1E7-A4C999D9F4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {26EB156E-CAED-45EA-A1E7-A4C999D9F4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {26EB156E-CAED-45EA-A1E7-A4C999D9F4C2}.Release|Any CPU.Build.0 = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(SolutionProperties) = preSolution 27 | HideSolutionNode = FALSE 28 | EndGlobalSection 29 | GlobalSection(NestedProjects) = preSolution 30 | {26EB156E-CAED-45EA-A1E7-A4C999D9F4C2} = {D70E7405-ECEE-4BDC-BBF7-DDD0918A1141} 31 | EndGlobalSection 32 | GlobalSection(ExtensibilityGlobals) = postSolution 33 | SolutionGuid = {031A0414-EAD5-45CB-A4EF-CECC2D80B9B7} 34 | EndGlobalSection 35 | EndGlobal 36 | -------------------------------------------------------------------------------- /src/ReactiveSignalR/HubConnectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reactive; 3 | using System.Reactive.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.SignalR.Client; 6 | 7 | 8 | 9 | namespace ReactiveSignalR 10 | { 11 | /// 12 | /// Provides extension methods. 13 | /// 14 | public static class HubConnectionExtensions 15 | { 16 | #region Inner classes 17 | /// 18 | /// Provides observable sequence for method. 19 | /// 20 | /// 21 | private sealed class OnObservable : ObservableBase 22 | { 23 | #region Properties 24 | private HubConnection Connection { get; } 25 | private string MethodName { get; } 26 | private Type[] ParameterTypes { get; } 27 | private Func Handler { get; } 28 | #endregion 29 | 30 | 31 | #region Constructors 32 | public OnObservable(HubConnection connection, string methodName, Type[] parameterTypes, Func handler) 33 | { 34 | this.Connection = connection; 35 | this.MethodName = methodName; 36 | this.ParameterTypes = parameterTypes; 37 | this.Handler = handler; 38 | } 39 | #endregion 40 | 41 | 42 | #region ObservableBase implementations 43 | protected override IDisposable SubscribeCore(IObserver observer) 44 | => this.Connection.On(this.MethodName, this.ParameterTypes, this.Handler, observer); 45 | #endregion 46 | } 47 | #endregion 48 | 49 | 50 | #region On as observable 51 | /// 52 | /// Gets the observable sequence that will be invoked when the hub method with the specified method name is invoked. 53 | /// 54 | /// Hub connection. 55 | /// The name of the hub method to define. 56 | /// 57 | public static IObservable On(this HubConnection connection, string methodName) 58 | { 59 | if (connection == null) throw new ArgumentNullException(nameof(connection)); 60 | if (methodName == null) throw new ArgumentNullException(nameof(methodName)); 61 | 62 | return new OnObservable 63 | ( 64 | connection, 65 | methodName, 66 | Type.EmptyTypes, 67 | (_, state) => 68 | { 69 | var observer = (IObserver)state; 70 | observer.OnNext(Unit.Default); 71 | return Task.CompletedTask; 72 | } 73 | ); 74 | } 75 | 76 | 77 | /// 78 | /// Gets the observable sequence that will be invoked when the hub method with the specified method name is invoked. 79 | /// 80 | /// 1st argument type. 81 | /// Hub connection. 82 | /// The name of the hub method to define. 83 | /// 84 | public static IObservable On(this HubConnection connection, string methodName) 85 | { 86 | if (connection == null) throw new ArgumentNullException(nameof(connection)); 87 | if (methodName == null) throw new ArgumentNullException(nameof(methodName)); 88 | 89 | return new OnObservable 90 | ( 91 | connection, 92 | methodName, 93 | new[] { typeof(T) }, 94 | (args, state) => 95 | { 96 | var observer = (IObserver)state; 97 | observer.OnNext((T)args[0]); 98 | return Task.CompletedTask; 99 | } 100 | ); 101 | } 102 | 103 | 104 | /// 105 | /// Gets the observable sequence that will be invoked when the hub method with the specified method name is invoked. 106 | /// 107 | /// 1st argument type. 108 | /// 2nd argument type. 109 | /// Hub connection. 110 | /// The name of the hub method to define. 111 | /// 112 | public static IObservable<(T1, T2)> On(this HubConnection connection, string methodName) 113 | { 114 | if (connection == null) throw new ArgumentNullException(nameof(connection)); 115 | if (methodName == null) throw new ArgumentNullException(nameof(methodName)); 116 | 117 | return new OnObservable<(T1, T2)> 118 | ( 119 | connection, 120 | methodName, 121 | new[] { typeof(T1), typeof(T2) }, 122 | (args, state) => 123 | { 124 | var observer = (IObserver<(T1, T2)>)state; 125 | var a1 = (T1)args[0]; 126 | var a2 = (T2)args[1]; 127 | observer.OnNext((a1, a2)); 128 | return Task.CompletedTask; 129 | } 130 | ); 131 | } 132 | 133 | 134 | /// 135 | /// Gets the observable sequence that will be invoked when the hub method with the specified method name is invoked. 136 | /// 137 | /// 1st argument type. 138 | /// 2nd argument type. 139 | /// 3rd argument type. 140 | /// Hub connection. 141 | /// The name of the hub method to define. 142 | /// 143 | public static IObservable<(T1, T2, T3)> On(this HubConnection connection, string methodName) 144 | { 145 | if (connection == null) throw new ArgumentNullException(nameof(connection)); 146 | if (methodName == null) throw new ArgumentNullException(nameof(methodName)); 147 | 148 | return new OnObservable<(T1, T2, T3)> 149 | ( 150 | connection, 151 | methodName, 152 | new[] { typeof(T1), typeof(T2), typeof(T3) }, 153 | (args, state) => 154 | { 155 | var observer = (IObserver<(T1, T2, T3)>)state; 156 | var a1 = (T1)args[0]; 157 | var a2 = (T2)args[1]; 158 | var a3 = (T3)args[2]; 159 | observer.OnNext((a1, a2, a3)); 160 | return Task.CompletedTask; 161 | } 162 | ); 163 | } 164 | 165 | 166 | /// 167 | /// Gets the observable sequence that will be invoked when the hub method with the specified method name is invoked. 168 | /// 169 | /// 1st argument type. 170 | /// 2nd argument type. 171 | /// 3rd argument type. 172 | /// 4th argument type. 173 | /// Hub connection. 174 | /// The name of the hub method to define. 175 | /// 176 | public static IObservable<(T1, T2, T3, T4)> On(this HubConnection connection, string methodName) 177 | { 178 | if (connection == null) throw new ArgumentNullException(nameof(connection)); 179 | if (methodName == null) throw new ArgumentNullException(nameof(methodName)); 180 | 181 | return new OnObservable<(T1, T2, T3, T4)> 182 | ( 183 | connection, 184 | methodName, 185 | new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4) }, 186 | (args, state) => 187 | { 188 | var observer = (IObserver<(T1, T2, T3, T4)>)state; 189 | var a1 = (T1)args[0]; 190 | var a2 = (T2)args[1]; 191 | var a3 = (T3)args[2]; 192 | var a4 = (T4)args[3]; 193 | observer.OnNext((a1, a2, a3, a4)); 194 | return Task.CompletedTask; 195 | } 196 | ); 197 | } 198 | 199 | 200 | /// 201 | /// Gets the observable sequence that will be invoked when the hub method with the specified method name is invoked. 202 | /// 203 | /// 1st argument type. 204 | /// 2nd argument type. 205 | /// 3rd argument type. 206 | /// 4th argument type. 207 | /// 5th argument type. 208 | /// Hub connection. 209 | /// The name of the hub method to define. 210 | /// 211 | public static IObservable<(T1, T2, T3, T4, T5)> On(this HubConnection connection, string methodName) 212 | { 213 | if (connection == null) throw new ArgumentNullException(nameof(connection)); 214 | if (methodName == null) throw new ArgumentNullException(nameof(methodName)); 215 | 216 | return new OnObservable<(T1, T2, T3, T4, T5)> 217 | ( 218 | connection, 219 | methodName, 220 | new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5) }, 221 | (args, state) => 222 | { 223 | var observer = (IObserver<(T1, T2, T3, T4, T5)>)state; 224 | var a1 = (T1)args[0]; 225 | var a2 = (T2)args[1]; 226 | var a3 = (T3)args[2]; 227 | var a4 = (T4)args[3]; 228 | var a5 = (T5)args[4]; 229 | observer.OnNext((a1, a2, a3, a4, a5)); 230 | return Task.CompletedTask; 231 | } 232 | ); 233 | } 234 | 235 | 236 | /// 237 | /// Gets the observable sequence that will be invoked when the hub method with the specified method name is invoked. 238 | /// 239 | /// 1st argument type. 240 | /// 2nd argument type. 241 | /// 3rd argument type. 242 | /// 4th argument type. 243 | /// 5th argument type. 244 | /// 6th argument type. 245 | /// Hub connection. 246 | /// The name of the hub method to define. 247 | /// 248 | public static IObservable<(T1, T2, T3, T4, T5, T6)> On(this HubConnection connection, string methodName) 249 | { 250 | if (connection == null) throw new ArgumentNullException(nameof(connection)); 251 | if (methodName == null) throw new ArgumentNullException(nameof(methodName)); 252 | 253 | return new OnObservable<(T1, T2, T3, T4, T5, T6)> 254 | ( 255 | connection, 256 | methodName, 257 | new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6) }, 258 | (args, state) => 259 | { 260 | var observer = (IObserver<(T1, T2, T3, T4, T5, T6)>)state; 261 | var a1 = (T1)args[0]; 262 | var a2 = (T2)args[1]; 263 | var a3 = (T3)args[2]; 264 | var a4 = (T4)args[3]; 265 | var a5 = (T5)args[4]; 266 | var a6 = (T6)args[5]; 267 | observer.OnNext((a1, a2, a3, a4, a5, a6)); 268 | return Task.CompletedTask; 269 | } 270 | ); 271 | } 272 | 273 | 274 | /// 275 | /// Gets the observable sequence that will be invoked when the hub method with the specified method name is invoked. 276 | /// 277 | /// 1st argument type. 278 | /// 2nd argument type. 279 | /// 3rd argument type. 280 | /// 4th argument type. 281 | /// 5th argument type. 282 | /// 6th argument type. 283 | /// 7th argument type. 284 | /// Hub connection. 285 | /// The name of the hub method to define. 286 | /// 287 | public static IObservable<(T1, T2, T3, T4, T5, T6, T7)> On(this HubConnection connection, string methodName) 288 | { 289 | if (connection == null) throw new ArgumentNullException(nameof(connection)); 290 | if (methodName == null) throw new ArgumentNullException(nameof(methodName)); 291 | 292 | return new OnObservable<(T1, T2, T3, T4, T5, T6, T7)> 293 | ( 294 | connection, 295 | methodName, 296 | new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) }, 297 | (args, state) => 298 | { 299 | var observer = (IObserver<(T1, T2, T3, T4, T5, T6, T7)>)state; 300 | var a1 = (T1)args[0]; 301 | var a2 = (T2)args[1]; 302 | var a3 = (T3)args[2]; 303 | var a4 = (T4)args[3]; 304 | var a5 = (T5)args[4]; 305 | var a6 = (T6)args[5]; 306 | var a7 = (T7)args[6]; 307 | observer.OnNext((a1, a2, a3, a4, a5, a6, a7)); 308 | return Task.CompletedTask; 309 | } 310 | ); 311 | } 312 | 313 | 314 | /// 315 | /// Gets the observable sequence that will be invoked when the hub method with the specified method name is invoked. 316 | /// 317 | /// 1st argument type. 318 | /// 2nd argument type. 319 | /// 3rd argument type. 320 | /// 4th argument type. 321 | /// 5th argument type. 322 | /// 6th argument type. 323 | /// 7th argument type. 324 | /// 8th argument type. 325 | /// Hub connection. 326 | /// The name of the hub method to define. 327 | /// 328 | public static IObservable<(T1, T2, T3, T4, T5, T6, T7, T8)> On(this HubConnection connection, string methodName) 329 | { 330 | if (connection == null) throw new ArgumentNullException(nameof(connection)); 331 | if (methodName == null) throw new ArgumentNullException(nameof(methodName)); 332 | 333 | return new OnObservable<(T1, T2, T3, T4, T5, T6, T7, T8)> 334 | ( 335 | connection, 336 | methodName, 337 | new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8) }, 338 | (args, state) => 339 | { 340 | var observer = (IObserver<(T1, T2, T3, T4, T5, T6, T7, T8)>)state; 341 | var a1 = (T1)args[0]; 342 | var a2 = (T2)args[1]; 343 | var a3 = (T3)args[2]; 344 | var a4 = (T4)args[3]; 345 | var a5 = (T5)args[4]; 346 | var a6 = (T6)args[5]; 347 | var a7 = (T7)args[6]; 348 | var a8 = (T8)args[7]; 349 | observer.OnNext((a1, a2, a3, a4, a5, a6, a7, a8)); 350 | return Task.CompletedTask; 351 | } 352 | ); 353 | } 354 | #endregion 355 | 356 | 357 | #region Event as observable 358 | /// 359 | /// Gets the observable sequence that will be invoked when the connection is closed. 360 | /// 361 | /// Hub connection. 362 | /// 363 | public static IObservable CloseAsObservable(this HubConnection connection) 364 | { 365 | if (connection == null) 366 | throw new ArgumentNullException(nameof(connection)); 367 | 368 | return Observable.FromEvent, Exception> 369 | ( 370 | handler => ex => 371 | { 372 | handler(ex); 373 | return Task.CompletedTask; 374 | }, 375 | handler => connection.Closed += handler, 376 | handler => connection.Closed -= handler 377 | ); 378 | } 379 | #endregion 380 | } 381 | } 382 | -------------------------------------------------------------------------------- /src/ReactiveSignalR/ReactiveSignalR.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | latest 6 | true 7 | 1.0.0 8 | 9 | true 10 | true 11 | http://opensource.org/licenses/MIT 12 | https://github.com/xin9le/ReactiveSignalR 13 | Provides reactive programming for ASP.NET Core SignalR client application. 14 | - ASP.NET Core support 15 | Copyright© xin9le, All rights reserved. 16 | SignalR, Rx 17 | https://github.com/xin9le/ReactiveSignalR 18 | Git 19 | https://raw.githubusercontent.com/xin9le/ReactiveSignalR/master/assets/icon/rx.png 20 | xin9le 21 | ReactiveSignalR 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | --------------------------------------------------------------------------------