private string ConvertValueToValidItemName(object value, ILogger logger, PipelineContext pipelineContext)
        {
            if (value == null)
            {
                return((string)null);
            }
            string str = value.ToString();
            SitecoreItemUtilities plugin = pipelineContext.GetPlugin <SitecoreItemUtilities>();

            if (plugin == null)
            {
                plugin = new SitecoreItemUtilities();
            }
            if (plugin.IsItemNameValid == null)
            {
                // this.Log(new Action<string>(logger.Error), pipelineContext, "No delegate is specified on the plugin that can determine whether or not the specified value is a valid item name. The original value will be used.", string.Format("plugin: {0}", (object)typeof(SitecoreItemUtilities).FullName), string.Format("delegate: {0}", (object)"IsItemNameValid"), string.Format("original value: {0}", (object)str));
                return(str);
            }
            if (plugin.IsItemNameValid(str))
            {
                return(str);
            }
            if (plugin.ProposeValidItemName != null)
            {
                return(plugin.ProposeValidItemName(str));
            }
            //logger.Error("No delegate is specified on the plugin that can propose a valid item name. The original value will be used. (plugin: {0}, delegate: {1}, original value: {2})", (object)typeof(SitecoreItemUtilities).FullName, (object)"ProposeValidItemName", (object)str);
            return(str);
        }
コード例 #2
0
        protected override void ReadData(
            Endpoint endpoint,
            PipelineStep pipelineStep,
            PipelineContext pipelineContext)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }
            if (pipelineStep == null)
            {
                throw new ArgumentNullException(nameof(pipelineStep));
            }
            if (pipelineContext == null)
            {
                throw new ArgumentNullException(nameof(pipelineContext));
            }
            var logger = pipelineContext.PipelineBatchContext.Logger;
            //
            //get the file path from the plugin on the endpoint
            var settings = endpoint.GetDropboxSettings();

            if (settings == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(settings.ApplicationName))
            {
                logger.Error(
                    "No application name is specified on the endpoint. " +
                    "(pipeline step: {0}, endpoint: {1})",
                    pipelineStep.Name, endpoint.Name);
                return;
            }

            if (string.IsNullOrWhiteSpace(settings.AccessToken))
            {
                logger.Error(
                    "No access token name is specified on the endpoint. " +
                    "(pipeline step: {0}, endpoint: {1})",
                    pipelineStep.Name, endpoint.Name);
                return;
            }

            if (string.IsNullOrWhiteSpace(settings.RootPath))
            {
                logger.Error(
                    "No root path is specified on the endpoint. " +
                    "(pipeline step: {0}, endpoint: {1})",
                    pipelineStep.Name, endpoint.Name);
                return;
            }

            var dropboxRepository = new DropBoxRepository();

            var dropboxFiles = dropboxRepository.ReadAll(settings);

            //
            //add the data that was read from the file to a plugin
            var dataSettings = new IterableDataSettings(dropboxFiles);

            logger.Info(
                "{0} rows were read from the file. (pipeline step: {1}, endpoint: {2})",
                dropboxFiles.Count(), pipelineStep.Name, endpoint.Name);


            SitecoreItemUtilities sitecoreItemUtility = new SitecoreItemUtilities()
            {
                IsItemNameValid      = (string x) => ItemUtil.IsItemNameValid(x),
                ProposeValidItemName = (string x) => ItemUtil.ProposeValidItemName(x)
            };

            Context.Plugins.Add(sitecoreItemUtility);

            //add the plugin to the pipeline context
            pipelineContext.Plugins.Add(dataSettings);
        }