实现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"]; } }
用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; }
时间: 2024-10-09 18:20:36