private void AddUpdateSitecoreItemSettings(ItemModel source, PipelineStep pipelineStep)
        {
            var settings     = new UpdateSitecoreItemSettings();
            var endpointFrom = base.ConvertReferenceToModel <Endpoint>(source, UpdateSitecoreItemWithLanguageVersionStepItemModel.EndpointFrom);

            if (endpointFrom != null)
            {
                settings.EndpointFrom = endpointFrom;
            }

            settings.LanguageField =
                base.GetStringValue(source, UpdateSitecoreItemWithLanguageVersionStepItemModel.LanguageField);

            pipelineStep.Plugins.Add(settings);
        }
        private IItemModelRepository GetItemModelRepository(PipelineStep pipelineStep, PipelineContext pipelineContext)
        {
            UpdateSitecoreItemSettings settings = pipelineStep.GetPlugin <UpdateSitecoreItemSettings>();

            if (settings == null)
            {
                return(null);
            }
            Endpoint endpointTo = settings.EndpointFrom;

            if (endpointTo == null)
            {
                return(null);
            }
            ItemModelRepositorySettings repositorySettings = endpointTo.GetItemModelRepositorySettings();

            if (repositorySettings == null)
            {
                return(null);
            }

            return(repositorySettings.ItemModelRepository);
        }
        protected override void ReadData(
            Endpoint endpoint,
            PipelineStep pipelineStep,
            PipelineContext pipelineContext)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }
            if (pipelineStep == null)
            {
                throw new ArgumentNullException("pipeline");
            }
            if (pipelineContext == null)
            {
                throw new ArgumentNullException("pipelineContext");
            }
            var logger = pipelineContext.PipelineBatchContext.Logger;

            UpdateSitecoreItemSettings settings = pipelineStep.GetPlugin <UpdateSitecoreItemSettings>();

            if (settings == null || settings.LanguageField == string.Empty)
            {
                logger.Error("Language Field is not set");
                throw new ArgumentException("Language Field");
            }
            var langField = settings.LanguageField;

            var itemModelRepository = this.GetItemModelRepository(pipelineStep, pipelineContext);

            if (itemModelRepository == null)
            {
                logger.Error("Item Model Repository is null");
                return;
            }

            //assume language is in source, and not necessarily mapped to target.
            ItemModel sourceAsItemModel = this.GetSourceObjectAsItemModel(pipelineStep, pipelineContext);

            if (sourceAsItemModel == null)
            {
                logger.Error("Cannot read Source Objec to determine language");
                return;
            }

            var language = sourceAsItemModel[langField].ToString();

            ItemModel objectAsItemModel = this.GetTargetObjectAsItemModel(pipelineStep, pipelineContext);

            if (objectAsItemModel == null)
            {
                logger.Error("Target Item Is not an Item Model.");
                return;
            }


            this.FixItemModel(objectAsItemModel);

            //possible enhancement, wire up Version as well (figure out how to determine latest version of item

            if (itemModelRepository.Update(objectAsItemModel.GetItemId(), objectAsItemModel, language.Trim()))
            {
                logger.Info($"UpdateSitecoreItemWithLanguageVersionStepProcessor: item update succeeded for Id:{objectAsItemModel.GetItemId()}, Language:{language}");
            }
            else
            {
                logger.Error($"UpdateSitecoreItemWithLanguageVersionStepProcessor: item update failed for Id:{objectAsItemModel.GetItemId()}, Language:{language}");
            }
        }