当前位置:网站首页>Dynamics 365: explain the execution depth of plug-ins (pluginexecutioncontext.depth)
Dynamics 365: explain the execution depth of plug-ins (pluginexecutioncontext.depth)
2022-07-22 07:32:00 【Stone-hdj】
Depth This property will tell you how deep the plug-in is in a call stack , Is the number of times it is called .
Let's use a piece of code directly to Depth Value :
1. First of all, let's write a Account Entity plug-ins and use RetrieveMultiple event , When we click in each time Accont This will be called whenever a view of RetrieveMultiple event , But there is only one note in it log nothing more :
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. Every time we click in Accont This event will be triggered when a view of , We go through Plug-in Trace Log It can be seen that , It only executes once in this transaction , because Depth by 1.
3. We modify the code as follows , Judge Depth Value , Be equal to 1 When , We call again in the code RetrieveMultiple, At this time, the plug-in will be executed again , And its Depth The value of also becomes 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. So let's run this Account Attempts by entities , This time through Plug-in Trace Log It can be seen that , This time it came in twice , for the first time Depth by 1, The second time Depth by 2.
for the first time :
The second time :
Notes:
- Depth The most important function is to prevent the plug-in from falling into an infinite loop , Most of the time , We can ignore this value
- Depth The default maximum value for is 8, The time limit is one hour . That is to say if Depth Property increases to its maximum value within the one hour time limit (8), Then the system will think that the transaction has fallen into an infinite loop , Plug-in or Workflow The execution of will be forcibly suspended , And will report the following errors :
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:
- We can use the following Powershell Script to Depth Modify the default value of
$setting = Get-CrmSetting -SettingType WorkflowSettings
$setting.MaxDepth = 10
Set-CrmSetting -Setting $setting
Reference documents :
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 Docs
https://docs.microsoft.com/en-us/powershell/module/microsoft.crm.powershell/get-crmsetting?view=dynamics365ce-psWorkflowSettings.MaxDepth Property (Microsoft.Xrm.Sdk.Deployment) | Microsoft Docs
https://docs.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.deployment.workflowsettings.maxdepth?view=dataverse-sdk-latest
边栏推荐
- tsconfig.json在配置文件中找不到任何输入,怎么办?
- 同花顺开户能直接开吗?开户安全吗?怎么办理开户??
- G026-DB-GS-INS-03 OpenEuler 部署 OpenGauss(1主2备或多备)
- 105从前序与中序遍历序列构造二叉树
- 使用C#控制台程序读取Azure Service Bus队列中的消息
- ligerui 表格控件grid 根据内容更改行(单元格)颜色
- The properties of variables and functions beginning with static specifiers in C language
- Web3, encrypted VC new air outlet
- 【log4j.properties完整配置,适合刚入门】
- Piecemeal knowledge - machine learning
猜你喜欢
pycharm读取JY-901S数据
“新能源+储能“从数字孪生开始,图扑将智慧电力做到极致
Keras deep learning practice (13) -- detailed explanation of the basis of target detection
"New energy + energy storage" starts from the digital twin, Tupu will make smart power to the extreme
集合之HashSet
Talking about load
ECCV 2022 | fix the performance damage of large targets caused by FPN: you should look at all objects
torch_scatter.scatter()的使用方法详解
Steps for installing and using redis [Linux and windows environment]
TMECH发表优必选运控技术最新进展:实现人形机器人高鲁棒性行走
随机推荐
架构师成长:当谈到架构,究竟是谈什么
Keras深度学习实战(13)——目标检测基础详解
About troubleshooting MySQL driver version errors, cause: com mysql. jdbc. exceptions. jdbc4、Unknown system variable ‘query_ cache_ size
Basic settings of visualization
快速查看服务器中 Redis 的版本
20、shell编程之变量
手机对比redmi note8与realme x2
关于mybatics中起始与结束时间的处理方法
G026-DB-GS-INS-03 OpenEuler 部署 OpenGauss(1主2备或多备)
【log4j.properties完整配置,适合刚入门】
微信小程序实现音乐播放器
主机psql连接虚拟机Oracle
Vlookup function
Let me show you eight fallacies in software design
Keras deep learning practice (13) -- detailed explanation of the basis of target detection
31下一个排列
集合之HashSet
8.026 billion yuan! The state Internet Information Office imposed administrative penalties related to network security review on didi in accordance with the law
吃了爱优腾的药,奈飞病情好转
Dynamics 365: 如何在Azure AD中創建用戶並添加到Dynamics 365 Online中