public async Task <Results <FileData> > GetAsync(int projectId) { var results = new Results <FileData>(); var projectResults = await _getProjectForUserProcessor.GetAsync(projectId); if (projectResults.HasProblem) { results.Merge(projectResults); return(results); } var documentIds = projectResults.Data.ProjectReferences .Select(pr => pr.ReferenceId); var bibCitations = projectResults.Data.ProjectReferences .Select(async pr => await _documentSearchProcessor.GetBibTexCitationAsync(pr.ReferenceId)); // Actually get documents var bibFile = new StringBuilder(); foreach (var bibCitation in bibCitations) { bibFile.AppendLine(await bibCitation); } results.Data.Content = Encoding.UTF8.GetBytes(bibFile.ToString()); results.Data.Filename = "references.bib"; return(results); }
public async Task <Results <List <string> > > AddAsync(int projectId, IEnumerable <string> documentIds) { var documentIdList = documentIds.ToList(); var results = new Results <List <string> >(); try { var projectResults = await _getProjectForUserProcessor.GetAsync(projectId); if (results.HasProblem) { results.Merge(projectResults); return(results); } List <string> documentsToAdd = documentIdList.Except(projectResults.Data.ProjectReferences.Select(pr => pr.ReferenceId)).ToList(); projectResults.Data.ProjectReferences.AddRange(documentsToAdd.Select(d => new ProjectReference { ReferenceId = d })); await _projectContext.SaveChangesAsync(); foreach (var d in documentsToAdd) { _queueManager.QueueArticleScrape(d, _scrapeDepth); } results.Data = documentsToAdd; } catch (System.Exception e) { results.AddException(new System.Exception("Failed to add this reference", e)); } return(results); }
public async Task <Results <ExportData> > GetAsync(int projectId) { var results = new Results <ExportData>(); var projectResults = await _getProjectForUserProcessor.GetAsync(projectId); if (projectResults.HasProblem) { results.Merge(projectResults); return(results); } foreach (var reference in projectResults.Data.ProjectReferences) { results.Data.RichTextCitations.Add(await _documentSearchProcessor.GetPlainTextCitationAsync(reference.ReferenceId)); } return(results); }
public async Task <Results <SearchVm> > LoadAsync(int projectId) { var results = new Results <SearchVm> { Data = { ProjectId = projectId } }; var projectResults = await _getProjectForUserProcessor.GetAsync(projectId); if (projectResults.HasProblem) { results.Merge(projectResults); return(results); } // Add loaded references, then pending var loadedDocuments = await _getDocumentProcessor.GetDocumentsAsync(projectResults.Data.ProjectReferences .Where(pr => pr.IsPending == false) .Select(pr => pr.ReferenceId)); results.Data.References.AddRange(loadedDocuments.Select(d => new ReferenceVm { Id = d.Id, Title = d.Title, IsPending = false, Abstract = d.Abstract })); results.Data.References.AddRange(projectResults.Data.ProjectReferences .Where(pr => pr.IsPending == true) .Select(pr => new ReferenceVm { Id = pr.ReferenceId, IsPending = true })); // Sort options results.Data.DefaultSortOption = SearchSortType.PageRank; foreach (SearchSortType sortType in Enum.GetValues(typeof(SearchSortType))) { results.Data.SortOptions.Add(new DropdownOption <SearchSortType> { Text = sortType.GetDescription(), Value = sortType }); } // Search Depth results.Data.DefaultSearchDepth = SearchDepth.Medium; foreach (SearchDepth searchDepth in Enum.GetValues(typeof(SearchDepth))) { results.Data.SearchDepths.Add(new DropdownOption <SearchDepth> { Text = searchDepth.GetDescription(), Value = searchDepth, HelpText = searchDepth.GetHelpText() }); } return(results); }