Change from SQL CE to SQL Express

This commit is contained in:
2015-01-14 14:41:04 -05:00
parent 822f6ccdea
commit f54f92330b
21 changed files with 383 additions and 413 deletions

View File

@@ -1,95 +1,146 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<configSections> <configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <sectionGroup name="applicationSettings"
<section name="WeatherService.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
</sectionGroup> <section name="WeatherService.Settings"
</configSections> type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
<startup> requirePermission="false" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </sectionGroup>
</startup> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<applicationSettings> <section name="entityFramework"
<WeatherService.Settings> type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
<setting name="LogDatabase" serializeAs="String"> requirePermission="false" />
<value>False</value> </configSections>
</setting> <startup>
<setting name="LcdTemplate" serializeAs="String"> <supportedRuntime version="v4.0"
<value /> sku=".NETFramework,Version=v4.5" />
</setting> </startup>
<setting name="PollingInterval" serializeAs="String"> <applicationSettings>
<value>00:00:01</value> <WeatherService.Settings>
</setting> <setting name="LogDatabase"
<setting name="DatabaseFile" serializeAs="String"> serializeAs="String">
<value>C:\WeatherCenter\WeatherCenter.sdf</value> <value>False</value>
</setting> </setting>
<setting name="SignalR_ListenUrl" serializeAs="String"> <setting name="PollingInterval"
<value>http://*:9090</value> serializeAs="String">
</setting> <value>00:00:01</value>
<setting name="SignalR_ConnectUrl" serializeAs="String"> </setting>
<value>http://localhost:9090</value> <setting name="SignalR_ListenUrl"
</setting> serializeAs="String">
</WeatherService.Settings> <value>http://*:9090</value>
</applicationSettings> </setting>
<system.serviceModel> <setting name="SignalR_ConnectUrl"
<bindings> serializeAs="String">
<webHttpBinding> <value>http://localhost:9090</value>
<binding name="webHttpBindingWithJson" crossDomainScriptAccessEnabled="true" /> </setting>
</webHttpBinding> </WeatherService.Settings>
<netTcpBinding> </applicationSettings>
<binding name="netTcpBindingNoSecurity"> <system.serviceModel>
<security mode="None"></security> <bindings>
</binding> <webHttpBinding>
</netTcpBinding> <binding name="webHttpBindingWithJson"
</bindings> crossDomainScriptAccessEnabled="true" />
<services> </webHttpBinding>
<service behaviorConfiguration="Default" name="WeatherService.WeatherServiceDuplex"> <netTcpBinding>
<endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBindingNoSecurity" contract="WeatherService.IWeatherServiceDuplex" /> <binding name="netTcpBindingNoSecurity">
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" /> <security mode="None"></security>
<host> </binding>
<baseAddresses> </netTcpBinding>
<add baseAddress="net.tcp://server:9001" /> </bindings>
</baseAddresses> <services>
</host> <service behaviorConfiguration="Default"
</service> name="WeatherService.WeatherServiceDuplex">
<service behaviorConfiguration="Default" name="WeatherService.WeatherService"> <endpoint address=""
<endpoint address="json" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJson" contract="WeatherService.IWeatherService" /> binding="netTcpBinding"
<host> bindingConfiguration="netTcpBindingNoSecurity"
<baseAddresses> contract="WeatherService.IWeatherServiceDuplex" />
<add baseAddress="http://server:9000" /> <endpoint address="mex"
</baseAddresses> binding="mexTcpBinding"
</host> contract="IMetadataExchange" />
</service> <host>
</services> <baseAddresses>
<behaviors> <add baseAddress="net.tcp://server:9001" />
<serviceBehaviors> </baseAddresses>
<behavior name="Default"> </host>
<serviceMetadata httpGetEnabled="true" /> </service>
</behavior> <service behaviorConfiguration="Default"
</serviceBehaviors> name="WeatherService.WeatherService">
</behaviors> <endpoint address="json"
</system.serviceModel> binding="webHttpBinding"
<runtime> bindingConfiguration="webHttpBindingWithJson"
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> contract="WeatherService.IWeatherService" />
<dependentAssembly> <host>
<assemblyIdentity name="Microsoft.AspNet.SignalR.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <baseAddresses>
<bindingRedirect oldVersion="0.0.0.0-2.0.3.0" newVersion="2.0.3.0" /> <add baseAddress="http://server:9000" />
</dependentAssembly> </baseAddresses>
<dependentAssembly> </host>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" /> </service>
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" /> </services>
</dependentAssembly> <behaviors>
<dependentAssembly> <serviceBehaviors>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <behavior name="Default">
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> <serviceMetadata httpGetEnabled="true" />
</dependentAssembly> </behavior>
<dependentAssembly> </serviceBehaviors>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" /> </behaviors>
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" /> </system.serviceModel>
</dependentAssembly> <runtime>
<dependentAssembly> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="System.Web.Cors" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <dependentAssembly>
<bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" /> <assemblyIdentity name="Microsoft.AspNet.SignalR.Core"
</dependentAssembly> publicKeyToken="31bf3856ad364e35"
</assemblyBinding> culture="neutral" />
</runtime> <bindingRedirect oldVersion="0.0.0.0-2.0.3.0"
newVersion="2.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin"
publicKeyToken="31bf3856ad364e35"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0"
newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"
publicKeyToken="30ad4fe6b2a6aeed"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0"
newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security"
publicKeyToken="31bf3856ad364e35"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0"
newVersion="2.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Cors"
publicKeyToken="31bf3856ad364e35"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.1.0.0"
newVersion="5.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="WeatherData"
connectionString="data source=localhost\Weather;initial catalog=Weather;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
<add name="WeatherArchiveData"
connectionString="data source=localhost\Weather;initial catalog=WeatherDataTest;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration> </configuration>

View File

@@ -1,99 +0,0 @@
using Common.Debug;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.SqlServerCe;
using System.Linq;
using WeatherService.Values;
namespace WeatherService.Data
{
/// <summary>
/// This class manages database connectivity and logging
/// </summary>
internal static class Database
{
private static DatabaseContext _databaseContext;
private static SqlCeConnection _connection;
public static void Connect(string databasePath)
{
_connection = new SqlCeConnection(string.Format("Data Source={0}", databasePath));
_connection.Open();
}
public static SqlCeConnection Connection
{
get
{
return _connection;
}
}
public static void Initialize(string databasePath)
{
Connect(databasePath);
// Create a database context
_databaseContext = new DatabaseContext(databasePath);
// Turn on logging if requested
if (Settings.Default.LogDatabase)
_databaseContext.Log = Tracer.Writer;
// Create the database engine
SqlCeEngine engine = new SqlCeEngine(string.Format("Data Source={0}", databasePath));
// Check to see if the database exists
if (!_databaseContext.DatabaseExists())
{
// Create the database itself
engine.CreateDatabase();
// Run the creation script
// executeScript(Resources.CreateDatabase);
}
// Compact the database
engine.Shrink();
}
public static Table<DeviceData> DeviceTable
{
get { return _databaseContext.DeviceTable; }
}
public static Table<ReadingData> ReadingTable
{
get { return _databaseContext.ReadingTable; }
}
public static IEnumerable<DeviceData> DeviceList
{
get { return from device in DeviceTable select device; }
}
public static IEnumerable<ReadingData> ReadingList(int deviceId)
{
return from reading in ReadingTable where reading.DeviceId == deviceId select reading;
}
public static IEnumerable<ReadingData> ReadingList(int deviceId, WeatherValueType valueType)
{
return from reading in ReadingTable where reading.DeviceId == deviceId && reading.Type == valueType select reading;
}
public static void SaveChanges()
{
_databaseContext.SubmitChanges(ConflictMode.ContinueOnConflict);
}
public static void DiscardChanges()
{
ChangeSet changeSet = _databaseContext.GetChangeSet();
_databaseContext.Refresh(RefreshMode.OverwriteCurrentValues, changeSet.Inserts);
_databaseContext.Refresh(RefreshMode.OverwriteCurrentValues, changeSet.Deletes);
_databaseContext.Refresh(RefreshMode.OverwriteCurrentValues, changeSet.Updates);
}
}
}

View File

@@ -1,12 +0,0 @@
using System.Data.Linq;
namespace WeatherService.Data
{
public class DatabaseContext : DataContext
{
public Table<DeviceData> DeviceTable;
public Table<ReadingData> ReadingTable;
public DatabaseContext(string databaseFile) : base(databaseFile) { }
}
}

21
Data/Device.cs Normal file
View File

@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WeatherService.Data
{
[Table("Device")]
public class Device
{
public int Id { get; set; }
[Required]
[StringLength(100)]
public string Address { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
public int ReadInterval { get; set; }
}
}

View File

@@ -1,28 +0,0 @@
using System.Data.Linq.Mapping;
namespace WeatherService.Data
{
[Table(Name = "Device")]
public class DeviceData
{
[Column(UpdateCheck = UpdateCheck.Never, IsDbGenerated = true, IsPrimaryKey = true)]
public int Id;
[Column(UpdateCheck = UpdateCheck.Never)]
public string Address;
[Column(UpdateCheck = UpdateCheck.Never)]
public string Name;
[Column(UpdateCheck = UpdateCheck.Never)]
public int ReadInterval;
//private readonly EntitySet<Reading> _readingSet = new EntitySet<Reading>();
//[Association(Storage = "_readingSet", OtherKey = "DeviceId", ThisKey = "Id")]
//public EntitySet<Reading> Readings
//{
// get { return _readingSet; }
// set { _readingSet.Assign(value); }
//}
}
}

19
Data/Reading.cs Normal file
View File

@@ -0,0 +1,19 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace WeatherService.Data
{
[Table("Reading")]
public class Reading
{
public int Id { get; set; }
public int DeviceId { get; set; }
public int Type { get; set; }
public double Value { get; set; }
public DateTimeOffset ReadTime { get; set; }
}
}

View File

@@ -1,60 +0,0 @@
using System;
using System.Data.Linq.Mapping;
using System.Data.SqlTypes;
using WeatherService.Values;
namespace WeatherService.Data
{
[Table(Name = "Reading")]
public class ReadingData
{
public ReadingData()
{
ReadTime = SqlDateTime.MinValue.Value;
}
[Column(UpdateCheck = UpdateCheck.Never, IsDbGenerated = true, IsPrimaryKey = true)]
public int Id
{
get;
internal set;
}
[Column(UpdateCheck = UpdateCheck.Never)]
public int DeviceId
{
get;
internal set;
}
[Column(UpdateCheck = UpdateCheck.Never)]
public WeatherValueType Type
{
get;
internal set;
}
[Column(UpdateCheck = UpdateCheck.Never)]
public double Value
{
get;
internal set;
}
[Column(UpdateCheck = UpdateCheck.Never)]
public DateTime ReadTime
{
get;
internal set;
}
//private EntityRef<DeviceData> _device;
//[Association(Storage = "_device", ThisKey = "DeviceId", OtherKey = "Id")]
//public DeviceData Device
//{
// get { return _device.Entity; }
// set { _device.Entity = value; }
//}
}
}

17
Data/Setting.cs Normal file
View File

@@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WeatherService.Data
{
[Table("Setting")]
public class Setting
{
[Key]
[StringLength(500)]
public string Name { get; set; }
[Required]
[StringLength(3500)]
public string Value { get; set; }
}
}

View File

@@ -0,0 +1,48 @@
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Data.SqlClient;
namespace WeatherService.Data
{
public class WeatherArchiveData : DbContext
{
private const string ConnectionStringTemplateName = "WeatherArchiveData";
private const string DatabaseNameYearTemplate = "WeatherData{0}";
private static readonly Dictionary<int, bool> DatabaseExists = new Dictionary<int, bool>();
private static string BuildConnectionString(int year)
{
var databaseName = string.Format(DatabaseNameYearTemplate, year);
var connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringTemplateName].ConnectionString;
var builder = new SqlConnectionStringBuilder(connectionString) { InitialCatalog = databaseName };
return builder.ConnectionString;
}
public WeatherArchiveData(int year)
: base(BuildConnectionString(year))
{
if (DatabaseExists.ContainsKey(year))
return;
DatabaseExists[year] = Database.Exists();
if (DatabaseExists[year])
return;
Database.Create();
DatabaseExists[year] = true;
}
public virtual DbSet<Reading> Readings { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
}
}
}

19
Data/WeatherData.cs Normal file
View File

@@ -0,0 +1,19 @@
using System.Data.Entity;
namespace WeatherService.Data
{
public class WeatherData : DbContext
{
public WeatherData()
: base("name=WeatherData")
{
}
public virtual DbSet<Device> Devices { get; set; }
public virtual DbSet<Setting> Settings { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
}
}
}

View File

@@ -100,13 +100,19 @@ namespace WeatherService.Devices
{ {
try try
{ {
// Get the device data from the database using (var weatherData = new WeatherData())
DeviceData deviceData = (from device in Database.DeviceTable where device.Address == _deviceAddress select device).First(); {
// Get the device data from the database
var deviceData = weatherData.Devices.FirstOrDefault(d => d.Address == _deviceAddress);
// Load the device data if (deviceData == null)
_deviceId = deviceData.Id; return false;
_displayName = deviceData.Name;
_refreshFrequency = deviceData.ReadInterval; // Load the device data
_deviceId = deviceData.Id;
_displayName = deviceData.Name;
_refreshFrequency = deviceData.ReadInterval;
}
return true; return true;
} }
@@ -118,12 +124,20 @@ namespace WeatherService.Devices
internal bool Save() internal bool Save()
{ {
// Get the device data from the database using (var weatherData = new WeatherData())
DeviceData deviceData = (from device in Database.DeviceTable where device.Address == _deviceAddress select device).First(); {
// Get the device data from the database
var deviceData = weatherData.Devices.FirstOrDefault(d => d.Address == _deviceAddress);
// Save device data if (deviceData == null)
deviceData.Name = _displayName; return false;
deviceData.ReadInterval = _refreshFrequency;
// Save device data
deviceData.Name = _displayName;
deviceData.ReadInterval = _refreshFrequency;
weatherData.SaveChanges();
}
return true; return true;
} }

View File

@@ -1,28 +0,0 @@
using System;
using WeatherService.Devices;
namespace WeatherService
{
#region DeviceRefreshed
[Serializable]
public class DeviceRefreshedEventArgs : EventArgs
{
private readonly DeviceBase _device;
public DeviceRefreshedEventArgs(DeviceBase Device)
{
_device = Device;
}
public DeviceBase Device
{
get
{
return _device;
}
}
}
#endregion
}

View File

@@ -204,6 +204,7 @@ namespace WeatherService.Framework
DisplayName = Configuration.DisplayName, DisplayName = Configuration.DisplayName,
Description = Configuration.Description, Description = Configuration.Description,
StartType = Configuration.StartMode, StartType = Configuration.StartMode,
ServicesDependedOn = new[] { "MSSQL$WEATHER" }
}; };
return result; return result;

View File

@@ -1,4 +1,5 @@
using Common.Debug; using System.Globalization;
using Common.Debug;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@@ -13,7 +14,7 @@ namespace WeatherService
static void Main(string[] args) static void Main(string[] args)
{ {
Tracer.Initialize(@"C:\WeatherCenter\Logs", "WeatherService", Process.GetCurrentProcess().Id.ToString(), Environment.UserInteractive); Tracer.Initialize(@"C:\WeatherCenter\Logs", "WeatherService", Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), Environment.UserInteractive);
if (args.Contains("-install", StringComparer.InvariantCultureIgnoreCase)) if (args.Contains("-install", StringComparer.InvariantCultureIgnoreCase))
{ {

View File

@@ -10,20 +10,23 @@ using WeatherService.SignalR;
namespace WeatherService namespace WeatherService
{ {
[WindowsService("WeatherService", DisplayName = "Weather Reporting Service", Description = "", StartMode = ServiceStartMode.Automatic, ServiceAccount = ServiceAccount.LocalSystem)] [WindowsService("WeatherReporting", DisplayName = "Weather Reporting", Description = "", StartMode = ServiceStartMode.Automatic, ServiceAccount = ServiceAccount.LocalSystem)]
public class ServiceImplementation : IWindowsService public class ServiceImplementation : IWindowsService
{ {
private List<WebServiceHost> _serviceHosts = new List<WebServiceHost>(); private List<WebServiceHost> _serviceHosts;
private IDisposable _signalR; private IDisposable _signalR;
public void OnStart(string[] args) public void OnStart(string[] args)
{ {
using (new BeginEndTracer(GetType().Name, "OnStart")) using (new BeginEndTracer(GetType().Name))
{ {
try try
{ {
_serviceHosts.Add(new WebServiceHost(typeof(WeatherService))); _serviceHosts = new List<WebServiceHost>
_serviceHosts.Add(new WebServiceHost(typeof(WeatherServiceDuplex))); {
new WebServiceHost(typeof (WeatherService)),
new WebServiceHost(typeof (WeatherServiceDuplex))
};
_serviceHosts.ForEach(h => h.Open()); _serviceHosts.ForEach(h => h.Open());
@@ -31,6 +34,7 @@ namespace WeatherService
Trace.Listeners.Remove("HostingTraceListener"); Trace.Listeners.Remove("HostingTraceListener");
Program.Session = new Session(); Program.Session = new Session();
Program.Session.Initialize(); Program.Session.Initialize();
Program.Session.StartRefresh(); Program.Session.StartRefresh();
} }
@@ -44,15 +48,15 @@ namespace WeatherService
public void OnStop() public void OnStop()
{ {
using (new BeginEndTracer(GetType().Name, "OnStop")) using (new BeginEndTracer(GetType().Name))
{ {
try try
{ {
_signalR.Dispose();
Program.Session.StopRefresh(); Program.Session.StopRefresh();
Program.Session.Terminate(); Program.Session.Terminate();
_signalR.Dispose();
_serviceHosts.ForEach(h => h.Close()); _serviceHosts.ForEach(h => h.Close());
_serviceHosts.Clear(); _serviceHosts.Clear();
} }

View File

@@ -6,7 +6,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using WeatherService.Data;
using WeatherService.Devices; using WeatherService.Devices;
using WeatherService.SignalR; using WeatherService.SignalR;
@@ -39,7 +38,7 @@ namespace WeatherService
public Session() public Session()
{ {
// Initialize the database // Initialize the database
Database.Initialize(Settings.Default.DatabaseFile); // DB CHANGE - Database.Initialize(Settings.Default.DatabaseFile);
// Create the list of devices // Create the list of devices
Devices = new List<DeviceBase>(); Devices = new List<DeviceBase>();

22
Settings.Designer.cs generated
View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
// Runtime Version:4.0.30319.18033 // Runtime Version:4.0.30319.34209
// //
// Changes to this file may cause incorrect behavior and will be lost if // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.
@@ -12,7 +12,7 @@ namespace WeatherService {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@@ -32,15 +32,6 @@ namespace WeatherService {
} }
} }
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string LcdTemplate {
get {
return ((string)(this["LcdTemplate"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("00:00:01")] [global::System.Configuration.DefaultSettingValueAttribute("00:00:01")]
@@ -50,15 +41,6 @@ namespace WeatherService {
} }
} }
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("C:\\WeatherCenter\\WeatherCenter.sdf")]
public string DatabaseFile {
get {
return ((string)(this["DatabaseFile"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("http://*:9090")] [global::System.Configuration.DefaultSettingValueAttribute("http://*:9090")]

View File

@@ -5,15 +5,9 @@
<Setting Name="LogDatabase" Type="System.Boolean" Scope="Application"> <Setting Name="LogDatabase" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value> <Value Profile="(Default)">False</Value>
</Setting> </Setting>
<Setting Name="LcdTemplate" Type="System.String" Scope="Application">
<Value Profile="(Default)" />
</Setting>
<Setting Name="PollingInterval" Type="System.TimeSpan" Scope="Application"> <Setting Name="PollingInterval" Type="System.TimeSpan" Scope="Application">
<Value Profile="(Default)">00:00:01</Value> <Value Profile="(Default)">00:00:01</Value>
</Setting> </Setting>
<Setting Name="DatabaseFile" Type="System.String" Scope="Application">
<Value Profile="(Default)">C:\WeatherCenter\WeatherCenter.sdf</Value>
</Setting>
<Setting Name="SignalR_ListenUrl" Type="System.String" Scope="Application"> <Setting Name="SignalR_ListenUrl" Type="System.String" Scope="Application">
<Value Profile="(Default)">http://*:9090</Value> <Value Profile="(Default)">http://*:9090</Value>
</Setting> </Setting>

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.SqlServerCe;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using WeatherService.Data; using WeatherService.Data;
@@ -71,23 +70,48 @@ namespace WeatherService.Values
// Figure out the minimum time we want to load into history // Figure out the minimum time we want to load into history
DateTime minimumTime = DateTime.Now.AddHours(-MaximumHours); DateTime minimumTime = DateTime.Now.AddHours(-MaximumHours);
// Build a list for this device using the right value type and limit to the maximum number of hours using (var weatherArchiveData = new WeatherArchiveData(minimumTime.Year))
var readingList = from reading in Database.ReadingTable
where reading.DeviceId == ownerDevice.Id && reading.Type == valueType && reading.ReadTime >= minimumTime
select reading;
// Loop over all readings and reload them into the history
foreach (ReadingData readingData in readingList)
{ {
// Get the value from the reading var readingList =
double dValue = readingData.Value; weatherArchiveData.Readings.Where(
reading =>
reading.DeviceId == ownerDevice.Id && reading.Type == (int) valueType &&
reading.ReadTime >= minimumTime);
// Get the timestamp from the reading // Loop over all readings and reload them into the history
DateTime dtTimestamp = readingData.ReadTime; foreach (var readingData in readingList)
{
// Get the value from the reading
double dValue = readingData.Value;
// Set the value into the history // Get the timestamp from the reading
SetValue(dValue, dtTimestamp, false); DateTime dtTimestamp = readingData.ReadTime.LocalDateTime;
// Set the value into the history
SetValue(dValue, dtTimestamp, false);
}
} }
/*
// Build a list for this device using the right value type and limit to the maximum number of hours
var readingList = from reading in Database.ReadingTable
where reading.DeviceId == ownerDevice.Id && reading.Type == valueType && reading.ReadTime >= minimumTime
select reading;
// Loop over all readings and reload them into the history
foreach (ReadingData readingData in readingList)
{
// Get the value from the reading
double dValue = readingData.Value;
// Get the timestamp from the reading
DateTime dtTimestamp = readingData.ReadTime;
// Set the value into the history
SetValue(dValue, dtTimestamp, false);
}
*/
} }
#endregion #endregion
@@ -217,24 +241,19 @@ namespace WeatherService.Values
if (save) if (save)
{ {
// Save the reading // Save the reading
/* using (var weatherArchiveData = new WeatherArchiveData(timeStamp.Year))
ReadingData readingData = new ReadingData {
{ var reading = new Data.Reading
DeviceId = _ownerDevice.Id, {
Value = value, DeviceId = _ownerDevice.Id,
Type = _valueType, Type = (int) ValueType,
ReadTime = timeStamp Value = value,
}; ReadTime = timeStamp
Database.ReadingTable.InsertOnSubmit(readingData); };
Database.SaveChanges();
*/
string query = weatherArchiveData.Readings.Add(reading);
string.Format( weatherArchiveData.SaveChanges();
"INSERT INTO Reading (DeviceID, Type, Value, ReadTime) VALUES ({0}, {1:d}, {2}, '{3}')", }
_ownerDevice.Id, ValueType, value, timeStamp);
SqlCeCommand command = new SqlCeCommand(query, Database.Connection);
command.ExecuteScalar();
// Update the minimum value // Update the minimum value
CheckMinimumValue(value, timeStamp); CheckMinimumValue(value, timeStamp);

View File

@@ -50,7 +50,14 @@
<PropertyGroup> <PropertyGroup>
<StartupObject /> <StartupObject />
</PropertyGroup> </PropertyGroup>
<PropertyGroup />
<ItemGroup> <ItemGroup>
<Reference Include="EntityFramework">
<HintPath>packages\EntityFramework.6.1.2\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer">
<HintPath>packages\EntityFramework.6.1.2\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.SignalR.Client"> <Reference Include="Microsoft.AspNet.SignalR.Client">
<HintPath>packages\Microsoft.AspNet.SignalR.Client.2.0.3\lib\net45\Microsoft.AspNet.SignalR.Client.dll</HintPath> <HintPath>packages\Microsoft.AspNet.SignalR.Client.2.0.3\lib\net45\Microsoft.AspNet.SignalR.Client.dll</HintPath>
</Reference> </Reference>
@@ -83,11 +90,14 @@
<HintPath>packages\Owin.1.0\lib\net40\Owin.dll</HintPath> <HintPath>packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" /> <Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Data.Linq" /> <Reference Include="System.Data.Linq" />
<Reference Include="System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" /> <Reference Include="System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" />
<Reference Include="System.Runtime.Serialization" /> <Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.ServiceModel" /> <Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" /> <Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web.Cors"> <Reference Include="System.Web.Cors">
@@ -102,10 +112,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Conversion.cs" /> <Compile Include="Conversion.cs" />
<Compile Include="Data\Database.cs" /> <Compile Include="Data\Device.cs" />
<Compile Include="Data\DatabaseContext.cs" /> <Compile Include="Data\Reading.cs" />
<Compile Include="Data\DeviceData.cs" /> <Compile Include="Data\Setting.cs" />
<Compile Include="Data\ReadingData.cs" /> <Compile Include="Data\WeatherArchiveData.cs" />
<Compile Include="Data\WeatherData.cs" />
<Compile Include="Devices\DeviceBase.cs" /> <Compile Include="Devices\DeviceBase.cs" />
<Compile Include="Devices\HumidityDevice.cs" /> <Compile Include="Devices\HumidityDevice.cs" />
<Compile Include="Devices\PressureDevice.cs" /> <Compile Include="Devices\PressureDevice.cs" />
@@ -113,7 +124,6 @@
<Compile Include="Devices\TemperatureDevice.cs" /> <Compile Include="Devices\TemperatureDevice.cs" />
<Compile Include="Devices\WindDirectionDevice.cs" /> <Compile Include="Devices\WindDirectionDevice.cs" />
<Compile Include="Devices\WindSpeedDevice.cs" /> <Compile Include="Devices\WindSpeedDevice.cs" />
<Compile Include="EventArguments.cs" />
<Compile Include="Format.cs" /> <Compile Include="Format.cs" />
<Compile Include="Framework\ConsoleHarness.cs" /> <Compile Include="Framework\ConsoleHarness.cs" />
<Compile Include="Framework\IWindowsService.cs" /> <Compile Include="Framework\IWindowsService.cs" />
@@ -193,12 +203,11 @@
<Install>false</Install> <Install>false</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
<Error Condition="!Exists('packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
<Error Condition="Exists('packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">

View File

@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="EntityFramework" version="6.1.2" targetFramework="net45" />
<package id="Microsoft.AspNet.Cors" version="5.1.2" targetFramework="net45" /> <package id="Microsoft.AspNet.Cors" version="5.1.2" targetFramework="net45" />
<package id="Microsoft.AspNet.SignalR.Client" version="2.0.3" targetFramework="net45" /> <package id="Microsoft.AspNet.SignalR.Client" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.AspNet.SignalR.Core" version="2.0.3" targetFramework="net45" /> <package id="Microsoft.AspNet.SignalR.Core" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.AspNet.SignalR.Owin" version="1.2.1" targetFramework="net45" /> <package id="Microsoft.AspNet.SignalR.Owin" version="1.2.1" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="Microsoft.Owin" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Cors" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Cors" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Host.HttpListener" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Host.HttpListener" version="2.1.0" targetFramework="net45" />