リボン定義のエクスポート

 

公開日: 2017年1月

対象: Dynamics 365 (online)、Dynamics 365 (on-premises)、Dynamics CRM 2016、Dynamics CRM Online

既定の RibbonXml に対する変更を効率的に定義するには、リボンを定義する RibbonXml データを参照できる必要があります。

組織のリボン定義へのアクセス

組織のリボンが変更されたときに、カスタマイズされたリボン要素を扱う予定がある場合には現在の定義をエクスポートする必要があります。 エクスポートには、SampleCode\CS\Client\Ribbon\ExportRibbonXml にある exportribbonxml サンプルを使用します。

既定のリボン データへのアクセス

Microsoft Dynamics 365 の既定のリボン定義は、SDK パッケージの SDK\Resources\ExportedRibbonXml にあります。Microsoft Dynamics CRM SDK パッケージをダウンロードします。

applicationRibbon.xml ファイルには、コア アプリケーション リボンの定義が含まれています。

残りのファイルには、エンティティ テンプレートとは異なるリボン定義を持つエンティティによって使用される定義が含まれます。 各ファイルの名前は、エンティティの名前に従って付けられています (論理エンティティ名 + Ribbon.xml)。

これらのファイルは、サンプル: リボン定義をエクスポートするを使用して次の 2 つのメッセージの出力を表します。

  • RetrieveApplicationRibbonRequest
    このメッセージは、エンティティ テンプレートを含むコア アプリケーション リボンを取得します。

  • RetrieveEntityRibbonRequest
    このメッセージは、特定のエンティティで使用されるリボン定義を取得します。

リボン データを解凍する

リボン データは、圧縮ファイルとしてエクスポートされます。 このファイルを 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. All rights reserved. 著作権