Exemplo n.º 1
0
        public static bool Display(MongoJsonEditorViewModel viewModel, FunctionDesigner context)
        {
            MongoJsonEditor editor = new MongoJsonEditor(viewModel, context);

            editor.Owner = Application.Current.MainWindow;
            return(editor.ShowDialog() ?? false);
        }
Exemplo n.º 2
0
        public void ValidateSplitOutputStructure()
        {
            var tester = new FunctionTester <PdfOperationsProvider>();
            FunctionDesigner designer = tester.CreateDesigner();

            Assert.IsNull(designer.Output);

            Property operation = designer.Properties[PropertyNames.Operation];

            operation.Value = Operation.Split;

            Property loopResults = designer.Properties[PropertyNames.SplitLoopResults];

            loopResults.Value = false;

            Assert.AreEqual(0, designer.ExecutionPaths.Count);

            IEnumerable <ITypeProperty> properties = designer.Output.GetProperties();

            Assert.AreEqual(2, properties.Count());
            properties.ElementAt(0).AssertList(OutputNames.PageFiles, typeof(string));
            properties.ElementAt(1).AssertCompiled(OutputNames.NumberOfPages, typeof(int));

            loopResults.Value = true;

            Assert.AreEqual(1, designer.ExecutionPaths.Count);
            ExecutionPath executionPath = designer.ExecutionPaths[0];

            Assert.AreEqual(ExecutionPathNames.PageFiles, executionPath.Name);
            Assert.AreEqual(TypeReference.Create(typeof(string)), executionPath.Output);

            properties = designer.Output.GetProperties();
            Assert.AreEqual(1, properties.Count());
            properties.ElementAt(0).AssertCompiled(OutputNames.NumberOfPages, typeof(int));
        }
Exemplo n.º 3
0
        public void ProtectWithScreenReaderRestrictions(
            [Values(
                 FileAuthentication.Password /*,
                                              * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file
                                              * FileAuthentication.CertificateFile,
                                              * FileAuthentication.CertificateStore*/)] FileAuthentication protectAuth,
            [Values(
                 true,
                 false)] bool allowScreenReaders)
        {
            string inputFilePath  = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ChangeProtection.Resources.Protect.pdf", this.inputDirectory);
            string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <ChangeProtectionProvider>();

            ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
            ConfigureProtectFunctionValues(designer, protectAuth, Encryption.AES256, true, true, allowScreenReaders: allowScreenReaders);
            designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath;

            var tester = new FunctionTester <ChangeProtectionProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            PdfComparer.AssertProtection(outputFilePath, protectAuth, this.authenticationManager, true, true,
                                         expectedAllowScreenReaders: allowScreenReaders);

            if (protectAuth == FileAuthentication.Password)
            {
                using (var permissionsAuthHelper = new AuthenticationManager(permissionsPassword))
                {
                    PdfComparer.AssertProtectionAllRights(outputFilePath, FileAuthentication.Password, permissionsAuthHelper, true, true);
                }
            }
        }
Exemplo n.º 4
0
        private void ConfigureSignCertificateProperties(FunctionDesigner designer, FileAuthentication signAuth, bool lockDocument)
        {
            designer.Properties[PropertyNames.Operation].Value = Operation.Sign;

            switch (signAuth)
            {
            case FileAuthentication.CertificateFile:
                designer.Properties[PropertyNames.SignCertificateSource].Value       = CertificateSource.File;
                designer.Properties[PropertyNames.SignCertificateFilePath].Value     = this.authenticationManager.CertificateFilePath;
                designer.Properties[PropertyNames.SignCertificateFilePassword].Value = this.authenticationManager.CertificateFilePassword;
                break;

            case FileAuthentication.CertificateStore:
                designer.Properties[PropertyNames.SignCertificateSource].Value = CertificateSource.Store;
                designer.Properties[PropertyNames.SignCertificate].Value       = this.authenticationManager.StoredCertificate;
                break;

            default:
                throw new NotSupportedException();
            }

            designer.Properties[PropertyNames.SignSignedAt].Value         = signLocation;
            designer.Properties[PropertyNames.SignReason].Value           = signReason;
            designer.Properties[PropertyNames.SignLockAfterSigning].Value = lockDocument;
        }
        public void Concatenate()
        {
            string inputFilePath1 = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.Concatenate1.pdf", this.inputDirectory);

            PdfComparer.AssertPageCount(inputFilePath1, FileAuthentication.None, this.authenticationManager, 1);
            PdfComparer.AssertText(inputFilePath1, FileAuthentication.None, this.authenticationManager, "1", "function Script1()\r\n{}\n");
            string inputFilePath2 = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.Concatenate2.pdf", this.inputDirectory);

            PdfComparer.AssertPageCount(inputFilePath2, FileAuthentication.None, this.authenticationManager, 1);
            PdfComparer.AssertText(inputFilePath2, FileAuthentication.None, this.authenticationManager, "2", "function Script2()\r\n{}\n");
            string outputFilePath = Path.Combine(this.outputDirectory, "Concat.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <PdfOperationsProvider>();

            designer.Properties[PropertyNames.Operation].Value  = Operation.Concatenate;
            designer.Properties[PropertyNames.InputFiles].Value = new List <string> {
                inputFilePath1, inputFilePath2
            };
            designer.Properties[PropertyNames.InputAuthenticationType].Value = AuthenticationType.None;
            designer.Properties[PropertyNames.OutputFilePath].Value          = outputFilePath;

            var tester = new FunctionTester <PdfOperationsProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            Assert.IsTrue(File.Exists(outputFilePath));
            PdfComparer.AssertPageCount(outputFilePath, FileAuthentication.None, this.authenticationManager, 2);
            PdfComparer.AssertText(outputFilePath, FileAuthentication.None, this.authenticationManager, $"1{Environment.NewLine}2", "function Script1()\r\n{}\n\nfunction Script2()\r\n{}\n\n");
        }
Exemplo n.º 6
0
		public void ReadXfaFormDataWithListOutput()
		{
			string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormDataXFA.pdf", this.inputDirectory);
			FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>();
			ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
			designer.Properties[PropertyNames.ReadFormData].Value = true;
			designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.List;

			var tester = new FunctionTester<ReadProvider>();
			FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters());

			List<KeyValuePair<string, string>> dataList = result.Value.FormDataList;
			Assert.AreEqual(5, dataList.Count);
			KeyValuePair<string, string> item = dataList[0];
			Assert.AreEqual("form1[0].FullName[0]", item.Key);
			Assert.AreEqual("John", item.Value);
			item = dataList[1];
			Assert.AreEqual("form1[0].Surname[0]", item.Key);
			Assert.AreEqual("Doe", item.Value);
			item = dataList[2];
			Assert.AreEqual("form1[0].EmailMe[0]", item.Key);
			Assert.AreEqual("1", item.Value);
			item = dataList[3];
			Assert.AreEqual("form1[0].Email[0]", item.Key);
			Assert.AreEqual("*****@*****.**", item.Value);
			item = dataList[4];
			Assert.AreEqual("form1[0]", item.Key);
			Assert.AreEqual("*****@*****.**", item.Value);
		}
        public void ReadText(
            [Values(
                 TextSplit.Never,
                 TextSplit.Page)] TextSplit splitText)
        {
            string           inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ReadPdf.Resources.Text.pdf", this.inputDirectory);
            FunctionDesigner designer      = ProviderHelpers.CreateDesigner <ReadPdfProvider>();

            ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
            designer.Properties[PropertyNames.ReadText].Value  = true;
            designer.Properties[PropertyNames.SplitText].Value = splitText;

            var            tester = new FunctionTester <ReadPdfProvider>();
            FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters());

            switch (splitText)
            {
            case TextSplit.Never:
                Assert.AreEqual("Text on page 1\nFooter text on page 1\r\nText on page 2\r\nText on page 3", result.Value.Text);
                break;

            case TextSplit.Page:
                Assert.AreEqual(new List <string> {
                    "Text on page 1\nFooter text on page 1", "Text on page 2", "Text on page 3"
                }, result.Value.Text);
                break;
            }
        }
Exemplo n.º 8
0
		public void ReadAcroFormDataWithCustomTypeOutput()
		{
			string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormData.pdf", this.inputDirectory);
			FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>();
			ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
			designer.Properties[PropertyNames.ReadFormData].Value = true;

			ITypeReference dataType = TypeReference.CreateGeneratedType(
				new TypeProperty("First_32Name", typeof(string)),
				new TypeProperty("Surname", typeof(string)),
				new TypeProperty("Gender", typeof(string)),
				new TypeProperty("AcceptTCs", typeof(string)));

			designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.CustomType;
			designer.Properties[PropertyNames.FormDataType].Value = dataType;

			var tester = new FunctionTester<ReadProvider>();
			tester.CustomTypes.Add(dataType);
			FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters());

			Assert.AreEqual("Jeremy", result.Value.FormData.First_32Name);
			Assert.AreEqual("Woods", result.Value.FormData.Surname);
			Assert.AreEqual("Male", result.Value.FormData.Gender);
			Assert.AreEqual("Yes", result.Value.FormData.AcceptTCs);
		}
Exemplo n.º 9
0
		public void ReadXfaFormDataWithCustomTypeOutput()
		{
			string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormDataXFA.pdf", this.inputDirectory);
			FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>();
			ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
			designer.Properties[PropertyNames.ReadFormData].Value = true;

			ITypeReference dataType = TypeReference.CreateGeneratedType(
				new TypeProperty("form1_910_93_46FullName_910_93", typeof(string)),
				new TypeProperty("form1_910_93_46Surname_910_93", typeof(string)),
				new TypeProperty("form1_910_93_46Email_910_93", typeof(string)),
				new TypeProperty("form1_910_93_46EmailMe_910_93", typeof(string)));

			designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.CustomType;
			designer.Properties[PropertyNames.FormDataType].Value = dataType;

			var tester = new FunctionTester<ReadProvider>();
			tester.CustomTypes.Add(dataType);
			FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters());

			Assert.AreEqual("John", result.Value.FormData.form1_910_93_46FullName_910_93);
			Assert.AreEqual("Doe", result.Value.FormData.form1_910_93_46Surname_910_93);
			Assert.AreEqual("*****@*****.**", result.Value.FormData.form1_910_93_46Email_910_93);
			Assert.AreEqual("1", result.Value.FormData.form1_910_93_46EmailMe_910_93);
		}
Exemplo n.º 10
0
        public void ValidateReadTextOutputStructure()
        {
            var tester = new FunctionTester <ReadPdfProvider>();
            FunctionDesigner designer = tester.CreateDesigner();

            Assert.IsNull(designer.Output);

            Property readText = designer.Properties[PropertyNames.ReadText];

            Assert.IsFalse(readText.GetValue <bool>());
            readText.Value = true;

            Property splitText = designer.Properties[PropertyNames.SplitText];

            splitText.Value = TextSplit.Never;
            IEnumerable <ITypeProperty> properties = designer.Output.GetProperties();

            Assert.AreEqual(1, properties.Count());
            properties.ElementAt(0).AssertCompiled(OutputNames.Text, typeof(string));

            splitText.Value = TextSplit.Page;
            properties      = designer.Output.GetProperties();
            Assert.AreEqual(1, properties.Count());
            properties.ElementAt(0).AssertList(OutputNames.Text, typeof(string));
        }
Exemplo n.º 11
0
		public void ReadSignature()
		{
			var store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser);
			store.Open(OpenFlags.ReadWrite);
			store.Add(this.authenticationManager.Certificate);
			store.Close();

			string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Signature.pdf", this.inputDirectory);
			FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>();
			ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
			designer.Properties[PropertyNames.ReadSignature].Value = true;

			var tester = new FunctionTester<ReadProvider>();
			FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters());

			Assert.IsTrue(result.Value.Signatures.IsSigned);
			AssertSignature(result.Value.Signatures.LatestSignature, false, "I moderated the doc", "Office location 2", "Jane Doe", new DateTime(2016, 8, 8, 15, 12, 57, DateTimeKind.Utc), true, 1,
				"A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.\r\n", false);
			dynamic allSignatures = result.Value.Signatures.AllSignatures;
			Assert.AreEqual(2, allSignatures.Count);
			AssertSignature(allSignatures[0], false, "I created the doc", "Office location 1", "John Smith", new DateTime(2016, 8, 8, 15, 12, 14, DateTimeKind.Utc), true, 1,
				string.Empty, true);
			AssertSignature(allSignatures[1], false, "I moderated the doc", "Office location 2", "Jane Doe", new DateTime(2016, 8, 8, 15, 12, 57, DateTimeKind.Utc), true, 1,
				"A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.\r\n", false);

			store.Open(OpenFlags.ReadWrite);
			store.Remove(this.authenticationManager.Certificate);
			store.Close();
		}
Exemplo n.º 12
0
        public void AddWatermarkWithAuthentication(
            [Values(
                 FileAuthentication.None,
                 FileAuthentication.Password,
                 FileAuthentication.CertificateFile,
                 FileAuthentication.CertificateStore)] FileAuthentication watermarkAuth)
        {
            string inputFilePath     = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Watermark.pdf", this.inputDirectory);
            string watermarkFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Overlay.pdf", this.inputDirectory);
            string outputFilePath    = Path.Combine(this.outputDirectory, "Watermark.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <AddWatermarkProvider>();

            ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
            var watermarkPages = string.Empty;

            ConfigureWatermarkFunctionValues(designer, watermarkAuth, watermarkFilePath, WatermarkPosition.Below, watermarkPages);
            designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath;

            var tester = new FunctionTester <AddWatermarkProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            PdfComparer.AssertText(outputFilePath, FileAuthentication.None, this.authenticationManager, "1\nWatermark\r\n2\nWatermark\r\n3\nWatermark\r\n4\nWatermark", null);
        }
Exemplo n.º 13
0
		public void ValidateReadSignatureOutputStructure()
		{
			var tester = new FunctionTester<ReadProvider>();
			FunctionDesigner designer = tester.CreateDesigner();
			Assert.IsNull(designer.Output);

			Property readSignature = designer.Properties[PropertyNames.ReadSignature];
			Assert.IsFalse(readSignature.GetValue<bool>());
			readSignature.Value = true;

			IEnumerable<ITypeProperty> properties = designer.Output.GetProperties();
			Assert.AreEqual(1, properties.Count());
			properties.ElementAt(0).AssertGenerated(OutputNames.Signatures);

			properties = properties.ElementAt(0).TypeReference.GetProperties();
			Assert.AreEqual(3, properties.Count());
			properties.ElementAt(0).AssertCompiled(OutputNames.IsSigned, typeof(bool));
			properties.ElementAt(1).AssertGenerated(OutputNames.LatestSignature);
			ITypeReference signatureType = properties.ElementAt(1).TypeReference;
			properties.ElementAt(2).AssertList(OutputNames.AllSignatures, signatureType);

			properties = signatureType.GetProperties();
			Assert.AreEqual(9, properties.Count());
			properties.ElementAt(0).AssertCompiled(OutputNames.SignedBy, typeof(string));
			properties.ElementAt(1).AssertCompiled(OutputNames.SignedAt, typeof(string));
			properties.ElementAt(2).AssertCompiled(OutputNames.Reason, typeof(string));
			properties.ElementAt(3).AssertCompiled(OutputNames.SignedOn, typeof(DateTime));
			properties.ElementAt(4).AssertCompiled(OutputNames.Unmodified, typeof(bool));
			properties.ElementAt(5).AssertCompiled(OutputNames.SignedRevision, typeof(int));
			properties.ElementAt(6).AssertCompiled(OutputNames.IsLatestRevision, typeof(bool));
			properties.ElementAt(7).AssertCompiled(OutputNames.Verified, typeof(bool));
			properties.ElementAt(8).AssertCompiled(OutputNames.VerificationMessage, typeof(string));
		}
Exemplo n.º 14
0
        public void AddWatermark(
            [Values(
                 FileAuthentication.None,
                 FileAuthentication.Password /*,
                                              * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file
                                              * FileAuthentication.CertificateFile,
                                              * FileAuthentication.CertificateStore*/)] FileAuthentication inputAuth,
            [Values(
                 WatermarkPosition.Above,
                 WatermarkPosition.Below)] WatermarkPosition position)
        {
            string inputFilePath     = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Watermark.pdf", this.inputDirectory);
            string watermarkFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Overlay.pdf", this.inputDirectory);
            string outputFilePath    = Path.Combine(this.outputDirectory, "Watermark.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <AddWatermarkProvider>();

            ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath);
            var watermarkPages = "4;1-2,2,2";

            ConfigureWatermarkFunctionValues(designer, FileAuthentication.None, watermarkFilePath, position, watermarkPages);
            designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath;

            var tester = new FunctionTester <AddWatermarkProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            PdfComparer.AssertText(outputFilePath, inputAuth, this.authenticationManager, "1\nWatermark\r\n2\nWatermark\r\n3\r\n4\nWatermark", null);
        }
Exemplo n.º 15
0
		public void ReadAcroFormDataWithListOutput()
		{
			string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormData.pdf", this.inputDirectory);
			FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>();
			ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
			designer.Properties[PropertyNames.ReadFormData].Value = true;
			designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.List;

			var tester = new FunctionTester<ReadProvider>();
			FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters());

			List<KeyValuePair<string, string>> dataList = result.Value.FormDataList;
			Assert.AreEqual(4, dataList.Count);
			KeyValuePair<string, string> item = dataList[0];
			Assert.AreEqual("First Name", item.Key);
			Assert.AreEqual("Jeremy", item.Value);
			item = dataList[1];
			Assert.AreEqual("Surname", item.Key);
			Assert.AreEqual("Woods", item.Value);
			item = dataList[2];
			Assert.AreEqual("Gender", item.Key);
			Assert.AreEqual("Male", item.Value);
			item = dataList[3];
			Assert.AreEqual("AcceptTCs", item.Key);
			Assert.AreEqual("Yes", item.Value);
		}
Exemplo n.º 16
0
        public void SignAcroWithPageSignature()
        {
            string inputFilePath  = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Sign.Resources.Sign.pdf", this.inputDirectory);
            string outputFilePath = Path.Combine(this.outputDirectory, "Sign.pdf");
            int    left           = 45;
            int    top            = 223;
            int    width          = 109;
            int    height         = 79;
            int    page           = 2;

            this.lockDocument = !this.lockDocument;

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <SignProvider>();

            ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
            ConfigureSignCertificateProperties(designer, FileAuthentication.CertificateFile, this.lockDocument);
            designer.Properties[PropertyNames.Placement].Value                 = SignaturePosition.OnPage;
            designer.Properties[PropertyNames.PositionX].Value                 = left;
            designer.Properties[PropertyNames.PositionY].Value                 = top;
            designer.Properties[PropertyNames.Width].Value                     = width;
            designer.Properties[PropertyNames.Height].Value                    = height;
            designer.Properties[PropertyNames.Page].Value                      = page;
            designer.Properties[PropertyNames.BackgroundImage].Value           = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Sign.Resources.Sign_Image.png", this.inputDirectory);
            designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath;

            var tester = new FunctionTester <SignProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            PdfComparer.AssertPageSignature(outputFilePath, FileAuthentication.None, this.authenticationManager, signName, signLocation, signReason, this.lockDocument,
                                            page, Utilities.MillimetersToPoints(left), Utilities.MillimetersToPoints(top), Utilities.MillimetersToPoints(width), Utilities.MillimetersToPoints(height));
        }
Exemplo n.º 17
0
        public void SignWithInvisibleSignature(
            [Values(
                 FileAuthentication.None,
                 FileAuthentication.Password /*,
                                              * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file
                                              * FileAuthentication.CertificateFile,
                                              * FileAuthentication.CertificateStore*/)] FileAuthentication inputAuth,
            [Values(
                 FileAuthentication.CertificateFile,
                 FileAuthentication.CertificateStore)] FileAuthentication signAuth,
            [Values(
                 "Sign.pdf",
                 "SignXFA.pdf")] string fileName)
        {
            string inputFilePath  = ResourceHelpers.WriteResourceToFile($"Twenty57.Linx.Components.Pdf.Tests.Sign.Resources.{fileName}", this.inputDirectory);
            string outputFilePath = Path.Combine(this.outputDirectory, fileName);

            this.lockDocument = !this.lockDocument;

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <SignProvider>();

            ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath);
            ConfigureSignCertificateProperties(designer, signAuth, this.lockDocument);
            designer.Properties[PropertyNames.Placement].Value = SignaturePosition.Hidden;
            designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath;

            var tester = new FunctionTester <SignProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            PdfComparer.AssertPageSignature(outputFilePath, inputAuth, this.authenticationManager, signName, signLocation, signReason, this.lockDocument, 1, 0, 0, 0, 0);
        }
Exemplo n.º 18
0
 public static ParameterValue[] GetParameters(this FunctionDesigner designer)
 {
     return(designer.GetFunctionData().Properties.Values
            .Where(prop => prop.ValueUsage == ValueUseOption.RuntimeRead)
            .Select(param => new ParameterValue(param.Name, param.Value))
            .ToArray());
 }
Exemplo n.º 19
0
		public void ReadWithNoInputFileSpecified([Values(null, "")] string inputFile)
		{
			FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>();
			designer.Properties[PropertyNames.PdfFilePath].Value = inputFile;

			Assert.That(() => new FunctionTester<ReadProvider>().Execute(designer.GetProperties(), designer.GetParameters()),
				Throws.Exception.TypeOf<ExecuteException>()
				.With.Property("Message").EqualTo("Value cannot be null.\r\nParameter name: PDF_32file_32path\r\nSee Code and Parameter properties for more information."));
		}
Exemplo n.º 20
0
        public void ProtectWithPrintRestrictions(
            [Values(
                 FileAuthentication.Password /*,
                                              * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file
                                              * FileAuthentication.CertificateFile,
                                              * FileAuthentication.CertificateStore*/)] FileAuthentication protectAuth,
            [Values(
                 Printing.None,
                 Printing.LowResolution,
                 Printing.HighResolution)] Printing printing)
        {
            string inputFilePath  = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ChangeProtection.Resources.Protect.pdf", this.inputDirectory);
            string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <ChangeProtectionProvider>();

            ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
            ConfigureProtectFunctionValues(designer, protectAuth, Encryption.AES256, true, true, printing: printing);
            designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath;

            var tester = new FunctionTester <ChangeProtectionProvider>();

            tester.Execute(designer.GetProperties(), designer.GetParameters());

            bool allowDegradedPrinting = false;
            bool allowPrinting         = false;

            switch (printing)
            {
            case Printing.None:
                break;

            case Printing.LowResolution:
                allowDegradedPrinting = true;
                break;

            case Printing.HighResolution:
                allowDegradedPrinting = true;
                allowPrinting         = true;
                break;

            default:
                throw new NotSupportedException("Invalid Printing specified.");
            }

            PdfComparer.AssertProtection(outputFilePath, protectAuth, this.authenticationManager, true, true,
                                         expectedAllowDegradedPrinting: allowDegradedPrinting,
                                         expectedAllowPrinting: allowPrinting);

            if (protectAuth == FileAuthentication.Password)
            {
                using (var permissionsAuthHelper = new AuthenticationManager(permissionsPassword))
                {
                    PdfComparer.AssertProtectionAllRights(outputFilePath, FileAuthentication.Password, permissionsAuthHelper, true, true);
                }
            }
        }
Exemplo n.º 21
0
		public void ReadWithInvalidInputFileSpecified()
		{
			string invalidFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
			Assert.IsFalse(File.Exists(invalidFilePath));

			FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>();
			designer.Properties[PropertyNames.PdfFilePath].Value = invalidFilePath;

			Assert.That(() => new FunctionTester<ReadProvider>().Execute(designer.GetProperties(), designer.GetParameters()),
				Throws.Exception.TypeOf<ExecuteException>()
				.With.Property("Message").EqualTo($"File [{invalidFilePath}] does not exist.\r\nSee Code and Parameter properties for more information."));
		}
Exemplo n.º 22
0
		public void ValidateReadFormDataOutputStructure()
		{
			var tester = new FunctionTester<ReadProvider>();
			FunctionDesigner designer = tester.CreateDesigner();
			Assert.IsNull(designer.Output);

			Property readFormData = designer.Properties[PropertyNames.ReadFormData];
			Assert.IsFalse(readFormData.GetValue<bool>());
			readFormData.Value = true;

			Property returnDataAs = designer.Properties[PropertyNames.ReturnFormDataAs];
			returnDataAs.Value = FormExtraction.CustomType;
			IEnumerable<ITypeProperty> properties = designer.Output.GetProperties();
			Assert.AreEqual(1, properties.Count());
			properties.ElementAt(0).AssertCompiled(OutputNames.FormData, typeof(object));

			Property formDataType = designer.Properties[PropertyNames.FormDataType];
			formDataType.Value = TypeReference.Create(typeof(string));
			properties = designer.Output.GetProperties();
			Assert.AreEqual(1, properties.Count());
			properties.ElementAt(0).AssertCompiled(OutputNames.FormData, typeof(string));

			returnDataAs.Value = FormExtraction.Infer;
			Property samplePdf = designer.Properties[PropertyNames.SamplePdf];
			Assert.AreEqual(string.Empty, samplePdf.GetValue<string>());
			properties = designer.Output.GetProperties();
			Assert.AreEqual(1, properties.Count());
			properties.ElementAt(0).AssertGenerated(OutputNames.FormData);
			Assert.AreEqual(0, properties.ElementAt(0).TypeReference.GetProperties().Count());

			string blankPdfFile = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Blank.pdf", this.inputDirectory);
			samplePdf.Value = blankPdfFile;
			properties = designer.Output.GetProperties();
			Assert.AreEqual(1, properties.Count());
			properties.ElementAt(0).AssertGenerated(OutputNames.FormData);
			Assert.AreEqual(0, properties.ElementAt(0).TypeReference.GetProperties().Count());

			string inferPdfFile = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.InferFields.pdf", this.inputDirectory);
			samplePdf.Value = inferPdfFile;
			properties = designer.Output.GetProperties();
			Assert.AreEqual(1, properties.Count());
			properties.ElementAt(0).AssertGenerated(OutputNames.FormData);
			IEnumerable<ITypeProperty> outputProperties = properties.ElementAt(0).TypeReference.GetProperties();
			Assert.AreEqual(2, outputProperties.Count());
			outputProperties.ElementAt(0).AssertCompiled("First_32Name", typeof(string));
			outputProperties.ElementAt(1).AssertCompiled("Surname", typeof(string));

			returnDataAs.Value = FormExtraction.List;
			properties = designer.Output.GetProperties();
			Assert.AreEqual(1, properties.Count());
			properties.ElementAt(0).AssertList(OutputNames.FormDataList, typeof(KeyValuePair<string, string>));
		}
Exemplo n.º 23
0
		private void ConfigureInputFileFunctionValues(FunctionDesigner designer, FileAuthentication inputAuth, string inputFilePath)
		{
			ConfigureInputFileFunctionValues(
				designer,
				inputAuth,
				inputFilePath,
				PropertyNames.PdfFilePath,
				PropertyNames.AuthenticationType,
				PropertyNames.PdfPassword,
				PropertyNames.CertificateSource,
				PropertyNames.CertificateFilePath,
				PropertyNames.CertificateFilePassword,
				PropertyNames.Certificate);
		}
Exemplo n.º 24
0
		public void ReadSignatureWithUnsignedDocument()
		{
			string blankPdfFile = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Blank.pdf", this.inputDirectory);

			FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>();
			designer.Properties[PropertyNames.ReadSignature].Value = true;
			designer.Properties[PropertyNames.PdfFilePath].Value = blankPdfFile;
			designer.Properties[PropertyNames.AuthenticationType].Value = AuthenticationType.None;

			var tester = new FunctionTester<ReadProvider>();
			FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters());

			Assert.IsFalse(result.Value.Signatures.IsSigned);
			Assert.AreEqual(0, result.Value.Signatures.AllSignatures.Count);
			AssertSignature(result.Value.Signatures.LatestSignature, true, string.Empty, string.Empty, string.Empty, DateTime.MinValue.ToUniversalTime(), true, 0, "No certificate found.", false);
		}
        public void ConcatenateWithInvalidInputFileSpecified()
        {
            string inputFilePath1  = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Concatenate.Resources.Concatenate1.pdf", this.inputDirectory);
            string invalidFilePath = Path.Combine(this.inputDirectory, Path.GetRandomFileName());
            string outputFilePath  = Path.Combine(this.outputDirectory, "Concat.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <ConcatenateProvider>();

            designer.Properties[PropertyNames.InputFiles].Value = new List <string> {
                inputFilePath1, invalidFilePath
            };
            designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath;

            Assert.That(() => new FunctionTester <ConcatenateProvider>().Execute(designer.GetProperties(), designer.GetParameters()),
                        Throws.Exception.TypeOf <ExecuteException>()
                        .With.Property("Message").EqualTo($"File [{invalidFilePath}] does not exist.\r\nSee Code and Parameter properties for more information."));
        }
Exemplo n.º 26
0
		public void ReadWithNoOutput(
			[Values(
				FileAuthentication.None,
				FileAuthentication.Password,
				FileAuthentication.CertificateFile,
				FileAuthentication.CertificateStore)] FileAuthentication inputAuth)
		{
			string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Blank.pdf", this.inputDirectory);
			FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>();
			ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath);
			designer.Properties[PropertyNames.ReadText].Value = false;
			designer.Properties[PropertyNames.ReadFormData].Value = false;
			designer.Properties[PropertyNames.ReadSignature].Value = false;

			var tester = new FunctionTester<ReadProvider>();
			Assert.DoesNotThrow(() => tester.Execute(designer.GetProperties(), designer.GetParameters()));
		}
Exemplo n.º 27
0
        public void Split(
            [Values(
                 FileAuthentication.None,
                 FileAuthentication.Password,
                 FileAuthentication.CertificateFile,
                 FileAuthentication.CertificateStore)] FileAuthentication inputAuth,
            [Values(
                 true,
                 false)] bool loopResults)
        {
            string inputFilePath  = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.Split.pdf", this.inputDirectory);
            string outputFilePath = Path.Combine(this.outputDirectory, "Split.pdf");

            FunctionDesigner designer = ProviderHelpers.CreateDesigner <PdfOperationsProvider>();

            ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath);
            designer.Properties[PropertyNames.Operation].Value        = Operation.Split;
            designer.Properties[PropertyNames.SplitLoopResults].Value = loopResults;
            designer.Properties[PropertyNames.OutputFilePath].Value   = outputFilePath;

            var            tester = new FunctionTester <PdfOperationsProvider>();
            FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters());

            Assert.AreEqual(2, result.Value.NumberOfPages);
            if (loopResults)
            {
                Assert.AreEqual(2, result.ExecutionPathResult.Count());
                NextResult nextResult = result.ExecutionPathResult.ElementAt(0);
                Assert.AreEqual(ExecutionPathNames.PageFiles, nextResult.Name);
                AssertOutputFile(nextResult.Value, inputAuth, Path.Combine(this.outputDirectory, "Split_1.pdf"), 1, "1");

                nextResult = result.ExecutionPathResult.ElementAt(1);
                Assert.AreEqual(ExecutionPathNames.PageFiles, nextResult.Name);
                AssertOutputFile(nextResult.Value, inputAuth, Path.Combine(this.outputDirectory, "Split_2.pdf"), 1, "2");
            }
            else
            {
                Assert.AreEqual(2, result.Value.PageFiles.Count);
                string pageFile = result.Value.PageFiles[0];
                AssertOutputFile(pageFile, inputAuth, Path.Combine(this.outputDirectory, "Split_1.pdf"), 1, "1");

                pageFile = result.Value.PageFiles[1];
                AssertOutputFile(pageFile, inputAuth, Path.Combine(this.outputDirectory, "Split_2.pdf"), 1, "2");
            }
        }
Exemplo n.º 28
0
        private MongoJsonEditor(MongoJsonEditorViewModel viewModel, FunctionDesigner context)
            : this()
        {
            base.DataContext   = viewModel;
            viewModel.Designer = context;
            base.Title         = viewModel.Title;
            foreach (var source in viewModel.TemplateSources)
            {
                var treeView = new TemplateTreeView(source);
                templateTabs.Items.Add(treeView);
            }

            viewModel.InitialiseDocument(this.textEditor.Document);
            Watermark.Visibility    = String.IsNullOrEmpty(textEditor.Text) ? Visibility.Visible : Visibility.Hidden;
            textEditor.TextChanged += (sender, e) => HideWatermark();
            textEditor.GotFocus    += (sender, e) => HideWatermark();
            textEditor.LostFocus   += (sender, e) => HideWatermark();
        }
Exemplo n.º 29
0
        private void ConfigureWatermarkFunctionValues(FunctionDesigner designer, FileAuthentication watermarkAuth, string watermarkFilePath, WatermarkPosition position,
                                                      string watermarkPages)
        {
            designer.Properties[PropertyNames.Position].Value = position;
            designer.Properties[PropertyNames.Pages].Value    = watermarkPages;

            ConfigureInputFileFunctionValues(
                designer,
                watermarkAuth,
                watermarkFilePath,
                PropertyNames.FilePath,
                PropertyNames.AuthenticationType,
                PropertyNames.Password,
                PropertyNames.CertificateSource,
                PropertyNames.CertificateFilePath,
                PropertyNames.CertificateFilePassword,
                PropertyNames.Certificate);
        }
Exemplo n.º 30
0
		public void ReadXfaFormDataWithInferredOutput()
		{
			string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormDataXFA.pdf", this.inputDirectory);
			FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>();
			ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath);
			designer.Properties[PropertyNames.ReadFormData].Value = true;

			designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.Infer;
			string inferFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.InferFieldsXFA.pdf", this.inputDirectory);
			designer.Properties[PropertyNames.SamplePdf].Value = inferFilePath;

			var tester = new FunctionTester<ReadProvider>();
			FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters());

			Assert.AreEqual("John", result.Value.FormData.form1_910_93_46FullName_910_93);
			Assert.AreEqual("Doe", result.Value.FormData.form1_910_93_46Surname_910_93);
			Assert.AreEqual("*****@*****.**", result.Value.FormData.form1_910_93_46Email_910_93);
			Assert.AreEqual("1", result.Value.FormData.form1_910_93_46EmailMe_910_93);
		}