<Settings>
<setting name="TracingEnabled">
<value>true</value>
</setting>
</Settings>
Code to extract value from XML document
class PluginConfiguration
{
private static string GetValueNode(XmlDocument doc, string key)
{
XmlNode node = doc.SelectSingleNode(String.Format("Settings/setting[@name='{0}']", key));
if (node != null)
{
return node.SelectSingleNode("value").InnerText;
}
return string.Empty;
}
public static Guid GetConfigDataGuid(XmlDocument doc, string label)
{
string tempString = GetValueNode(doc, label);
if (tempString != string.Empty)
{
return new Guid(tempString);
}
return Guid.Empty;
}
public static bool GetConfigDataBool(XmlDocument doc, string label)
{
bool retVar;
if (bool.TryParse(GetValueNode(doc, label), out retVar))
{
return retVar;
}
else
{
return false;
}
}
public static int GetConfigDataInt(XmlDocument doc, string label)
{
int retVar;
if (int.TryParse(GetValueNode(doc, label), out retVar))
{
return retVar;
}
else
{
return -1;
}
}
public static string GetConfigDataString(XmlDocument doc, string label)
{
return GetValueNode(doc, label);
}
}
Plugin code to retrieve config data
public TracingPluginSimple(string unsecureString, string secureString)
{
if (!String.IsNullOrWhiteSpace(unsecureString))
{
try
{
_unsecureString = unsecureString;
XmlDocument doc = new XmlDocument();
doc.LoadXml(_unsecureString);
bool TracingEnabled = PluginConfiguration.GetConfigDataBool(doc, "TracingEnabled");
_unsecureString = unsecureString;
//_secureString = secureString;
_tracingEnabled = TracingEnabled;
}
catch (Exception ex)
{
throw new InvalidOperationException("Unsecure or secure strings are required by the TracingPluginSimple Plug-in, but not provided.");
}
}
if (!String.IsNullOrWhiteSpace(secureString))
{
try
{
_secureString = secureString;
XmlDocument doc = new XmlDocument();
doc.LoadXml(unsecureString);
bool TracingEnabled = PluginConfiguration.GetConfigDataBool(doc, "TracingEnabled");
//_unsecureString = unsecureString;
_secureString = secureString;
_tracingEnabled = TracingEnabled;
}
catch (Exception ex)
{
throw new InvalidOperationException("Unsecure or secure strings are required by the TracingPluginSimple Plug-in, but not provided.");
}
}
public void Execute(IServiceProvider serviceProvider)
{
if (_tracingEnabled)
{
//Implement functionality
}
}
No comments:
Post a Comment