📄 configmanager.cs
字号:
using System;
using System.Collections;
using System.IO;
using System.Reflection;
namespace NiceTracker.Config
{
/// <summary>
/// Summary description for Config.
/// </summary>
public class ConfigManager
{
public const string NOT_SET = "";
public const string DB_LOCATION = "dbLocation";
public const string UPDATE_FREQUENCY = "updateFreq";
public const string COLLECT_CELLS = "collectCells";
public const string PROCESS_EVENTS = "processEvents";
public const string WRAP_LIMIT = "wrapLimit";
public const string COM_PORT = "comPort";
public const string EXPAND_SIP = "expandSip";
public const string SHOW_DBM_CHART = "showDBMChart";
public const string SHOW_DBM_VALUE = "showDBMValue";
public const string SHOW_LAC_CI_HEX = "showLacCiHex";
public static string dbLocDefault = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
private static ConfigDB configDB = null;
private static Hashtable ht = null;
public ConfigManager()
{
}
public static string Get( string key )
{
if ( configDB == null )
setupConfigDB();
if ( ht == null )
ht = configDB.GetConfig();
if ( ht.ContainsKey( key ) )
return ht[ key ].ToString();
else
return NOT_SET;
}
private static string Get( string key, string dflt )
{
if ( configDB == null )
setupConfigDB();
if ( ht == null )
ht = configDB.GetConfig();
if ( ht.ContainsKey( key ) )
return ht[ key ].ToString();
else
return dflt;
}
public static void Set( string key, string val )
{
if ( ht == null )
ht = configDB.GetConfig();
if ( !ht.ContainsKey( key ) )
ht.Add( key, val );
else
ht[ key ] = val;
}
public static void Refresh()
{
ht = configDB.GetConfig();
}
private static void setupConfigDB()
{
configDB = new ConfigDB();
configDB.Load();
}
public static void Save()
{
// Clear DB
configDB.Clear();
// Add all config items to DB
configDB.Add( ht );
// Save
configDB.Save();
}
public static int UpdateFrequency
{
get
{
return Convert.ToInt32( Get( UPDATE_FREQUENCY, "20" ) );
}
set
{
Set( ConfigManager.UPDATE_FREQUENCY, value.ToString() );
}
}
public static int ChartWrapLimit
{
get
{
return Convert.ToInt32( Get( WRAP_LIMIT, "40" ) );
}
set
{
Set( ConfigManager.WRAP_LIMIT, value.ToString() );
}
}
public static bool CollectCells
{
get
{
int collect = Convert.ToInt32( ConfigManager.Get( ConfigManager.COLLECT_CELLS, "1" ) );
return (collect == 1);
}
set
{
if ( value )
ConfigManager.Set( ConfigManager.COLLECT_CELLS, "1" );
else
ConfigManager.Set( ConfigManager.COLLECT_CELLS, "0" );
}
}
public static bool ProcessEvents
{
get
{
int collect = Convert.ToInt32( ConfigManager.Get( ConfigManager.PROCESS_EVENTS, "1" ) );
return (collect == 1);
}
set
{
if ( value )
ConfigManager.Set( ConfigManager.PROCESS_EVENTS, "1" );
else
ConfigManager.Set( ConfigManager.PROCESS_EVENTS, "0" );
}
}
public static bool ExpandSip
{
get
{
int expand = Convert.ToInt32( ConfigManager.Get( ConfigManager.EXPAND_SIP, "1" ) );
return (expand == 1);
}
set
{
if ( value )
ConfigManager.Set( ConfigManager.EXPAND_SIP, "1" );
else
ConfigManager.Set( ConfigManager.EXPAND_SIP, "0" );
}
}
public static bool ShowDBMChart
{
get
{
int showDBM = Convert.ToInt32( ConfigManager.Get( ConfigManager.SHOW_DBM_CHART, "1" ) );
return (showDBM == 1);
}
set
{
if ( value )
ConfigManager.Set( ConfigManager.SHOW_DBM_CHART, "1" );
else
ConfigManager.Set( ConfigManager.SHOW_DBM_CHART, "0" );
}
}
public static bool ShowDBMValue
{
get
{
int showDBM = Convert.ToInt32( ConfigManager.Get( ConfigManager.SHOW_DBM_VALUE, "1" ) );
return (showDBM == 1);
}
set
{
if ( value )
ConfigManager.Set( ConfigManager.SHOW_DBM_VALUE, "1" );
else
ConfigManager.Set( ConfigManager.SHOW_DBM_VALUE, "0" );
}
}
public static bool ShowLacCiInHex
{
get
{
int inHex = Convert.ToInt32( ConfigManager.Get( ConfigManager.SHOW_LAC_CI_HEX, "1" ) );
return (inHex == 1);
}
set
{
if ( value )
ConfigManager.Set( ConfigManager.SHOW_LAC_CI_HEX, "1" );
else
ConfigManager.Set( ConfigManager.SHOW_LAC_CI_HEX, "0" );
}
}
public static string DBLocation
{
get
{
return ConfigManager.Get( ConfigManager.DB_LOCATION, dbLocDefault );
}
set
{
ConfigManager.Set( ConfigManager.DB_LOCATION, value );
}
}
public static int ComPort
{
get
{
return int.Parse( ConfigManager.Get( ConfigManager.COM_PORT, "-1" ) );
}
set
{
ConfigManager.Set( ConfigManager.COM_PORT, value.ToString() );
}
}
public static string ComPortString
{
get
{
if ( ComPort >= 1 )
return "COM" + ComPort.ToString() + ":";
else
return "";
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -