SafeNet/.svn/pristine/40/409a40762d65a7e05463d7eea18...

117 lines
4.3 KiB
Plaintext

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nini.Config;
using System.Collections;
using SafeNetLib;
namespace Hytera_SOC
{
public class Config
{
private IConfigSource source = null;
private string CFG_FILE = "config.ini";
public string hyteraIP;
public string hyteraIMEI;
public string gatewayID;
public byte subNet;
public int ping_interval;
public bool useRadioTime;
public bool gw_restart;
public string SERVER;
public string DATABASE;
public string UID;
public string PASSWORD;
public string report;
public bool db_active;
public int debug_port;
//email service
public string smtpServer = "";
public string pop3Server = "";
public string pop3Port = "";
public string smtpPort = "";
public bool sslState = false;
public bool enableEmailService = false;
public string user, psw;
public ArrayList ar_radioIPs = new ArrayList();
public Config(string CFG_FILE = "config.ini")
{
LoadConfig();
}
private void LoadConfig()
{
try
{
source = new IniConfigSource(CFG_FILE);
pop3Server = source.Configs["EmailService"].Get("Pop3Server");
smtpServer = source.Configs["EmailService"].Get("SmtpServer");
pop3Port = source.Configs["EmailService"].Get("Pop3Port");
smtpPort = source.Configs["EmailService"].Get("SmtpPort");
sslState = Convert.ToBoolean(source.Configs["EmailService"].Get("EnableSSL"));
enableEmailService = Convert.ToBoolean(source.Configs["EmailService"].Get("Enable"));
user = source.Configs["EmailService"].Get("User");
psw = source.Configs["EmailService"].Get("Pass");
gatewayID = source.Configs["GATEWAY"].Get("id");
report = source.Configs["GATEWAY"].Get("report");
hyteraIP = source.Configs["GATEWAY"].Get("MasterRadioIP");
hyteraIMEI = source.Configs["GATEWAY"].Get("MasterRadioIMEI");
subNet = Convert.ToByte(source.Configs["GATEWAY"].Get("MR_subnet"));
ping_interval = Convert.ToInt32(source.Configs["GATEWAY"].Get("ping_interval"));
useRadioTime = Convert.ToBoolean(source.Configs["GATEWAY"].Get("UseRadioTime"));
gw_restart = Convert.ToBoolean(source.Configs["GATEWAY"].Get("gw_restart"));
//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);
LoadRadioIP();
}
catch (Exception ex)
{
Utils.ConsWrite(DebugMSG_Type.always, "LoadSetup() Exception: " + ex.ToString());
}
Utils.ConsWrite(DebugMSG_Type.CTRL, "LoadSetup file OK !");
}
private void LoadRadioIP()
{
try
{
source = new IniConfigSource(CFG_FILE);
ar_radioIPs.Add(source.Configs["GATEWAY"].Get("MasterRadioIP"));
/*
string[] keys = source.Configs["GATEWAY_IPS"].GetKeys();
foreach (string key in keys)
{
if (!ar_radioIPs.Contains(source.Configs["GATEWAY_IPS"].Get(key)))
ar_radioIPs.Add(source.Configs["GATEWAY_IPS"].Get(key));
}
*/
}
catch (Exception ex)
{
Utils.ConsWrite(DebugMSG_Type.always, "LoadRadiosIP() Exception: " + ex.ToString());
}
Utils.ConsWrite(DebugMSG_Type.CTRL, "LoadRadiosIP OK !");
}
}
}