// process all pages public void Process(List <LineDataOfPage> data) { // initializing. pageData = data; article = InitializeProcessingArticle(); tempArticle = ""; left = InitializeProcessingColumn(); right = InitializeProcessingColumn(); _logger.LogInformation($"======================= Script Running! ===================="); int pageNumber = 1; foreach (var pg in pageData) { _logger.LogInformation($"======================= Page {pageNumber} Processing ===================="); page = pg; ProcessPage(); pageNumber++; } left = ProcessColumn(left); right = ProcessColumn(right); }
// Add Extend Article. public ProcessingArticle AddArticleExtend(ProcessingArticle article) { if (article.ParentId == 0) { var parentArticle = _context.Article.FirstOrDefault(x => x.Name == article.Article); article.ParentId = parentArticle.Id; } var articleEntry = _context.Article.FirstOrDefault(x => x.Name == article.Extension && x.ParentId == article.ParentId); if (articleEntry == null) { articleEntry = new Article() { Name = article.Extension, ParentId = article.ParentId }; _context.Article.Add(articleEntry); _context.SaveChanges(); } article.Id = articleEntry.Id; return(article); }
//process current line; private void ProcessLine() { // ignoring all non-article lines if article was not set yet. if (string.IsNullOrEmpty(article.Article)) { return; } // check whether current line is for article extension or not. if (CheckExtendArticleLine()) { left = ProcessColumn(left); right = ProcessColumn(right); article.Extension = GetEntireLineText(); article = daService.AddArticleExtend(article); _logger.LogInformation($">>Extend Article Added. Extend Article : {article.Extension}, Parent Article : {article.Article}"); return; } // check whether this line is for first column or second column by line's X position. if (line.Box.X < 100) { left = LineDataProcess(left); } else { right = LineDataProcess(right); } }
// Add Article which having Modifiers public ProcessingArticle AddArticleWithModifiers(ProcessingArticle article) { var articleEntry = _context.Article.FirstOrDefault(x => x.Name == article.Article); if (articleEntry == null) { articleEntry = new Article { Name = article.Article }; _context.Article.Add(articleEntry); _context.SaveChanges(); } foreach (var item in article.Modifiers) { var modifierContentEntry = _context.ArticleModifierContent.FirstOrDefault(x => x.Value == item); if (modifierContentEntry == null) { modifierContentEntry = new ArticleModifierContent() { Value = item }; _context.ArticleModifierContent.Add(modifierContentEntry); _context.SaveChanges(); } var modifierEntry = _context.ArticleModifier.FirstOrDefault(x => x.ArticleModifierContentId == modifierContentEntry.Id && x.ArticleId == articleEntry.Id); if (modifierEntry == null) { modifierEntry = new ArticleModifier() { ArticleId = articleEntry.Id, ArticleModifierContentId = modifierContentEntry.Id }; _context.ArticleModifier.Add(modifierEntry); _context.SaveChanges(); } } article.Id = articleEntry.Id; return(article); }
private void ProcessArticle() { try { string art = tempArticle; article = InitializeProcessingArticle(); if (art.IndexOf('(') >= 0) // In case of there's some modifier or continued for article { string modifier = art.Substring(art.IndexOf('(') + 1, art.IndexOf(')') - art.IndexOf('(') - 1); article.Article = art.Substring(0, art.IndexOf('(') - 1); article.Article = article.Article.Trim(); if (modifier == Continue) { article.Id = daService.AddArticle(article.Article); _logger.LogInformation($">>Article Continuing. Article : {article.Article}"); return; } else { _logger.LogInformation($">>Article Added. Article : {article.Article}"); } foreach (var item in modifier.Split(',')) { article.Modifiers.Add(item.Trim()); _logger.LogInformation($">>Article Modifier Added. Modifier : {item.Trim()}, Article : {article.Article}"); } article = daService.AddArticleWithModifiers(article); } else { article.Article = art.Trim(); article.Id = daService.AddArticle(article.Article); _logger.LogInformation($">>Article Added. Article : {article.Article}"); } } catch (Exception ex) { _logger.LogError(ex.Message); } }