private ExtendedArticleList GetArticles(ExtendedArticleList articlesList, bool onlyExisting) { ExtendedArticleList existingArticles; if (_importSettings.UniqueContentField == null) { var existingIds = GetExistingArticleIds(articlesList.GetBaseArticleIds()); existingArticles = articlesList.Filter(a => !onlyExisting ^ existingIds.Contains(a.Id)); } else { existingArticles = new ExtendedArticleList(articlesList); var existingIdsMap = GetExistingArticleIdsMap(_uniqueValuesList, _importSettings.UniqueContentField.Name); for (var i = 0; i < articlesList.Count; i++) { var article = articlesList[i]; var uniqueValue = _uniqueValuesList[i]; var articleExists = existingIdsMap.ContainsKey(uniqueValue); if (articleExists) { article.BaseArticle.Id = existingIdsMap[uniqueValue]; } if (!onlyExisting ^ articleExists) { existingArticles.Add(article); } } } return(existingArticles); }
private void ConvertCsvLinesToArticles() { foreach (var line in _csvLines) { if (string.IsNullOrEmpty(line.Value)) { continue; } var fieldValues = SplitToValues(_titleHeaders.Count, line.Value); var baseArticle = InitializeArticle(_contentId); if (int.TryParse(fieldValues.First(), out var articleId)) { baseArticle.Id = articleId; } ReadLineFields(baseArticle, fieldValues, _contentId, line.Number); var article = new ExtendedArticle(baseArticle); foreach (var fv in article.BaseArticle.FieldValues) { if (fv.Field.IsClassifier) { if (int.TryParse(fv.Value, out var classifierContentId)) { AddExtensionArticle(article, fv.Field, classifierContentId, fieldValues, line); } else { article.Extensions[fv.Field] = null; } } } if (!article.BaseArticle.FieldValues.Any() && _aggregatedContentsMap.Where(w => w.Key != article.BaseArticle.Id).Any()) { var classifierFields = _importSettings.FieldsList.Where(w => w.Value.IsClassifier).Select(s => s.Value); foreach (var classifier in classifierFields) { foreach (var classifierContentId in _aggregatedContentsMap.Where(w => w.Key != classifier.ContentId).Select(s => s.Key)) { if (_importSettings.FieldsList.Where(w => w.Key != "-1" && w.Value.ContentId == classifierContentId).Any()) { AddExtensionArticle(article, classifier, classifierContentId, fieldValues, line); } } } } _articlesListFromCsv.Add(article); } }