本人微信公众号:微软动态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. 使用cAdvisor+Influxdb+Grafana监控系统

      今天准备开始研究研究当前非常流行的Grafana+Influxdb监控系统,两者都是非常轻量级的应用但是功能却异常强大,可以说Grafana在作图显示方面真的毫不逊色与Cacti. 组件介绍 cA ...

  2. 依赖注入[2]: 基于IoC的设计模式

    正如我们在<控制反转>提到过的,很多人将IoC理解为一种"面向对象的设计模式",实际上IoC自身不仅与面向对象没有必然的联系,它也算不上是一种设计模式.一般来讲,设计模 ...

  3. PHP GZIP压缩+BASE64

    <?php $str = ' {"pf":"AC25c","dt":"2017-02-04 09:49:49",& ...

  4. python glob的安装和使用

    基本概念 glob是python自己带的一个文件操作相关模块,用它可以查找符合自己目的的文件,类似于Windows下的文件搜索,支持通配符操作.*,?,[]这三个通配符,*代表0个或多个字符,?代表一 ...

  5. Python数据写入csv格式文件

    (只是传递,基础知识也是根基) Python读取数据,并存入Excel打开的CSV格式文件内! 这里需要用到bs4,csv,codecs,os模块. 废话不多说,直接写代码!该重要的内容都已经注释了, ...

  6. .NET Core实战项目之CMS 第十一章 开发篇-数据库生成及实体代码生成器开发

    上篇给大家从零开始搭建了一个我们的ASP.NET Core CMS系统的开发框架,具体为什么那样设计我也已经在第十篇文章中进行了说明.不过文章发布后很多人都说了这样的分层不是很合理,什么数据库实体应该 ...

  7. SignalR的Javascript客户端API使用方式整合

      PersistentConnection Hub/生成Proxy模式 Hub/非生成Proxy模式 服务端配置 app.Map("/messageConnection", ma ...

  8. C# 获取 ipv4的方法

    NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adap ...

  9. 使用ML.NET实现基于RFM模型的客户价值分析

    RFM模型 在众多的客户价值分析模型中,RFM模型是被广泛应用的,尤其在零售和企业服务领域堪称经典的分类手段.它的核心定义从基本的交易数据中来,借助恰当的聚类算法,反映出对客户较为直观的分类指示,对于 ...

  10. 基础才是重中之重~Dictionary<K,V>里V的设计决定的性能

    回到目录 字典对象Dictionary<K,V>我们经常会用到,而在大数据环境下,字典使用不当可能引起性能问题,严重的可能引起内在的溢出! 字典的值建议为简单类型,反正使用Tuple< ...