Exemple #1
0
        public async Task BurnMarkupAsync_fails_with_a_useful_error_message_when_the_markup_file_cannot_be_found()
        {
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            AffinitySession affinitySession        = Util.RestClient.CreateAffinitySession();
            RemoteWorkFile  existingSourceDocument = await affinitySession.UploadAsync("documents/confidential-contacts.pdf");

            RemoteWorkFile nonExistentMarkupFile = new RemoteWorkFile(affinitySession, "non-existent-id", existingSourceDocument.AffinityToken, "pdf");

            await UtilAssert.ThrowsExceptionWithMessageAsync <RestApiErrorException>(
                async() =>
            {
                await prizmDocServer.BurnMarkupAsync(existingSourceDocument, nonExistentMarkupFile);
            }, "Could not use the given RemoteWorkFile as the markup JSON file: the work file resource could not be found on the remote server. It may have expired.");
        }
        public async Task Will_reupload_an_existing_RemoteWorkFile_when_the_affinity_is_wrong()
        {
            AffinitySession session1 = Util.RestClient.CreateAffinitySession();
            AffinitySession session2 = Util.RestClient.CreateAffinitySession();

            RemoteWorkFile file1;

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("File 1")))
            {
                file1 = await session1.UploadAsync(stream);
            }

            RemoteWorkFile file2;

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("File 2")))
            {
                file2 = await session2.UploadAsync(stream);
            }

            Assert.AreNotEqual(file1.AffinityToken, file2.AffinityToken);

            var            source2 = new ConversionSourceDocument(file2);
            RemoteWorkFile originalRemoteWorkFile = source2.RemoteWorkFile;

            Assert.AreEqual(file2, originalRemoteWorkFile);

            // Ensure file2 is re-uploaded to the same machine as file1...
            await source2.EnsureUsableRemoteWorkFileAsync(Util.RestClient.CreateAffinitySession(), affinityToken : file1.AffinityToken);

            // Verify source RemoteWorkFile assignment was changed to something new
            Assert.AreNotEqual(source2.RemoteWorkFile, originalRemoteWorkFile);

            // Verify the affinity token of file1 and source2.RemoteWorkFile now match
            Assert.AreEqual(file1.AffinityToken, source2.RemoteWorkFile.AffinityToken);

            // Verify the contents of the file are still correct
            using (var stream = new MemoryStream())
            {
                await source2.RemoteWorkFile.CopyToAsync(stream);

                stream.Position = 0;
                using (var reader = new StreamReader(stream, Encoding.UTF8))
                {
                    string text = reader.ReadToEnd();
                    Assert.AreEqual("File 2", text);
                }
            }
        }
        /// <summary>
        /// Ensures the RemoteWorkFile property is assigned a RemoteWorkFile instance with the given affinityToken.
        /// </summary>
        /// <param name="affinitySession">Affinity session to use for uploading files.</param>
        /// <param name="affinityToken">Existing affinity token to use for each upload.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        internal async Task EnsureUsableRemoteWorkFileAsync(AffinitySession affinitySession, string affinityToken = null)
        {
            if (this.RemoteWorkFile == null)
            {
                if (!File.Exists(this.LocalFilePath))
                {
                    throw new FileNotFoundException($"File not found: \"{this.LocalFilePath}\"");
                }

                this.RemoteWorkFile = await affinitySession.UploadAsync(this.LocalFilePath, affinityToken : affinityToken);
            }
            else
            {
                this.RemoteWorkFile = await this.RemoteWorkFile.GetInstanceWithAffinity(affinitySession, affinityToken);
            }
        }
Exemple #4
0
        public async Task Can_use_RemoteWorkFile_for_document_and_local_file_path_for_markup_JSON()
        {
            // Arrange
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            AffinitySession affinitySession = Util.RestClient.CreateAffinitySession();
            RemoteWorkFile  document        = await affinitySession.UploadAsync("documents/confidential-contacts.pdf");

            // Act
            RemoteWorkFile result = await prizmDocServer.BurnMarkupAsync(document, "documents/confidential-contacts.pdf.markup.json");

            // Assert
            await result.SaveAsync("burned.pdf");

            await this.AssertRedactionOccurredFor(result);
        }
        public async Task Will_use_existing_RemoteWorkFile()
        {
            AffinitySession affinitySession = Util.RestClient.CreateAffinitySession();

            RemoteWorkFile remoteWorkFile;

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("Hello world!")))
            {
                remoteWorkFile = await affinitySession.UploadAsync(stream);
            }

            var input = new ConversionSourceDocument(remoteWorkFile);

            Assert.AreEqual(remoteWorkFile, input.RemoteWorkFile);
            await input.EnsureUsableRemoteWorkFileAsync(affinitySession);

            Assert.AreEqual(remoteWorkFile, input.RemoteWorkFile);
        }
Exemple #6
0
        /// <summary>
        /// Upload a local file, creating a new <see cref="RemoteWorkFile"/>.
        /// </summary>
        internal static async Task <RemoteWorkFile> UploadAsync(this AffinitySession affinitySession, string localFilePath, string affinityToken = null)
        {
            if (affinitySession is null)
            {
                throw new ArgumentNullException(nameof(affinitySession));
            }

            if (!File.Exists(localFilePath))
            {
                throw new FileNotFoundException($"File not found: \"{localFilePath}\"", "localFilePathToDocument");
            }

            string fileExtension = Path.GetExtension(localFilePath);

            using (FileStream localFileReadStream = File.OpenRead(localFilePath))
            {
                return(await affinitySession.UploadAsync(localFileReadStream, fileExtension, affinityToken));
            }
        }
Exemple #7
0
        public async Task Can_use_RemoteWorkFile_instances_with_different_affinity()
        {
            // Arrange
            PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient();

            AffinitySession session1 = Util.RestClient.CreateAffinitySession();
            AffinitySession session2 = Util.RestClient.CreateAffinitySession();

            RemoteWorkFile document = await session1.UploadAsync("documents/confidential-contacts.pdf");

            RemoteWorkFile markupJson = await session2.UploadAsync("documents/confidential-contacts.pdf.markup.json");

            Assert.AreNotEqual(document.AffinityToken, markupJson.AffinityToken);

            // Act
            RemoteWorkFile result = await prizmDocServer.RedactToPlainTextAsync(document, markupJson, "\n");

            // Assert
            await this.AssertPlainTextRedactionOccurredFor(result, "\n");
        }
Exemple #8
0
        /// <summary>
        /// Uploads a stream of bytes to PrizmDoc Server, creating a remote work file which can be used as input to document processing operations.
        /// </summary>
        /// <param name="stream">Stream of bytes for the file to upload.</param>
        /// <param name="fileExtension">File extension for the stream of bytes being uploaded. For plain text formats, this can influence how PrizmDoc Server will render the file.</param>
        /// <param name="affinityToken">Optional affinity token defining which remote PrizmDoc Server this file should be uploaded to. This is an advanced option that you do not need to use.</param>
        /// <returns>RemoteWorkFile instance which can be used as input to other document processing methods.</returns>
        public async Task <RemoteWorkFile> UploadAsync(Stream stream, string fileExtension = "txt", string affinityToken = null)
        {
            AffinitySession affinitySession = this.restClient.CreateAffinitySession();

            return(await affinitySession.UploadAsync(stream, fileExtension, affinityToken));
        }
Exemple #9
0
        /// <summary>
        /// Uploads a local file to PrizmDoc Server, creating a remote work file which can be used as input to document processing operations.
        /// </summary>
        /// <param name="localFilePath">Path to a local file to upload.</param>
        /// <param name="affinityToken">Optional affinity token defining which remote PrizmDoc Server this file should be uploaded to. This is an advanced option that you do not need to use.</param>
        /// <returns>RemoteWorkFile instance which can be used as input to other document processing methods.</returns>
        public async Task <RemoteWorkFile> UploadAsync(string localFilePath, string affinityToken = null)
        {
            AffinitySession affinitySession = this.restClient.CreateAffinitySession();

            return(await affinitySession.UploadAsync(localFilePath, affinityToken));
        }