163 lines
4.9 KiB
C#
163 lines
4.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Xml;
|
|
using System.Xml.Serialization;
|
|
|
|
namespace bsmd.AISService.AIS
|
|
{
|
|
[Serializable]
|
|
public class AIS_Configuration
|
|
{
|
|
private string filename;
|
|
private string dbConnectionString;
|
|
private int dbUpdateInterval = 500; // milliseconds
|
|
private int dbMinPosReportTimeDifference = 120; // seconds
|
|
private int stationIsOfflineTimeDifferenceSecs = 180; // seconds
|
|
private int targetStaleMins = 31; // minutes
|
|
|
|
public List<SerialPort> SerialPorts = new List<SerialPort>();
|
|
public List<TelnetConnection> TelnetConnections = new List<TelnetConnection>();
|
|
|
|
#region Properties
|
|
|
|
public string Configuration_Path
|
|
{
|
|
get { return this.filename; }
|
|
set { this.filename = value; }
|
|
}
|
|
|
|
public string DBConnectionString
|
|
{
|
|
get { return this.dbConnectionString; }
|
|
set { this.dbConnectionString = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// timer interval for database updates
|
|
/// </summary>
|
|
public int DBUpdateInterval
|
|
{
|
|
get { return this.dbUpdateInterval; }
|
|
set { this.dbUpdateInterval = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// minimum amount of minutes between two position reports to be
|
|
/// written to database
|
|
/// </summary>
|
|
public int DBMinPosReportTimeDifference
|
|
{
|
|
get { return this.dbMinPosReportTimeDifference; }
|
|
set { this.dbMinPosReportTimeDifference = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// number of seconds after which a station is marked offline since
|
|
/// sending the last pos report
|
|
/// </summary>
|
|
public int StationIsOfflineTimeDifferenceSecs
|
|
{
|
|
get { return this.stationIsOfflineTimeDifferenceSecs; }
|
|
set { this.stationIsOfflineTimeDifferenceSecs = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// if last update is older than this value then the target ist removed from
|
|
/// the current target queue (target went offline or out of range)
|
|
/// </summary>
|
|
public int TargetStaleMins
|
|
{
|
|
get { return this.targetStaleMins; }
|
|
set { this.targetStaleMins = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Root path to where Viewer stores OSM tiles
|
|
/// </summary>
|
|
public string TilePath { get; set; }
|
|
|
|
/// <summary>
|
|
/// full path to logfile
|
|
/// </summary>
|
|
public string LogfilePath { get; set; }
|
|
|
|
/// <summary>
|
|
/// outputs assembly version
|
|
/// </summary>
|
|
public static string VersionInfo
|
|
{
|
|
get
|
|
{
|
|
Version version = Assembly.GetExecutingAssembly().GetName().Version;
|
|
return version.ToString();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Load/Save
|
|
|
|
public static AIS_Configuration Load(string filename)
|
|
{
|
|
if (!File.Exists(filename)) return null;
|
|
|
|
// Create an instance of the XmlSerializer specifying type and namespace.
|
|
XmlSerializer serializer = new XmlSerializer(typeof(AIS_Configuration));
|
|
|
|
// A FileStream is needed to read the XML document.
|
|
FileStream fs = new FileStream(filename, FileMode.Open);
|
|
XmlReader reader = new XmlTextReader(fs);
|
|
|
|
AIS_Configuration configuration = serializer.Deserialize(reader) as AIS_Configuration;
|
|
reader.Close();
|
|
configuration.filename = filename;
|
|
|
|
|
|
return configuration;
|
|
}
|
|
|
|
public bool Save()
|
|
{
|
|
bool retval = true;
|
|
try
|
|
{
|
|
XmlSerializer serializer = new XmlSerializer(typeof(AIS_Configuration));
|
|
Stream fs = new FileStream(this.filename, FileMode.Create);
|
|
XmlWriter writer = new XmlTextWriter(fs, new UTF8Encoding());
|
|
serializer.Serialize(writer, this);
|
|
writer.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
System.Diagnostics.Debug.Write("Error during Serialize: " + e.ToString());
|
|
retval = false;
|
|
}
|
|
return retval;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region internal classes
|
|
|
|
public class SerialPort
|
|
{
|
|
public string station;
|
|
public string ComPort;
|
|
public int BaudRate = 9600;
|
|
public bool enabled = false;
|
|
}
|
|
|
|
public class TelnetConnection
|
|
{
|
|
public string ipAddress;
|
|
public int port;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|