void AssignCertificateProperty(string certificatePropertyName, Twenty57.Linx.Components.Pdf.CertificateSource certificateSource,
                                       string certificateFilePathPropertyName, string certificateFilePasswordPropertyName,
                                       Twenty57.Linx.Components.Pdf.StoredCertificate storedCertificatePropertyName)
        {
        #line default
        #line hidden

        #line 59 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            if (certificateSource == Twenty57.Linx.Components.Pdf.CertificateSource.File)
            {
        #line default
        #line hidden

        #line 60 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(certificatePropertyName));


        #line default
        #line hidden

        #line 60 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(" = new System.Security.Cryptography.X509Certificates.X509Certificate2(");


        #line default
        #line hidden

        #line 60 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(certificateFilePathPropertyName));


        #line default
        #line hidden

        #line 60 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(", ");


        #line default
        #line hidden

        #line 60 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(certificateFilePasswordPropertyName));


        #line default
        #line hidden

        #line 60 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(", System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.Exportable);\r" +
                           "\n");


        #line default
        #line hidden

        #line 61 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            }
            else if (certificateSource == Twenty57.Linx.Components.Pdf.CertificateSource.Store)
            {
        #line default
        #line hidden

        #line 62 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(certificatePropertyName));


        #line default
        #line hidden

        #line 62 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(" = new Twenty57.Linx.Components.Pdf.StoredCertificate(\r\n\t");


        #line default
        #line hidden

        #line 63 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(Twenty57.Linx.Plugin.Common.CodeGeneration.CSharpUtilities.EnumAsString(storedCertificatePropertyName.StoreLocation)));


        #line default
        #line hidden

        #line 63 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(", \r\n\t");


        #line default
        #line hidden

        #line 64 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(Twenty57.Linx.Plugin.Common.CodeGeneration.CSharpUtilities.EnumAsString(storedCertificatePropertyName.StoreName)));


        #line default
        #line hidden

        #line 64 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(", \r\n\t\"");


        #line default
        #line hidden

        #line 65 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(storedCertificatePropertyName.ThumbPrint));


        #line default
        #line hidden

        #line 65 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write("\").GetCertificate();\r\n");


        #line default
        #line hidden

        #line 66 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            }

        #line default
        #line hidden

        #line 67 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
        }
        void AssignPdfReader(string readerPropertyName, AuthenticationType authenticationType, string filePropertyName, string passwordPropertyName,
                             Twenty57.Linx.Components.Pdf.CertificateSource certificateSource, string certificateFilePathPropertyName, string certificateFilePasswordPropertyName,
                             Twenty57.Linx.Components.Pdf.StoredCertificate certificate, string contextPropertyName)
        {
        #line default
        #line hidden

        #line 6 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write("if (string.IsNullOrEmpty(");


        #line default
        #line hidden

        #line 7 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write(this.ToStringHelper.ToStringWithCulture(filePropertyName));


        #line default
        #line hidden

        #line 7 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write("))\r\n\tthrow new ArgumentNullException(\"");


        #line default
        #line hidden

        #line 8 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write(this.ToStringHelper.ToStringWithCulture(filePropertyName));


        #line default
        #line hidden

        #line 8 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write("\");\r\nif (!System.IO.File.Exists(");


        #line default
        #line hidden

        #line 9 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write(this.ToStringHelper.ToStringWithCulture(filePropertyName));


        #line default
        #line hidden

        #line 9 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write("))\r\n\tthrow new System.IO.FileNotFoundException(string.Format(\"File [{0}] does not" +
                       " exist.\", ");


        #line default
        #line hidden

        #line 10 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write(this.ToStringHelper.ToStringWithCulture(filePropertyName));


        #line default
        #line hidden

        #line 10 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write("));\r\n\r\n");


        #line default
        #line hidden

        #line 12 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write(this.ToStringHelper.ToStringWithCulture(contextPropertyName));


        #line default
        #line hidden

        #line 12 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write(".Log(string.Format(\"Opening file [{0}].\", ");


        #line default
        #line hidden

        #line 12 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write(this.ToStringHelper.ToStringWithCulture(filePropertyName));


        #line default
        #line hidden

        #line 12 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            this.Write("));\r\n");


        #line default
        #line hidden

        #line 13 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"

            if (authenticationType == AuthenticationType.None)
            {
        #line default
        #line hidden

        #line 17 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(readerPropertyName));


        #line default
        #line hidden

        #line 17 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(" = new iTextSharp.text.pdf.PdfReader(");


        #line default
        #line hidden

        #line 17 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(filePropertyName));


        #line default
        #line hidden

        #line 17 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(");\r\n");


        #line default
        #line hidden

        #line 18 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            }
            else if (authenticationType == AuthenticationType.Password)
            {
        #line default
        #line hidden

        #line 23 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(readerPropertyName));


        #line default
        #line hidden

        #line 23 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(" = new iTextSharp.text.pdf.PdfReader(");


        #line default
        #line hidden

        #line 23 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(filePropertyName));


        #line default
        #line hidden

        #line 23 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(", System.Text.Encoding.UTF8.GetBytes(");


        #line default
        #line hidden

        #line 23 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(passwordPropertyName));


        #line default
        #line hidden

        #line 23 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write("));\r\n");


        #line default
        #line hidden

        #line 24 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            }
            else if (authenticationType == AuthenticationType.Certificate)
            {
                string certificatePropertyName = "inputCertificate";


        #line default
        #line hidden

        #line 29 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write("System.Security.Cryptography.X509Certificates.X509Certificate2 ");


        #line default
        #line hidden

        #line 30 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(certificatePropertyName));


        #line default
        #line hidden

        #line 30 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(" = null;\r\n");


        #line default
        #line hidden

        #line 31 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                AssignCertificateProperty(certificatePropertyName, certificateSource, certificateFilePathPropertyName, certificateFilePasswordPropertyName, certificate);

        #line default
        #line hidden

        #line 31 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(@"if (!inputCertificate.HasPrivateKey)
	throw new NotSupportedException(""Certificate must have a private key."");

Org.BouncyCastle.X509.X509Certificate inputBouncyCertficate = Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate(inputCertificate);
Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair inputKeyPair = Org.BouncyCastle.Security.DotNetUtilities.GetKeyPair(inputCertificate.PrivateKey);
");


        #line default
        #line hidden

        #line 37 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(readerPropertyName));


        #line default
        #line hidden

        #line 37 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(" = new iTextSharp.text.pdf.PdfReader(");


        #line default
        #line hidden

        #line 37 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(filePropertyName));


        #line default
        #line hidden

        #line 37 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
                this.Write(", inputBouncyCertficate, inputKeyPair.Private);\r\n");


        #line default
        #line hidden

        #line 38 "D:\Hg\Linx5Components\PDF\PDF-2455\Linx5.Components.PDF\src\Pdf\ChangeProtection\Templates\..\..\Common\ManagePdfReaderTemplate.t4"
            }
        }