导出功能区定义

 

发布日期: 2017年1月

适用于: Dynamics 365 (online),Dynamics 365 (on-premises),Dynamics CRM 2016,Dynamics CRM Online

为了有效定义对默认 RibbonXml 的更改,您必须能够引用可定义这些功能区的 RibbonXml 数据。

访问组织的功能区定义

如果已修改组织的功能区,并且想要使用自定义的功能区元素,则应导出当前定义。 要执行此操作,请使用 exportribbonxml 示例(位于 SampleCode\CS\Client\Ribbon\ExportRibbonXml 中)。

访问默认功能区数据

Microsoft Dynamics 365 的默认功能区定义可在 SDK 包 SDK\Resources\ExportedRibbonXml 中找到。下载 Microsoft Dynamics CRM SDK 包。

applicationRibbon.xml 文件包含核心应用程序功能区的定义。

其余文件包含其功能区定义与实体模板不同的实体所使用的定义。 每个文件都根据实体名称加以命名:逻辑实体名称 + Ribbon.xml。

这些文件代表使用 示例:导出功能区定义的以下两个消息的输出:

解压缩功能区数据

功能区数据将被作为压缩文件导出。 若要将该文件解压缩到 XML 中,您必须使用 System.IO.Packaging.ZipPackage 类。 以下示例是 SDK 示例中所使用的一种用来解压缩文件的帮助程序方法。


/// <summary>
/// A helper method that decompresses the the Ribbon data returned
/// </summary>
/// <param name="data">The compressed ribbon data</param>
/// <returns></returns>
public byte[] unzipRibbon(byte[] data)
{
 System.IO.Packaging.ZipPackage package = null;
 MemoryStream memStream = null;

 memStream = new MemoryStream();
 memStream.Write(data, 0, data.Length);
 package = (ZipPackage)ZipPackage.Open(memStream, FileMode.Open);

 ZipPackagePart part = (ZipPackagePart)package.GetPart(new Uri("/RibbonXml.xml", UriKind.Relative));
 using (Stream strm = part.GetStream())
 {
  long len = strm.Length;
  byte[] buff = new byte[len];
  strm.Read(buff, 0, (int)len);
  return buff;
 }
}

''' <summary>
''' A helper method that decompresses the the Ribbon data returned
''' </summary>
''' <param name="data">The compressed ribbon data</param>
''' <returns></returns>
Public Function unzipRibbon(ByVal data() As Byte) As Byte()
 Dim package As System.IO.Packaging.ZipPackage = Nothing
 Dim memStream As MemoryStream = Nothing

 memStream = New MemoryStream()
 memStream.Write(data, 0, data.Length)
 package = CType(ZipPackage.Open(memStream, FileMode.Open), ZipPackage)

 Dim part As ZipPackagePart = CType(package.GetPart(New Uri("/RibbonXml.xml", UriKind.Relative)), ZipPackagePart)
 Using strm As Stream = part.GetStream()
  Dim len As Long = strm.Length
              Dim buff(CInt(len - 1)) As Byte
  strm.Read(buff, 0, CInt(len))
  Return buff
 End Using
End Function

检索应用程序功能区数据

可以使用 RetrieveApplicationRibbonRequest 检索应用程序功能区,如以下示例所示:


//Retrieve the Appliation Ribbon
RetrieveApplicationRibbonRequest appribReq = new RetrieveApplicationRibbonRequest();
RetrieveApplicationRibbonResponse appribResp = (RetrieveApplicationRibbonResponse)_serviceProxy.Execute(appribReq);

System.String applicationRibbonPath = Path.GetFullPath(exportFolder + "\\applicationRibbon.xml");
File.WriteAllBytes(applicationRibbonPath, unzipRibbon(appribResp.CompressedApplicationRibbonXml));

'Retrieve the Appliation Ribbon
Dim appribReq As New RetrieveApplicationRibbonRequest()
Dim appribResp As RetrieveApplicationRibbonResponse = CType(_serviceProxy.Execute(appribReq), RetrieveApplicationRibbonResponse)

Dim applicationRibbonPath As String = Path.GetFullPath(exportFolder &amp; "\applicationRibbon.xml")
File.WriteAllBytes(applicationRibbonPath, unzipRibbon(appribResp.CompressedApplicationRibbonXml))

检索实体功能区

若要检索实体的功能区定义,您只能将实体的名称作为参数包括在 RetrieveEntityRibbonRequest 中。

若要检索支持功能区的所有实体的功能区定义,您需要其功能区定义与实体功能区模板不同的那些系统实体的列表。 以下示例显示了具有功能区定义的所有系统实体。


  //This array contains all of the system entities that use the ribbon.
  public System.String[] entitiesWithRibbons = {"account",
"activitymimeattachment",
"activitypointer",
"appointment",
"bulkoperation",
"calendar",
"campaign",
"campaignactivity",
"campaignresponse",
"competitor",
"connection",
"contact",
"contract",
"contractdetail",
"convertrule",
"convertruleitem",
"customeraddress",
"discount",
"discounttype",
"email",
"emailserverprofile",
"entitlement",
"entitlementchannel",
"entitlementtemplate",
"entitlementtemplatechannel",
"fax",
"goal",
"goalrollupquery",
"importfile",
"incident",
"invoice",
"invoicedetail",
"kbarticle",
"kbarticlecomment",
"lead",
"letter",
"list",
"listmember",
"mailbox",
"metric",
"opportunity",
"opportunityproduct",
"partnerapplication",
"phonecall",
"postfollow",
"pricelevel",
"product",
"productpricelevel",
"queue",
"queueitem",
"quote",
"quotedetail",
"recurringappointmentmaster",
"report",
"rollupfield",
"routingrule",
"routingruleitem",
"salesliterature",
"salesliteratureitem",
"salesorder",
"salesorderdetail",
"service",
"serviceappointment",
"sharepointdocument",
"sharepointdocumentlocation",
"sharepointsite",
"site",
"sla",
"slaitem",
"socialactivity",
"socialprofile",
"systemuser",
"task",
"team",
"teamtemplate",
"territory",
"uom",
"uomschedule",
"userquery"};

'This array contains all of the system entities that use the ribbon.
      Public entitiesWithRibbons() As String = {"account", "activitymimeattachment", "activitypointer", "appointment", "bulkoperation", _
                                                "campaign", "campaignactivity", "campaignresponse", "competitor", "connection", "contact", _
                                                "contract", "contractdetail", "customeraddress", "discount", "discounttype", "email", "fax", "goal", _
                                                "importfile", "incident", "invoice", "invoicedetail", "kbarticle", "kbarticlecomment", "lead", _
                                                "letter", "list", "listmember", "metric", "opportunity", "opportunityproduct", "phonecall", _
                                                "pricelevel", "product", "productpricelevel", "queueitem", "quote", "quotedetail", _
                                                "recurringappointmentmaster", "report", "salesliterature", "salesorder", "salesorderdetail", _
                                                "service", "serviceappointment", "sharepointdocumentlocation", "sharepointsite", "systemuser", _
                                                "task", "team", "territory", "uom", "uomschedule", "userquery"}

以下示例显示了如何检索一组实体的功能区定义。


//Retrieve system Entity Ribbons
RetrieveEntityRibbonRequest entRibReq = new RetrieveEntityRibbonRequest() { RibbonLocationFilter = RibbonLocationFilters.All };

foreach (System.String entityName in entitiesWithRibbons)
{
 entRibReq.EntityName = entityName;
 RetrieveEntityRibbonResponse entRibResp = (RetrieveEntityRibbonResponse)_serviceProxy.Execute(entRibReq);

 System.String entityRibbonPath = Path.GetFullPath(exportFolder + "\\" + entityName + "Ribbon.xml");
 File.WriteAllBytes(entityRibbonPath, unzipRibbon(entRibResp.CompressedEntityXml));
 //Write the path where the file has been saved.
 Console.WriteLine(entityRibbonPath);
}

'Retrieve system Entity Ribbons
Dim entRibReq As New RetrieveEntityRibbonRequest() With {.RibbonLocationFilter = RibbonLocationFilters.All}

For Each entityName As String In entitiesWithRibbons
 entRibReq.EntityName = entityName
 Dim entRibResp As RetrieveEntityRibbonResponse = CType(_serviceProxy.Execute(entRibReq), RetrieveEntityRibbonResponse)

 Dim entityRibbonPath As String = Path.GetFullPath(exportFolder &amp; "\" &amp; entityName &amp; "Ribbon.xml")
 File.WriteAllBytes(entityRibbonPath, unzipRibbon(entRibResp.CompressedEntityXml))
 'Write the path where the file has been saved.
 Console.WriteLine(entityRibbonPath)
Next entityName

任何自定义实体同时还支持功能区自定义项。 若要获取自定义实体的列表,请使用 RetrieveAllEntitiesRequest 并检索自定义实体的名称。 以下示例显示了如何检索所有自定义实体的功能区定义。


 //Check for custom entities
 RetrieveAllEntitiesRequest raer = new RetrieveAllEntitiesRequest() { EntityFilters = EntityFilters.Entity };

 RetrieveAllEntitiesResponse resp = (RetrieveAllEntitiesResponse)_serviceProxy.Execute(raer);

 foreach (EntityMetadata em in resp.EntityMetadata)
 {
  if (em.IsCustomEntity == true &amp;&amp; em.IsIntersect == false)
  {
   entRibReq.EntityName = em.LogicalName;
   RetrieveEntityRibbonResponse entRibResp = (RetrieveEntityRibbonResponse)_serviceProxy.Execute(entRibReq);

   System.String entityRibbonPath = Path.GetFullPath(exportFolder + "\\" + em.LogicalName + "Ribbon.xml");
   File.WriteAllBytes(entityRibbonPath, unzipRibbon(entRibResp.CompressedEntityXml));
   //Write the path where the file has been saved.
   Console.WriteLine(entityRibbonPath);
  }
 }
}

 'Check for custom entities
 Dim raer As New RetrieveAllEntitiesRequest() With {.EntityFilters = EntityFilters.Entity}

 Dim resp As RetrieveAllEntitiesResponse = CType(_serviceProxy.Execute(raer), RetrieveAllEntitiesResponse)

 For Each em As EntityMetadata In resp.EntityMetadata
  If em.IsCustomEntity = True AndAlso em.IsIntersect = False Then
   entRibReq.EntityName = em.LogicalName
   Dim entRibResp As RetrieveEntityRibbonResponse = CType(_serviceProxy.Execute(entRibReq), RetrieveEntityRibbonResponse)

   Dim entityRibbonPath As String = Path.GetFullPath(exportFolder &amp; "\" &amp; em.LogicalName &amp; "Ribbon.xml")
   File.WriteAllBytes(entityRibbonPath, unzipRibbon(entRibResp.CompressedEntityXml))
   'Write the path where the file has been saved.
   Console.WriteLine(entityRibbonPath)
  End If
 Next em
End Using

另请参阅

自定义命令和功能区
命令栏或功能区演示
导出功能区、准备编辑和导入功能区

Microsoft Dynamics 365

© 2017 Microsoft。 保留所有权利。 版权