Skip to content

Commit 5d0d939

Browse files
committed
Converting more projects to .netstandard2.0
1 parent 087f576 commit 5d0d939

File tree

11 files changed

+191
-30
lines changed

11 files changed

+191
-30
lines changed

NuGet/WampSharp.Vtortola.nuspec

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
<authors>CodeSharp</authors>
66
<owners />
77
<dependencies>
8-
<dependency id="WampSharp" version="[$version$]" />
9-
<dependency id="vtortola.WebSocketListener" version="[2.2.2]" />
8+
<group targetFramework="net45">
9+
<dependency id="WampSharp" version="[$version$]" />
10+
<dependency id="vtortola.WebSocketListener" version="[2.2.2]" />
11+
</group>
12+
<group targetFramework="netstandard2.0">
13+
<dependency id="WampSharp" version="[$version$]" />
14+
<dependency id="vtortola.WebSocketListener" version="[3.0.0-beta]" />
15+
</group>
1016
</dependencies>
1117
<id>WampSharp.Vtortola</id>
1218
<title>WampSharp Vtortola support</title>
@@ -18,5 +24,7 @@
1824
<files>
1925
<file src="$bin$\net45\WampSharp.Vtortola.dll" target="lib\net45\WampSharp.Vtortola.dll" />
2026
<file src="$bin$\net45\WampSharp.Vtortola.xml" target="lib\net45\WampSharp.Vtortola.xml" />
27+
<file src="$bin$\netstandard2.0\WampSharp.Vtortola.dll" target="lib\netstandard2.0\WampSharp.Vtortola.dll" />
28+
<file src="$bin$\netstandard2.0\WampSharp.Vtortola.xml" target="lib\netstandard2.0\WampSharp.Vtortola.xml" />
2129
</files>
2230
</package>

src/net45/Extensions/WampSharp.Vtortola/VtortolaWampBinaryConnection.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.IO;
2+
using System.Threading;
23
using System.Threading.Tasks;
34
using vtortola.WebSockets;
45
using WampSharp.Core.Message;
@@ -12,9 +13,10 @@ internal class VtortolaWampBinaryConnection<TMessage> : VtortolaWampConnection<T
1213
private readonly IWampBinaryBinding<TMessage> mBinding;
1314

1415
public VtortolaWampBinaryConnection(WebSocket connection,
15-
IWampBinaryBinding<TMessage> binding,
16-
ICookieAuthenticatorFactory cookieAuthenticatorFactory) :
17-
base(connection, cookieAuthenticatorFactory)
16+
CancellationToken cancellationToken,
17+
IWampBinaryBinding<TMessage> binding,
18+
ICookieAuthenticatorFactory cookieAuthenticatorFactory) :
19+
base(connection, cancellationToken, cookieAuthenticatorFactory)
1820
{
1921
mBinding = binding;
2022
}

src/net45/Extensions/WampSharp.Vtortola/VtortolaWampConnection.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ internal abstract class VtortolaWampConnection<TMessage> : AsyncWebSocketWampCon
1616
IDetailedWampConnection<TMessage>
1717
{
1818
protected readonly WebSocket mWebsocket;
19+
private readonly CancellationToken mCancellationToken;
1920
private readonly VtortolaTransportDetails mTransportDetails;
2021

2122
protected VtortolaWampConnection(WebSocket websocket,
22-
ICookieAuthenticatorFactory cookieAuthenticatorFactory)
23+
CancellationToken cancellationToken,
24+
ICookieAuthenticatorFactory cookieAuthenticatorFactory)
2325
: base(new CookieCollectionCookieProvider(websocket.HttpRequest.Cookies),
24-
cookieAuthenticatorFactory)
26+
cookieAuthenticatorFactory)
2527
{
2628
mWebsocket = websocket;
29+
mCancellationToken = cancellationToken;
2730
mTransportDetails = new VtortolaTransportDetails(mWebsocket);
2831
}
2932

@@ -33,7 +36,7 @@ public async Task HandleWebSocketAsync()
3336
{
3437
RaiseConnectionOpen();
3538

36-
while (mWebsocket.IsConnected)
39+
while (IsConnected)
3740
{
3841
WebSocketMessageReadStream message =
3942
await mWebsocket.ReadMessageAsync(CancellationToken.None)
@@ -63,7 +66,8 @@ protected override bool IsConnected
6366
{
6467
get
6568
{
66-
return mWebsocket.IsConnected;
69+
return !mCancellationToken.IsCancellationRequested &&
70+
mWebsocket.IsConnected;
6771
}
6872
}
6973

src/net45/Extensions/WampSharp.Vtortola/VtortolaWampTextConnection.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.IO;
2+
using System.Threading;
23
using System.Threading.Tasks;
34
using vtortola.WebSockets;
45
using WampSharp.Core.Message;
@@ -12,9 +13,10 @@ internal class VtortolaWampTextConnection<TMessage> : VtortolaWampConnection<TMe
1213
private readonly IWampTextBinding<TMessage> mBinding;
1314

1415
public VtortolaWampTextConnection(WebSocket connection,
15-
IWampTextBinding<TMessage> binding,
16-
ICookieAuthenticatorFactory cookieAuthenticatorFactory) :
17-
base(connection, cookieAuthenticatorFactory)
16+
CancellationToken cancellationToken,
17+
IWampTextBinding<TMessage> binding,
18+
ICookieAuthenticatorFactory cookieAuthenticatorFactory) :
19+
base(connection, cancellationToken, cookieAuthenticatorFactory)
1820
{
1921
mBinding = binding;
2022
}

src/net45/Extensions/WampSharp.Vtortola/VtortolaWebSocketHttpResponse.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System.Linq;
22
using System.Net;
33
using vtortola.WebSockets;
4+
#if NETCORE
5+
using HttpStatusCode = vtortola.WebSockets.HttpStatusCode;
6+
#endif
47

58
namespace WampSharp.Vtortola
69
{

src/net45/Extensions/WampSharp.Vtortola/VtortolaWebSocketTransport.cs

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
using System.Security.Cryptography.X509Certificates;
44
using System.Threading;
55
using System.Threading.Tasks;
6-
using WampSharp.Logging;
76
using vtortola.WebSockets;
87
using vtortola.WebSockets.Deflate;
98
using vtortola.WebSockets.Rfc6455;
9+
using WampSharp.Logging;
1010
using WampSharp.Core.Listener;
1111
using WampSharp.V2.Authentication;
1212
using WampSharp.V2.Binding;
@@ -17,13 +17,14 @@ namespace WampSharp.Vtortola
1717
/// <summary>
1818
/// Represents a WebSocket transport implemented with Vtortola.
1919
/// </summary>
20-
public class VtortolaWebSocketTransport : WebSocketTransport<WebSocket>
20+
public class VtortolaWebSocketTransport : WebSocketTransport<WebSocketData>
2121
{
2222
private readonly IPEndPoint mEndpoint;
2323
private WebSocketListener mListener;
2424
private readonly bool mPerMessageDeflate;
2525
private readonly X509Certificate2 mCertificate;
2626
private readonly WebSocketListenerOptions mOptions;
27+
private CancellationTokenSource mCancellationToken;
2728

2829
/// <summary>
2930
/// Creates a new instance of <see cref="VtortolaWebSocketTransport"/>
@@ -71,6 +72,7 @@ protected VtortolaWebSocketTransport
7172

7273
public override void Dispose()
7374
{
75+
mCancellationToken.Cancel();
7476
mListener.Stop();
7577
mListener.Dispose();
7678
}
@@ -82,42 +84,56 @@ public override void Open()
8284
WebSocketListenerOptions options = mOptions ?? new WebSocketListenerOptions();
8385

8486
options.SubProtocols = protocols;
85-
87+
8688
WebSocketListener listener = new WebSocketListener(mEndpoint, options);
8789

90+
#if NETCORE
91+
WebSocketFactoryRfc6455 factory = new WebSocketFactoryRfc6455();
92+
#else
8893
WebSocketFactoryRfc6455 factory = new WebSocketFactoryRfc6455(listener);
8994

95+
#endif
9096
if (mPerMessageDeflate)
9197
{
92-
factory.MessageExtensions.RegisterExtension(new WebSocketDeflateExtension());
98+
#if NETCORE
99+
listener.MessageExtensions.RegisterExtension(new WebSocketDeflateExtension());
100+
#else
101+
factory.MessageExtensions.RegisterExtension(new WebSocketDeflateExtension());
102+
#endif
93103
}
94104

95105
listener.Standards.RegisterStandard(factory);
96-
106+
97107
if (mCertificate != null)
98108
{
99109
listener.ConnectionExtensions.RegisterExtension(new WebSocketSecureConnectionExtension(mCertificate));
100110
}
101111

112+
mCancellationToken = new CancellationTokenSource();
113+
114+
#if NETCORE
115+
listener.StartAsync(mCancellationToken.Token);
116+
#else
102117
listener.Start();
118+
#endif
103119

104120
mListener = listener;
105121

106-
Task.Run(new Func<Task>(ListenAsync));
122+
Task.Run(new Func<Task>(() => ListenAsync(mCancellationToken.Token)));
107123
}
108124

109-
private async Task ListenAsync()
125+
private async Task ListenAsync(CancellationToken cancellationToken)
110126
{
111-
while (mListener.IsStarted)
127+
while (!cancellationToken.IsCancellationRequested)
112128
{
113129
try
114130
{
115-
WebSocket websocket = await mListener.AcceptWebSocketAsync(CancellationToken.None)
131+
WebSocket websocket = await mListener.AcceptWebSocketAsync(cancellationToken)
116132
.ConfigureAwait(false);
117133

118134
if (websocket != null)
119135
{
120-
OnNewConnection(websocket);
136+
OnNewConnection(new WebSocketData(websocket, cancellationToken));
121137
}
122138
}
123139
catch (Exception ex)
@@ -127,27 +143,33 @@ private async Task ListenAsync()
127143
}
128144
}
129145

130-
protected override string GetSubProtocol(WebSocket connection)
146+
protected override string GetSubProtocol(WebSocketData connection)
131147
{
132-
return connection.HttpResponse.WebSocketProtocol;
148+
return connection.WebSocket.HttpResponse.WebSocketProtocol;
133149
}
134150

135-
protected override void OpenConnection<TMessage>(WebSocket original, IWampConnection<TMessage> connection)
151+
protected override void OpenConnection<TMessage>(WebSocketData original, IWampConnection<TMessage> connection)
136152
{
137153
VtortolaWampConnection<TMessage> casted = connection as VtortolaWampConnection<TMessage>;
138154
Task.Run(new Func<Task>(casted.HandleWebSocketAsync));
139155
}
140156

141157
protected override IWampConnection<TMessage> CreateBinaryConnection<TMessage>
142-
(WebSocket connection, IWampBinaryBinding<TMessage> binding)
158+
(WebSocketData connection, IWampBinaryBinding<TMessage> binding)
143159
{
144-
return new VtortolaWampBinaryConnection<TMessage>(connection, binding, AuthenticatorFactory);
160+
return new VtortolaWampBinaryConnection<TMessage>(connection.WebSocket,
161+
connection.CancellationToken,
162+
binding,
163+
AuthenticatorFactory);
145164
}
146165

147166
protected override IWampConnection<TMessage> CreateTextConnection<TMessage>
148-
(WebSocket connection, IWampTextBinding<TMessage> binding)
167+
(WebSocketData connection, IWampTextBinding<TMessage> binding)
149168
{
150-
return new VtortolaWampTextConnection<TMessage>(connection, binding, AuthenticatorFactory);
169+
return new VtortolaWampTextConnection<TMessage>(connection.WebSocket,
170+
connection.CancellationToken,
171+
binding,
172+
AuthenticatorFactory);
151173
}
152174
}
153175
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Threading;
2+
using vtortola.WebSockets;
3+
4+
namespace WampSharp.Vtortola
5+
{
6+
public class WebSocketData
7+
{
8+
public WebSocket WebSocket { get; }
9+
public CancellationToken CancellationToken { get; }
10+
11+
public WebSocketData(WebSocket webSocket, CancellationToken cancellationToken)
12+
{
13+
WebSocket = webSocket;
14+
CancellationToken = cancellationToken;
15+
}
16+
}
17+
}

src/net45/WampSharp.WAMP1/WAMP1/V1/Api/Server/WampRequestContext.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
2+
#if !NETSTANDARD2_0
23
using System.Runtime.Remoting.Messaging;
4+
#endif
5+
using System.Threading;
36
using WampSharp.V1.Core.Contracts;
47
using WampSharp.V1.Cra;
58

@@ -10,6 +13,7 @@ public class WampRequestContext
1013
{
1114
#region Static Members
1215

16+
#if !NETSTANDARD2_0
1317
public static WampRequestContext Current
1418
{
1519
get
@@ -21,6 +25,21 @@ internal set
2125
CallContext.LogicalSetData(typeof (WampRequestContext).Name, value);
2226
}
2327
}
28+
#else
29+
private static readonly AsyncLocal<WampRequestContext> mCurrent = new AsyncLocal<WampRequestContext>();
30+
31+
public static WampRequestContext Current
32+
{
33+
get
34+
{
35+
return mCurrent.Value;
36+
}
37+
internal set
38+
{
39+
mCurrent.Value = value;
40+
}
41+
}
42+
#endif
2443

2544
#endregion
2645

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
6+
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
7+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
8+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
9+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
10+
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
11+
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
12+
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
13+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<Compile Include="..\..\..\net45\Extensions\WampSharp.Vtortola\**\*.cs" Exclude="..\..\..\net45\Extensions\WampSharp.Vtortola\**\bin\**;..\..\..\net45\Extensions\WampSharp.Vtortola\**\obj\**;" />
18+
</ItemGroup>
19+
20+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
21+
<DefineConstants>NETCORE</DefineConstants>
22+
</PropertyGroup>
23+
24+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
25+
<ProjectReference Include="..\..\WampSharp\WampSharp.csproj" />
26+
<PackageReference Include="vtortola.WebSocketListener" Version="3.0.0-beta" />
27+
</ItemGroup>
28+
29+
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<AssemblyTitle>WampSharp.WAMP1</AssemblyTitle>
5+
<Authors>CodeSharp</Authors>
6+
<TargetFramework>netstandard2.0</TargetFramework>
7+
<AssemblyName>WampSharp.WAMP1</AssemblyName>
8+
<PackageId>WampSharp.WAMP1</PackageId>
9+
<PackageTags>websockets;wampws;rpc;pubsub;wampv2</PackageTags>
10+
<PackageProjectUrl>https://github.com/Code-Sharp/WampSharp/</PackageProjectUrl>
11+
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
12+
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
13+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
14+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
15+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
16+
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
17+
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
18+
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
19+
<GenerateDocumentationFile>true</GenerateDocumentationFile> </PropertyGroup>
20+
21+
<ItemGroup>
22+
<Compile Include="..\..\net45\WampSharp.WAMP1\**\*.cs" Exclude="..\..\net45\WampSharp.WAMP1\**\bin\**;..\..\net45\WampSharp.WAMP1\**\obj\**;" />
23+
</ItemGroup>
24+
25+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
26+
<DefineConstants>$(DefineConstants);NET45;</DefineConstants>
27+
</PropertyGroup>
28+
29+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
30+
<ProjectReference Include="..\WampSharp\WampSharp.csproj" />
31+
</ItemGroup>
32+
33+
</Project>

0 commit comments

Comments
 (0)