Dynamics CRM Plugin开发之Unseure Configuration

       本篇要分享的内容不是什么新特性很早就有了,只是自己许久没用了有些生疏再次记录下。很多新入行的朋友可能不太会注意到,或者注意到了也没去细究,插件注册器中右边这一大块白的是干嘛的,如果还不知道的朋友可以自己去谷歌,资料很多理解起来也很简单,同时理解下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)
        {
		}
	}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值