Commit 3c0d2389 by Stefan Schreistetter

Added logic to provide configuration parameters in app.config-file. From now on…

Added logic to provide configuration parameters in app.config-file. From now on the application only continues if the defined serial number matches the number of the connected tracker.
parent cbbd24f5
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TrackerSerialNumber" value="" />
<add key="TrackerFrequency_Hz" value="600" />
<add key="WebSocketPort" value="8001" />
<add key="WebSocketEndpoint" value="/gaze" />
<add key="DebugFlag" value="false" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
......
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
<Class Name="GazeWebSocketServer.ConfigurationData">
<Position X="0.5" Y="2.25" Width="2" />
<TypeIdentifier>
<HashCode>gEAAQAAAAAAAYAAAAAAAAAAQAAAgBAAAAAAAAAAAAAA=</HashCode>
<FileName>ConfigurationData.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="GazeWebSocketServer.EyeTrackerClient">
<Position X="6" Y="0.5" Width="1.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAACAAAAAABAAAAAAEAQAAAAAAIAAAAAAAAAA=</HashCode>
<FileName>EyeTrackerClient.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Field Name="gazeDataProcessor" />
</ShowAsAssociation>
</Class>
<Class Name="GazeWebSocketServer.GazeCoordinateBehavior">
<Position X="2.5" Y="0.5" Width="2.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAgAAAAAAAAAA=</HashCode>
<FileName>GazeCoordinateBehavior.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Field Name="eyeTrackerClient" />
</ShowAsAssociation>
</Class>
<Class Name="GazeWebSocketServer.GazeDataProcessor">
<Position X="9.5" Y="0.5" Width="1.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAAABAQAAAAAAAAAAAAAAAAAAAAAAAQAAAAAA=</HashCode>
<FileName>GazeDataProcessor.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="GazeWebSocketServer.Program" Collapsed="true">
<Position X="0.5" Y="0.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAA=</HashCode>
<FileName>Program.cs</FileName>
</TypeIdentifier>
</Class>
<Struct Name="GazeWebSocketServer.GazeData" Collapsed="true">
<Position X="0.5" Y="1.25" Width="1.5" />
<TypeIdentifier>
<HashCode>QAAAAAAAAAAAAAAEAAgAAAAAAAAAAAAAAAAAAAAAgAA=</HashCode>
<FileName>GazeData.cs</FileName>
</TypeIdentifier>
</Struct>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
namespace GazeWebSocketServer
{
public class ConfigurationData
{
public string TrackerSerialNumber { get; private set; }
public float TrackerFrequency { get; private set; }
public int WebSocketPort { get; private set; }
public string WebSocketEndpoint { get; private set; }
public bool DebugFlag { get; private set; }
public static ConfigurationData ParseToObject()
{
ConfigurationData result = new ConfigurationData
{
TrackerSerialNumber = ConfigurationManager.AppSettings["TrackerSerialNumber"],
TrackerFrequency = float.Parse(ConfigurationManager.AppSettings["TrackerFrequency_Hz"]),
WebSocketPort = int.Parse(ConfigurationManager.AppSettings["WebSocketPort"]),
WebSocketEndpoint = ConfigurationManager.AppSettings["WebSocketEndpoint"],
DebugFlag = bool.Parse(ConfigurationManager.AppSettings["DebugFlag"])
};
return result;
}
public static void InitializeUnexistingWithDefaults()
{
InitializeSetting("TrackerSerialNumber", "");
InitializeSetting("TrackerFrequency_Hz", "600");
InitializeSetting("WebSocketPort", "8001");
InitializeSetting("WebSocketEndpoint", "/gaze");
InitializeSetting("DebugFlag", "false");
}
private static void InitializeSetting(string key, string value)
{
try
{
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
if (settings[key] == null)
{
settings.Add(key, value);
}
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
}
catch (ConfigurationErrorsException)
{
Console.WriteLine("Error writing app settings");
}
}
}
}
......@@ -13,7 +13,7 @@ namespace GazeWebSocketServer
private GazeDataProcessor gazeDataProcessor;
private List<GazeCoordinateBehavior> gazeCoordinateBehaviors;
public EyeTrackerClient()
public EyeTrackerClient(ConfigurationData config)
{
gazeCoordinateBehaviors = new List<GazeCoordinateBehavior>();
while (eyeTracker == null)
......@@ -21,11 +21,17 @@ namespace GazeWebSocketServer
EyeTrackerCollection eyeTrackers = EyeTrackingOperations.FindAllEyeTrackers();
if (eyeTrackers.Count > 0)
{
eyeTracker = eyeTrackers[0];
foreach(IEyeTracker t in eyeTrackers)
{
if(config.TrackerSerialNumber == t.SerialNumber)
{
eyeTracker = t;
}
}
}
}
gazeDataProcessor = new GazeDataProcessor();
eyeTracker.SetGazeOutputFrequency(120f);
eyeTracker.SetGazeOutputFrequency(config.TrackerFrequency);
}
public void Start(GazeCoordinateBehavior gazeCoordinateBehavior)
......
......@@ -10,10 +10,10 @@ namespace GazeWebSocketServer
{
private EyeTrackerClient eyeTrackerClient;
public GazeCoordinateBehavior()
public GazeCoordinateBehavior(ConfigurationData config)
{
Console.WriteLine("Creating behavior...");
eyeTrackerClient = new EyeTrackerClient();
eyeTrackerClient = new EyeTrackerClient(config);
eyeTrackerClient.Start(this);
}
......
......@@ -37,6 +37,7 @@
<ItemGroup>
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
......@@ -52,6 +53,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigurationData.cs" />
<Compile Include="EyeTrackerClient.cs" />
<Compile Include="GazeCoordinateBehavior.cs" />
<Compile Include="GazeData.cs" />
......@@ -61,6 +63,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="ClassDiagram1.cd" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
......
......@@ -9,9 +9,12 @@ namespace GazeWebSocketServer
{
public static void Main(string[] args)
{
var wssv = new WebSocketServer(8001);
GazeCoordinateBehavior behavior = new GazeCoordinateBehavior();
wssv.AddWebSocketService("/gaze", () => behavior);
ConfigurationData.InitializeUnexistingWithDefaults();
ConfigurationData config = ConfigurationData.ParseToObject();
var wssv = new WebSocketServer(config.WebSocketPort);
GazeCoordinateBehavior behavior = new GazeCoordinateBehavior(config);
wssv.AddWebSocketService(config.WebSocketEndpoint, () => behavior);
wssv.Start();
Console.ReadKey(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment