6.3. Implement Request HeaderΒΆ
Follow these step to create the plugin, item model and converter for a request header.
In Visual Studio, add the following class:
using Sitecore.DataExchange; namespace DataExchange.Providers.RESTful.Plugins.Settings { public class RequestHeaderSettings : IPlugin { public string HeaderName { get; set; } public string HeaderValue { get; set; } } }
Add the following class:
using Sitecore.Services.Core.Model; namespace DataExchange.Providers.RESTful.Models.ItemModels.Settings { public class RequestHeaderItemModel : ItemModel { public const string HeaderName = Templates.RequestHeader.FieldNames.HeaderName; public const string HeaderValue = Templates.RequestHeader.FieldNames.HeaderValue; } }
Add the following class:
using Sitecore.DataExchange.Converters; using Sitecore.DataExchange.Repositories; using Sitecore.DataExchange; using Sitecore.Services.Core.Model; using DataExchange.Providers.RESTful.Models.ItemModels.Settings; using DataExchange.Providers.RESTful.Plugins.Settings; namespace DataExchange.Providers.RESTful.Converters.Settings { public class RequestHeaderConverter : BaseItemModelConverter<RequestHeaderSettings> { public RequestHeaderConverter(IItemModelRepository repository) : base(repository) { this.SupportedTemplateIds.Add(Templates.RequestHeader.TemplateId); } protected override ConvertResult<RequestHeaderSettings> ConvertSupportedItem(ItemModel source) { var requestHeaderSettings = new RequestHeaderSettings { HeaderName = base.GetStringValue(source, RequestHeaderItemModel.HeaderName), HeaderValue = base.GetStringValue(source, RequestHeaderItemModel.HeaderValue) }; return this.PositiveResult(requestHeaderSettings); } } }
Important
v1.4.1 or earlier: The
Sitecore.DataExchange.ConvertResult
class was introduced in Data Exchange Framework 2.0, and theConverter
classes were updated to use theConvertResult
class to track positive and negative results.using Sitecore.DataExchange.Converters; using Sitecore.DataExchange.Repositories; using Sitecore.Services.Core.Model; using DataExchange.Providers.RESTful.Models.ItemModels.Settings; using DataExchange.Providers.RESTful.Plugins.Settings; namespace DataExchange.Providers.RESTful.Converters.Settings { public class RequestHeaderConverter : BaseItemModelConverter<RequestHeaderSettings> { public RequestHeaderConverter(IItemModelRepository repository) : base(repository) { this.SupportedTemplateIds.Add(Templates.RequestHeader.TemplateId); } public override RequestHeaderSettings Convert(ItemModel source) { var requestHeaderSettings = new RequestHeaderSettings { HeaderName = base.GetStringValue(source, RequestHeaderItemModel.HeaderName), HeaderValue = base.GetStringValue(source, RequestHeaderItemModel.HeaderValue) }; return requestHeaderSettings; } } }
Important
See Tip and Note from Implement Tenant Settings for more information about
templates.cs
.