public IEnumerable <string> GetErrors(DocumentImportDTO item, IList <DocumentImportDTO> allItems)
 {
     if (string.IsNullOrWhiteSpace(item.DocumentType) || DocumentMetadataHelper.GetTypeByName(item.DocumentType) == null)
     {
         yield return("Document Type is not valid MrCMS type.");
     }
 }
Beispiel #2
0
 public IEnumerable <string> GetErrors(DocumentImportDTO item, IList <DocumentImportDTO> allItems)
 {
     if (!string.IsNullOrWhiteSpace(item.ParentUrl) && _documentService.GetDocumentByUrl <Webpage>(item.ParentUrl) == null && !allItems.Any(x => x.UrlSegment == item.ParentUrl))
     {
         yield return("The parent url specified is not present within the system.");
     }
 }
        public IEnumerable <string> GetErrors(DocumentImportDTO item, IList <DocumentImportDTO> allItems)
        {
            var value = Selector(item);

            if (!String.IsNullOrWhiteSpace(value))
            {
                if (value.Length > Length)
                {
                    yield return
                        (string.Format(
                             "{0} is too long - max length is {1} characters and your value is {2} characters in length.",
                             DisplayName, Length, value.Length));
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Parse and Import to DTOs
        /// </summary>
        /// <param name="spreadsheet"></param>
        /// <param name="parseErrors"></param>
        /// <returns></returns>
        public List <DocumentImportDTO> ValidateAndImportDocuments(ExcelPackage spreadsheet, ref Dictionary <string, List <string> > parseErrors)
        {
            List <DocumentImportDTO> items = new List <DocumentImportDTO>();

            if (spreadsheet != null && spreadsheet.Workbook != null)
            {
                ExcelWorksheet worksheet = spreadsheet.Workbook.Worksheets.SingleOrDefault(x => x.Name == "Items");
                if (worksheet == null)
                {
                    return(items);
                }
                int totalRows = worksheet.Dimension.End.Row;
                for (int rowId = 2; rowId <= totalRows; rowId++)
                {
                    //Prepare handle name for storing and grouping errors
                    string urlSegment = worksheet.GetValue <string>(rowId, 1);
                    string name       = worksheet.GetValue <string>(rowId, 4);
                    string handle     = urlSegment.HasValue() ? urlSegment : name;

                    if (string.IsNullOrWhiteSpace(handle) || items.Any(x => x.UrlSegment == urlSegment))
                    {
                        continue;
                    }

                    List <string> errors = parseErrors.ContainsKey(handle)
                        ? parseErrors[handle]
                        : new List <string>();

                    DocumentImportDTO item = GetDocumentImportDataTransferObject(worksheet, rowId, name, ref errors);
                    parseErrors[handle] = errors;

                    items.Add(item);
                }

                //Remove duplicate errors
                parseErrors = parseErrors.GroupBy(x => x.Value)
                              .Select(x => x.First())
                              .ToDictionary(pair => pair.Key, pair => pair.Value);
            }

            //Remove handles with no errors
            parseErrors = parseErrors.Where(x => x.Value.Any()).ToDictionary(pair => pair.Key, pair => pair.Value);

            return(items);
        }
        public void SetUrlHistory(DocumentImportDTO documentDto, Webpage webpage)
        {
            List <string> urlsToAdd =
                documentDto.UrlHistory.Where(
                    s =>
                    !webpage.Urls.Select(history => history.UrlSegment)
                    .Contains(s, StringComparer.InvariantCultureIgnoreCase)).ToList();
            List <UrlHistory> urlsToRemove =
                webpage.Urls.Where(
                    history =>
                    !documentDto.UrlHistory.Contains(history.UrlSegment, StringComparer.InvariantCultureIgnoreCase))
                .ToList();

            if (!urlsToAdd.Any() && !urlsToRemove.Any())
            {
                return;
            }
            UpdateUrlHistories(webpage, urlsToAdd, urlsToRemove);
        }
        public void SetTags(DocumentImportDTO documentDto, Webpage webpage)
        {
            List <string> tagsToAdd =
                documentDto.Tags.Where(
                    s => !webpage.Tags.Select(tag => tag.Name).Contains(s, StringComparer.InvariantCultureIgnoreCase))
                .ToList();
            List <Tag> tagsToRemove =
                webpage.Tags.Where(
                    tag => !documentDto.Tags.Contains(tag.Name, StringComparer.InvariantCultureIgnoreCase)).ToList();

            foreach (string item in tagsToAdd)
            {
                Tag  tag   = GetExistingTag(item);
                bool isNew = tag == null;
                if (isNew)
                {
                    tag = new Tag {
                        Name = item
                    };
                    _session.Transact(session => session.Save(tag));
                }
                if (!webpage.Tags.Contains(tag))
                {
                    webpage.Tags.Add(tag);
                }

                if (!tag.Documents.Contains(webpage))
                {
                    tag.Documents.Add(webpage);
                }
                _session.Transact(session => session.Update(tag));
            }

            foreach (Tag tag in tagsToRemove)
            {
                webpage.Tags.Remove(tag);
                tag.Documents.Remove(webpage);
                Tag closureTag = tag;
                _session.Transact(session => session.Update(closureTag));
            }
        }
        public IEnumerable <string> GetErrors(DocumentImportDTO item, IList <DocumentImportDTO> allItems)
        {
            if (item.UrlHistory.Count <= 0)
            {
                yield break;
            }

            Webpage document = _documentService.GetDocumentByUrl <Webpage>(item.UrlSegment);

            if (document == null)
            {
                yield break;
            }

            List <UrlHistoryInfo> urls = _urlHistoryService.GetAllOtherUrls(document).ToList();

            foreach (string url in item.UrlHistory.Where(url => urls.Any(x => x.UrlSegment == url)))
            {
                yield return("One of url history segments is already within the system and belongs to another document.");
            }
        }
Beispiel #8
0
        private DocumentImportDTO GetDocumentImportDataTransferObject(ExcelWorksheet worksheet, int rowId,
                                                                      string name, ref List <string> parseErrors)
        {
            DocumentImportDTO item = new DocumentImportDTO();

            item.ParentUrl = worksheet.GetValue <string>(rowId, 2);
            if (worksheet.GetValue <string>(rowId, 3).HasValue())
            {
                item.DocumentType = worksheet.GetValue <string>(rowId, 3);
                item.UrlSegment   = worksheet.GetValue <string>(rowId, 1).HasValue()
                    ? worksheet.GetValue <string>(rowId, 1)
                    : _webpageUrlService.Suggest(null,
                                                 new SuggestParams {
                    PageName = name, DocumentType = item.DocumentType
                });
            }
            else
            {
                parseErrors.Add("Document Type is required.");
            }
            if (worksheet.GetValue <string>(rowId, 4).HasValue())
            {
                item.Name = worksheet.GetValue <string>(rowId, 4);
            }
            else
            {
                parseErrors.Add("Document Name is required.");
            }
            item.BodyContent     = worksheet.GetValue <string>(rowId, 5);
            item.MetaTitle       = worksheet.GetValue <string>(rowId, 6);
            item.MetaDescription = worksheet.GetValue <string>(rowId, 7);
            item.MetaKeywords    = worksheet.GetValue <string>(rowId, 8);
            item.Tags            = GetTags(worksheet, rowId, parseErrors);
            if (worksheet.GetValue <string>(rowId, 10).HasValue())
            {
                if (!worksheet.GetValue <string>(rowId, 10).IsValidInput <bool>())
                {
                    parseErrors.Add("Reveal in Navigation is not a valid boolean value.");
                }
                else
                {
                    item.RevealInNavigation = worksheet.GetValue <bool>(rowId, 10);
                }
            }
            else
            {
                item.RevealInNavigation = false;
            }

            if (worksheet.GetValue <string>(rowId, 11).HasValue())
            {
                if (!worksheet.GetValue <string>(rowId, 11).IsValidInput <int>())
                {
                    parseErrors.Add("Display Order is not a valid number.");
                }
                else
                {
                    item.DisplayOrder = worksheet.GetValue <int>(rowId, 11);
                }
            }
            else
            {
                item.DisplayOrder = 0;
            }

            if (worksheet.GetValue <string>(rowId, 12).HasValue())
            {
                if (!worksheet.GetValue <string>(rowId, 12).IsValidInput <bool>())
                {
                    parseErrors.Add("Require SSL is not a valid boolean value.");
                }
                else
                {
                    item.RequireSSL = worksheet.GetValue <bool>(rowId, 12);
                }
            }
            else
            {
                item.RequireSSL = false;
            }


            if (worksheet.GetValue <string>(rowId, 13).HasValue())
            {
                if (!worksheet.GetValue <string>(rowId, 13).IsValidInputDateTime())
                {
                    parseErrors.Add("Publish Date is not a valid date.");
                }
                else
                {
                    item.PublishDate = worksheet.GetValue <DateTime>(rowId, 13);
                }
            }

            item.UrlHistory = GetUrlHistory(worksheet, rowId, parseErrors);
            return(item);
        }
Beispiel #9
0
        public void SetTags(DocumentImportDTO documentDto, Webpage webpage)
        {
            var tags = documentDto.Tags;

            _documentTagsUpdateService.SetTags(tags, webpage);
        }