Fix SocialWeather sample (#1313)
This commit is contained in:
parent
1cc4098d3a
commit
4203540cb0
|
|
@ -22,7 +22,7 @@ namespace SocialWeather
|
||||||
public void OnConnectedAsync(ConnectionContext connection)
|
public void OnConnectedAsync(ConnectionContext connection)
|
||||||
{
|
{
|
||||||
connection.Metadata["groups"] = new HashSet<string>();
|
connection.Metadata["groups"] = new HashSet<string>();
|
||||||
connection.Metadata["format"] = "json";
|
connection.Metadata["format"] = connection.GetHttpContext().Request.Query["formatType"].ToString();
|
||||||
_connectionList.Add(connection);
|
_connectionList.Add(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,16 +31,16 @@ namespace SocialWeather.Pipe
|
||||||
temperature = int.MinValue;
|
temperature = int.MinValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokens.Length < 2 || !long.TryParse(tokens[1], out reportTime))
|
if (tokens.Length < 2 || !Enum.TryParse<Weather>(tokens[1], out weather))
|
||||||
{
|
|
||||||
temperature = int.MinValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tokens.Length < 3 || !Enum.TryParse<Weather>(tokens[2], out weather))
|
|
||||||
{
|
{
|
||||||
weather = (Weather)(-1);
|
weather = (Weather)(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tokens.Length < 3 || !long.TryParse(tokens[2], out reportTime))
|
||||||
|
{
|
||||||
|
reportTime = int.MinValue;
|
||||||
|
}
|
||||||
|
|
||||||
return new WeatherReport
|
return new WeatherReport
|
||||||
{
|
{
|
||||||
Temperature = temperature,
|
Temperature = temperature,
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace SocialWeather
|
||||||
public async Task ProcessRequests(ConnectionContext connection)
|
public async Task ProcessRequests(ConnectionContext connection)
|
||||||
{
|
{
|
||||||
var formatter = _formatterResolver.GetFormatter<WeatherReport>(
|
var formatter = _formatterResolver.GetFormatter<WeatherReport>(
|
||||||
(string)connection.Metadata["formatType"]);
|
(string)connection.Metadata["format"]);
|
||||||
|
|
||||||
while (await connection.Transport.Reader.WaitToReadAsync())
|
while (await connection.Transport.Reader.WaitToReadAsync())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@
|
||||||
span.style.color = color;
|
span.style.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
let connectUrl = `ws://${document.location.host}/weather/ws?formatType=json`;
|
let connectUrl = `ws://${document.location.host}/weather?formatType=json`;
|
||||||
let webSocket = new WebSocket(connectUrl);
|
let webSocket = new WebSocket(connectUrl);
|
||||||
webSocket.onopen = event => {
|
webSocket.onopen = event => {
|
||||||
updateStatus('Connected', 'green');
|
updateStatus('Connected', 'green');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue