Ejemplo n.º 1
0
        public async Task <UploadedDocumentResponse> AddFormatToDocument(
            AddFormatFromObjectToDocumentModel model,
            IDictionary <string, object> customData = null)
        {
            using (var sourceStream = new MemoryStream(Encoding.UTF8.GetBytes(model.StringContent)))
            {
                using (var client = new HttpClient())
                {
                    using (
                        var content =
                            new MultipartFormDataContent("Upload----" +
                                                         DateTime.Now.ToString(CultureInfo.InvariantCulture)))
                    {
                        content.Add(
                            new StreamContent(sourceStream),
                            "stream",
                            model.FileName
                            );

                        customData = customData ?? new Dictionary <String, Object>();
                        customData.Add(AddFormatToDocumentParameters.CreatedBy, model.CreatedById);
                        customData.Add(AddFormatToDocumentParameters.DocumentHandle, model.DocumentHandle);
                        customData.Add(AddFormatToDocumentParameters.JobId, model.JobId);
                        customData.Add(AddFormatToDocumentParameters.QueueName, model.QueueName);
                        customData.Add(AddFormatToDocumentParameters.Format, model.Format);

                        var stringContent = new StringContent(JsonConvert.SerializeObject(customData));
                        content.Add(stringContent, "custom-data");

                        var endPoint = new Uri(_documentStoreUri, Tenant + "/documents/addformat/" + model.Format);

                        using (var message = await client.PostAsync(endPoint, content).ConfigureAwait(false))
                        {
                            var json = await message.Content.ReadAsStringAsync().ConfigureAwait(false);

                            message.EnsureSuccessStatusCode();
                            return(JsonConvert.DeserializeObject <UploadedDocumentResponse>(json));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected async Task <Boolean> AddFormatToDocumentFromObject(string tenantId,
                                                                     String queueName,
                                                                     String jobId,
                                                                     Client.Model.DocumentFormat format,
                                                                     Object obj,
                                                                     String originalFileName,
                                                                     IDictionary <string, object> customData)
        {
            DocumentStoreServiceClient         client = GetDocumentStoreClient(tenantId);
            AddFormatFromObjectToDocumentModel model  = new AddFormatFromObjectToDocumentModel
            {
                CreatedById   = this.PipelineId,
                JobId         = jobId,
                QueueName     = queueName,
                Format        = format,
                FileName      = originalFileName,
                StringContent = JsonConvert.SerializeObject(obj),
            };
            var response = await client.AddFormatToDocument(model, customData).ConfigureAwait(false);

            return(response != null);
        }
Ejemplo n.º 3
0
        public async Task Can_add_new_format_with_api_from_object()
        {
            //Upload original
            var handle = new DocumentHandle("Add_Format_Test");
            await _documentStoreClient.UploadAsync(TestConfig.PathToOpenDocumentText, handle);

            // wait background projection polling
            await UpdateAndWaitAsync().ConfigureAwait(false);

            DocumentContent content = new DocumentContent(new DocumentContent.DocumentPage[]
            {
                new DocumentContent.DocumentPage(1, "TEST"),
            }, new DocumentContent.MetadataHeader[] { });
            //now add format to document.
            AddFormatFromObjectToDocumentModel model = new AddFormatFromObjectToDocumentModel();

            model.DocumentHandle = handle;
            model.StringContent  = JsonConvert.SerializeObject(content);
            model.CreatedById    = "tika";
            model.FileName       = "add_format_test.content";
            model.Format         = new DocumentFormat("content");
            await _documentStoreClient.AddFormatToDocument(model, new Dictionary <String, Object>());

            // wait background projection polling
            await UpdateAndWaitAsync().ConfigureAwait(false);

            var formats = await _documentStoreClient.GetFormatsAsync(handle);

            Assert.NotNull(formats);
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("original")));
            Assert.IsTrue(formats.HasFormat(new DocumentFormat("content")));
            Assert.That(formats, Has.Count.EqualTo(2));

            await CompareDownloadedStreamToStringContent(
                model.StringContent,
                _documentStoreClient.OpenRead(handle, new DocumentFormat("content")));
        }