本人微信公众号:微软动态CRM专家罗勇 ,回复298或者20190120可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me 。

系统作业(逻辑名称asyncoperation)这个实体存储了工作流、异步SDK插件步骤的运行记录,若是不及时删除的话,这个实体记录数太多会严重影响系统性能。

所以我们一般做法分成两种,一个是建立一个系统批量删除作业,删除状态为成功、失败、已取消,且创建日期为X个月之前的记录(因为不少公司对日志保留有要求,起码保留一个月),这个批量删除作业最频繁可以每隔七天运行一次。

另外一个就是切记两个选项要选中,一个是工作流的【自动删除已完成的工作流作业(以节省磁盘空间)】要选中。

另一个就是SDK插件步骤的【Delete AsyncOperation if StatusCode = Successful】要选中。

这两个选项如果不选中,有时候会带来严重问题,比如说SDK插件步骤,注册在所有实体的RetrieveMutiple,Retrieve等运行非常频繁的消息上,那带来的系统作业记录会非常多,可能一天几百万。

难道每次都一个个用眼睛看手工检查,太Low,我们当然有程序办法,跑一下程序就可以检查出来,下面就是可以参考的代码。

using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Configuration;
using System.Net;
using System.ServiceModel.Description; namespace CheckWorkflowPluginStepAutoDelete
{
class Program
{
static void Main(string[] args)
{
try
{
string inputKey;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
IServiceManagement<IOrganizationService> orgServiceMgr = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri(ConfigurationManager.AppSettings["orgUrl"]));
AuthenticationCredentials orgAuCredentials = new AuthenticationCredentials();
orgAuCredentials.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["userName"];
orgAuCredentials.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["passWord"];
string needConfirm = ConfigurationManager.AppSettings["needConfirm"];
using (var orgSvc = GetProxy<IOrganizationService, OrganizationServiceProxy>(orgServiceMgr, orgAuCredentials))
{
orgSvc.Timeout = new TimeSpan(, , );
WhoAmIRequest whoReq = new WhoAmIRequest();
var whoRsp = orgSvc.Execute(whoReq) as WhoAmIResponse;
var userEntity = orgSvc.Retrieve("systemuser", whoRsp.UserId, new Microsoft.Xrm.Sdk.Query.ColumnSet("fullname"));
Console.WriteLine(string.Format("欢迎【{0}】登陆到【{1}】", userEntity.GetAttributeValue<string>("fullname"), ConfigurationManager.AppSettings["orgUrl"]));
Console.WriteLine("本程序用于检查工作流/SDK插件步骤是否选中了【运行成功后自动删除日志】!");
if (needConfirm == "Y")
{
Console.WriteLine("当前处于需要确认才会继续的模式,若要继续请输入Y然后回车确认!");
inputKey = Console.ReadLine();
if (inputKey.ToUpper() == "Y")
{
CheckSDKMessageProcessingStepAutoDelete(orgSvc);
CheckWorkflowAutoDelete(orgSvc);
}
else
{
Console.WriteLine("你选择了取消运行!");
}
}
else
{
CheckSDKMessageProcessingStepAutoDelete(orgSvc);
CheckWorkflowAutoDelete(orgSvc);
}
}
Console.Write("程序运行完成,按任意键退出." + DateTime.Now.ToString());
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("程序运行出错:" + ex.Message + ex.StackTrace);
Console.ReadLine();
}
} private static void CheckSDKMessageProcessingStepAutoDelete(OrganizationServiceProxy orgSvc)
{
const string functionName = "检查SDK插件步骤是否选中了【运行成功后自动删除日志】";
Console.WriteLine(string.Format("开始 {0} - {1}", functionName, DateTime.Now.ToString()));
try
{
QueryExpression qe = new QueryExpression("sdkmessageprocessingstep");
qe.ColumnSet = new ColumnSet("name");
qe.NoLock = true;
qe.Criteria.AddCondition(new ConditionExpression("mode", ConditionOperator.Equal, ));
qe.Criteria.AddCondition(new ConditionExpression("asyncautodelete", ConditionOperator.Equal, false));
qe.Criteria.AddCondition(new ConditionExpression("iscustomizable", ConditionOperator.Equal, true));
EntityCollection ec = orgSvc.RetrieveMultiple(qe);
if (ec.Entities.Count == )
{
Console.WriteLine("Perfect!所有SDK插件步骤都选中了成功后自动删除运行日志!");
}
else
{
Console.WriteLine("所有异步运行的SDK插件步骤没有选中【运行成功后自动删除日志】清单如下:");
foreach (Entity ent in ec.Entities)
{
Console.WriteLine(ent.GetAttributeValue<string>("name"));
Console.WriteLine(ent.Id);
}
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("运行 {0} 出现异常:{1}", functionName, ex.Message + ex.StackTrace));
}
Console.WriteLine(string.Format("结束 {0} - {1}", functionName, DateTime.Now.ToString()));
Console.WriteLine("================================================");
} private static void CheckWorkflowAutoDelete(OrganizationServiceProxy orgSvc)
{
const string functionName = "检查工作流是否选中了【运行成功后自动删除日志】";
Console.WriteLine(string.Format("开始 {0} - {1}", functionName, DateTime.Now.ToString()));
try
{
var fetchXml = @"<fetch version='1.0' mapping='logical' distinct='false' no-lock='true'>
<entity name='workflow'>
<attribute name='name' />
<filter type='and'>
<condition attribute='type' operator='eq' value='1' />
<condition attribute='category' operator='eq' value='0' />
<condition attribute='statecode' operator='eq' value='1' />
<condition attribute='asyncautodelete' operator='ne' value='1' />
<condition attribute='mode' operator='eq' value='0' />
</filter>
</entity>
</fetch>";
var workflowEntities = orgSvc.RetrieveMultiple(new FetchExpression(fetchXml));
if (workflowEntities.Entities.Count == )
{
Console.WriteLine("Perfect!所有工作流都选中了成功后自动删除运行日志!");
}
else
{
Console.WriteLine("所有异步运行的工作流没有选中【运行成功后自动删除日志】清单如下:");
foreach (var item in workflowEntities.Entities)
{
Console.WriteLine(item.GetAttributeValue<string>("name"));
}
}
}
catch (Exception ex)
{
Console.WriteLine(string.Format("运行 {0} 出现异常:{1}", functionName, ex.Message + ex.StackTrace));
}
Console.WriteLine(string.Format("结束 {0} - {1}", functionName, DateTime.Now.ToString()));
Console.WriteLine("================================================");
} private static TProxy GetProxy<TService, TProxy>(
IServiceManagement<TService> serviceManagement,
AuthenticationCredentials authCredentials)
where TService : class
where TProxy : ServiceProxy<TService>
{
Type classType = typeof(TProxy); if (serviceManagement.AuthenticationType !=
AuthenticationProviderType.ActiveDirectory)
{
AuthenticationCredentials tokenCredentials =
serviceManagement.Authenticate(authCredentials);
return (TProxy)classType
.GetConstructor(new Type[] { typeof(IServiceManagement<TService>), typeof(SecurityTokenResponse) })
.Invoke(new object[] { serviceManagement, tokenCredentials.SecurityTokenResponse });
}
return (TProxy)classType
.GetConstructor(new Type[] { typeof(IServiceManagement<TService>), typeof(ClientCredentials) })
.Invoke(new object[] { serviceManagement, authCredentials.ClientCredentials });
}
}
}

Dynamics 365检查工作流、SDK插件步骤是否选中运行成功后自动删除系统作业记录的更多相关文章

  1. Dynamics 365使用Execute Multiple Request删除系统作业实体记录

    摘要: 本人微信公众号:微软动态CRM专家罗勇 ,回复295或者20190112可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me ...

  2. Dynamics 365 Customer Engagement中插件的调试

    微软动态CRM专家罗勇 ,回复319或者20190319可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 本文主要根据官方的教 ...

  3. Dynamics 365 CE中AsyncOperationBase表记录太多,影响系统性能怎么办?

    微软动态CRM专家罗勇 ,回复311或者20190311可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 本文主要是根据微软官 ...

  4. Dynamics 365 Online通过OAuth 2 Client Credential授权(Server-to-Server Authentication)后调用Web API

    微软动态CRM专家罗勇 ,回复332或者20190505可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me! 本文很多内容来自 John Towgood 撰写的Dynamic ...

  5. Dynamics 365的系统作业实体记录增长太快怎么回事?

    摘要: 本人微信公众号:微软动态CRM专家罗勇 ,回复294或者20190111可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me ...

  6. 为Dynamics 365启用部署级的跟踪以及跟踪文件的定期删除

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复260或者20170712可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...

  7. Dynamics 365需要的最小的权限用来更改用户的业务部门和角色

    我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...

  8. Dynamics 365中的批量删除作业执行频率可以高于每天一次吗?

    微软动态CRM专家罗勇 ,回复317或者20190314可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 我先来做一个例子,登 ...

  9. 配置Postman通过OAuth 2 implicit grant获取Dynamics 365 CE Online实例的Access Token

    微软动态CRM专家罗勇 ,回复335或者20190516可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me. 对于测试Web API, Get 类型,不需要设定特别reque ...

随机推荐

  1. 谈一谈从 Delphi 2009 之后就支援的重要功能 – 泛型 (Generic)

    前言 在C++的语言基础当中,除了物件导向.事件驱动的概念之外,模版设计(Template)也是非常重要的一环.然而,C++的开发人员能够善用模版设计的并不多.模版设计这个好物,一般还有一个名称,就是 ...

  2. [Swift]LeetCode673. 最长递增子序列的个数 | Number of Longest Increasing Subsequence

    Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...

  3. [Swift]LeetCode872. 叶子相似的树 | Leaf-Similar Trees

    Consider all the leaves of a binary tree.  From left to right order, the values of those leaves form ...

  4. CentOS随笔——Service与防火墙关闭

    Service后台服务管理 基本语法 service 服务名 start 开启服务 service 服务名 stop 关闭服务 service 服务名 restart 重启服务 service 服务名 ...

  5. 关于video标签移动端开发遇到的问题,获取视频第一帧,全屏,自动播放,自适应等问题

    最近一直在处理video标签在IOS和Android端的兼容问题,其中遇到不少坑,绝大多数问题已经解决,下面是处理问题经验的总结: 1.获取视频的第一帧作为背景图: 技术:canvas绘图 windo ...

  6. 作为程序员必须掌握的Java虚拟机中的22个重难点

    Java虚拟机一直是比较重要的知识点,是Java高级开发必会的.本文为你总结了关于JVM的22个重点.难点,图文并茂的向你展示和JVM有关的重点知识.全文共7000字左右. 概念 虚拟机:指以软件的方 ...

  7. 『2019/3/19 USACO测试 反思与总结』

    2019/3/8 USACO测试 这是第三次考试了,不过这一次没有上一次考得好,也算是比较失误的,有一道题思路对但是写挂了. 还是看一下试题安排: 题号 试题分组 考察算法 思维难度 代码难度 1 银 ...

  8. SpringBoot入门教程(十)应用监控Actuator

    Actuator可能大家非常熟悉,它是springboot提供对应用自身监控,以及对应用系统配置查看等功能.spring-boot-starter-actuator模块的实现对于实施微服务的中小团队来 ...

  9. 补习系列(9)-springboot 定时器,你用对了吗

    目录 简介 一.应用启动任务 二.JDK 自带调度线程池 三.@Scheduled 定制 @Scheduled 线程池 四.@Async 定制 @Async 线程池 小结 简介 大多数的应用程序都离不 ...

  10. 查看服务器运行多少个ASP.NET Core程序

    有时候,我们会想知道某台机器上面跑了什么程序. 当程序部署到IIS上面的时候,我们只需要打开IIS一看,就知道有多少个站点在运行了. 当我们在CentOS上面部署的时候,就没那么的直观了. 当然对于熟 ...