From b5cef5944845622dcffceee41ba8698b99b57341 Mon Sep 17 00:00:00 2001 From: Pawel Kadluczka Date: Sun, 6 Nov 2016 00:12:43 -0700 Subject: [PATCH] Fixing - infinite loop when a client disconnects - enum values serialization Replacing reports div with a table --- .../SocialWeather/SocialWeatherEndPoint.cs | 4 +- samples/SocialWeather/WeatherReport.cs | 7 ++-- samples/SocialWeather/wwwroot/weather.html | 42 ++++++++++++++----- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/samples/SocialWeather/SocialWeatherEndPoint.cs b/samples/SocialWeather/SocialWeatherEndPoint.cs index c37cfd7a29..858091705a 100644 --- a/samples/SocialWeather/SocialWeatherEndPoint.cs +++ b/samples/SocialWeather/SocialWeatherEndPoint.cs @@ -34,9 +34,9 @@ namespace SocialWeather var formatter = _formatterResolver.GetFormatter( connection.Metadata.Get("formatType")); - while (true) + WeatherReport weatherReport; + while ((weatherReport = await formatter.ReadAsync(stream)) != null) { - var weatherReport = await formatter.ReadAsync(stream); lock(_lockObj) { _lastWeatherReport = weatherReport; diff --git a/samples/SocialWeather/WeatherReport.cs b/samples/SocialWeather/WeatherReport.cs index 366630698f..0963465183 100644 --- a/samples/SocialWeather/WeatherReport.cs +++ b/samples/SocialWeather/WeatherReport.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace SocialWeather { @@ -13,6 +11,7 @@ namespace SocialWeather public long ReportTime { get; set; } + [JsonConverter(typeof(StringEnumConverter))] public Weather Weather { get; set; } public string ZipCode { get; set; } diff --git a/samples/SocialWeather/wwwroot/weather.html b/samples/SocialWeather/wwwroot/weather.html index 22a8f953c8..5ba5ef7710 100644 --- a/samples/SocialWeather/wwwroot/weather.html +++ b/samples/SocialWeather/wwwroot/weather.html @@ -5,9 +5,6 @@ Social weather -
-

Weather:

-
@@ -19,18 +16,43 @@ - +
+
+

Weather reports

+
+

Status: