码迷,mamicode.com
首页 > 其他好文 > 详细

mscrm2015插件相关

时间:2016-03-16 17:05:06      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

实现IPlugin接口方法:

    public interface IPlugin
    {
        void Execute(IServiceProvider serviceProvider);
    }

相关服务的初始化

技术分享
   protected void Initialize(IServiceProvider ServiceProvider)
        {
            //调试沙箱插件使用的跟踪服务
            tracingservice = (ITracingService)ServiceProvider.GetService(typeof(ITracingService));
            //插件的上下文
            context = (IPluginExecutionContext)ServiceProvider.GetService(typeof(IPluginExecutionContext));
            //组织服务工厂
            serviceFactory = (IOrganizationServiceFactory)ServiceProvider.GetService(typeof(IOrganizationServiceFactory));
            //组织服务
            service = serviceFactory.CreateOrganizationService(context.UserId);
            serviceAdmin = serviceFactory.CreateOrganizationService(null);
            orgServiceContext = new OrganizationServiceContext(service);
            isCreate = context.MessageName == "Create";
            isUpdate = context.MessageName == "Update";
            isDelete = context.MessageName == "Delete";

            if (context.InputParameters.Contains("Target"))
            {
                if (context.InputParameters["Target"] is Entity)
                    target = (Entity)context.InputParameters["Target"];
                else if (context.InputParameters["Target"] is EntityReference)
                    targetref = (EntityReference)context.InputParameters["Target"];
            }
        } 
View Code

 用QueryByAttribute类检索数据

技术分享
                //创建对应实体的查询对象
                QueryByAttribute query = new QueryByAttribute("new_pluginconfigure");
                //查询字段
                query.ColumnSet = new ColumnSet("new_recordid");
                //查询条件
                query.AddAttributeValue("new_recordid", recordId.ToString());
                query.AddAttributeValue("new_active", true);
                //执行查询
                EntityCollection recordCollection = serviceAdmin.RetrieveMultiple(query);
                if (recordCollection != null && recordCollection.Entities.Count > 0)
                {
                    return;
                }    
View Code

 

mscrm2015插件相关

标签:

原文地址:http://www.cnblogs.com/servant/p/5284047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!