本篇要分享的内容不是什么新特性很早就有了,只是自己许久没用了有些生疏再次记录下。很多新入行的朋友可能不太会注意到,或者注意到了也没去细究,插件注册器中右边这一大块白的是干嘛的,如果还不知道的朋友可以自己去谷歌,资料很多理解起来也很简单,同时理解下unsecure和secure configuration的区别。
我们都知道插件的开发中没办法做一些config的配置,因为插件压根读不到,更多的采取的方式是在CRM中单独做个配置实体然后在插件里通过service去动态的读取,那有了Unseure&Secure Configuration,就又给了我们另一种选择,当然有人会说可以写死,但hardcode一向不在我们的选项中。
插件注册器里的配置是一段简单的xml,例如
<Settings>
<setting name='interfaceUrl'>
<value></value>
</setting>
<setting name='webUrl'>
<value></value>
</setting>
</Settings>
然后再插件中 读取
public class offer : IPlugin
{
public static string interfaceUrl = "";
public static string webUrl = "";
public offer(string unsecureConfig, string secureConfig)
{
if (string.IsNullOrEmpty(unsecureConfig))
{
throw new InvalidPluginExecutionException("Unsecure configuration missing.");
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(unsecureConfig);
XmlNode node = doc.SelectSingleNode(String.Format("Settings/setting[@name='{0}']", "interfaceUrl"));
if (node != null)
{
interfaceUrl = node.SelectSingleNode("value").InnerText;
}
node = doc.SelectSingleNode(String.Format("Settings/setting[@name='{0}']", "webUrl"));
if (node != null)
{
webUrl = node.SelectSingleNode("value").InnerText;
}
}
public void Execute(IServiceProvider serviceProvider)
{
}
}