diff --git a/App.config b/App.config
index 29d9083..0b3980c 100644
--- a/App.config
+++ b/App.config
@@ -1,27 +1,37 @@
-
-
+
+
-
+
-
+
-
+
False
-
+
00:00:01
-
+
http://*:9090
-
+
http://localhost:9090
@@ -29,7 +39,8 @@
-
+
@@ -38,23 +49,21 @@
-
-
-
+
+
+
-
-
-
-
-
-
-
-
@@ -67,24 +76,39 @@
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
@@ -95,11 +119,16 @@
-
+
-
-
+
+
\ No newline at end of file
diff --git a/Remote/IWeatherService.cs b/Remote/IWeatherService.cs
deleted file mode 100644
index 681e68d..0000000
--- a/Remote/IWeatherService.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System.Collections.Generic;
-using System.ServiceModel;
-using System.ServiceModel.Web;
-using WeatherService.Devices;
-using WeatherService.Remote;
-using WeatherService.Values;
-
-namespace WeatherService
-{
- [ServiceContract]
- public interface IWeatherService
- {
- [WebGet(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
- List GetDevices();
-
- [WebGet(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
- ReadingBase GetLatestReading(string deviceAddress, WeatherValueType valueType);
-
- [WebGet(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
- DeviceHistory GetDeviceHistory(string deviceAddress);
-
- [WebGet(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
- Dictionary> GetDeviceHistoryByValueType(WeatherValueType valueType);
-
- [WebGet(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
- Dictionary> GetWindSpeedHistory(int groupIntervalMinutes);
-
- [WebGet(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
- Dictionary GetWindDirectionHistory();
- }
-}
diff --git a/Remote/IWeatherServiceCallback.cs b/Remote/IWeatherServiceCallback.cs
index 0a78017..39fa3f1 100644
--- a/Remote/IWeatherServiceCallback.cs
+++ b/Remote/IWeatherServiceCallback.cs
@@ -1,9 +1,9 @@
using System.ServiceModel;
using WeatherService.Devices;
-namespace WeatherService
+namespace WeatherService.Remote
{
- public interface IWeatherServiceCallback
+ public interface IWeatherServiceCallback : ICommunicationObject
{
[OperationContract(IsOneWay = true)]
void OnDeviceUpdate(DeviceBase device);
diff --git a/Remote/IWeatherServiceDuplex.cs b/Remote/IWeatherServiceDuplex.cs
index 7bae642..1d976a1 100644
--- a/Remote/IWeatherServiceDuplex.cs
+++ b/Remote/IWeatherServiceDuplex.cs
@@ -1,10 +1,9 @@
using System.Collections.Generic;
using System.ServiceModel;
using WeatherService.Devices;
-using WeatherService.Remote;
using WeatherService.Values;
-namespace WeatherService
+namespace WeatherService.Remote
{
[ServiceContract(CallbackContract = typeof(IWeatherServiceCallback))]
public interface IWeatherServiceDuplex
diff --git a/Remote/WeatherService.cs b/Remote/WeatherService.cs
deleted file mode 100644
index 2b2fc43..0000000
--- a/Remote/WeatherService.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using System.Collections.Generic;
-using System.ServiceModel.Activation;
-using System.ServiceModel.Web;
-using WeatherService.Devices;
-using WeatherService.Remote;
-using WeatherService.Values;
-
-namespace WeatherService
-{
- [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
- public class WeatherService : IWeatherService
- {
- public List GetDevices()
- {
- WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
-
- return WeatherServiceCommon.GetDevices();
- }
-
- public ReadingBase GetLatestReading(string deviceAddress, WeatherValueType valueType)
- {
- WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
-
- return WeatherServiceCommon.GetLatestReading(deviceAddress, valueType);
- }
-
- public DeviceHistory GetDeviceHistory(string deviceAddress)
- {
- WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
-
- return WeatherServiceCommon.GetDeviceHistory(deviceAddress);
- }
-
- public Dictionary> GetDeviceHistoryByValueType(WeatherValueType valueType)
- {
- WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
-
- return WeatherServiceCommon.GetDeviceHistoryByValueType(valueType);
- }
-
- public Dictionary> GetWindSpeedHistory(int groupIntervalMinutes)
- {
- WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
-
- return WeatherServiceCommon.GetWindSpeedHistory(groupIntervalMinutes);
- }
-
- public Dictionary GetWindDirectionHistory()
- {
- WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
-
- return WeatherServiceCommon.GetWindDirectionHistory();
- }
- }
-}
diff --git a/Remote/WeatherServiceCommon.cs b/Remote/WeatherServiceCommon.cs
index 3da0570..1660344 100644
--- a/Remote/WeatherServiceCommon.cs
+++ b/Remote/WeatherServiceCommon.cs
@@ -17,7 +17,7 @@ namespace WeatherService.Remote
public static ReadingBase GetLatestReading(string deviceAddress, WeatherValueType valueType)
{
- DeviceBase deviceBase = Program.Session.Devices.Where(d => d.Address == deviceAddress).FirstOrDefault();
+ var deviceBase = Program.Session.Devices.FirstOrDefault(d => d.Address == deviceAddress);
if (deviceBase == null)
return null;
@@ -27,12 +27,12 @@ namespace WeatherService.Remote
public static DeviceHistory GetDeviceHistory(string deviceAddress)
{
- DeviceBase deviceBase = Program.Session.Devices.Where(d => d.Address == deviceAddress).FirstOrDefault();
+ var deviceBase = Program.Session.Devices.FirstOrDefault(d => d.Address == deviceAddress);
if (deviceBase == null)
return null;
- DeviceHistory deviceHistory = new DeviceHistory();
+ var deviceHistory = new DeviceHistory();
foreach (var valueEntry in deviceBase.Values)
{
@@ -46,7 +46,7 @@ namespace WeatherService.Remote
{
var devices = Program.Session.Devices.Where(d => d.SupportedValues.Contains(valueType));
- Dictionary> deviceHistoryList = new Dictionary>();
+ var deviceHistoryList = new Dictionary>();
foreach (var device in devices)
{
@@ -60,20 +60,20 @@ namespace WeatherService.Remote
{
var windSpeedHistory = new Dictionary>();
- var device = Program.Session.Devices.Where(d => d.SupportedValues.Contains(WeatherValueType.WindSpeed)).FirstOrDefault();
+ var device = Program.Session.Devices.FirstOrDefault(d => d.SupportedValues.Contains(WeatherValueType.WindSpeed));
if (device == null)
return null;
var values = device.GetValue(WeatherValueType.WindSpeed).History;
- TimeSpan interval = new TimeSpan(0, groupIntervalMinutes, 0);
+ var interval = new TimeSpan(0, groupIntervalMinutes, 0);
var groupList = values.GroupBy(reading => reading.ReadTime.Ticks / interval.Ticks).Select(d => new
{
ReadTime = new DateTime(d.Key * interval.Ticks),
Readings = d.Select(r => r.Value)
- });
+ }).ToList();
windSpeedHistory["Average"] = groupList.Select(d => new WindSpeedReading(WeatherValueType.WindSpeed) { ReadTime = d.ReadTime, Value = d.Readings.Average() }).ToList();
windSpeedHistory["Minimum"] = groupList.Select(d => new WindSpeedReading(WeatherValueType.WindSpeed) { ReadTime = d.ReadTime, Value = d.Readings.Min() }).ToList();
@@ -84,7 +84,7 @@ namespace WeatherService.Remote
public static Dictionary GetWindDirectionHistory()
{
- var device = Program.Session.Devices.Where(d => d.SupportedValues.Contains(WeatherValueType.WindDirection)).FirstOrDefault();
+ var device = Program.Session.Devices.FirstOrDefault(d => d.SupportedValues.Contains(WeatherValueType.WindDirection));
if (device == null)
return null;
diff --git a/Remote/WeatherServiceDuplex.cs b/Remote/WeatherServiceDuplex.cs
index 23d17ff..b2be4ae 100644
--- a/Remote/WeatherServiceDuplex.cs
+++ b/Remote/WeatherServiceDuplex.cs
@@ -1,15 +1,14 @@
using System.Collections.Generic;
using System.ServiceModel;
using WeatherService.Devices;
-using WeatherService.Remote;
using WeatherService.Values;
-namespace WeatherService
+namespace WeatherService.Remote
{
[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
public class WeatherServiceDuplex : IWeatherServiceDuplex
{
- private static readonly List subscribers = new List();
+ private static readonly List Subscribers = new List();
public List GetDevices()
{
@@ -45,10 +44,10 @@ namespace WeatherService
{
try
{
- IWeatherServiceCallback callback = OperationContext.Current.GetCallbackChannel();
+ var callback = OperationContext.Current.GetCallbackChannel();
- if (!subscribers.Contains(callback))
- subscribers.Add(callback);
+ if (!Subscribers.Contains(callback))
+ Subscribers.Add(callback);
return true;
}
@@ -62,10 +61,10 @@ namespace WeatherService
{
try
{
- IWeatherServiceCallback callback = OperationContext.Current.GetCallbackChannel();
+ var callback = OperationContext.Current.GetCallbackChannel();
- if (subscribers.Contains(callback))
- subscribers.Remove(callback);
+ if (Subscribers.Contains(callback))
+ Subscribers.Remove(callback);
return true;
}
@@ -81,7 +80,7 @@ namespace WeatherService
var removeList = new List();
// Loop over each subscriber
- foreach (var callback in subscribers)
+ foreach (var callback in Subscribers)
{
// If the callback connection isn't open...
if ((callback as ICommunicationObject).State != CommunicationState.Opened)
@@ -105,7 +104,7 @@ namespace WeatherService
}
// Remove all callbacks in the remove list
- removeList.ForEach(o => subscribers.Remove(o));
+ removeList.ForEach(o => Subscribers.Remove(o));
}
}
}
diff --git a/ServiceImplementation.cs b/ServiceImplementation.cs
index 634f464..a8bf4fa 100644
--- a/ServiceImplementation.cs
+++ b/ServiceImplementation.cs
@@ -1,11 +1,11 @@
using Common.Debug;
using Microsoft.Owin.Hosting;
using System;
-using System.Collections.Generic;
using System.Diagnostics;
using System.ServiceModel.Web;
using System.ServiceProcess;
using WeatherService.Framework;
+using WeatherService.Remote;
using WeatherService.SignalR;
namespace WeatherService
@@ -13,7 +13,7 @@ namespace WeatherService
[WindowsService("WeatherReporting", DisplayName = "Weather Reporting", Description = "", StartMode = ServiceStartMode.Automatic, ServiceAccount = ServiceAccount.LocalSystem)]
public class ServiceImplementation : IWindowsService
{
- private List _serviceHosts;
+ private WebServiceHost _serviceHost;
private IDisposable _signalR;
public void OnStart(string[] args)
@@ -22,13 +22,8 @@ namespace WeatherService
{
try
{
- _serviceHosts = new List
- {
- new WebServiceHost(typeof (WeatherService)),
- new WebServiceHost(typeof (WeatherServiceDuplex))
- };
-
- _serviceHosts.ForEach(h => h.Open());
+ _serviceHost = new WebServiceHost(typeof(WeatherServiceDuplex));
+ _serviceHost.Open();
_signalR = WebApp.Start(Settings.Default.SignalR_ListenUrl);
Trace.Listeners.Remove("HostingTraceListener");
@@ -57,8 +52,7 @@ namespace WeatherService
_signalR.Dispose();
- _serviceHosts.ForEach(h => h.Close());
- _serviceHosts.Clear();
+ _serviceHost.Close();
}
catch (Exception exception)
{
diff --git a/Session.cs b/Session.cs
index 25654de..8ea35f5 100644
--- a/Session.cs
+++ b/Session.cs
@@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using WeatherService.Devices;
+using WeatherService.Remote;
using WeatherService.SignalR;
namespace WeatherService
diff --git a/SignalR/WeatherHub.cs b/SignalR/WeatherHub.cs
index 714ef0e..aa265eb 100644
--- a/SignalR/WeatherHub.cs
+++ b/SignalR/WeatherHub.cs
@@ -1,7 +1,8 @@
-using System.Collections.Generic;
-using Microsoft.AspNet.SignalR;
+using Microsoft.AspNet.SignalR;
+using System.Collections.Generic;
using WeatherService.Devices;
using WeatherService.Remote;
+using WeatherService.Values;
namespace WeatherService.SignalR
{
@@ -9,11 +10,32 @@ namespace WeatherService.SignalR
{
public List GetDevices()
{
- var devices = WeatherServiceCommon.GetDevices();
+ return WeatherServiceCommon.GetDevices();
+ }
- //var json = JsonConvert.SerializeObject(devices);
+ public ReadingBase GetLatestReading(string deviceAddress, WeatherValueType valueType)
+ {
+ return WeatherServiceCommon.GetLatestReading(deviceAddress, valueType);
+ }
- return devices;
+ public DeviceHistory GetDeviceHistory(string deviceAddress)
+ {
+ return WeatherServiceCommon.GetDeviceHistory(deviceAddress);
+ }
+
+ public Dictionary> GetDeviceHistoryByValueType(WeatherValueType valueType)
+ {
+ return WeatherServiceCommon.GetDeviceHistoryByValueType(valueType);
+ }
+
+ public Dictionary> GetWindSpeedHistory(int groupIntervalMinutes)
+ {
+ return WeatherServiceCommon.GetWindSpeedHistory(groupIntervalMinutes);
+ }
+
+ public Dictionary GetWindDirectionHistory()
+ {
+ return WeatherServiceCommon.GetWindDirectionHistory();
}
}
}
diff --git a/WeatherService.csproj b/WeatherService.csproj
index a4849fd..b8cde52 100644
--- a/WeatherService.csproj
+++ b/WeatherService.csproj
@@ -151,12 +151,10 @@
WindowsServiceInstaller.cs
-
-