Add IPMonitor
This commit is contained in:
86
IPMonitor/CommandArgs.cs
Normal file
86
IPMonitor/CommandArgs.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System.Text;
|
||||
using MarketData.Utils;
|
||||
|
||||
namespace IPMonitor
|
||||
{
|
||||
public class CommandArgs : Dictionary<String,NVP>
|
||||
{
|
||||
private String[] arguments = default;
|
||||
|
||||
public String[] GetArguments()
|
||||
{
|
||||
return arguments;
|
||||
}
|
||||
// While the commands are converted to uppercase care must be taken to preserve the case of the arguments.
|
||||
public CommandArgs(String[] args)
|
||||
{
|
||||
arguments = args;
|
||||
for(int index=1;index<args.Length;index++)
|
||||
{
|
||||
String command=args[index];
|
||||
String[] nvp=null;
|
||||
if(command.StartsWith("/"))
|
||||
{
|
||||
command=command.Substring(1);
|
||||
nvp=command.Split(':');
|
||||
if(nvp.Length>2)
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
for(int subIndex=1;subIndex<nvp.Length;subIndex++)
|
||||
{
|
||||
sb.Append(nvp[subIndex]);
|
||||
if(subIndex<nvp.Length-1)sb.Append(":");
|
||||
}
|
||||
nvp=new String[]{nvp[0].ToUpper(),sb.ToString()};
|
||||
}
|
||||
}
|
||||
else nvp=command.Split('=');
|
||||
if(2!=nvp.Length)continue;
|
||||
if(ContainsKey(nvp[0].ToUpper()))continue;
|
||||
Add(nvp[0].ToUpper(),new NVP(nvp[0].ToUpper(),nvp[1]));
|
||||
}
|
||||
}
|
||||
public bool Contains(String name)
|
||||
{
|
||||
return ContainsKey(name);
|
||||
}
|
||||
public bool Has(String commandList)
|
||||
{
|
||||
commandList=commandList.ToUpper();
|
||||
String[] commands=commandList.Split(',');
|
||||
if(0==commands.Length)return false;
|
||||
foreach(String command in commands)
|
||||
{
|
||||
if(!ContainsKey(command))return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public T Get<T>(String name)
|
||||
{
|
||||
T result=default(T);
|
||||
try {result = (T)Convert.ChangeType(this[name].Value, typeof(T));}
|
||||
catch {result = default(T);}
|
||||
return result;
|
||||
}
|
||||
|
||||
public T Coalesce<T>(String name,T coalesce)
|
||||
{
|
||||
T result=default(T);
|
||||
try
|
||||
{
|
||||
if(!Contains(name))result=coalesce;
|
||||
else result = (T)Convert.ChangeType(this[name].Value, typeof(T));
|
||||
}
|
||||
catch {result = default(T);}
|
||||
return result;
|
||||
}
|
||||
|
||||
public T Coalesce<T>(String name)
|
||||
{
|
||||
T result=default(T);
|
||||
try {result = (T)Convert.ChangeType(this[name].Value, typeof(T));}
|
||||
catch {result = default(T);}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user