Dynamics 365: 详解插件的执行深度(PluginExecutionContext.Depth)
Depth这个属性会告诉你插件它在一个调用堆栈中有多深,是第几次被调用。
我们直接用段代码对Depth值来进行说明:
1. 首先我们写一个Account实体插件并用到RetrieveMultiple事件,就是当我们每次点进Accont的一个视图的时候都会调用这个RetrieveMultiple事件,但里面只是记了一条log而已:
using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace PluginDepthTest
{public class RetrieveMutiple : IPlugin{public void Execute(IServiceProvider serviceProvider){IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));if (context.Depth == 1){tracingService.Trace($"The plugin depth is: {context.Depth}");}else if (context.Depth > 1){tracingService.Trace($"The plugin depth is: {context.Depth}");}}}
}
2. 当我们每次点进Accont的一个视图的时候都会触发这个事件,我们通过Plug-in Trace Log可以看出,在这次的事务中它只执行了一次,因为Depth为1.
3. 我们将代码进行如下修改,判断一下Depth的值,当等于1的时候,我们在代码中再调用一次RetrieveMultiple, 这个时候插件会再次被执行,并且它的Depth的值也变成2。
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace PluginDepthTest
{public class RetrieveMutiple : IPlugin{public void Execute(IServiceProvider serviceProvider){IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));if (context.Depth == 1){QueryExpression query = new QueryExpression("account");query.ColumnSet.AddColumns("name");EntityCollection result = service.RetrieveMultiple(query);tracingService.Trace($"The plugin depth is: {context.Depth}");}else if (context.Depth > 1){tracingService.Trace($"The plugin depth is: {context.Depth}");}}}
}
4. 我们运行一下Account实体的试图,这个时候通过Plug-in Trace Log可以看出,这次它进来了两次,第一次Depth为1,第二次Depth为2.
第一次:
第二次:
Notes:
- Depth最大的作用就是为了防止插件陷入无限循环,大多数情况下,我们可以忽略此值
- Depth的默认最大值为8,时间限制为一小时。也就是说如果Depth属性在一个小时的时间限制内增加到其最大值(8),则那么系统会认为这个事务陷入了一个无限循环,插件或Workflow的执行将被强行中止,并会报以下的错:
Message: This workflow job was canceled because the workflow that started it included an infinite loop. Correct the workflow logic and try again. For information about workflow logic, see Help.Detail:
- 我们可以使用以下的Powershell脚本来对Depth的默认值进行修改
$setting = Get-CrmSetting -SettingType WorkflowSettings
$setting.MaxDepth = 10
Set-CrmSetting -Setting $setting
参考文档:
IExecutionContext.Depth Property (Microsoft.Xrm.Sdk) | Microsoft Docshttps://docs.microsoft.com/zh-cn/dotnet/api/microsoft.xrm.sdk.iexecutioncontext.depth?f1url=%3FappId%3DDev16IDEF1&l=EN-US&k=k(Microsoft.Xrm.Sdk.IExecutionContext.Depth)%3Bk(SolutionItemsProject)%3Bk(TargetFrameworkMoniker-.NETFramework%2CVersion%3Dv4.6.2)%3Bk(DevLang-csharp)&rd=true&view=dataverse-sdk-latestGet-CrmSetting (Microsoft.Crm.PowerShell) | Microsoft Docshttps://docs.microsoft.com/en-us/powershell/module/microsoft.crm.powershell/get-crmsetting?view=dynamics365ce-psWorkflowSettings.MaxDepth Property (Microsoft.Xrm.Sdk.Deployment) | Microsoft Docshttps://docs.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.deployment.workflowsettings.maxdepth?view=dataverse-sdk-latest
Dynamics 365: 详解插件的执行深度(PluginExecutionContext.Depth)相关推荐
- 干货|详解最新语音识别框架 深度全序列卷积神经网络
原标题:干货|详解最新语音识别框架 深度全序列卷积神经网络 导读:目前最好的语音识别系统采用双向长短时记忆网络(LSTM,LongShort Term Memory),但是,这一系统存在训练复杂度高. ...
- java批量执行查询sql语句_详解MyBatis直接执行SQL查询及数据批量插入
一.直接执行SQL查询: 1.mappers文件节选 ${paramSQL} 2.DAO类节选 public interface SomeDAO{ List getInstanceModel(@Par ...
- 读Java并发编程实践记录_原子性_锁_同步容器详解_任务执行
原子性: 单独的,不可分割的操作 不要使用过期状态值来决策当下的状态, 一定要先检查再执行(不检查, 将引发数据修改,丢失) 避免延迟初始化(懒加载: 先查看对象 == null, 然后new), 有 ...
- linux socket bind 内核详解,Socket与系统调用深度分析(示例代码)
1. 什么是系统调用 操作系统通过系统调用为运行于其上的进程提供服务.当用户态进程发起一个系统调用, CPU 将切换到 内核态 并开始执行一个 内核函数 . 内核函数负责响应应用程序的要求,例如操作文 ...
- 详解 6 大主流深度学习框架
导读:近几年,随着深度学习的爆炸式发展,相关理论和基础架构得到了很大突破,它们奠定了深度学习繁荣发展的基础.这其中涌现了几个著名的深度学习平台,本文将对这些平台进行简要介绍. 作者:涂铭 金智勇 来源 ...
- 【maven详解-插件】maven插件学习之maven-source-plugin
在pom.xml文件build节点下加入以下代码: 1 <plugin> 2 <groupId>org.apache.maven.plugins</groupId> ...
- 人工智能300年!LSTM之父最新长文:详解现代AI和深度学习发展史(附下载)
来源:新智元 Abner说AI 本文约8900字,建议阅读15+分钟 本文包括神经网络.深度学习.人工智能等领域的重要事件,以及那些为AI奠定基础的科学家们. 关注微信公众号"数据派THU& ...
- 恒生电子:数据中台详解+海内外对比(深度)
公司深度系列 - 作者:徐紫薇 - 数据中台具体做什么 1.1. 数据中台是什么? 恒生电子对数据中台的定义:作为全领域数据的共享能力中心,旨在提供数据采集.数据模型.数据计算.数据治理.数据资产.数 ...
- 万字长文:详解现代AI和深度学习发展史
来源:新智元 本文约9000字,建议阅读10+分钟 本文带你了解人工智能理论起源和深度学习的演变史. 「人工智能」一词,首次在1956年达特茅斯会议上,由约翰麦卡锡等人正式提出. 实用AI地提出,最早 ...
最新文章
- 多媒体制作技术心得体会_多媒体课件制作学习心得体会
- linux 修改jmeter内存溢出,jmeter本机内存溢出如何修改?
- Swift封装 滑出式导航栏
- Jenkins 配置邮箱 530Authentication required ,535 uthentication failed 的解决方法
- 转:开源项目学习方法ABC
- 单例初始化(MRC模式之autorelease)
- 百度AI攻略:iOCR自定义模板功能
- WIN10远程控制(局域网+外网)
- 使用 Love2D 开发游戏
- #AI边缘计算单元-想搞开发,买树莓派还是Nano?
- linux下交叉编译date命令,arm移植NTP(同步嵌入式linux系统时间)
- 开发步骤_APP开发和上市的步骤
- Java 中的Date(获取一天的开始时间和结束时间)
- 全球及中国表面保护胶带行业研究及十四五规划分析报告
- 三星官方smdkv210 uboot移植到我的s5pv210开发板
- 微信小程序自定义card图文组件
- 大数据分析就业培训课程大纲分享
- 小程序开发教程,深入解析android核心组件和应用框架,附面试题答案
- Lind.DDD.SSO单点登陆组件的使用(原创)
- 自然资源“数字赋能”重点任务进行梳理