Exemple #1
0
        public override PipelineProcessorResponseValue ProcessRequest()
        {
            var itemTitle = RequestContext.Argument;

            if (ItemUtil.IsItemNameValid(itemTitle))
            {
                var currentItem = RequestContext.Item;
                var currentBlog = ManagerFactory.BlogManagerInstance.GetCurrentBlog(currentItem);
                if (currentBlog != null)
                {
                    var template   = new TemplateID(currentBlog.BlogSettings.CategoryTemplateID);
                    var categories = ManagerFactory.CategoryManagerInstance.GetCategoryRoot(currentItem);
                    var newItem    = ItemManager.AddFromTemplate(itemTitle, template, categories);

                    return(new PipelineProcessorResponseValue
                    {
                        Value = newItem.ID.Guid
                    });
                }
            }
            return(new PipelineProcessorResponseValue
            {
                Value = null
            });
        }
Exemple #2
0
        public override PipelineProcessorResponseValue ProcessRequest()
        {
            var itemTitle = RequestContext.Argument;

            if (ItemUtil.IsItemNameValid(itemTitle ?? string.Empty))
            {
                var currentItem = RequestContext.Item;
                var currentBlog = _blogManager.GetCurrentBlog(currentItem);
                if (currentBlog != null)
                {
                    var templateId = GetTemplateId(currentBlog);
                    var parentItem = GetParentItem(currentBlog);

                    Item newItem = _itemManager.AddFromTemplate(itemTitle, templateId, parentItem);

                    return(new PipelineProcessorResponseValue
                    {
                        Value = new
                        {
                            itemId = newItem.ID.Guid
                        }
                    });
                }
            }
            return(new PipelineProcessorResponseValue
            {
                Value = null
            });
        }
        public override bool Filter(object element)
        {
            Item item = element as Item;

            if (item != null)
            {
                return(!ItemUtil.IsItemNameValid(item.Name));
            }
            return(true);
        }
Exemple #4
0
        public virtual IEnumerable <JsonInvalidItemName> GetInvalidItemNames(List <JsonSitecoreTemplate> templates)
        {
            // maps the item name (key) to the value (value) indicating whether or not it is valid (valid = true)
            var nameValidationCache = new Dictionary <string, bool>();

            // get the models for the item names from the templates template folders and template fields
            var models = templates
                         .SelectMany(
                template =>
                template.Path
                // split the path into item names
                .Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
                // reverse so that the template name is first
                .Reverse()
                // get the models for the template and template folder items
                .Select((name, i) => new JsonInvalidItemName()
            {
                ItemName     = name,
                ItemType     = i == 0 ? ItemType.Template : ItemType.TemplateFolder,
                TemplatePath = i == 0 ? template.Path : null
            })
                // add in the models for the template field items
                .Concat(
                    template.Fields
                    .Select(field => new JsonInvalidItemName()
            {
                ItemName     = field.Name,
                ItemType     = ItemType.TemplateField,
                TemplatePath = template.Path
            }))
                // add in the models for the template field section items
                .Concat(
                    template.Fields
                    .Where(field => !string.IsNullOrEmpty(field.SectionName))
                    .Select(field => new JsonInvalidItemName()
            {
                ItemName     = field.SectionName,
                ItemType     = ItemType.TemplateFieldSection,
                TemplatePath = template.Path
            })));

            // get the list of models with invalid item names
            var invalidItemNames = models
                                   .Where(
                model =>
            {
                // if the name has already been checked then return the cached result
                if (nameValidationCache.ContainsKey(model.ItemName))
                {
                    return(!nameValidationCache[model.ItemName]);
                }

                // check the names in the models with the InvalidItemNameChars setting
                var isValid = ItemUtil.IsItemNameValid(model.ItemName);

                // add the name and result to the cache and return true if the name is invalid
                nameValidationCache.Add(model.ItemName, isValid);
                return(!isValid);
            });

            return(invalidItemNames);
        }
        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);
        }
        protected virtual bool UpdateVariableValues(MultivariateTestVariableItem variableItem, out List <ID> modifiedVariations)
        {
            Assert.ArgumentNotNull(variableItem, "variableItem");
            modifiedVariations = new List <ID>();
            List <VariableValueItemStub> variableValues = VariableValues;
            var list2    = new List <MultivariateTestValueItem>(TestingUtil.MultiVariateTesting.GetVariableValues(variableItem));
            var comparer = new DefaultComparer();

            list2.Sort((lhs, rhs) => comparer.Compare(lhs, rhs));
            int num        = (list2.Count > 0) ? (list2[0].InnerItem.Appearance.Sortorder - 1) : Settings.DefaultSortOrder;
            var templateID = new TemplateID(MultivariateTestValueItem.TemplateID);
            var list3      = new List <KeyValuePair <MultivariateTestValueItem, VariableValueItemStub> >();
            var list4      = new List <KeyValuePair <int, VariableValueItemStub> >();

            for (int i = variableValues.Count - 1; i >= 0; i--)
            {
                VariableValueItemStub stub = variableValues[i];
                ID  currentId = stub.Id;
                int index     = list2.FindIndex(item => item.ID == currentId);
                if (index < 0)
                {
                    var pair = new KeyValuePair <int, VariableValueItemStub>(num--, stub);
                    list4.Add(pair);
                }
                else
                {
                    MultivariateTestValueItem item = list2[index];
                    if (IsVariableValueChanged(item, stub))
                    {
                        list3.Add(new KeyValuePair <MultivariateTestValueItem, VariableValueItemStub>(item, stub));
                    }
                    list2.RemoveAt(index);
                }
            }
            if (list2.Count != 0)
            {
            }

            foreach (Item item2 in list2)
            {
                modifiedVariations.Add(item2.ID);
                item2.Delete();
            }
            foreach (var pair2 in list4)
            {
                VariableValueItemStub variableStub = pair2.Value;
                int    key  = pair2.Key;
                string name = variableStub.Name;
                if (ContainsNonASCIISymbols(name))
                {
                    Item item3 = variableItem.Database.GetItem(templateID.ID);
                    name = (item3 != null) ? item3.Name : "Unnamed item";
                }
                if (!ItemUtil.IsItemNameValid(name))
                {
                    try
                    {
                        name = ItemUtil.ProposeValidItemName(name);
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
                name = ItemUtil.GetUniqueName(variableItem, name);
                Item item4 = variableItem.InnerItem.Add(name, templateID);
                Assert.IsNotNull(item4, "newVariableValue");
                UpdateVariableValueItem((MultivariateTestValueItem)item4, variableStub, key);
            }
            foreach (var pair3 in list3)
            {
                MultivariateTestValueItem variableValue = pair3.Key;
                VariableValueItemStub     stub3         = pair3.Value;
                modifiedVariations.Add(variableValue.ID);
                UpdateVariableValueItem(variableValue, stub3);
            }
            return(true);
        }