/**
         * This scenario demonstrates the creation of a document
         * that will be signed by a sign rule.
         * In a signing rule multiples users are assigned to the
         * same action but just an arbitrary number of them are
         * required to sign in order to complete that action.
         */
        public override async Task RunAsync()
        {
            // 1. The file's bytes must be read by the application and uploaded
            var filePath    = "sample.pdf";
            var fileName    = Path.GetFileName(filePath);
            var file        = File.ReadAllBytes(filePath);
            var uploadModel = await SignerClient.UploadFileAsync(fileName, file, "application/pdf");

            // 2. Define the name of the document which will be visible in the application
            var fileUploadModel = new FileUploadModel(uploadModel)
            {
                DisplayName = "Signing Rule Sample"
            };

            // 3. For each participant on the flow, create one instance of ParticipantUserModel
            var participantUserOne = new ParticipantUserModel()
            {
                Name       = "Jack Bauer",
                Email      = "*****@*****.**",
                Identifier = "75502846369"
            };

            var participantUserTwo = new ParticipantUserModel()
            {
                Name       = "James Bond",
                Email      = "*****@*****.**",
                Identifier = "95588148061"
            };

            // 4. Each signing rule requires just one FlowActionCreateModel no matter
            //    the number of participants assigned to it. The participants are assigned to
            //    it via a list of ParticipantUserModel assigned to the `SignRuleUsers` property.
            //    The number of required signatures from this list of participants is represented by
            //    the property `NumberRequiredSignatures`.
            var flowActionCreateModelSigningRule = new FlowActionCreateModel()
            {
                Type = FlowActionType.SignRule,
                NumberRequiredSignatures = 1,
                SignRuleUsers            = new List <ParticipantUserModel>()
                {
                    participantUserOne, participantUserTwo
                }
            };

            // 5. Send the document create request
            var documentRequest = new CreateDocumentRequest()
            {
                Files = new List <FileUploadModel>()
                {
                    fileUploadModel
                },
                FlowActions = new List <FlowActionCreateModel>()
                {
                    flowActionCreateModelSigningRule
                }
            };
            var result = (await SignerClient.CreateDocumentAsync(documentRequest)).First();

            System.Console.WriteLine($"Document {result.DocumentId} created");
        }
        /**
         * This scenario demonstrates the creation of a document
         * and the generation of an action URL for the embedded signature
         * integration.
         */
        public override async Task RunAsync()
        {
            // 1. The file's bytes must be read by the application and uploaded
            var filePath    = "sample.pdf";
            var fileName    = Path.GetFileName(filePath);
            var file        = File.ReadAllBytes(filePath);
            var uploadModel = await SignerClient.UploadFileAsync(fileName, file, "application/pdf");

            // 2. Define the name of the document which will be visible in the application
            var fileUploadModel = new FileUploadModel(uploadModel)
            {
                DisplayName = "Embedded Signature Sample"
            };

            // 3. For each participant on the flow, create one instance of ParticipantUserModel
            var participantUser = new ParticipantUserModel()
            {
                Name       = "Jack Bauer",
                Email      = "*****@*****.**",
                Identifier = "75502846369"
            };

            // 4. Create a FlowActionCreateModel instance for each action (signature or approval) in the flow.
            //    This object is responsible for defining the personal data of the participant and the type of
            //    action that he will perform on the flow
            var flowActionCreateModel = new FlowActionCreateModel()
            {
                Type = FlowActionType.Signer,
                User = participantUser
            };

            // 5. Send the document create request
            var documentRequest = new CreateDocumentRequest()
            {
                Files = new List <FileUploadModel>()
                {
                    fileUploadModel
                },
                FlowActions = new List <FlowActionCreateModel>()
                {
                    flowActionCreateModel
                }
            };
            var result = (await SignerClient.CreateDocumentAsync(documentRequest)).First();

            // 6. Get the embed URL for the participant
            var actionUrlRequest = new ActionUrlRequest()
            {
                Identifier = participantUser.Identifier
            };
            var actionUrlResponse = await SignerClient.GetActionUrlAsync(result.DocumentId, actionUrlRequest);

            // 7. Load the embed URL in your own application using the LacunaSignerWidget as described in
            //    https://docs.lacunasoftware.com/pt-br/articles/signer/embedded-signature.html
            System.Console.WriteLine(actionUrlResponse.EmbedUrl);
        }
        /**
         * This scenario demonstrates the creation of a document
         * that needs to be signed using the XAdES format for a
         * specific XML element.
         */
        public override async Task RunAsync()
        {
            // 1. The file's bytes must be read by the application and uploaded
            var filePath    = "sample.xml";
            var fileName    = Path.GetFileName(filePath);
            var file        = File.ReadAllBytes(filePath);
            var uploadModel = await SignerClient.UploadFileAsync(fileName, file, "application/xml");

            // 2. Define the name of the document which will be visible in the application
            var fileUploadModel = new FileUploadModel(uploadModel)
            {
                DisplayName = "XML Element Sign Sample"
            };

            // 3. For each participant on the flow, create one instance of ParticipantUserModel
            var participantUser = new ParticipantUserModel()
            {
                Name       = "Jack Bauer",
                Email      = "*****@*****.**",
                Identifier = "75502846369"
            };

            // 4. Specify the type of the element (Id is used below) and the value of the identifier
            var xadesOptionsModel = new XadesOptionsModel()
            {
                SignatureType = XadesSignatureTypes.XmlElement,
                ElementToSignIdentifierType = XadesElementIdentifierTypes.Id,
                ElementToSignIdentifier     = "NFe35141214314050000662550010001084271182362300"
            };

            // 5. Create a FlowActionCreateModel instance for each action (signature or approval) in the flow.
            //    This object is responsible for defining the personal data of the participant and the type of
            //    action that he will perform on the flow.
            var flowActionCreateModel = new FlowActionCreateModel()
            {
                Type         = FlowActionType.Signer,
                User         = participantUser,
                XadesOptions = xadesOptionsModel
            };

            // 6. Send the document create request
            var documentRequest = new CreateDocumentRequest()
            {
                Files = new List <FileUploadModel>()
                {
                    fileUploadModel
                },
                FlowActions = new List <FlowActionCreateModel>()
                {
                    flowActionCreateModel
                }
            };
            var result = (await SignerClient.CreateDocumentAsync(documentRequest)).First();

            System.Console.WriteLine($"Document {result.DocumentId} created");
        }
        /**
         * This scenario demonstrates the creation of a PDF document
         * that needs to be signed using the CAdES format.
         */
        public override async Task RunAsync()
        {
            // 1. The file's bytes must be read by the application and uploaded
            var filePath    = "sample.pdf";
            var fileName    = Path.GetFileName(filePath);
            var file        = File.ReadAllBytes(filePath);
            var uploadModel = await SignerClient.UploadFileAsync(fileName, file, "application/pdf");

            // 2. Define the name of the document which will be visible in the application
            var fileUploadModel = new FileUploadModel(uploadModel)
            {
                DisplayName = "PDF Cades Sample"
            };

            // 3. For each participant on the flow, create one instance of ParticipantUserModel
            var participantUser = new ParticipantUserModel()
            {
                Name       = "Jack Bauer",
                Email      = "*****@*****.**",
                Identifier = "75502846369"
            };

            // 4. Create a FlowActionCreateModel instance for each action (signature or approval) in the flow.
            //    This object is responsible for defining the personal data of the participant and the type of
            //    action that he will perform on the flow
            var flowActionCreateModel = new FlowActionCreateModel()
            {
                Type = FlowActionType.Signer,
                User = participantUser
            };

            // 5. Send the document create request specifying that it requires CAdES signatures, since PAdES is
            //    the default for PDF files.
            var documentRequest = new CreateDocumentRequest()
            {
                Files = new List <FileUploadModel>()
                {
                    fileUploadModel
                },
                FlowActions = new List <FlowActionCreateModel>()
                {
                    flowActionCreateModel
                },
                ForceCadesSignature = true
            };
            var result = (await SignerClient.CreateDocumentAsync(documentRequest)).First();

            System.Console.WriteLine($"Document {result.DocumentId} created");
        }
Exemplo n.º 5
0
        /**
         * This scenario demonstrates the creation of a document with description
         *
         */
        public override async Task RunAsync()
        {
            // 1. The file's bytes must be read by the application and uploaded
            var filePath    = "sample.pdf";
            var fileName    = Path.GetFileName(filePath);
            var file        = File.ReadAllBytes(filePath);
            var uploadModel = await SignerClient.UploadFileAsync(fileName, file, "application/pdf");

            // 2. Define the name of the document which will be visible in the application
            var fileUploadModel = new FileUploadModel(uploadModel)
            {
                DisplayName = "One Description Sample"
            };

            // 3. For each participant on the flow, create one instance of ParticipantUserModel
            var participantUser = new ParticipantUserModel()
            {
                Name       = "Jack Bauer",
                Email      = "*****@*****.**",
                Identifier = "75502846369"
            };

            // 4. Create a FlowActionCreateModel instance for each action (signature or approval) in the flow.
            var flowActionCreateModel = new FlowActionCreateModel()
            {
                Type = FlowActionType.Signer,
                User = participantUser
            };

            // 5. Send the document create request writing the description as a string
            var documentRequest = new CreateDocumentRequest()
            {
                Files = new List <FileUploadModel>()
                {
                    fileUploadModel
                },
                Description = "Some Description Sample",
                FlowActions = new List <FlowActionCreateModel>()
                {
                    flowActionCreateModel
                }
            };
            var result = (await SignerClient.CreateDocumentAsync(documentRequest)).First();

            System.Console.WriteLine($"Document {result.DocumentId} created");
        }
Exemplo n.º 6
0
        // Creates a generic document, useful for certain scenarios.
        protected async Task <CreateDocumentResult> CreateDocumentAsync()
        {
            var filePath    = "sample.pdf";
            var fileName    = Path.GetFileName(filePath);
            var file        = File.ReadAllBytes(filePath);
            var uploadModel = await SignerClient.UploadFileAsync(fileName, file, "application/pdf");

            var documentModel = new FileUploadModel(uploadModel)
            {
                DisplayName = "Check Status Sample"
            };

            var participant = new ParticipantUserModel()
            {
                Name       = "Jack Bauer",
                Email      = "*****@*****.**",
                Identifier = "75502846369"
            };

            var flowAction = new FlowActionCreateModel()
            {
                Type = FlowActionType.Signer,
                User = participant
            };

            var documentRequest = new CreateDocumentRequest()
            {
                Files = new List <FileUploadModel>()
                {
                    documentModel
                },
                FlowActions = new List <FlowActionCreateModel>()
                {
                    flowAction
                }
            };

            return((await SignerClient.CreateDocumentAsync(documentRequest)).First());
        }
Exemplo n.º 7
0
        /**
         * This scenario demonstrates the creation of a document with Attachment.
         */
        public override async Task RunAsync()
        {
            // 1. The file's bytes must be read by the application and uploaded
            var filePath    = "sample.pdf";
            var fileName    = Path.GetFileName(filePath);
            var file        = File.ReadAllBytes(filePath);
            var uploadModel = await SignerClient.UploadFileAsync(fileName, file, "application/pdf");

            var fileUploadModel = new FileUploadModel(uploadModel)
            {
                DisplayName = "One Signer Sample"
            };


            // Repeat the same steps above but now for the attachment
            var attachmentPath   = "sample.pdf";
            var attachmentName   = Path.GetFileName(attachmentPath);
            var attachment       = File.ReadAllBytes(attachmentPath);
            var attachmentUpload = await SignerClient.UploadFileAsync(attachmentName, attachment, "application/pdf");

            // 2. Define the name of the attachment which will be visible in the application using "AttachmentUploadModel"
            var attachmentUploadModel = new AttachmentUploadModel(attachmentUpload)
            {
                DisplayName = "One Attachment Sample",
                IsPrivate   = true
            };


            // 3. For each participant on the flow, create one instance of ParticipantUserModel
            var participantUser = new ParticipantUserModel()
            {
                Name       = "Jack Bauer",
                Email      = "*****@*****.**",
                Identifier = "75502846369"
            };

            // 4. Create a FlowActionCreateModel instance for each action (signature or approval) in the flow.
            //    This object is responsible for defining the personal data of the participant and the type of
            //    action that he will perform on the flow
            var flowActionCreateModel = new FlowActionCreateModel()
            {
                Type = FlowActionType.Signer,
                User = participantUser
            };

            // 5. Send the document create request with whith the attachment attribute
            var documentRequest = new CreateDocumentRequest()
            {
                Files = new List <FileUploadModel>()
                {
                    fileUploadModel
                },
                Attachments = new List <AttachmentUploadModel>()
                {
                    attachmentUploadModel
                },
                FlowActions = new List <FlowActionCreateModel>()
                {
                    flowActionCreateModel
                }
            };
            var result = (await SignerClient.CreateDocumentAsync(documentRequest)).First();

            System.Console.WriteLine($"Document {result.DocumentId} created");
        }
        /**
         * This scenario demonstrates the creation of a document with
         * two signers and without a particular order for the signatures.
         */
        public override async Task RunAsync()
        {
            // 1. The file's bytes must be read by the application and uploaded
            var filePath    = "sample.pdf";
            var fileName    = Path.GetFileName(filePath);
            var file        = File.ReadAllBytes(filePath);
            var uploadModel = await SignerClient.UploadFileAsync(fileName, file, "application/pdf");

            // 2. Define the name of the document which will be visible in the application
            var fileUploadModel = new FileUploadModel(uploadModel)
            {
                DisplayName = "Two Signers Without Order Sample"
            };

            // 3. For each participant on the flow, create one instance of ParticipantUserModel
            var participantUserOne = new ParticipantUserModel()
            {
                Name       = "Jack Bauer",
                Email      = "*****@*****.**",
                Identifier = "75502846369"
            };

            var participantUserTwo = new ParticipantUserModel()
            {
                Name       = "James Bond",
                Email      = "*****@*****.**",
                Identifier = "95588148061"
            };

            // 4. Create a FlowActionCreateModel instance for each action (signature or approval) in the flow.
            //    This object is responsible for defining the personal data of the participant, the type of
            //    action that he will perform on the flow and the order in which this action will take place
            //    (Step property). If the Step property of all action are the same or not specified they
            //    may be executed at any time
            var flowActionCreateModelOne = new FlowActionCreateModel()
            {
                Type = FlowActionType.Signer,
                User = participantUserOne
            };

            var flowActionCreateModelTwo = new FlowActionCreateModel()
            {
                Type = FlowActionType.Signer,
                User = participantUserTwo
            };

            // 5. Send the document create request
            var documentRequest = new CreateDocumentRequest()
            {
                Files = new List <FileUploadModel>()
                {
                    fileUploadModel
                },
                FlowActions = new List <FlowActionCreateModel>()
                {
                    flowActionCreateModelOne,
                    flowActionCreateModelTwo
                }
            };
            var result = (await SignerClient.CreateDocumentAsync(documentRequest)).First();

            System.Console.WriteLine($"Document {result.DocumentId} created");
        }
        /**
         * This scenario demonstrates the creation of a digital degree compliant with "PORTARIA Nº 554, DE 11 DE MARÇO DE 2019".
         */
        public override async Task RunAsync()
        {
            // 1. The file's bytes must be read by the application and uploaded
            var filePath    = "sample-degree.xml";
            var fileName    = Path.GetFileName(filePath);
            var file        = File.ReadAllBytes(filePath);
            var uploadModel = await SignerClient.UploadFileAsync(fileName, file, "application/xml");

            // 2. Define the name of the document which will be visible in the application
            var fileUploadModel = new FileUploadModel(uploadModel)
            {
                DisplayName = "Digital Degree Sample"
            };

            // 3. For each participant on the flow, create one instance of ParticipantUserModel
            var participantUserOne = new ParticipantUserModel()
            {
                Name       = "Jack Bauer",
                Email      = "*****@*****.**",
                Identifier = "75502846369"
            };

            var participantUserTwo = new ParticipantUserModel()
            {
                Name       = "James Bond",
                Email      = "*****@*****.**",
                Identifier = "95588148061"
            };

            var ParticipantUserThree = new ParticipantUserModel()
            {
                Name       = "Gary Eggsy",
                Email      = "*****@*****.**",
                Identifier = "87657257008"
            };

            // 4. Specify the element that holds the namespace of the issuer
            var xmlNamespacesModel = new XmlNamespaceModel()
            {
                Prefix = "dip",
                Uri    = @"http://portal.mec.gov.br/diplomadigital/arquivos-em-xsd"
            };

            // 5. The fields 'DadosDiploma' and 'DadosRegistro' and the entire XML file must be signed
            var xadesOptionsDegreeData = new XadesOptionsModel()
            {
                SignatureType = XadesSignatureTypes.XmlElement,
                ElementToSignIdentifierType = XadesElementIdentifierTypes.XPath,
                ElementToSignIdentifier     = @"//dip:DadosDiploma",
                InsertionOption             = XadesInsertionOptions.AppendChild
            };

            var xadesOptionsModelRegisterData = new XadesOptionsModel()
            {
                SignatureType = XadesSignatureTypes.XmlElement,
                ElementToSignIdentifierType = XadesElementIdentifierTypes.XPath,
                ElementToSignIdentifier     = @"//dip:DadosRegistro",
                InsertionOption             = XadesInsertionOptions.AppendChild
            };

            var xadesOptionsModelFull = new XadesOptionsModel()
            {
                SignatureType = XadesSignatureTypes.FullXml
            };

            // 6. Each signature requires its own flow action
            var degreeDataAction = new FlowActionCreateModel()
            {
                Type         = FlowActionType.Signer,
                User         = participantUserOne,
                XadesOptions = xadesOptionsDegreeData
            };

            var registerDataAction = new FlowActionCreateModel()
            {
                Type         = FlowActionType.Signer,
                User         = participantUserTwo,
                XadesOptions = xadesOptionsModelRegisterData
            };

            var flowActionCreateModelFull = new FlowActionCreateModel()
            {
                Type         = FlowActionType.Signer,
                User         = ParticipantUserThree,
                XadesOptions = xadesOptionsModelFull
            };

            // 7. Send the document create request
            var documentRequest = new CreateDocumentRequest()
            {
                Files = new List <FileUploadModel>()
                {
                    fileUploadModel
                },
                XmlNamespaces = new List <XmlNamespaceModel>()
                {
                    xmlNamespacesModel
                },
                FlowActions = new List <FlowActionCreateModel>()
                {
                    degreeDataAction,
                    registerDataAction,
                    flowActionCreateModelFull
                },
            };
            var result = (await SignerClient.CreateDocumentAsync(documentRequest)).First();

            System.Console.WriteLine($"Document {result.DocumentId} created");
        }
Exemplo n.º 10
0
        /**
         * This scenario demonstrates the creation of a document into an existing folder.
         */
        public override async Task RunAsync()
        {
            // 1. The file's bytes must be read by the application and uploaded
            var filePath    = "sample.pdf";
            var fileName    = Path.GetFileName(filePath);
            var file        = File.ReadAllBytes(filePath);
            var uploadModel = await SignerClient.UploadFileAsync(fileName, file, "application/pdf");

            // 2. Define the name of the document which will be visible in the application
            var fileUploadModel = new FileUploadModel(uploadModel)
            {
                DisplayName = "Document in Folder Sample"
            };

            // 3. For each participant on the flow, create one instance of ParticipantUserModel
            var participantUser = new ParticipantUserModel()
            {
                Name       = "Jack Bauer",
                Email      = "*****@*****.**",
                Identifier = "75502846369"
            };

            // 4. Create a FlowActionCreateModel instance for each action (signature or approval) in the flow.
            //    This object is responsible for defining the personal data of the participant and the type of
            //    action that he will perform on the flow
            var flowActionCreateModel = new FlowActionCreateModel()
            {
                Type = FlowActionType.Signer,
                User = participantUser
            };

            // 5. Search a folder by it's name
            var paginatedSearchParams = new PaginatedSearchParams()
            {
                Q = "Sample Folder"
            };
            var paginatedSearchResult = await SignerClient.ListFoldersPaginatedAsync(paginatedSearchParams, null);

            var folder = paginatedSearchResult.Items.FirstOrDefault();

            if (folder == null)
            {
                throw new Exception("Folder was not found");
            }

            // 6. Send the document create request setting the FolderId property
            var documentRequest = new CreateDocumentRequest()
            {
                Files = new List <FileUploadModel>()
                {
                    fileUploadModel
                },
                FlowActions = new List <FlowActionCreateModel>()
                {
                    flowActionCreateModel
                },
                FolderId = folder.Id
            };
            var result = (await SignerClient.CreateDocumentAsync(documentRequest)).First();

            System.Console.WriteLine($"Document {result.DocumentId} created");
        }
        /**
         * This scenario demonstrates the creation of a document with
         * Prepositioned signatures.
         */
        public override async Task RunAsync()
        {
            // 1. The file's bytes must be read by the application and uploaded
            var filePath    = "sample.pdf";
            var fileName    = Path.GetFileName(filePath);
            var file        = File.ReadAllBytes(filePath);
            var uploadModel = await SignerClient.UploadFileAsync(fileName, file, "application/pdf");

            // 2. Define the name of the document which will be visible in the application
            var fileUploadModel = new FileUploadModel(uploadModel)
            {
                DisplayName = "Prepositioned signatures"
            };

            // 3. For each participant on the flow, create one instance of ParticipantUserModel
            var participantUser = new ParticipantUserModel()
            {
                Name       = "Jack Bauer",
                Email      = "*****@*****.**",
                Identifier = "75502846369"
            };


            // 4. Create a FlowActionCreateModel instance for each action (signature or approval) in the flow.
            //    This object is responsible for defining the personal data of the participant, the type of
            //    action that he will perform on the flow and the order in which this action will take place
            //    (Step property) and the pre-positioned marks for placing signatures. If the Step property of all action are the same or not specified they
            //    may be executed at any time
            var flowActionCreateModel = new FlowActionCreateModel()
            {
                Type = FlowActionType.Signer,
                User = participantUser,
                PrePositionedMarks = new List <PrePositionedDocumentMarkModel>
                {
                    new PrePositionedDocumentMarkModel()
                    {
                        Type       = DocumentMarkType.SignatureVisualRepresentation, //This is the attribute responsible for defining the Type of signature you are going to use
                        UploadId   = fileUploadModel.Id,                             //Document id
                        TopLeftX   = 395.0,                                          //Signature position, in pixels, over the X axis
                        TopLeftY   = 560.0,                                          //Signature position, in pixels, over the Y axis
                        Width      = 170.0,                                          //Width of the rectagular where signature will be placed in (It already has a default value)
                        Height     = 94.0,                                           //Height of the rectagular where signature will be placed in (It already has a default value)
                        PageNumber = 1                                               //Page where the signature wil be placed
                    }
                }
            };


            // 5. Send the document create request
            var documentRequest = new CreateDocumentRequest()
            {
                Files = new List <FileUploadModel>()
                {
                    fileUploadModel
                },
                FlowActions = new List <FlowActionCreateModel>()
                {
                    flowActionCreateModel
                }
            };


            var result = (await SignerClient.CreateDocumentAsync(documentRequest)).First();

            System.Console.WriteLine($"Document {result.DocumentId} created");
        }