---
title: "カスタムストレージプロバイダーとプロファイルの例"
slug: "custom-storage-provider-and-profiles-example"
abstract: "xConnect Data Exportツールでカスタムストレージプロバイダーとそのプロファイルを作成・設定する方法。"
---
# カスタムストレージプロバイダーとプロファイルの例

カスタムプロバイダーおよびプロファイルを導入するために:

1.  **カスタムプロバイダーを導入します。IStorageProviderから継承したデータの保存方法を実装する必要があります。**
    
    using Sitecore.XConnect.DataTools.CortexWorkers.DataExport.StorageProviders;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace CortexWorkers.DataExport.StorageProviders.Examples
    {
     internal class CustomProvider : IStorageProvider
     {
     public CustomProvider(IEnumerable<CustomProfile> profiles)
     {
     Profiles = profiles == null
     ? new Dictionary<string, CustomProfile>()
     : profiles.ToDictionary(x => x.ProfileName, x => x);
     }
     public IReadOnlyCollection<string> ProfileNames => Profiles.Keys;
     protected Dictionary<string, CustomProfile> Profiles { get; }
     protected CustomProfile GetProfile(string profileName)
     {
     if (!Profiles.TryGetValue(profileName, out CustomProfile profile))
     {
     throw new InvalidOperationException();
     }
     return profile;
     }
     public Task UploadAsync(string fileName, string fileContent, string profileName, CancellationToken cancellationToken)
     {
     /\*Implement the logic of the custom provider\*/
     }
     }
    }
    
2.  特定のストレージパラメータを定義するカスタムストレージプロファイルを導入します。適切なプロファイルを特定するためにProfileNameパラメータを追加する必要があります。
    
    using System;
    using System.Globalization;
    using Microsoft.Extensions.Configuration;
    
    namespace CortexWorkers.DataExport.StorageProviders.Examples
    {
     internal class CustomProfile
     {
     public CustomProfile(IConfiguration options)
     : this((options ?? throw new ArgumentNullException(nameof(options))).GetValue<string>(nameof(ProfileName)),
     options.GetValue<string>(nameof(Param1)), options.GetValue<string>(nameof(Param2)), options.GetValue<string>(nameof(Param3)))
     {
     }
     public CustomProfile(string profileName, string param1, string param2, string param3)
     {
     if (string.IsNullOrWhiteSpace(profileName))
     {
     throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Looks up a localized string similar to The {0} is not valid..", nameof(profileName)));
     }
     if (string.IsNullOrWhiteSpace(param1))
     {
     throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Looks up a localized string similar to The {0} is not valid..", nameof(param1)));
     }
     if (string.IsNullOrWhiteSpace(param2))
     {
     throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Looks up a localized string similar to The {0} is not valid..", nameof(param2)));
     }
     if (string.IsNullOrWhiteSpace(param3))
     {
     throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Looks up a localized string similar to The {0} is not valid..", nameof(param3)));
     }
     ProfileName = profileName;
     Param1 = param1;
     Param2 = param2;
     Param3 = param3;
     }
     public string ProfileName { get; }
     public string Param1 { get; }
     public string Param2 { get; }
     public string Param3 { get; }
     }
    }
    
3.  Cortex Processingの役割とProcessing Engineサービス構成*Sitecore\\Processing\\Services*セクションを新しいカスタムプロバイダーとプロファイルでパッチしてください。
    
    <?xml version="1.0" encoding="utf-8" ?>
    <Settings>
     <Sitecore>
     <Processing>
     <Services>
     <StorageProviders.CustomProfile>
     <Type>CortexWorkers.DataExport.StorageProviders.Examples.CustomProfile, CortexWorkers.DataExport.StorageProviders.Examples</Type>
     <As>CortexWorkers.DataExport.StorageProviders.Examples.CustomProfile, CortexWorkers.DataExport.StorageProviders.Examples</As>
     <LifeTime>Singleton</LifeTime>
     <Options>
     <ProfileName>CustomProfile</ProfileName>
     <Param1>Value1</Param1>
     <Param2>Value2</Param2>
     <Param3>Value3</Param3>
     </Options>
     </StorageProviders.CustomProfile>
     <StorageProviders.CustomProvider>
     <Type>CortexWorkers.DataExport.StorageProviders.Examples.CustomProvider, CortexWorkers.DataExport.StorageProviders.Examples</Type>
     <As>Sitecore.XConnect.DataTools.CortexWorkers.DataExport.StorageProviders.IStorageProvider, Sitecore.XConnect.DataTools.CortexWorkers</As>
     <LifeTime>Singleton</LifeTime>
     </StorageProviders.CustomProvider>
     </Services>
     </Processing>
     </Sitecore>
    </Settings>
    
4.  ソリューションを構築しましょう。DLLファイルをCortex Processingの役割とProcessing Engineサービスに追加してください。
    
5.  変更を適用するには、Processing Engineサービスを再起動してください。
    

現在では、CustomProfileをDataExport Toolに渡し、新しいカスタムプロバイダーでアップロードを実行することが可能になりました。