private IEnumerable <Document> GetDocuments() { IEnumerable <Document> documents; if (_startsWith != null) { if (_isAllDocsCollection) { documents = _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, null, _start, _query.PageSize); } else { documents = _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, null, _start, _query.PageSize, _collection); } } else if (_ids != null) { if (_ids.Count == 0) { documents = Enumerable.Empty <Document>(); } else { documents = _isAllDocsCollection ? _documents.GetDocuments(_context, _ids, _start, _query.PageSize, _totalResults) : _documents.GetDocuments(_context, _ids, _collection, _start, _query.PageSize, _totalResults); } } else if (_isAllDocsCollection) { documents = _documents.GetDocumentsFrom(_context, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetNumberOfDocuments(_context); } else { documents = _documents.GetDocumentsFrom(_context, _collection, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetCollection(_collection, _context).Count; } return(documents); }
private IEnumerable <Document> GetDocuments() { IEnumerable <Document> documents; if (_ids != null && _ids.Count > 0) { documents = _documents.GetDocuments(_context, _ids, _start, _query.PageSize, _totalResults); } else if (_isAllDocsCollection) { documents = _documents.GetDocumentsFrom(_context, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetNumberOfDocuments(_context); } else { documents = _documents.GetDocumentsFrom(_context, _collection, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetCollection(_collection, _context).Count; } return(ApplySorting(documents)); }
private IEnumerable <Document> GetDocuments() { IEnumerable <Document> documents; if (_startsWith != null) { var countQuery = false; if (_query.PageSize == 0) { countQuery = true; _query.PageSize = int.MaxValue; } if (_isAllDocsCollection) { documents = _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, null, _start, _query.PageSize); } else { documents = _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, null, _start, _query.PageSize, _collection); } if (countQuery) { foreach (var document in documents) { using (document.Data) _totalResults.Value++; } documents = Enumerable.Empty <Document>(); _query.PageSize = 0; } } else if (_ids != null) { if (_ids.Count == 0) { documents = Enumerable.Empty <Document>(); } else { documents = _isAllDocsCollection ? _documents.GetDocuments(_context, _ids, _start, _query.PageSize, _totalResults) : _documents.GetDocuments(_context, _ids, _collection, _start, _query.PageSize, _totalResults); } } else if (_isAllDocsCollection) { documents = _documents.GetDocumentsFrom(_context, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetNumberOfDocuments(_context); } else { documents = _documents.GetDocumentsFrom(_context, _collection, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetCollection(_collection, _context).Count; } return(documents); }
private void ProcessDocuments() { if (_State != State.TemplateLoaded) { StatusStringChanged(this, new StatusStringChangedArgs("Can't process documents if template isn't loaded")); return; } _State = State.DocumentProcessing; StatusStringChanged(this, new StatusStringChangedArgs("Checking of output directories")); DirectoryInfo outputDirectory = new DirectoryInfo(appSettings.OutputDirectoryPath); if (!outputDirectory.Exists) { outputDirectory.Create(); } cardBuilder.SetOutputDirectory(outputDirectory.FullName); StatusStringChanged(this, new StatusStringChangedArgs("Documents are processing...")); procentProcessed = 0f; countOfDocumentProcessed = 0; var documents = ds.GetDocuments(); var documentNumber = documents.Count(); foreach (var document in documents) { string errorMessage; if (!string.IsNullOrEmpty(document.TextFileName)) { loggerManager.Add(new LogMessage(document, $"Копирование текстового файла")); fileManager.TryToCopyTextFile(document, out errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { loggerManager.Add(new ErrorMessage(document, errorMessage)); } } if (!string.IsNullOrEmpty(document.ScanFileName)) { loggerManager.Add(new LogMessage(document, $"Копирование скан файла")); fileManager.TryToCopyScanFile(document, out errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { loggerManager.Add(new ErrorMessage(document, errorMessage)); } } if (!string.IsNullOrEmpty(document.TextPdfFileName)) { loggerManager.Add(new LogMessage(document, $"Копирование текстового Pdf файла")); fileManager.TryToCopyTextPdfFile(document, out errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { loggerManager.Add(new ErrorMessage(document, errorMessage)); } } if (!string.IsNullOrEmpty(document.AttachmentsFilesNames)) { loggerManager.Add(new LogMessage(document, $"Копирование файлов вложений")); fileManager.TryToCopyAttachmentFiles(document, out errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { loggerManager.Add(new ErrorMessage(document, errorMessage)); } } loggerManager.Add(new LogMessage(document, $"Создание карточки документа")); cardBuilder.BuildCard(document.Identifier, document); if (document.CopiedScanFileInfo != null && document.CopiedScanFileInfo.Exists) { loggerManager.Add(new LogMessage(document, $"Создание дополнительной карточки документа")); cardBuilder.BuildAdditionalCard(document.Identifier, document); } if (document.CopiedAttachmentsFilesInfos != null && document.CopiedAttachmentsFilesInfos.Length > 0) { loggerManager.Add(new LogMessage(document, $"Создание карточек вложений")); for (int attachmentCount = 1; attachmentCount <= document.CopiedAttachmentsFilesInfos.Length; attachmentCount++) { loggerManager.Add(new LogMessage(document, $"Вложение{attachmentCount}")); cardBuilder.BuildAdditionalCardForAttachment($"Вложение{attachmentCount}", attachmentCount - 1, document); } } loggerManager.Add(new LogMessage(document, $"Обработка документа завершена")); countOfDocumentProcessed++; procentProcessed = countOfDocumentProcessed / (float)documentNumber; DocumentProcessed?.Invoke(document); } StatusStringChanged(this, new StatusStringChangedArgs($"Documents processing finished.")); _State = State.DocumentMoved; }
private IEnumerable <Document> GetDocuments() { IEnumerable <Document> documents; if (_startsWith != null) { var countQuery = false; if (_query.PageSize == 0) { countQuery = true; _query.PageSize = int.MaxValue; } documents = _isAllDocsCollection ? _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, _startAfterId, _start, _query.PageSize, fields: _fields) : _documents.GetDocumentsStartingWith(_context, _startsWith, null, null, _startAfterId, _start, _query.PageSize, _collection, _fields); if (countQuery) { foreach (var document in documents) { using (document.Data) _totalResults.Value++; } documents = Enumerable.Empty <Document>(); _query.PageSize = 0; } } else if (_ids != null) { if (_ids.Count == 0) { documents = Enumerable.Empty <Document>(); } else if (_alreadySeenIdsCount != null) { var idsLeft = _ids.Count - _alreadySeenIdsCount.Value; if (idsLeft == 0) { documents = Enumerable.Empty <Document>(); } else { var count = idsLeft >= _query.PageSize ? _query.PageSize : idsLeft; var ids = _ids.Skip((int)_alreadySeenIdsCount.Value).Take((int)count); _alreadySeenIdsCount.Value += count; documents = _isAllDocsCollection ? _documents.GetDocuments(_context, ids, 0, _query.PageSize, _totalResults) : _documents.GetDocuments(_context, ids, _collection, 0, _query.PageSize, _totalResults); } } else { documents = _isAllDocsCollection ? _documents.GetDocuments(_context, _ids, _start, _query.PageSize, _totalResults) : _documents.GetDocuments(_context, _ids, _collection, _start, _query.PageSize, _totalResults); } } else if (_isAllDocsCollection) { documents = _documents.GetDocumentsFrom(_context, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetNumberOfDocuments(_context); } else { documents = _documents.GetDocumentsFrom(_context, _collection, 0, _start, _query.PageSize); _totalResults.Value = (int)_documents.GetCollection(_collection, _context).Count; } return(documents); }