---
title: "カスタムモデルを展開する"
slug: "deploy-a-custom-model"
abstract: "xConnectにカスタムモデルをシリアライズし展開する方法。"
---
# カスタムモデルを展開する

このトピックでは、カスタムモデルをxConnectにシリアライズし展開する方法について説明します。モデル展開は、モデルのJSON表現をxConnectのすべてのインスタンスにコピーする手作業です。

## モデルをJSONにシリアライズする

モデルをJSONにシリアライズするには:

1.  xConnectモデルをシリアライズするコンソールアプリケーションを作成しましょう。
    
2.  モデルを示されたようにJSONにシリアライズします。以下の例はSitecoreのデフォルトのコレクションモデルを使用しています。
    
    using Sitecore.XConnect.Serialization;
    
    namespace Documentation
    {
     public class DeployModel
     {
     public void Serialize()
     {
     // File name will be Sitecore.XConnect.Collection.Model, 9.0.json
     var json = XdbModelWriter.Serialize(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
     }
     }
    }
    
    > !重要ファイル名は変更しないでください。ファイル名はモデルクラスで宣言された名前と一致しなければなりません。
    

## モデルをxConnectおよびマーケティングオートメーション運用に展開してください

xConnectおよびマーケティングオートメーションオペレーションの役割にカスタムモデルを展開するには:

1.  xConnect Collection SearchおよびxConnect Collectionの役割のすべてのインスタンスで、モデルJSONファイルを以下のパスにコピーしてください:
    
    C:\\<Path to xConnect>\\root\\App\_Data\\Models
    
2.  モデルJSONファイルをxConnect Search Indexerの次のパスにコピーします。
    
    C:\\<Path to indexer>\\root\\App\_data\\Models
    
    > !注デフォルトでは、xConnect SearchインデクサーはC:\\<Path to xConnect>\\App\_data\\jobs\\continuous\\IndexWorkerの下に位置しています。
    
3.  Sitecore 9.0 Update 2以降では、マーケティングオートメーションオペレーションの役割のすべてのインスタンスで、モデルJSONファイルを以下のパスにコピーする必要があります。このモデルはライブイベントを処理するために必要です:
    
    C:\\<Path to marketing automation operations>\\root\\App\_Data\\Models
    
    > !注マーケティングオートメーションオペレーションの役割がxConnect Collection SearchまたはxConnect Collectionと組み合わせている場合、ステップ3は不要です。
    

## モデルをマーケティングオートメーションエンジンに展開します

カスタムアクティビティタイプの文脈でカスタムモデルデータを扱うために、以下のステップを踏みます。この機能は9.0アップデート1以降で利用可能です。

モデルをマーケティングオートメーションエンジンに展開するには:

1.  モデルDLLをマーケティングオートメーションエンジンのすべてのインスタンスのルートにコピーします。
    
    > !注マーケティングオートメーションエンジンはモデルのJSON表現を必要としません。デフォルトでは、マーケティングオートメーションエンジンはC:\\<Path to xConnect>\\App\_data\\jobs\\continuous\\AutomationEngineの下に位置しています。
    
2.  C:\\<Path to xConnect>\\App\_data\\jobs\\continuous\\AutomationEngine\\AppData\\config\\sitecoreで、sc.Sample.CustomModel.xmlという名前の設定ファイルを作成します。ファイル名はscで始まり、.xmlで終わらなければなりません。以下のモデル構成を貼り付け、以下の変更を加えます。
    
    -   TypeNameをモデルの完全なクオリファイド名に変更してください。
    -   オプションとして、 CustomModel1 ノードの名前を変更することも可能です。
    
    <Settings>
     <Sitecore>
     <XConnect>
     <Services>
     <XConnect.Client.Configuration>
     <Options>
     <Models>
     <CustomModel1>
     <TypeName>Sitecore.Xdb.MarketingAutomation.Stub.Model.StubModel, Sitecore.Xdb.MarketingAutomation.Stub</TypeName>
     </CustomModel1>
     </Models>
     </Options>
     </XConnect.Client.Configuration>
     </Services>
     </XConnect>
     </Sitecore>
    </Settings>
    

モデルがModelという静的プロパティを公開していると仮定し、そのXdbModelを返します。カスタムモデルが異なる静的プロパティからモデルを公開する場合は、CustomModel要素内のPropertyName要素にそのプロパティ名を含めてください。

<Settings>
 <Sitecore>
 <XConnect>
 <Services>
 <XConnect.Client.Configuration>
 <Options>
 <Models>
 <CustomModel1>
 <TypeName>Sitecore.Xdb.MarketingAutomation.Stub.Model.StubModel, Sitecore.Xdb.MarketingAutomation.Stub</TypeName>
 <PropertyName>TheModel</PropertyName>
 </CustomModel1>
 </Models>
 </Options>
 </XConnect.Client.Configuration>
 </Services>
 </XConnect>
 </Sitecore>
</Settings>

## モデルをコアロールに展開する

最後に、カスタムモデルをすべてのコアSitecoreインスタンスに展開する必要があります。これには以下の役割が含まれます:

-   Content Delivery
-   Content Management
-   xDB処理

各コアSitecoreインスタンスで:

1.  モデルのDLLをコアのSitecoreインスタンスのbinディレクトリにコピーしてください。
    
2.  自分のモデルクラスを示されたようにパッチ \\App\_Config\\Sitecore\\XConnect.Client.Configuration\\Sitecore.XConnect.Client.configします:
    
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
     <xconnect>
     <runtime type="Sitecore.XConnect.Client.Configuration.RuntimeModelConfiguration,Sitecore.XConnect.Client.Configuration">
     <schemas hint="list:AddModelConfiguration">
     <!-- value of 'name' property must be unique -->
     <schema name="documentationmodel" type="Sitecore.XConnect.Client.Configuration.StaticModelConfiguration,Sitecore.XConnect.Client.Configuration" patch:after="schema@name='collectionmodel'">
     <param desc="modeltype">Documentation.Model.CollectionModel, Documentation.Model</param>
     </schema>
     </schemas>
     </runtime>
     </xconnect>
    </sitecore>
    </configuration>
    
3.  コード内でモデルDLLを参照してください。
    
4.  xConnect Client APIを使って [イベントをトリガー](https://doc.sitecore.com/xp/ja/developers/105/sitecore-experience-platform/add-interaction-events.html "Add interaction events") したり、[連絡先の側面を入力し](https://doc.sitecore.com/xp/ja/developers/105/sitecore-experience-platform/set-contact-facets.html "Set contact facets")てください。
    

> !注 [モデルはSitecoreのコンテキスト外でも使用できます](https://doc.sitecore.com/xp/ja/developers/105/sitecore-experience-platform/instantiate-client-in-a-non-sitecore-context.html "Instantiate client in a non-Sitecore context")。