protected ApplicationSettings ConvertApplicationSettings(ItemModel source)
        {
            var applicationSettings = new ApplicationSettings
            {
                ItemId          = source.GetItemId(),
                BaseUrl         = base.GetStringValue(source, ApplicationItemModel.BaseUrl),
                RefreshToken    = base.GetStringValue(source, ApplicationItemModel.RefreshToken),
                AccessToken     = base.GetStringValue(source, ApplicationItemModel.AccessToken),
                AccessTokenDate = base.GetDateTimeValue(source, ApplicationItemModel.AccessTokenDate),
                ExpiresIn       = base.GetIntValue(source, ApplicationItemModel.ExpiresIn),
                RefreshPlugin   = () => this.RefreshPlugin(source.GetItemId())
            };

            var resource = this.ConvertReferenceToModel <ResourceSettings>(source, ApplicationItemModel.AuthenticationResource);

            if (resource != null)
            {
                applicationSettings.AuthenticationResource = resource;
            }

            if (string.IsNullOrWhiteSpace(applicationSettings.BaseUrl))
            {
                Context.Logger.Warn("No Base Url was specified in application settings. (item: {0}, field: {1})", source.GetItemId(), Templates.Application.FieldNames.BaseUrl);
            }

            if (string.IsNullOrWhiteSpace(applicationSettings.RefreshToken))
            {
                Context.Logger.Warn("No refresh token was specified in application settings. (item: {0}, field: {1})", source.GetItemId(), Templates.Application.FieldNames.RefreshToken);
            }

            if (applicationSettings.AuthenticationResource == null)
            {
                Context.Logger.Warn("No authentication resource was specified in application settings. (item: {0}, field: {1})", source.GetItemId(), Templates.Application.FieldNames.AuthenticationResource);
            }

            return(applicationSettings);
        }
Пример #2
0
        public void AddResourceSettings(ItemModel source, PipelineStep pipelineStep)
        {
            var resourceSettings = this.ConvertReferenceToModel <ResourceSettings>(source, BaseResourceEndpointPipelineStepItemModel.Resource);

            if (resourceSettings == null)
            {
                Context.Logger.Error("No resource was specified for the pipeline step. (item: {0}, field: {1})", source.GetItemId(), Templates.BaseResourceEndpointPipelineStep.FieldNames.Resource);
            }
            else
            {
                pipelineStep.Plugins.Add(resourceSettings);
            }
        }
Пример #3
0
        public void AddEndpointSettings(ItemModel source, PipelineStep pipelineStep)
        {
            var endpointSettings = new EndpointSettings();
            var model            = this.ConvertReferenceToModel <Endpoint>(source, BaseEndpointPipelineStepItemModel.EndpointFrom);

            if (model != null)
            {
                endpointSettings.EndpointFrom = model;
            }

            if (endpointSettings.EndpointFrom == null)
            {
                Context.Logger.Error("No endpoint from was specified for the pipeline step. (item: {0}, field: {1})", source.GetItemId(), Templates.BaseEndpointPipelineStep.FieldNames.EndpointFrom);
            }

            pipelineStep.Plugins.Add(endpointSettings);
        }
        protected override void AddPlugins(ItemModel source, Endpoint endpoint)
        {
            var applicationEndpointSettings = new ApplicationEndpointSettings();
            var model = this.ConvertReferenceToModel <ApplicationSettings>(source, ApplicationEndpointItemModel.Application);

            if (model != null)
            {
                applicationEndpointSettings.Application = model;
            }

            if (applicationEndpointSettings.Application == null)
            {
                Context.Logger.Error("No application was specified for the endpoint. (item: {0}, field: {1})", source.GetItemId(), Templates.RESTfulEndpoint.FieldNames.Application);
            }

            endpoint.Plugins.Add(applicationEndpointSettings);
        }
        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}");
            }
        }
        protected override ConvertResult <ResourceSettings> ConvertSupportedItem(ItemModel source)
        {
            var resourceSettings = new ResourceSettings
            {
                Url        = base.GetStringValue(source, ResourceItemModel.ResourceUrl),
                Method     = base.GetStringValue(source, ResourceItemModel.Method),
                Headers    = base.ConvertReferencesToModels <RequestHeaderSettings>(source, ResourceItemModel.Headers) ?? new List <RequestHeaderSettings>(),
                Parameters = base.ConvertReferencesToModels <RequestParameterSettings>(source, ResourceItemModel.Parameters) ?? new List <RequestParameterSettings>(),
                Paging     = base.ConvertReferenceToModel <PagingSettings>(source, ResourceItemModel.Paging)
            };

            if (resourceSettings.Url == null)
            {
                Context.Logger.Error("No Url was specified in resource settings. (item: {0}, field: {1})", source.GetItemId(), Templates.Resource.FieldNames.Url);
            }

            if (resourceSettings.Method == null)
            {
                Context.Logger.Error("No method was specified in resource settings. (item: {0}, field: {1})", source.GetItemId(), Templates.Resource.FieldNames.Method);
            }

            return(this.PositiveResult(resourceSettings));
        }
Пример #7
0
        public virtual ITroubleshooterResult Troubleshoot(
            TroubleshooterContext context)
        {
            if (context == null)
            {
                return(TroubleshooterResult.FailResult("The context object passed to the troubleshooter is null."));
            }

            ItemModel configuration = context.Configuration as ItemModel;

            if (configuration == null)
            {
                return(TroubleshooterResult.FailResult("The configuration object on the troubleshooter context is null or could not be converted into an item model."));
            }

            IConverter <ItemModel, PipelineStep> converter = configuration.GetConverter <PipelineStep>(context.ItemModelRepository);

            if (converter == null)
            {
                return(TroubleshooterResult.FailResult(string.Format("No pipeline step converter was resolved. Item id: {0}", configuration.GetItemId().ToString())));
            }

            ConvertResult <PipelineStep> convertResult = converter.Convert(configuration);

            if (!convertResult.WasConverted)
            {
                return(TroubleshooterResult.FailResult("The configuration object on the troubleshooter context could not be converted into a pipeline step."));
            }

            return(this.Troubleshoot(convertResult.ConvertedValue, context));
        }