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 SerialPorts = new List(); public List TelnetConnections = new List(); #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; } } /// /// timer interval for database updates /// public int DBUpdateInterval { get { return this.dbUpdateInterval; } set { this.dbUpdateInterval = value; } } /// /// minimum amount of minutes between two position reports to be /// written to database /// public int DBMinPosReportTimeDifference { get { return this.dbMinPosReportTimeDifference; } set { this.dbMinPosReportTimeDifference = value; } } /// /// number of seconds after which a station is marked offline since /// sending the last pos report /// public int StationIsOfflineTimeDifferenceSecs { get { return this.stationIsOfflineTimeDifferenceSecs; } set { this.stationIsOfflineTimeDifferenceSecs = value; } } /// /// 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) /// public int TargetStaleMins { get { return this.targetStaleMins; } set { this.targetStaleMins = value; } } /// /// Root path to where Viewer stores OSM tiles /// public string TilePath { get; set; } /// /// full path to logfile /// public string LogfilePath { get; set; } /// /// Delete positions after this many days /// public int PurgeDays { get; set; } = 30; /// /// outputs assembly version /// 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 } }