Permalink
Browse files

Adding Websockets transport

  • Loading branch information...
1 parent 9e5449b commit be8a4ed8238ec8f5f08fd5fb04a14e35d7ad4145 @moozzyk moozzyk committed Nov 18, 2015
View
@@ -34,6 +34,5 @@ jquery.signalR.min.js
xamarin/SignalRPackage/component/lib/mobile/
tests/Microsoft.AspNet.SignalR.Client.Store.Tests/AppPackages/
/Microsoft.AspNet.SignalR.sln.ide
-<<<<<<< HEAD
/.vs/
-.lock.json
+project.lock.json
@@ -57,7 +57,7 @@
<Link>Properties\CommonVersionInfo.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Resources.cs" />
+ <Compile Include="ResourcesStore.cs" />
<Compile Include="Transports\IWebSocketResponse.cs" />
<Compile Include="Transports\MessageReceivedEventArgsWrapper.cs" />
<Compile Include="Transports\WebSocketRequest.cs" />
@@ -4,7 +4,7 @@
namespace Microsoft.AspNet.SignalR.Client
{
- internal class Resources
+ internal static class ResourcesStore
{
private static readonly ResourceLoader ResourceLoader =
ResourceLoader.GetForViewIndependentUse("Microsoft.AspNet.SignalR.Client.Store/Resources");
@@ -153,12 +153,12 @@ public override Task Send(IConnection connection, string data, string connection
if (connection.State != ConnectionState.Disconnected)
{
// Make this a faulted task and trigger the OnError even to maintain consistency with the HttpBasedTransports
- ex = new InvalidOperationException(Resources.GetResourceString("Error_DataCannotBeSentDuringWebSocketReconnect"));
+ ex = new InvalidOperationException(ResourcesStore.GetResourceString("Error_DataCannotBeSentDuringWebSocketReconnect"));
connection.OnError(ex);
}
else
{
- ex = new InvalidOperationException(Resources.GetResourceString("Error_WebSocketUninitialized"));
+ ex = new InvalidOperationException(ResourcesStore.GetResourceString("Error_DataCannotBeSentDuringWebSocketReconnect"));
}
var tcs = new TaskCompletionSource<object>();
@@ -11,7 +11,7 @@
<AssemblyName>Microsoft.AspNet.SignalR.Client</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
- <TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
+ <TargetPlatformVersion>10.0.10586.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
@@ -314,12 +314,24 @@
<Compile Include="..\Microsoft.AspNet.SignalR.Core\TaskAsyncHelper.cs">
<Link>Infrastructure\TaskAsyncHelper.cs</Link>
</Compile>
+ <Compile Include="..\Microsoft.AspNet.SignalR.Client.Store\Transports\IWebSocketResponse.cs">
+ <Link>Transports\WebSockets\IWebSocketResponse.cs</Link>
+ </Compile>
+ <Compile Include="..\Microsoft.AspNet.SignalR.Client.Store\Transports\MessageReceivedEventArgsWrapper.cs">
+ <Link>Transports\WebSockets\MessageReceivedEventArgsWrapper.cs</Link>
+ </Compile>
+ <Compile Include="..\Microsoft.AspNet.SignalR.Client.Store\Transports\WebSocketRequest.cs">
+ <Link>Transports\WebSockets\WebSocketRequest.cs</Link>
+ </Compile>
+ <Compile Include="..\Microsoft.AspNet.SignalR.Client.Store\Transports\WebSocketTransport.cs">
+ <Link>Transports\WebSockets\WebSocketTransport.cs</Link>
+ </Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="ResourcesStore.cs" />
</ItemGroup>
<ItemGroup>
- <EmbeddedResource Include="Resources.resx">
- <Link>Resources.resx</Link>
- </EmbeddedResource>
+ <EmbeddedResource Include="Resources.resx" />
+ <EmbeddedResource Include="Store.Resources.resx" />
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
@@ -328,6 +340,7 @@
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<Target Name="BeforeBuild">
<Copy SourceFiles="..\Microsoft.AspNet.SignalR.Client\Resources.resx" DestinationFiles="$(ProjectDir)Resources.resx" SkipUnchangedFiles="true" />
+ <Copy SourceFiles="..\Microsoft.AspNet.SignalR.Client.Store\Resources.resw" DestinationFiles="$(ProjectDir)Store.Resources.resx" SkipUnchangedFiles="true" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@@ -0,0 +1,31 @@
+using System.Globalization;
+using System.Reflection;
+using System.Resources;
+
+namespace Microsoft.AspNet.SignalR.Client
+{
+ internal static class ResourcesStore
+ {
+ private static ResourceManager resourceMan;
+
+ internal static ResourceManager ResourceManager
+ {
+ get
+ {
+ if (ReferenceEquals(resourceMan, null))
+ {
+ var assembly = typeof(Resources).GetTypeInfo().Assembly;
+ var temp = new ResourceManager("Microsoft.AspNet.SignalR.Client.Store.Resources", assembly);
+ resourceMan = temp;
+ }
+
+ return resourceMan;
+ }
+ }
+
+ public static string GetResourceString(string resourceName)
+ {
+ return ResourceManager.GetString(resourceName, null);
+ }
+ }
+}
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="Error_WebSocketUninitialized" xml:space="preserve">
+ <value>The underlying WebSocket is not initialized. Call the 'Start' method to initialize the WebSocket.</value>
+ </data>
+ <data name="Error_DataCannotBeSentDuringWebSocketReconnect" xml:space="preserve">
+ <value>Data cannot be sent because the WebSocket connection is reconnecting.</value>
+ </data>
+</root>
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
+using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
@@ -102,7 +103,7 @@ public static byte[] ProcessPostData(IDictionary<string, string> postData)
continue;
}
- sb.AppendFormat("{0}={1}", pair.Key, UrlEncoder.UrlEncode(pair.Value));
+ sb.AppendFormat(CultureInfo.InvariantCulture, "{0}={1}", pair.Key, UrlEncoder.UrlEncode(pair.Value));
}
return Encoding.UTF8.GetBytes(sb.ToString());
@@ -27,7 +27,7 @@ public AutoTransport(IHttpClient httpClient)
_transports = new List<IClientTransport>()
{
-#if NET45
+#if NET45 || WINDOWS_UWP
new WebSocketTransport(httpClient),
#endif
new ServerSentEventsTransport(httpClient),
@@ -7,7 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Xunit;
-using StoreClientResources = StoreClient::Microsoft.AspNet.SignalR.Client.Resources;
+using StoreClientResources = StoreClient::Microsoft.AspNet.SignalR.Client.ResourcesStore;
namespace Microsoft.AspNet.SignalR.Client.Store.Tests
{
@@ -92,7 +92,7 @@ public class EndToEndTests
Assert.True(reconnectingInvoked);
Assert.Equal(ConnectionState.Connected, hubConnection.State);
- // TODO: this is a workaround to a race condition in WebSocket.
+ // TODO: this is a workaround to a race condition in WebSocket.
// Should be removed once the race in WebSockets is fixed
await Task.Delay(200);
@@ -131,7 +131,7 @@ public class EndToEndTests
if (stateChange.OldState == ConnectionState.Connected &&
stateChange.NewState == ConnectionState.Reconnecting)
{
- // Reverting quick timeout
+ // Reverting quick timeout
((IConnection) hubConnection).KeepAliveData = new KeepAliveData(
timeoutWarning: TimeSpan.FromSeconds(30),
timeout: TimeSpan.FromSeconds(20),
@@ -161,7 +161,7 @@ public class EndToEndTests
Assert.True(await Task.Run(() => reconnectedWh.Wait(5000)));
- // TODO: this is a workaround to a race condition in WebSocket.
+ // TODO: this is a workaround to a race condition in WebSocket.
// Should be removed once the race in WebSockets is fixed
await Task.Delay(200);
@@ -200,7 +200,7 @@ public void MessageReceivedReadsAndProcessesMessages()
var fakeConnection = new FakeConnection {State = ConnectionState.Disconnected};
Assert.Equal(
- StoreClient::Microsoft.AspNet.SignalR.Client.Resources.GetResourceString("Error_WebSocketUninitialized"),
+ StoreClient::Microsoft.AspNet.SignalR.Client.ResourcesStore.GetResourceString("Error_WebSocketUninitialized"),
(await Assert.ThrowsAsync<InvalidOperationException>(
async () => await new WebSocketTransport().Send(fakeConnection, null, null))).Message);
}

0 comments on commit be8a4ed

Please sign in to comment.