public async Task can_upload_document_with_name_greater_than_250_char() { var handle = DocumentHandle.FromString("Pdf_3"); String longFileName = Path.Combine( Path.GetTempPath(), "_lfn" + new string('X', 240) + ".pdf"); if (!File.Exists(longFileName)) { File.Copy(TestConfig.PathToDocumentPdf, longFileName); } await _documentStoreClient.UploadAsync(longFileName, handle); // wait background projection polling await UpdateAndWaitAsync().ConfigureAwait(false); // check readmodel var tenantAccessor = ContainerAccessor.Instance.Resolve <ITenantAccessor>(); var tenant = tenantAccessor.GetTenant(new TenantId(TestConfig.Tenant)); var docReader = tenant.Container.Resolve <IMongoDbReader <DocumentDescriptorReadModel, DocumentDescriptorId> >(); var allDocuments = docReader.AllUnsorted.Count(); Assert.AreEqual(1, allDocuments); }
protected async override Task <ProcessResult> OnPolling(PollerJobParameters parameters, string workingFolder) { string pathToFile = await DownloadBlob(parameters.TenantId, parameters.JobId, parameters.FileName, workingFolder).ConfigureAwait(false); String fileName = Path.Combine(Path.GetDirectoryName(pathToFile), parameters.All[JobKeys.FileName]); Logger.DebugFormat("Move blob id {0} to real filename {1}", pathToFile, fileName); if (File.Exists(fileName)) { File.Delete(fileName); } File.Copy(pathToFile, fileName); var converter = new HtmlToPdfConverterFromDiskFile(fileName, base.JobsHostConfiguration) { Logger = Logger }; var pdfConvertedFileName = converter.Run(parameters.TenantId, parameters.JobId); await AddFormatToDocumentFromFile( parameters.TenantId, parameters.JobId, new DocumentFormat(DocumentFormats.Pdf), pdfConvertedFileName, new Dictionary <string, object>()).ConfigureAwait(false); return(ProcessResult.Ok); }
public void Verify_sanitize_of_single_mhtml_file() { var tempFile = Path.ChangeExtension(Path.GetTempFileName(), ".mht"); File.Copy(TestConfig.PathToMht, tempFile); string mhtml = File.ReadAllText(tempFile); MHTMLParser parser = new MHTMLParser(mhtml) { OutputDirectory = Path.GetDirectoryName(tempFile), DecodeImageData = true }; var outFile = Path.ChangeExtension(tempFile, ".html"); File.WriteAllText(outFile, parser.getHTMLText()); _sanitizer = new SafeHtmlConverter(outFile) { Logger = NullLogger.Instance }; var result = _sanitizer.Run("jobtest"); Assert.That(File.Exists(result), "Output pdf file not created"); File.Delete(result); }
public void Verify_preview_of_single_html_file() { var tempFile = Path.ChangeExtension(Path.GetTempFileName(), ".html"); File.Copy(TestConfig.PathToSimpleHtmlFile, tempFile); _converter = new HtmlToPdfConverterFromDiskFileOld(tempFile, _config); _converter.Logger = NullLogger.Instance; var result = _converter.Run("jobtest"); Assert.That(File.Exists(result), "Output pdf file not created"); File.Delete(result); }
public void SetUp() { longFolderName = Path.Combine(Path.GetTempPath(), new String('a', 230)); _blobId = new BlobId(_originalFormat, 1); _pathToTask = Path.Combine(longFolderName, "File_1.dsimport"); _fileToImport = Path.Combine(longFolderName, "A Word Document.docx"); _fileUri = new Uri(Path.Combine(longFolderName, "A word document.docx")); ClearQueueTempFolder(); Directory.CreateDirectory(longFolderName); File.Copy(Path.Combine(TestConfig.DocumentsFolder, "Queue\\File_1.dsimport"), _pathToTask); File.Copy(TestConfig.PathToWordDocument, _fileToImport); var accessor = Substitute.For <ITenantAccessor>(); var tenant = Substitute.For <ITenant>(); tenant.Id.Returns(new TenantId("tests")); var container = Substitute.For <IWindsorContainer>(); _commandBus = Substitute.For <ICommandBus>(); var identityGenerator = Substitute.For <IIdentityGenerator>(); _blobstore = Substitute.For <IBlobStore>(); _blobstore.Upload(Arg.Is(_originalFormat), Arg.Any <string>()).Returns(_blobId); _blobstore.Upload(Arg.Is(_originalFormat), Arg.Any <FileNameWithExtension>(), Arg.Any <Stream>()).Returns(_blobId); accessor.GetTenant(_testTenant).Returns(tenant); accessor.Current.Returns(tenant); tenant.Container.Returns(container); container.Resolve <IBlobStore>().Returns(_blobstore); container.Resolve <IIdentityGenerator>().Returns(identityGenerator); container.Resolve <IMongoDatabase>().Returns(MongoDbTestConnectionProvider.ReadModelDb); var collection = MongoDbTestConnectionProvider.ReadModelDb.GetCollection <ImportFailure>("sys.importFailures"); collection.Drop(); DocumentStoreTestConfiguration config = new DocumentStoreTestConfiguration(tenantId: "tests"); config.SetFolderToMonitor(longFolderName); var sysDb = config.TenantSettings.Single(t => t.TenantId == "tests").Get <IMongoDatabase>("system.db"); sysDb.Drop(); _queue = new ImportFormatFromFileQueue(config, accessor, _commandBus) { Logger = new ConsoleLogger() }; _queue.DeleteTaskFileAfterImport = false; }
public void Verify_sanitize_of_single_html_file() { var tempFile = Path.ChangeExtension(Path.GetTempFileName(), ".html"); File.Copy(TestConfig.PathToSimpleHtmlFile, tempFile); _sanitizer = new SafeHtmlConverter(tempFile) { Logger = NullLogger.Instance }; var result = _sanitizer.Run("jobtest"); Assert.That(File.Exists(result), "HTML file sanitized"); File.Delete(result); }
public string Download(BlobId blobId, string folder) { if (blobId == null) { throw new ArgumentNullException(nameof(blobId)); } if (String.IsNullOrEmpty(folder)) { throw new ArgumentNullException(nameof(folder)); } if (!Directory.Exists(folder)) { throw new ArgumentException($"folder {folder} does not exists", nameof(folder)); } var descriptor = _mongodDbFileSystemBlobDescriptorStorage.FindOneById(blobId); if (descriptor == null) { throw new ArgumentException($"Descriptor for {blobId} not found in {_mongodDbFileSystemBlobDescriptorStorage.GetType().Name}"); } var localFileName = _directoryManager.GetFileNameFromBlobId(blobId, descriptor.FileNameWithExtension); if (!File.Exists(localFileName)) { Logger.Error($"Blob {blobId} has descriptor, but blob file {localFileName} not found in the system."); throw new ArgumentException($"Blob {blobId} not found"); } var originalFileName = descriptor.FileNameWithExtension.ToString(); string destinationFileName = Path.Combine(folder, originalFileName); Int32 uniqueId = 1; while (File.Exists(destinationFileName)) { destinationFileName = Path.Combine(folder, Path.GetFileNameWithoutExtension(originalFileName) + $" ({uniqueId++})") + Path.GetExtension(originalFileName); } File.Copy(localFileName, destinationFileName); if (Logger.IsDebugEnabled) { Logger.Debug($"Blob {blobId} downloaded in folder {folder} with name {destinationFileName}"); } return(destinationFileName); }