protected async Task<Boolean> AddFormatToDocumentFromFile(
            string tenantId,
            String jobId,
            Client.Model.DocumentFormat format,
            string pathToFile,
            IDictionary<string, object> customData)
        {
            DocumentStoreServiceClient client = GetDocumentStoreClient(tenantId);
            AddFormatFromFileToDocumentModel model = new AddFormatFromFileToDocumentModel
            {
                CreatedById = this.PipelineId,
                JobId = jobId,
                QueueName = this.QueueName,
                Format = format,
                PathToFile = pathToFile
            };

            var response = await client.AddFormatToDocument(model, customData);
            return response != null;
        }
 public void upload_doc_then_add_format_to_doc()
 {
     _docs.UploadAsync(TestConfig.PathToWordDocument, DocumentHandle.FromString("doc_2")).Wait();
     AddFormatFromFileToDocumentModel model = new AddFormatFromFileToDocumentModel();
     model.CreatedById = "tika";
     model.DocumentHandle = DocumentHandle.FromString("doc_2");
     model.PathToFile = TestConfig.PathToTextDocument;
     model.Format = new DocumentFormat(DocumentFormats.Tika);
     _docs.AddFormatToDocument(model, null).Wait();
 }
        public async void removing_format_from_document()
        {
            //Upload original
            var handle = new DocumentHandle("Add_Format_Test");
            await _documentStoreClient.UploadAsync(TestConfig.PathToOpenDocumentText, handle);

            // wait background projection polling
            await UpdateAndWaitAsync();

            //now add format to document.
            AddFormatFromFileToDocumentModel model = new AddFormatFromFileToDocumentModel();
            model.DocumentHandle = handle;
            model.PathToFile = TestConfig.PathToTextDocument;
            model.CreatedById = "tika";
            model.Format = new DocumentFormat("tika");
            await _documentStoreClient.AddFormatToDocument(model, new Dictionary<String, Object>());

            // wait background projection polling
            await UpdateAndWaitAsync();

            //now get the blob for the format
            var descriptor = _documentDescriptorCollection.FindAll().Single();
            var blobId = descriptor.Formats
                .Where(f => f.Key == new DocumentFormat("tika"))
                .Single().Value.BlobId;

            //now delete format
            await _documentStoreClient.RemoveFormatFromDocument(handle, new DocumentFormat("tika"));

            await UpdateAndWaitAsync();

            var formats = await _documentStoreClient.GetFormatsAsync(handle);
            Assert.NotNull(formats);
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("original")));
            Assert.That(formats, Has.Count.EqualTo(1), "Tika format should be removed from the projection");

            //Uncomment the test if you want to verify that blob id is deleted from a projection
            //Assert.Throws<Exception>(() => _blobStore.GetDescriptor(blobId), "Blob Id for artifact is not deleted");
        }
        public async void adding_two_time_same_format_overwrite_older()
        {
            //Upload original
            var handle = new DocumentHandle("Add_Format_Test");
            await _documentStoreClient.UploadAsync(TestConfig.PathToOpenDocumentText, handle);

            // wait background projection polling
            await UpdateAndWaitAsync();

            //now add format to document.
            AddFormatFromFileToDocumentModel model = new AddFormatFromFileToDocumentModel();
            model.DocumentHandle = handle;
            model.PathToFile = TestConfig.PathToTextDocument;
            model.CreatedById = "tika";
            model.Format = new DocumentFormat("tika");
            await _documentStoreClient.AddFormatToDocument(model, new Dictionary<String, Object>());

            // wait background projection polling
            await UpdateAndWaitAsync();

            //get blobId of the original format
            var descriptor = _documentDescriptorCollection.FindAll().Single();
            var blobId = descriptor.Formats
                .Where(f => f.Key == new DocumentFormat("tika"))
                .Single().Value.BlobId;

            //now add same format with different content.
            model = new AddFormatFromFileToDocumentModel();
            model.DocumentHandle = handle;
            model.PathToFile = TestConfig.PathToHtml;
            model.CreatedById = "tika";
            model.Format = new DocumentFormat("tika");
            await _documentStoreClient.AddFormatToDocument(model, new Dictionary<String, Object>());

            // wait background projection polling
            await UpdateAndWaitAsync();
            var formats = await _documentStoreClient.GetFormatsAsync(handle);
            Assert.NotNull(formats);
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("original")));
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("tika")));
            Assert.That(formats, Has.Count.EqualTo(2));

            await CompareDownloadedStreamToFile(TestConfig.PathToHtml, _documentStoreClient.OpenRead(handle, new DocumentFormat("tika")));

            //verify old blob storage was deleted
            //Assert.Throws<Exception>(() => _blobStore.GetDescriptor(blobId), "Blob Id for artifact is not deleted");
        }
        public async void can_add_new_format_with_api_and_automatic_format_detection()
        {
            //Upload original
            var handle = new DocumentHandle("Add_Format_Test");
            await _documentStoreClient.UploadAsync(TestConfig.PathToOpenDocumentText, handle);

            // wait background projection polling
            await UpdateAndWaitAsync();

            //now add format to document.
            AddFormatFromFileToDocumentModel model = new AddFormatFromFileToDocumentModel();
            model.DocumentHandle = handle;
            model.PathToFile = TestConfig.PathToDocumentPdf;
            model.CreatedById = "office";
            model.Format = null; //NO FORMAT, I want document store to be able to detect format
            await _documentStoreClient.AddFormatToDocument(model, new Dictionary<String, Object>());

            // wait background projection polling
            await UpdateAndWaitAsync();
            var formats = await _documentStoreClient.GetFormatsAsync(handle);
            Assert.NotNull(formats);
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("original")));
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("pdf")));
            Assert.That(formats, Has.Count.EqualTo(2));
        }