Implement an endpoint converter

Abstract

How to convert a Sitecore item into a component in Sitecore Data Exchange Framework.

You need a converter in order to convert a Sitecore item that represents a component into an actual component. In this example, a converter converts the settings on an endpoint item into an endpoint settings plugin. That plugin can then be added to the endpoint.

To implement an endpoint converter:

  1. In Visual Studio, add the following class:

    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);
            }
        }
    }
    

    Important

    You must change the value of [ENDPOINT TEMPLATE ID] to match the ID from the endpoint template named Text File Endpoint.

    Note

    By inheriting from BaseEndpointConverter you get access to a number of methods that facilitate reading values from fields on a Sitecore item.

  2. Compile the project.

  3. Deploy Examples.DataExchange.Providers.FileSystem.dll to the Sitecore server.