Permalink
Browse files

updated decoder and database modules

  • Loading branch information...
1 parent cb383de commit 8cc76b2b355d6255aa21024a59025eaacad0fa02 @ashawnbandy committed Nov 5, 2012
@@ -15,7 +15,7 @@ public class ConsoleLogger : Module
public override void onRealTimeEvent(RealTimeEvent rte)
{
- System.Console.WriteLine("(event) " + rte);
+ System.Console.WriteLine(rte);
}
public override string getModuleName()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,84 +1,83 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using EventSlice.Interfaces;
-using EventSlice;
-using MySql.Data.MySqlClient;
-using System.Data;
-
-
-namespace Database
-{
- public class Database : Module
- {
- string connectionString {private get; private set;}
-
- public Database(Dispatcher dispatcher, string host = "localhost", string db = "csulbsha_sharktopus", string user = "testuser", string pass = "testpass")
- :base(dispatcher)
- {
- connectionString = "Server=" + host + ";Database=" + db + ";Uid=" + user + ";Pwd=" + pass + ";";
- }
-
- public override string getModuleName()
- { return "Database"; }
-
- public override void onRealTimeEvent(RealTimeEvent realTimeEvent)
- {
- if(realTimeEvent.GetType() == typeof(Decoder.RealTimeEvents.Decoded))
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using EventSlice.Interfaces;
+using EventSlice;
+using MySql.Data.MySqlClient;
+using System.Data;
+
+
+namespace Databases
+{
+ public class Database : Module
+ {
+ private string connectionString {get; set;}
+
+ public Database(Dispatcher dispatcher, string host = "localhost", string db = "csulbsha_sharktopus", string user = "testuser", string pass = "testpass")
+ {
+ connectionString = "Server=" + host + ";Database=" + db + ";Uid=" + user + ";Pwd=" + pass + ";";
+ }
+
+ public override string getModuleName()
+ { return "Database"; }
+
+ public override void onRealTimeEvent(RealTimeEvent realTimeEvent)
+ {
+ if(realTimeEvent.GetType() == typeof(Decoder.RealTimeEvents.Decoded))
{
Decoder.RealTimeEvents.Decoded rte = (Decoder.RealTimeEvents.Decoded)realTimeEvent;
- string eventType = rte["messagetype"];
- if (eventType == "detection_event")
- detectionInsert(rte);
- }
+ string eventType = rte["messagetype"];
+ if (eventType == "detection_event")
+ detectionInsert(rte);
+ }
else if(realTimeEvent.GetType() == typeof(ReceiverSlice.RealTimeEvents.NewReceiver))
- receiverInsert((ReceiverSlice.RealTimeEvents.NewReceiver)realTimeEvent);
- }
-
- private void receiverInsert(ReceiverSlice.RealTimeEvents.NewReceiver newReceiver)
- {
- string statement = "INSERT INTO receivers (id) VALUES ('" + newReceiver["serialnumber"] + "');");
- int response = doInsert(statement);
- dispatcher.enqueueEvent(new DatabaseResponse(statement, response));
+ receiverInsert((ReceiverSlice.RealTimeEvents.NewReceiver)realTimeEvent);
+ }
+
+ private void receiverInsert(ReceiverSlice.RealTimeEvents.NewReceiver newReceiver)
+ {
+ string statement = "INSERT INTO receivers (id) VALUES ('" + newReceiver["serialnumber"] + "');";
+ int response = doInsert(statement);
+ dispatcher.enqueueEvent(new Databases.RealTimeEvents.DatabaseResponse(statement, response, newReceiver));
+ }
+
+ private void detectionInsert(Decoder.RealTimeEvents.Decoded detection)
+ {
+ string statement;
+ if(detection["decodedmessage"]["sensor_value"] == null)
+ statement = "INSERT INTO vue (date, time, frequency_codespace, transmitter_id, receivers_id) VALUES ('" +
+ detection["decodedmessage"]["date"] + "', '" + detection["decodedmessage"]["time"] + "', '" + detection["decodedmessage"]["frequency_codespace"] + "', " + detection["decodedmessage"]["transmitter_id"] + ", '" + detection["decodedmessage"]["receivers_id"] + "');";
+ else
+ statement = "INSERT INTO vue (date, time, frequency_codespace, transmitter_id, sensor_value, sensor_unit, receivers_id) VALUES ('" +
+ detection["decodedmessage"]["date"] + "', '" + detection["decodedmessage"]["time"] + "', '" + detection["decodedmessage"]["frequency_codespace"] + "', " + detection["decodedmessage"]["transmitter_id"] + ", " + detection["decodedmessage"]["sensor_value"] + ", 'm', '" + detection["decodedmessage"]["receivers_id"] + "');";
+ int response = doInsert(statement);
+ dispatcher.enqueueEvent(new Databases.RealTimeEvents.DatabaseResponse(statement, response, detection));
}
- private void detectionInsert(Decoder.RealTimeEvents.Decoded detection)
- {
- string statement;
- if(detection.payload["sensor_value"] == null)
- statement = "INSERT INTO vue (date, time, frequency_codespace, transmitter_id, receivers_id) VALUES ('" +
- detection.payload["date"] + "', '" + detection.payload["time"] + "', '" + detection.payload["frequency_codespace"] + "', " + detection.payload["transmitter_id"] + ", '" + detection.payload["receivers_id"] + "');";
- else
- statement = "INSERT INTO vue (date, time, frequency_codespace, transmitter_id, sensor_value, sensor_unit, receivers_id) VALUES ('" +
- detection.payload["date"] + "', '" + detection.payload["time"] + "', '" + detection.payload["frequency_codespace"] + "', " + detection.payload["transmitter_id"] + ", " + detection.payload["sensor_value"] + ", 'm', '" + detection.payload["receivers_id"] + "');";
- int response = doInsert(statement);
- dispatcher.enqueueEvent(new DatabaseResponse(statement, response));
- }
-
- private int doInsert(string statement)
- {
- int response = -1;
- MySqlConnection connection = new MySqlConnection(connectionString);
- MySqlCommand command;
- connection.Open();
- try
- {
- command = connection.CreateCommand();
- command.CommandText = statement;
- response = command.ExecuteNonQuery();
- }
- catch (Exception e)
- {}
- finally
- {
- if(connection.State == ConnectionState.Open)
- {
- connection.Close();
- }
- }
- return response;
- }
- }
-}
+ private int doInsert(string statement)
+ {
+ int response = -1;
+ MySqlConnection connection = new MySqlConnection(connectionString);
+ MySqlCommand command;
+ connection.Open();
+ try
+ {
+ command = connection.CreateCommand();
+ command.CommandText = statement;
+ response = command.ExecuteNonQuery();
+ }
+ catch (Exception e)
+ {}
+ finally
+ {
+ if(connection.State == ConnectionState.Open)
+ {
+ connection.Close();
+ }
+ }
+ return response;
+ }
+ }
+}
@@ -5,9 +5,9 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{30231B33-86BB-476A-A725-E35187541402}</ProjectGuid>
- <OutputType>Exe</OutputType>
+ <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Database</RootNamespace>
+ <RootNamespace>Databases</RootNamespace>
<AssemblyName>Database</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
@@ -31,6 +31,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
+ <PropertyGroup>
+ <StartupObject />
+ </PropertyGroup>
<ItemGroup>
<Reference Include="Decoder">
<HintPath>F:\cecs491\Modules\Decoder\obj\Release\Decoder.dll</HintPath>
@@ -55,10 +58,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Database.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="DatabaseResponse.cs" />
</ItemGroup>
<ItemGroup>
- <None Include="App.config" />
+ <Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
View
Binary file not shown.

0 comments on commit 8cc76b2

Please sign in to comment.