public void UpdatePluginJSON(params String[] parms)
{
/*
parms[0]: Name of caller plugin
parms[1]: JSON with this format:
{
"plugin":"string",
"type":"string",
"key":"string",
"value":"string"
}
*/
if (parms.Length != 2)
{
if (DebugLevel >= 5) ConsoleWarn("UpdatePluginJSON called with incorrect parameter count: " + parms.Length);
return;
}
if (String.IsNullOrEmpty(parms[0])) {
if (DebugLevel >= 5) ConsoleWarn("UpdatePluginJSON parms[0]: caller name is invalid!");
return;
}
if (String.IsNullOrEmpty(parms[1])) {
if (DebugLevel >= 5) ConsoleWarn("UpdatePluginJSON(" + parms[0] + ") parms[1]: JSON is invalid!");
return;
}
try {
Hashtable json = (Hashtable)JSON.JsonDecode(parms[1]);
String plugin = null;
String type = null;
String key = null;
String value = null;
if (json == null) {
String tmp = parms[1].Replace('{','(').Replace('}',')');
if (DebugLevel >= 5) ConsoleWarn("UpdatePluginJSON(" + parms[0] + "): JSON is invalid (null): " + tmp);
return;
}
if (!json.ContainsKey("plugin")) {
if (DebugLevel >= 5) ConsoleWarn("UpdatePluginJSON(" + parms[0] + ") parms[1]: JSON does not contain 'plugin' key!");
return;
} else {
plugin = (String)json["plugin"];
}
if (!json.ContainsKey("type")) {
if (DebugLevel >= 5) ConsoleWarn("UpdatePluginJSON(" + parms[0] + ") parms[1]: JSON does not contain 'type' key!");
return;
} else {
type = (String)json["type"];
}
if (!json.ContainsKey("key")) {
if (DebugLevel >= 5) ConsoleWarn("UpdatePluginJSON(" + parms[0] + ") parms[1]: JSON does not contain 'key' key!");
return;
} else {
key = (String)json["key"];
}
if (!json.ContainsKey("value")) {
if (DebugLevel >= 5) ConsoleWarn("UpdatePluginJSON(" + parms[0] + ") parms[1]: JSON does not contain 'value' key!");
return;
} else {
value = (String)json["value"];
}
UpdatePluginData(plugin, type, key, value);
} catch (Exception e) {
if (DebugLevel >= 5) ConsoleException(e);
}
}