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

有时候我想将系统中的实体信息导出来,若是多语言,一个实体会有多个显示名称,有时候对应起来不方便,我便写了个程序导出来,实例是导出简体中文和英文的显示名称,架构名称,XrmtoolsBox也可以导出,不过导出时候是实体的逻辑名称,架构名称有时候更有用,架构名称转成逻辑名称方便,全小写就行了。不多说了,上代码,主要参考官方的 RetrieveAllEntitiesRequest Class 官方实例更加详细,导出的是XML文件,我这里转成Excel,大家用这个更多点。

 using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Configuration;
using System.Linq;
using System.ServiceModel.Description;
using Excel = Microsoft.Office.Interop.Excel; namespace ExportEntityMetadata
{
class Program
{
static void Main(string[] args)
{
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"];
using (OrganizationServiceProxy orgSvc = GetProxy<IOrganizationService, OrganizationServiceProxy>(orgServiceMgr, orgAuCredentials))
{
WhoAmIRequest whoReq = new WhoAmIRequest();
WhoAmIResponse whoRep = orgSvc.Execute(whoReq) as WhoAmIResponse;
var userEntity = orgSvc.Retrieve("systemuser", whoRep.UserId, new ColumnSet("fullname"));
Console.WriteLine(string.Format("登录组织{0}成功,欢迎{1},继续操作请输入y!", ConfigurationManager.AppSettings["orgUrl"], userEntity.GetAttributeValue<string>("fullname")));
var input = Console.ReadLine().ToString().ToUpper();
if (input == "Y")
{
Console.WriteLine(string.Format("程序开始处理 - {0}", DateTime.Now.ToString()));
RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest()
{
EntityFilters = EntityFilters.Entity,
RetrieveAsIfPublished = true
};
RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)orgSvc.Execute(request);
var excelApp = new Excel.Application();
excelApp.Visible = false;
Excel.Workbook metadataWorkbook = excelApp.Workbooks.Add();
Excel.Worksheet rolesWorksheet = (Excel.Worksheet)excelApp.ActiveSheet;
rolesWorksheet.Name = "实体信息";
int row = ;
rolesWorksheet.Cells[, ] = "实体架构名称";
rolesWorksheet.Cells[, ] = "所有者类型";
rolesWorksheet.Cells[, ] = "是否活动实体";
rolesWorksheet.Cells[, ] = "实体显示名称(中文)";
rolesWorksheet.Cells[, ] = "实体显示名称(英文)";
rolesWorksheet.Cells[, ] = "实体说明";
rolesWorksheet.Rows[].Font.Bold = true;//字体加粗
row++; foreach (EntityMetadata currentEntity in response.EntityMetadata)
{
rolesWorksheet.Cells[row, ] = currentEntity.SchemaName;
rolesWorksheet.Cells[row, ] = currentEntity.OwnershipType.Value.ToString();
rolesWorksheet.Cells[row, ] = currentEntity.IsActivity.Value.ToString();
rolesWorksheet.Cells[row, ] = currentEntity.DisplayName.LocalizedLabels.Where(a => a.LanguageCode == ).Count() >= ? currentEntity.DisplayName.LocalizedLabels.Where(a => a.LanguageCode == ).FirstOrDefault().Label : string.Empty;
rolesWorksheet.Cells[row, ] = currentEntity.DisplayName.LocalizedLabels.Where(a => a.LanguageCode == ).Count() >= ? currentEntity.DisplayName.LocalizedLabels.Where(a => a.LanguageCode == ).FirstOrDefault().Label : string.Empty;
rolesWorksheet.Cells[row, ] = currentEntity.Description.LocalizedLabels.Where(a => a.LanguageCode == ).Count() >= ? currentEntity.Description.LocalizedLabels.Where(a => a.LanguageCode == ).FirstOrDefault().Label : string.Empty; ;
row++;
Console.WriteLine(string.Format("第{0}行处理完毕 - {1}", row - , DateTime.Now.ToString()));
}
rolesWorksheet.Columns[].AutoFit();//自动列宽
rolesWorksheet.Columns[].AutoFit();//自动列宽
rolesWorksheet.Columns[].AutoFit();//自动列宽
rolesWorksheet.Columns[].AutoFit();//自动列宽
rolesWorksheet.Columns[].AutoFit();//自动列宽
rolesWorksheet.Columns[].AutoFit();//自动列宽
metadataWorkbook.SaveAs(Filename: @"D:\CRMMetadata.xlsx", FileFormat: Excel.XlFileFormat.xlWorkbookDefault);
metadataWorkbook.Close();
excelApp.Quit();
}
}
Console.Write("程序执行完毕!");
Console.ReadKey();
} 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实体信息到Excel中。的更多相关文章

  1. 自定义控制台程序导出角色对实体的权限为Excel文件

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

  2. 微信公众号开发之如何一键导出微信所有用户信息到Excel

    微信开发交流群:148540125 系列文章参考地址 极速开发微信公众号欢迎留言.转发.打赏 项目源码参考地址 点我点我--欢迎Start 极速开发微信公众号系列文章之如何一键导出微信所有用户信息到E ...

  3. 无依赖简单易用的Dynamics 365实体记录数计数器并能计算出FetchXml返回的记录数

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

  4. 嵌入Canvas App到Dynamics 365 Customer Engagement(Model-Driven App)中,创造更多可能!

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

  5. 控制台程序读取Excel设置角色权限

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

  6. 将Dynamics 365中的用户及其角色、角色导出到Excel中

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

  7. Dynamics 365 POA表记录的查询

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

  8. Dynamics 365中的非交互式账号(Non-interactive User)介绍

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

  9. Dynamics 365中的事件框架与事件执行管道(Event execution pipeline)

    本文介绍了Microsoft Dynamics 365(以下简称D365)中的两个概念,事件框架(Event Framework)与事件执行管道(Event execution pipeline). ...

随机推荐

  1. WebGL绘制有宽度的线

    WebGL中有宽度的线一直都是初学者的一道门槛,因为在windows系统中底层的渲染接口都是D3D提供的,所以无论你的lineWidth设置为多少,最终绘制出来的只有一像素.即使在移动端可以设置有宽度 ...

  2. React Native调试实用技巧,React Native开发者必会的调试技巧

    在做React Native开发时,少不了的需要对React Native程序进行调试.调试程序是每一位开发者的基本功,高效的调试不仅能提高开发效率,也能降低Bug率.本文将向大家分享React Na ...

  3. 源码级调试的XNU内核

    i春秋翻译小组-FWorldCodeZ 源码级调试的XNU内核 无论你是在开发内核扩展,进行漏洞研究,还是还有其他需要进入macOS / iOS内核,XNU,有时你需要附加调试器.当你这样做时,使用源 ...

  4. [Swift]LeetCode632. 最小区间 | Smallest Range

    You have k lists of sorted integers in ascending order. Find the smallest range that includes at lea ...

  5. [Swift]LeetCode775. 全局倒置与局部倒置 | Global and Local Inversions

    We have some permutation Aof [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...

  6. [Swift]LeetCode881. 救生艇 | Boats to Save People

    The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each boat c ...

  7. [Swift]LeetCode897. 递增顺序查找树 | Increasing Order Search Tree

    Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root o ...

  8. 微信小程序请求API接口PHPSESSID变化的解决方式

    微信小程序开发,请求服务器API的方法使用的是微信官方提供的wx.request()方法.在开发中发现,每一个请求都会生成一个独立的PHPSESSID,如下图示: 搜索后得知,这是由于wx.reque ...

  9. [Reversing.kr] Easy_KeygenMe Writeup

    IDA打开.Main()函数就是关键算法 v6,v7,v8 是连续的 .可看成 L=[16,32,48].输入的name每位分别于L[]异或 得到的值存在v13.然后清空v9的值 ,输入Serial储 ...

  10. BBS论坛(二十二)

    22.1.七牛js上传轮播图图片 (1)common/zlqiniu.js 'use strict'; var zlqiniu = { 'setup': function (args) { var d ...