ErrorResult() public static méthode

public static ErrorResult ( IEnumerable errors ) : ProcessResult
errors IEnumerable
Résultat ProcessResult
Exemple #1
0
        public ProcessResult FillContent(XElement content, IEnumerable <IContentItem> data)
        {
            var errors         = new List <string>();
            var processedItems = new List <string>();

            data = data.ToList();

            foreach (var contentItems in data.GroupBy(d => d.Name))
            {
                if (processedItems.Contains(contentItems.Key))
                {
                    continue;
                }

                var contentControls = FindContentControls(content, contentItems.Key).ToList();

                //Need to get error message from processor.
                if (!contentControls.Any())
                {
                    contentControls.Add(null);
                }

                foreach (var xElement in contentControls)
                {
                    if (contentItems.Any(item => item is TableContent) && xElement != null)
                    {
                        processedItems.AddRange(ProcessTableFields(data.OfType <FieldContent>(), xElement));
                    }


                    foreach (var processor in _processors)
                    {
                        var result = processor.FillContent(xElement, contentItems);
                        if (result.Handled && !result.Success)
                        {
                            errors.AddRange(result.Errors);
                        }
                    }
                }
                processedItems.Add(contentItems.Key);
            }

            return(errors.Any()
                                ? ProcessResult.ErrorResult(errors)
                                : ProcessResult.SuccessResult);
        }
        public ProcessResult FillContent(XElement content, IEnumerable <IContentItem> data)
        {
            var errors         = new List <string>();
            var processedItems = new List <string>();

            data = data.ToList();

            foreach (var contentItems in data.GroupBy(d => d.Name))
            {
                if (processedItems.Contains(contentItems.Key))
                {
                    continue;
                }

                var contentControls = FindContentControls(content, contentItems.Key).ToList();

                var removeContentItem = contentItems.OfType <RemoveContent>().FirstOrDefault();
                if (removeContentItem != null)
                {
                    foreach (var ctrl in contentControls.ToList())
                    {
                        if (ctrl.Parent == null ||
                            ctrl.Parent.Name.LocalName == "body" ||
                            removeContentItem.Options.DontRemoveParagraph
                            )
                        {
                            ctrl.Remove();
                        }
                        else
                        {
                            ctrl.Parent.Remove();
                        }

                        contentControls.Remove(ctrl);
                    }
                }

                //Need to get error message from processor.
                if (!contentControls.Any() &&
                    removeContentItem == null
                    )
                {
                    contentControls.Add(null);
                }

                foreach (var xElement in contentControls)
                {
                    if (contentItems.Any(item => item is TableContent) && xElement != null)
                    {
                        processedItems.AddRange(ProcessTableFields(data.OfType <FieldContent>(), xElement));
                    }


                    foreach (var processor in _processors)
                    {
                        var result = processor.FillContent(xElement, contentItems);
                        if (result.Handled && !result.Success)
                        {
                            errors.AddRange(result.Errors);
                        }
                    }
                }
                processedItems.Add(contentItems.Key);
            }

            return(errors.Any()
                                ? ProcessResult.ErrorResult(errors)
                                : ProcessResult.SuccessResult);
        }