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,31 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="WeatherService.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="WeatherService.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.5" />
</startup>
<applicationSettings>
<WeatherService.Settings>
<setting name="LogDatabase" serializeAs="String">
<setting name="LogDatabase"
serializeAs="String">
<value>False</value>
</setting>
<setting name="LcdTemplate" serializeAs="String">
<value />
</setting>
<setting name="PollingInterval" serializeAs="String">
<setting name="PollingInterval"
serializeAs="String">
<value>00:00:01</value>
</setting>
<setting name="DatabaseFile" serializeAs="String">
<value>C:\WeatherCenter\WeatherCenter.sdf</value>
</setting>
<setting name="SignalR_ListenUrl" serializeAs="String">
<setting name="SignalR_ListenUrl"
serializeAs="String">
<value>http://*:9090</value>
</setting>
<setting name="SignalR_ConnectUrl" serializeAs="String">
<setting name="SignalR_ConnectUrl"
serializeAs="String">
<value>http://localhost:9090</value>
</setting>
</WeatherService.Settings>
@@ -33,7 +39,8 @@
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJson" crossDomainScriptAccessEnabled="true" />
<binding name="webHttpBindingWithJson"
crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
<netTcpBinding>
<binding name="netTcpBindingNoSecurity">
@@ -42,17 +49,27 @@
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="Default" name="WeatherService.WeatherServiceDuplex">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBindingNoSecurity" contract="WeatherService.IWeatherServiceDuplex" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<service behaviorConfiguration="Default"
name="WeatherService.WeatherServiceDuplex">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="netTcpBindingNoSecurity"
contract="WeatherService.IWeatherServiceDuplex" />
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://server:9001" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="Default" name="WeatherService.WeatherService">
<endpoint address="json" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJson" contract="WeatherService.IWeatherService" />
<service behaviorConfiguration="Default"
name="WeatherService.WeatherService">
<endpoint address="json"
binding="webHttpBinding"
bindingConfiguration="webHttpBindingWithJson"
contract="WeatherService.IWeatherService" />
<host>
<baseAddresses>
<add baseAddress="http://server:9000" />
@@ -71,25 +88,59 @@
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.AspNet.SignalR.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.3.0" newVersion="2.0.3.0" />
<assemblyIdentity name="Microsoft.AspNet.SignalR.Core"
publicKeyToken="31bf3856ad364e35"
culture="neutral" />
<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" />
<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" />
<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" />
<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" />
<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>

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

@@ -99,14 +99,20 @@ namespace WeatherService.Devices
internal bool Load()
{
try
{
using (var weatherData = new WeatherData())
{
// Get the device data from the database
DeviceData deviceData = (from device in Database.DeviceTable where device.Address == _deviceAddress select device).First();
var deviceData = weatherData.Devices.FirstOrDefault(d => d.Address == _deviceAddress);
if (deviceData == null)
return false;
// Load the device data
_deviceId = deviceData.Id;
_displayName = deviceData.Name;
_refreshFrequency = deviceData.ReadInterval;
}
return true;
}
@@ -117,14 +123,22 @@ namespace WeatherService.Devices
}
internal bool Save()
{
using (var weatherData = new WeatherData())
{
// Get the device data from the database
DeviceData deviceData = (from device in Database.DeviceTable where device.Address == _deviceAddress select device).First();
var deviceData = weatherData.Devices.FirstOrDefault(d => d.Address == _deviceAddress);
if (deviceData == null)
return false;
// Save device data
deviceData.Name = _displayName;
deviceData.ReadInterval = _refreshFrequency;
weatherData.SaveChanges();
}
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,
Description = Configuration.Description,
StartType = Configuration.StartMode,
ServicesDependedOn = new[] { "MSSQL$WEATHER" }
};
return result;

View File

@@ -1,4 +1,5 @@
using Common.Debug;
using System.Globalization;
using Common.Debug;
using System;
using System.Diagnostics;
using System.Linq;
@@ -13,7 +14,7 @@ namespace WeatherService
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))
{

View File

@@ -10,20 +10,23 @@ using WeatherService.SignalR;
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
{
private List<WebServiceHost> _serviceHosts = new List<WebServiceHost>();
private List<WebServiceHost> _serviceHosts;
private IDisposable _signalR;
public void OnStart(string[] args)
{
using (new BeginEndTracer(GetType().Name, "OnStart"))
using (new BeginEndTracer(GetType().Name))
{
try
{
_serviceHosts.Add(new WebServiceHost(typeof(WeatherService)));
_serviceHosts.Add(new WebServiceHost(typeof(WeatherServiceDuplex)));
_serviceHosts = new List<WebServiceHost>
{
new WebServiceHost(typeof (WeatherService)),
new WebServiceHost(typeof (WeatherServiceDuplex))
};
_serviceHosts.ForEach(h => h.Open());
@@ -31,6 +34,7 @@ namespace WeatherService
Trace.Listeners.Remove("HostingTraceListener");
Program.Session = new Session();
Program.Session.Initialize();
Program.Session.StartRefresh();
}
@@ -44,15 +48,15 @@ namespace WeatherService
public void OnStop()
{
using (new BeginEndTracer(GetType().Name, "OnStop"))
using (new BeginEndTracer(GetType().Name))
{
try
{
_signalR.Dispose();
Program.Session.StopRefresh();
Program.Session.Terminate();
_signalR.Dispose();
_serviceHosts.ForEach(h => h.Close());
_serviceHosts.Clear();
}

View File

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

22
Settings.Designer.cs generated
View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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
// the code is regenerated.
@@ -12,7 +12,7 @@ namespace WeatherService {
[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 {
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.Diagnostics.DebuggerNonUserCodeAttribute()]
[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.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("http://*:9090")]

View File

@@ -5,15 +5,9 @@
<Setting Name="LogDatabase" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="LcdTemplate" Type="System.String" Scope="Application">
<Value Profile="(Default)" />
</Setting>
<Setting Name="PollingInterval" Type="System.TimeSpan" Scope="Application">
<Value Profile="(Default)">00:00:01</Value>
</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">
<Value Profile="(Default)">http://*:9090</Value>
</Setting>

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Data.SqlServerCe;
using System.Linq;
using System.Runtime.Serialization;
using WeatherService.Data;
@@ -71,6 +70,30 @@ namespace WeatherService.Values
// Figure out the minimum time we want to load into history
DateTime minimumTime = DateTime.Now.AddHours(-MaximumHours);
using (var weatherArchiveData = new WeatherArchiveData(minimumTime.Year))
{
var readingList =
weatherArchiveData.Readings.Where(
reading =>
reading.DeviceId == ownerDevice.Id && reading.Type == (int) valueType &&
reading.ReadTime >= minimumTime);
// Loop over all readings and reload them into the history
foreach (var readingData in readingList)
{
// Get the value from the reading
double dValue = readingData.Value;
// Get the timestamp from the reading
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
@@ -88,6 +111,7 @@ namespace WeatherService.Values
// Set the value into the history
SetValue(dValue, dtTimestamp, false);
}
*/
}
#endregion
@@ -217,24 +241,19 @@ namespace WeatherService.Values
if (save)
{
// Save the reading
/*
ReadingData readingData = new ReadingData
using (var weatherArchiveData = new WeatherArchiveData(timeStamp.Year))
{
var reading = new Data.Reading
{
DeviceId = _ownerDevice.Id,
Type = (int) ValueType,
Value = value,
Type = _valueType,
ReadTime = timeStamp
};
Database.ReadingTable.InsertOnSubmit(readingData);
Database.SaveChanges();
*/
string query =
string.Format(
"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();
weatherArchiveData.Readings.Add(reading);
weatherArchiveData.SaveChanges();
}
// Update the minimum value
CheckMinimumValue(value, timeStamp);

View File

@@ -50,7 +50,14 @@
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup />
<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">
<HintPath>packages\Microsoft.AspNet.SignalR.Client.2.0.3\lib\net45\Microsoft.AspNet.SignalR.Client.dll</HintPath>
</Reference>
@@ -83,11 +90,14 @@
<HintPath>packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web.Cors">
@@ -102,10 +112,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Conversion.cs" />
<Compile Include="Data\Database.cs" />
<Compile Include="Data\DatabaseContext.cs" />
<Compile Include="Data\DeviceData.cs" />
<Compile Include="Data\ReadingData.cs" />
<Compile Include="Data\Device.cs" />
<Compile Include="Data\Reading.cs" />
<Compile Include="Data\Setting.cs" />
<Compile Include="Data\WeatherArchiveData.cs" />
<Compile Include="Data\WeatherData.cs" />
<Compile Include="Devices\DeviceBase.cs" />
<Compile Include="Devices\HumidityDevice.cs" />
<Compile Include="Devices\PressureDevice.cs" />
@@ -113,7 +124,6 @@
<Compile Include="Devices\TemperatureDevice.cs" />
<Compile Include="Devices\WindDirectionDevice.cs" />
<Compile Include="Devices\WindSpeedDevice.cs" />
<Compile Include="EventArguments.cs" />
<Compile Include="Format.cs" />
<Compile Include="Framework\ConsoleHarness.cs" />
<Compile Include="Framework\IWindowsService.cs" />
@@ -193,12 +203,11 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup />
<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.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<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.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.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.Cors" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Host.HttpListener" version="2.1.0" targetFramework="net45" />