Permalink
Browse files

Added StateChange type so that it's easier to make the old and new st…

…ate of the

connection available in the event.
  • Loading branch information...
1 parent ce609f0 commit a07d1a2b4a0dfbcf264a4f24d3151170521d3464 @davidfowl davidfowl committed Jun 5, 2012
@@ -77,6 +77,9 @@
<Compile Include="..\SignalR.Client\ConnectionState.cs">
<Link>ConnectionState.cs</Link>
</Compile>
+ <Compile Include="..\SignalR.Client\StateChange.cs">
+ <Link>StateChange.cs</Link>
+ </Compile>
<Compile Include="..\SignalR.Client\Http\DefaultHttpClient.cs">
<Link>Http\DefaultHttpClient.cs</Link>
</Compile>
@@ -69,6 +69,9 @@
<Compile Include="..\SignalR.Client\ConnectionState.cs">
<Link>ConnectionState.cs</Link>
</Compile>
+ <Compile Include="..\SignalR.Client\StateChange.cs">
+ <Link>StateChange.cs</Link>
+ </Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@@ -70,6 +70,9 @@
<Compile Include="..\SignalR.Client\ConnectionState.cs">
<Link>ConnectionState.cs</Link>
</Compile>
+ <Compile Include="..\SignalR.Client\StateChange.cs">
+ <Link>StateChange.cs</Link>
+ </Compile>
<Compile Include="..\SignalR.Client\Http\DefaultHttpClient.cs">
<Link>Http\DefaultHttpClient.cs</Link>
</Compile>
@@ -70,6 +70,9 @@
<Compile Include="..\SignalR.Client\ConnectionState.cs">
<Link>ConnectionState.cs</Link>
</Compile>
+ <Compile Include="..\SignalR.Client\StateChange.cs">
+ <Link>StateChange.cs</Link>
+ </Compile>
<Compile Include="..\SignalR.Client\Http\DefaultHttpClient.cs">
<Link>Http\DefaultHttpClient.cs</Link>
</Compile>
@@ -119,6 +119,9 @@
<Compile Include="..\SignalR.Client\ConnectionState.cs">
<Link>ConnectionState.cs</Link>
</Compile>
+ <Compile Include="..\SignalR.Client\StateChange.cs">
+ <Link>StateChange.cs</Link>
+ </Compile>
<Compile Include="..\SignalR.Client\Http\IHttpClient.cs">
<Link>Http\IHttpClient.cs</Link>
</Compile>
@@ -45,7 +45,7 @@ public class Connection : IConnection
/// <summary>
/// Occurs when the <see cref="Connection"/> state changes.
/// </summary>
- public event Action<ConnectionState> StateChanged;
+ public event Action<StateChange> StateChanged;
/// <summary>
/// Initializes a new instance of the <see cref="Connection"/> class.
@@ -132,7 +132,7 @@ public Connection(string url, string queryString)
/// Gets the querystring specified in the ctor.
/// </summary>
public string QueryString { get; private set; }
-
+
/// <summary>
/// Gets the current <see cref="ConnectionState"/> of the connection.
/// </summary>
@@ -148,7 +148,7 @@ private set
{
if (StateChanged != null)
{
- StateChanged(value);
+ StateChanged(new StateChange(_state, value));
}
_state = value;
@@ -78,6 +78,7 @@
<Compile Include="ObservableConnection.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Hubs\HubProxyExtensions.cs" />
+ <Compile Include="StateChange.cs" />
<Compile Include="Transports\AutoTransport.cs" />
<Compile Include="Transports\HttpBasedTransport.cs" />
<Compile Include="Transports\IClientTransport.cs" />
@@ -0,0 +1,29 @@
+namespace SignalR.Client
+{
+ /// <summary>
+ /// Represents a change in the connection state.
+ /// </summary>
+ public class StateChange
+ {
+ /// <summary>
+ /// Creates a new stance of <see cref="StateChange"/>.
+ /// </summary>
+ /// <param name="oldState">The old state of the connection.</param>
+ /// <param name="newState">The new state of the connection.</param>
+ public StateChange(ConnectionState oldState, ConnectionState newState)
+ {
+ OldState = oldState;
+ NewState = newState;
+ }
+
+ /// <summary>
+ /// Gets the old state of the connection.
+ /// </summary>
+ public ConnectionState OldState { get; private set; }
+
+ /// <summary>
+ /// Gets the new state of the connection.
+ /// </summary>
+ public ConnectionState NewState { get; private set; }
+ }
+}
@@ -91,9 +91,9 @@ private static void RunStreamingSample()
Console.WriteLine("[{0}]: Connection restablished", DateTime.Now);
};
- connection.StateChanged += newState =>
+ connection.StateChanged += change =>
{
- Console.WriteLine("{0} => {1}", connection.State, newState);
+ Console.WriteLine("{0} => {1}", change.OldState, change.NewState);
};
connection.Error += e =>

0 comments on commit a07d1a2

Please sign in to comment.