---
title: "ウォークスルー:トラブルシューティングコンポーネントの実装"
slug: "walkthrough--implementing-a-troubleshooter-component"
abstract: "Sitecore Data Exchange Frameworkにおけるトラブルシューティングコンポーネントの作成概要。"
---
# ウォークスルー:トラブルシューティングコンポーネントの実装

トラブルシューティングは、Sitecoreユーザーが選択したSitecoreアイテムが正しく設定され、正常に動作しているかを判断するロジックを実行するためのコンポーネントです。

このウォークスルーでは、「 [テキストファイルのカスタムプロバイダーを実装するウォークスルー」シリーズ](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")で設定されたファイルシステムプロバイダーにトラブルシューティング機能を追加します。ファイルシステムのエンドポイントがSitecoreサーバーがアクセス可能なファイルを使用するよう設定されているかどうかを判定するトラブルシューティング機能も追加します。

トラブルシューティングは元々エンドポイント向けに設計されました。ユーザーがエンドポイントが正しく設定されているかどうかを判断するために使われます。これがトラブルシューターの主な用途ですが、以下のData Exchange Frameworkのベーステンプレートを継承すれば、あらゆる種類のアイテムに使用可能です。

-   *Convertible*
-   *Troubleshootable*

このウォークスルーでは以下の方法が示されています:

-   トラブルシューティングコンポーネントを構築します
-   エンドポイントにトラブルシューティングツールを指定します
-   トラブルシューティングツールをテストしてください

> !注完成したコードとインストールパッケージは[GitHub](https://github.com/Sitecore/Sitecore.DataExchange.Examples/)で入手可能です。

## トラブルシューティングコンポーネントを構築します

Microsoft Visual Studioでトラブルシューティングコンポーネントを構築し、サーバーにデプロイする必要があります。

トラブルシューティングコンポーネントを構築するには:

1.  Visual Studioで、次のクラスを追加します:
    
    using Sitecore.DataExchange.Models;
    using Sitecore.DataExchange.Troubleshooters;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Examples.DataExchange.Providers.FileSystem
    {
     public class TextFileEndpointTroubleshooter : BaseEndpointTroubleshooter
     {
     public TextFileEndpointTroubleshooter()
     {
     }
     protected override ITroubleshooterResult Troubleshoot(Endpoint endpoint, TroubleshooterContext context)
     {
     var settings = endpoint.GetPlugin<TextFileSettings>();
     if (settings == null)
     {
     return TroubleshooterResult.FailResult("The endpoint is missing the plugin TextFileSettings.");
     }
     if (string.IsNullOrWhiteSpace(settings.Path))
     {
     return TroubleshooterResult.FailResult("The endpoint does not have a file path specified on it.");
     }
     if (!File.Exists(settings.Path))
     {
     return TroubleshooterResult.FailResult(
     "The path specified on the endpoint either " +
     "points to a file that does not exist " +
     "or the process does not have permission to read the file.");
     }
     return TroubleshooterResult.SuccessResult("The specified file exists and can be accessed.");
     }
     }
    }
    
    > !注このトラブルシューティングツールはSitecore.DataExchange.Troubleshooters.BaseEndpointTroubleshooterから継承しています。 Sitecore.DataExchange.Troubleshooters.ITroubleshooterから継承することで、あらゆる種類のコンポーネントに対してカスタムトラブルシューティングを作成できます。
    
2.  プロジェクトをコンパイルします。
    
3.  Examples.DataExchange.Providers.FileSystem.dllをSitecoreサーバーにデプロイしてください。
    

## エンドポイントにトラブルシューティングツールを指定します

Data Exchange Frameworkテンプレートから継承する任意の項目に対してトラブルシューティングを指定できます*Convertible**Troubleshootable*。

この例では、トラブルシューティングはテキストファイルのエンドポイントに追加されており、これは条件を満たす*Base Endpoint*テンプレートから継承されるため、追加の作業は不要です。

エンドポイントのトラブルシューティングを指定するには:

1.  コンテンツエディターで */sitecore/templates/Data Exchange/Providers/File System/endpoints/Text File Endpoint/\_\_Standard Values*に移動します。
    
2.  右側のパネルで、以下のフィールド値を指定します:
    
    フィールド
    
    価値
    
    **トラブルシューティングタイプ**
    
    例:DataExchange.Providers.FileSystem.TextFileEndpointTroubleshooter、例:DataExchange.Providers.FileSystem
    
3.  アイテムを保存してください。
    

## トラブルシューティングツールをテストしてください

トラブルシューティングはテキストファイルのエンドポイントに割り当てられているため、トラブルシューティングをテストするには以下が必要です:

1.  コンテンツエディターでテナントを選択してください。 *Endpoints/Providers/File System/City Information File*に移動します。
    
    ![Tenant endpoint provider file system item in content tree](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/def/80/data-exchange-framework/images/text-file-endpoint.png)
    
2.  メニューのリボンで **「トラブルシューティング**を実行する」をクリックします。
    
    ![Run Troubleshooter button in menu ribbon](<https://doc.sitecore.com/api/markdown-image/xp/ja/developers/def/80/data-exchange-framework/images/run%20troubleshooter%20button.png>)
    

エンドポイントが正しく設定され、ファイルが存在し、Sitecoreサーバーがファイルにアクセスできる場合、成功メッセージが表示されます。

![Success message](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/def/80/data-exchange-framework/images/success.png)

エンドポイントにファイルパスが指定されていない場合、エラーメッセージが表示されます。

![Missing file path error message](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/def/80/data-exchange-framework/images/fail-no-path-specified.png)

エンドポイントにファイルパスが指定されていても、そのファイルが存在しない場合や、ファイル権限の関係でSitecoreサーバーがファイルにアクセスできない場合、エラーメッセージが表示されます。

![File cannot be read error message](https://doc.sitecore.com/api/markdown-image/xp/ja/developers/def/80/data-exchange-framework/images/fail-no-file.png)