---
title: "ウォークスルー:エンドポイントの実装"
slug: "walkthrough--implementing-an-endpoint"
abstract: "カスタムプロバイダーの実装の一環として、Sitecore Data Exchange Frameworkでカスタムエンドポイントを実装するためのガイド。"
---
# ウォークスルー:エンドポイントの実装

このウォークスルーは「 [テキストファイルのカスタムプロバイダーを実装](https://doc.sitecore.com/xp/ja/developers/def/80/data-exchange-framework/implementing-a-custom-provider-for-text-files-walkthrough-series.html "Implementing a custom provider for text files walkthrough series") するウォークスルー」シリーズの第2部であり、カスタムエンドポイントの実装方法を説明しています。エンドポイントとは、読み書き可能なものを表します。この例では、エンドポイントは読み取れるテキストファイルを表します。

このウォークスルーでは、以下の方法を説明します:

-   エンドポイント用のテンプレートを作成します
-   エンドポイントにテンプレートフィールドを追加する
-   エンドポイント設定プラグインを実装してください
-   エンドポイントコンバータを実装する
-   エンドポイントテンプレートに標準値を設定します

## エンドポイント用のテンプレートを作成します

Sitecore Content Editorを使ってデータ同期プロセスをモデル化します。これにより、慣れたインターフェースで設定を行えます。設定には、Sitecoreが読み取れるテキストファイルを表現するためのテンプレートが必要です。

テンプレートを作成するには:

1.  コンテンツエディターで*Templates*に移動します。
    
2.  メニューリボンの **「挿入** 」グループで「 **新しいテンプレート**」をクリックします。
    
    ![New template option in menu ribbon](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/def/80/data-exchange-framework/images/add-template.png)
    
3.  「 **名前選択** 」ダイアログで、以下の値を入力してください:
    
    フィールド
    
    価値
    
    **名称**
    
    *Text File Endpoint*
    
    **ベーステンプレート**
    
    *テンプレート/データ交換/フレームワーク/エンドポイント/ベーステンプレート/ベースエンドポイント*
    
4.  **次へ**クリック。
    
5.  **ロケーション**ダイアログで*Templates/Data Exchange/Providers/File System/Endpoints*を選択します。**「次へ**」をクリックします。
    
6.  確認ダイアログで **「閉じる**」をクリックしてください。
    
7.  新しいテンプレートのアイコンを設定するには、コンテンツツリーでテンプレートを選択してください。例えば、*テンプレート/データ交換/プロバイダー/ファイルシステム/エンドポイント/テキストファイルエンドポイント*などです。
    
8.  右側のペインの **「コンテンツ** 」タブで、タイトルの横にあるアイコンをクリックしてください。
    
    ![Setting the icon for an endpoint template](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/def/80/data-exchange-framework/images/icon1.png)
    
9.  アイコン **変更** ダイアログの **アイコン** フィールドで、例えば Office/32x32/cloud.png
    

## テンプレートフィールドを追加する

テキストファイルのエンドポイントでは、Sitecoreにテキストファイルの解析方法を指示する設定を設定する必要があります。例えば、データが単行か複数行か、ファイルがどの列区切りを使うか、列見出し付きの行が含まれているかを指定できます。

これらの設定を追加すると:

1.  *データ交換/プロバイダー/ファイルシステム/エンドポイント/テキストファイルエンドポイント*に移動してください。
    
2.  テンプレートセクションを追加してください。名前を*Settings*。
    
3.  設定**セクションの****ビルダー**タブで、以下のテンプレートフィールドを追加してください:
    
    名称
    
    種類
    
    共有
    
    *Path*
    
    *単行テキスト*
    
    選ばれました
    
    *ColumnSeparator*
    
    *単行テキスト*
    
    選ばれました
    
    *ColumnHeadersInFirstLine*
    
    *Checkbox*
    
    選ばれました
    
4.  アイテムを保存してください。
    

## エンドポイント設定プラグインを実装してください

エンドポイントの設定はエンドポイントテンプレートを使って設定されます。この例では、読み取れるファイルのパスや、ファイルの最初の行に列ヘッダーがあるかどうかなどの設定が可能です。

エンドポイントテンプレートは、エンドポイント設定へのデザインタイムアクセスを提供します。エンドポイント設定への実行時アクセスはプラグインを通じて提供されます。エンドポイントの特定の設定を処理するにはプラグインを使用する必要があります。

エンドポイント設定プラグインを実装するには:

1.  Visual Studioで、次のクラスを追加します:
    
    using Sitecore.DataExchange;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Examples.DataExchange.Providers.FileSystem
    {
     public class TextFileSettings : IPlugin
     {
     public TextFileSettings() { }
     public bool ColumnHeadersInFirstLine { get; set; }
     public string ColumnSeparator { get; set; }
     public string Path { get; set; }
     }
    }
    
2.  次のクラスを加えます:
    
    using Sitecore.DataExchange.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Examples.DataExchange.Providers.FileSystem
    {
     public static class EndpointExtensions
     {
     public static TextFileSettings GetTextFileSettings(this Endpoint endpoint)
     {
     return endpoint.GetPlugin<TextFileSettings>();
     }
     public static bool HasTextFileSettings(this Endpoint endpoint)
     {
     return (GetTextFileSettings(endpoint) != null);
     }
     }
    }
    

> !注この拡張メソッドは、必要なときにプラグインにアクセスしやすくします。
> 
> プラグインへのアクセスための拡張メソッドを提供することは、Data Exchange Frameworkのプロバイダーを実装する際に考慮すべきベストプラクティスです。

## エンドポイントコンバータを実装する

コンポーネントを表すSitecoreアイテムを実際のコンポーネントに変換するにはコンバーターが必要です。この例では、コンバーターがエンドポイントアイテムの設定をエンドポイント設定プラグインに変換します。そのプラグインをエンドポイントに追加できます。

エンドポイントコンバータを実装するには:

1.  Visual Studioで、次のクラスを追加します:
    
    using Sitecore.DataExchange.Attributes;
    using Sitecore.DataExchange.Converters.Endpoints;
    using Sitecore.DataExchange.Models;
    using Sitecore.DataExchange.Repositories;
    using Sitecore.Services.Core.Model;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Examples.DataExchange.Providers.FileSystem
    {
     SupportedIds(TextFileEndpointTemplateId)
     public class TextFileEndpointConverter : BaseEndpointConverter
     {
     public const string TextFileEndpointTemplateId = "ENDPOINT TEMPLATE ID";
     public const string TemplateFieldColumnSeparator = "ColumnSeparator";
     public const string TemplateFieldColumnHeadersInFirstLine = "ColumnHeadersInFirstLine";
     public const string TemplateFieldPath = "Path";
     public TextFileEndpointConverter(IItemModelRepository repository) : base(repository)
     {
     }
     protected override void AddPlugins(ItemModel source, Endpoint endpoint)
     {
     //
     //create the plugin
     var settings = new TextFileSettings
     {
     //
     //populate the plugin using values from the item
     ColumnHeadersInFirstLine = this.GetBoolValue(source, TemplateFieldColumnHeadersInFirstLine),
     ColumnSeparator = this.GetStringValue(source, TemplateFieldColumnSeparator),
     Path = this.GetStringValue(source, TemplateFieldPath)
     };
     //
     //add the plugin to the endpoint
     endpoint.AddPlugin(settings);
     }
     }
    }
    
    > !重要ENDPOINT TEMPLATE IDの値を、*Text File Endpoint*という名前のエンドポイントテンプレートのIDに合わせて変更しなければなりません。
    
    > !注BaseEndpointConverter(base-endpoint-converter.html "Base endpoint converter") から継承することで、Sitecore項目のフィールドから値を読み取るのを容易にする多くの手法にアクセスできます。
    
2.  プロジェクトをコンパイルします。
    
3.  Examples.DataExchange.Providers.FileSystem.dllをSitecoreサーバーにデプロイしてください。
    

## エンドポイントテンプレートに標準値を設定します

エンドポイントテンプレートを使う前に、テンプレート上のフィールドのデフォルト値を指定する必要があります。

エンドポイントテンプレートの値を設定するには:

1.  コンテンツエディターで、*テンプレート/データ交換/プロバイダー/ファイルシステム/エンドポイント/テキストフィールドエンドポイント*に移動します。
    
2.  新しいアイテムを作成するには、リボンのビル **ダーオプション** タブで「 **標準値**」をクリックしてください。
    
    ![Standard values in menu ribbon](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/def/80/data-exchange-framework/images/standard-values-button.png)
    
3.  以下のフィールド値を設定します:
    
    フィールド
    
    価値
    
    列分離器
    
    *,*
    
    第一行の列ヘッダー
    
    選ばれました
    
    コンバータータイプ
    
    *例:DataExchange.Providers.FileSystem.TextFileEndpointConverter, examples.DataExchange.Providers.FileSystem*
    
    > !注コンバータータイプフィールドはデータ交換フレームワークのセクションにあります。フィールドを見る前にセクションを拡張する必要があるかもしれません。
    
4.  アイテムを保存してください。