SafeNet/Teltonika_SOC/Config.cs
2021-02-24 13:50:23 +02:00

83 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nini.Config;
using System.Collections;
using SafeNetLib;
namespace Teltonika_SOC
{
public class Config
{
private IConfigSource source = null;
private string CFG_FILE = "config.ini";
public string gatewayID;
public int locPort;
public string transport;
public string IMEI;
public string SERVER;
public string DATABASE;
public string UID;
public string PASSWORD;
public bool db_active;
public int debug_port;
//email service for alerts
public string alert_smtpServer = "";
public string alert_pop3Server = "";
public string alert_pop3Port = "";
public string alert_smtpPort = "";
public bool alert_sslState = false;
public string alert_user, alert_psw;
public ArrayList ar_radioIPs = new ArrayList();
public Config(string CFG_FILE = "config.ini")
{
LoadConfig();
}
private void LoadConfig()
{
try
{
source = new IniConfigSource(CFG_FILE);
gatewayID = source.Configs["GATEWAY"].Get("id");
locPort = Convert.ToInt32(source.Configs["GATEWAY"].Get("port"));
transport = source.Configs["GATEWAY"].Get("transport");
if (transport.ToLower() != "udp") transport = "tcp";
//MySQL connection info (for SMS)
SERVER = source.Configs["MySQL"].Get("SERVER");
DATABASE = source.Configs["MySQL"].Get("DATABASE");
UID = source.Configs["MySQL"].Get("UID");
PASSWORD = source.Configs["MySQL"].Get("PASSWORD");
db_active = Convert.ToBoolean(source.Configs["MySQL"].Get("active"));
//debug port is GWID with the first digit replage by 3. ex: 95001 -> 35001
string str_debug_port = "3" + gatewayID.Substring(1);
debug_port = Int32.Parse(str_debug_port);
//for alerts
alert_pop3Server = source.Configs["EmailServiceAlerts"].Get("Pop3Server");
alert_smtpServer = source.Configs["EmailServiceAlerts"].Get("SmtpServer");
alert_pop3Port = source.Configs["EmailServiceAlerts"].Get("Pop3Port");
alert_smtpPort = source.Configs["EmailServiceAlerts"].Get("SmtpPort");
alert_sslState = Convert.ToBoolean(source.Configs["EmailServiceAlerts"].Get("EnableSSL"));
alert_user = source.Configs["EmailServiceAlerts"].Get("User");
alert_psw = source.Configs["EmailServiceAlerts"].Get("Pass");
}
catch (Exception ex)
{
Utils.ConsWrite(DebugMSG_Type.always, "LoadSetup() Exception: " + ex.ToString());
}
Utils.ConsWrite(DebugMSG_Type.CTRL, "LoadSetup file OK !");
}
}
}