public static IDocumentIndex Map(this DocumentIndexDto source) { if (source == null) { return null; } return new DocumentIndex(source.DocumentID.ToString()) .Set(Common.DocumentIndex.FieldNames.DocumentCode, source.DocumentCode, DocumentIndexOptions.Store) .Set(Common.DocumentIndex.FieldNames.DocumentDirectoryCode, source.DocumentDirectoryCode, DocumentIndexOptions.Store) .Set(Common.DocumentIndex.FieldNames.Content, source.Content ?? string.Empty, DocumentIndexOptions.Analyze | DocumentIndexOptions.Store) .Set(Common.DocumentIndex.FieldNames.FileName, source.FileName, DocumentIndexOptions.Store); }
public void Should_Success_Instantiate() { var document = new List <ProductSKUInventoryDocumentModel>() { new ProductSKUInventoryDocumentModel() }; DocumentIndexDto dto = new DocumentIndexDto(document, 1, 1, 25); Assert.Equal(document, dto.data); Assert.Equal(1, dto.page); Assert.Equal(1, dto.size); Assert.Equal(25, dto.total); }
private void ShowDocument(int index) { if (SearchResult == null) { return; } if (_current != null && _current.DocumentID == SearchResult.Documents[index].DocumentID) { return; } _current = SearchResult.Documents[index]; ShowDocumentInDocumentViewer(); informationLabel.Text = string.Format(Strings.SearchResultForm_InformationLabel, index + 1, SearchResult.Documents.Length); documentPathLabel.Text = string.Format(Strings.SearchResultForm_DocumentPathLabel, _current.FileName); }
private DocumentIndexDto CreateDocumentIndex(string projectId, string branchName, ProjectDto project, BaseDocumentDto document, string documentContent) { string indexed = ClearContent(documentContent); string title = ClearTitle(document.Uri); var documentIndexDto = new DocumentIndexDto { Content = indexed, BranchName = branchName, ProjectName = project.Name, ProjectId = projectId, Title = title, Url = document.Uri, Id = ToAlphanumeric(document.Uri), Tags = project.Tags.ToArray() }; return(documentIndexDto); }
public async Task UploadDocumentIndex(string projectId, string branchName, DocumentIndexDto documentIndex) { var gatewayAddress = await _discoveryService.GetGatewayAddress(); var uploadIndexAddress = $"{gatewayAddress}/search/projects/{projectId}/branches/{branchName}"; var client = GetClient(); var documentsList = new List <DocumentIndexDto>(); documentsList.Add(documentIndex); var stringContent = JsonConvert.SerializeObject(documentsList); HttpContent content = new StringContent(stringContent, Encoding.UTF8, "application/json"); HttpResponseMessage httpResponseMessage = await client.PostAsync(uploadIndexAddress, content); if (!httpResponseMessage.IsSuccessStatusCode) { var message = await httpResponseMessage.Content.ReadAsStringAsync(); throw new UploadDocumentToIndexException($"Document wasn't successfully uploaded. Status code: {httpResponseMessage.StatusCode}. Response message: '{message}'."); } }
#pragma warning disable CSE0003 // Use expression-bodied members public Task HandleAsync(IndexDocumentDirectoryCommand command, CancellationToken cancellationToken = default(CancellationToken), IProgress <ProgressInfo> progress = null) { return(Task.Run(() => { var documentDirectory = _database.ExecuteReaderSingle(SQLs.GetDocumentDirectory, DocumentDirectory.Map, parameters: new[] { Parameter.CreateInputParameter(Common.DatabaseSchema.DocumentDirectories.DocumentDirectoryID, command.DocumentDirectoryID, DbType.Int32) }); var documentCount = (long)_database.ExecuteScalar(SQLs.GetDocumentCountByDocumentDirectory, parameters: new[] { Parameter.CreateInputParameter(Common.DatabaseSchema.Documents.DocumentDirectoryID, command.DocumentDirectoryID, DbType.Int32), Parameter.CreateInputParameter(Common.DatabaseSchema.Documents.Index, 0 /* false */, DbType.Int32) }); var actualStep = 0; var totalSteps = Convert.ToInt32(documentCount); try { progress.Start(totalSteps, Strings.IndexDocumentDirectory_Progress_Start_Title); if (totalSteps == 0) { progress.Complete(actualStep, totalSteps); return; } // Gets the Lucene Index var index = _indexProvider.GetOrCreate(documentDirectory.Code); var documentIndexList = new List <IDocumentIndex>(); var pageCount = Convert.ToInt32(documentCount / command.BatchSize); if (documentCount % command.BatchSize != 0) { pageCount++; } for (var page = 0; page < pageCount; page++) { var documents = _database.ExecuteReader(SQLs.PaginateDocumentsByDocumentDirectory, Document.Map, parameters: new[] { Parameter.CreateInputParameter(Common.DatabaseSchema.DocumentDirectories.DocumentDirectoryID, command.DocumentDirectoryID, DbType.Int32), Parameter.CreateInputParameter(Common.DatabaseSchema.Documents.Index, 0 /* false */, DbType.Int32), Parameter.CreateInputParameter("limit", command.BatchSize, DbType.Int32) }).ToArray(); foreach (var document in documents) { progress.PerformStep(++actualStep, totalSteps, Strings.IndexDocumentDirectory_Progress_Step_Message, document.FileName); if (cancellationToken.IsCancellationRequested) { progress.Cancel(actualStep, totalSteps); cancellationToken.ThrowIfCancellationRequested(); } var documentIndexDto = new DocumentIndexDto { DocumentID = document.DocumentID, DocumentCode = document.Code, DocumentDirectoryCode = documentDirectory.Code, Content = document.Content, FileName = document.FileName }; documentIndexList.Add(documentIndexDto.Map()); } index.StoreDocuments(documentIndexList.ToArray()); documentIndexList.Clear(); MarkAsIndex(documents); } progress.Complete(actualStep, totalSteps); } catch (Exception ex) { progress.Error(actualStep, totalSteps, ex.Message); throw; } }, cancellationToken)); }