Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        private void AddExtensionArticle(ExtendedArticle article, Field fv, int classifierContentId, string[] fieldValues, Line line)
        {
            var extensionArticle = InitializeArticle(classifierContentId);

            ReadLineFields(extensionArticle, fieldValues, classifierContentId, line.Number, true);

            var content = _aggregatedContentsMap[classifierContentId];
            var field   = content.Fields.First(f => f.Aggregated);

            extensionArticle.FieldValues.Add(new FieldValue {
                Field = field
            });
            article.Extensions[fv] = extensionArticle;
            _articlesListFromCsv.ExtensionFields.Add(fv);
        }