Ejemplo n.º 1
0
        private int HandleRestAgreementStatus(Esignature oSignature)
        {
            this.log.Msg("Loading document info for the key '{0}' started...", oSignature.DocumentKey);

            DocumentInfo oResult;
            int          agreementStatus = -1;

            EchoSignAgreementStatusResponse response;

            try {
                response        = this.restClient.GetAgreementStatus(oSignature.DocumentKey).Result;
                agreementStatus = (int)response.status;

                oResult = new DocumentInfo {
                    documentKey = response.agreementId,
                    name        = response.name,
                    message     = response.message,
                    expiration  = response.expiration ?? DateTime.MinValue,
                };
            } catch (Exception e) {
                this.log.Warn(e, "Failed to load document info for the '{0}'.", oSignature.DocumentKey);
                return(-1);
            }             // try

            this.log.Debug("Loading document info result:");
            this.log.Debug("Name: {0}", oResult.name);
            this.log.Debug("Status: {0}", response.status);
            this.log.Debug(
                "Expiration: {0}",
                oResult.expiration.ToString("MMMM d yyyy H:mm:ss", CultureInfo.InvariantCulture)
                );

            oSignature.SetHistoryAndStatus(response.events, response.participantSetInfos);

            EchoSignAgreementDocumentResponse docResponse = this.restClient.GetAgreementDocument(oSignature.DocumentKey).Result;

            var sp = new SpSaveSignedDocument(this.db, this.log)
            {
                EsignatureID    = oSignature.ID,
                StatusID        = agreementStatus,
                DoSaveDoc       = true,
                MimeType        = docResponse.MimeType,
                DocumentContent = docResponse.Content,
                SignerStatuses  = oSignature.SignerStatuses,
                HistoryEvents   = oSignature.HistoryEvents,
            };

            try
            {
                sp.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                this.log.Alert(e, "Failed to save signed document for the key '{0}'.", oSignature.DocumentKey);
            } // try

            this.log.Msg("Loading document info for the key '{0}' complete.", oSignature.DocumentKey);

            return(agreementStatus);
        }         // GetAgreementStatus
Ejemplo n.º 2
0
        }         // Send

        private SignedDoc GetDocuments(Esignature oSignature)
        {
            this.log.Msg("Loading documents for the key '{0}' started...", oSignature.DocumentKey);

            GetDocumentsResult oResult;

            try {
                oResult = this.echoSign.getDocuments(
                    this.apiKey,
                    oSignature.DocumentKey,
                    new GetDocumentsOptions {
                    combine = true,
                    attachSupportingDocuments = true,
                }
                    );
            } catch (Exception e) {
                this.log.Warn(e, "Failed to load documents for the key '{0}'.", oSignature.DocumentKey);
                return(new SignedDoc {
                    HasValue = false,
                });
            }             // try

            if (!oResult.success)
            {
                this.log.Warn(
                    "Error while retrieving documents for the key '{0}': code = {1}, message = {2}.",
                    oSignature.DocumentKey, oResult.errorCode, oResult.errorMessage
                    );

                return(new SignedDoc {
                    HasValue = false,
                });
            }             // if

            int nDocumentCount = oResult.documents == null ? 0 : oResult.documents.Length;

            if (nDocumentCount != 1)
            {
                this.log.Warn(
                    "No documents received for the key '{0}' (document count = {1}).",
                    oSignature.DocumentKey,
                    nDocumentCount
                    );
                return(new SignedDoc {
                    HasValue = false,
                });
            }             // if

            // ReSharper disable once PossibleNullReferenceException
            // Can be disabled because of documentCount != 1 check just above.
            DocumentContent doc = oResult.documents[0];

            this.log.Debug("Document '{0}' of type '{1}', size {2} bytes.", doc.name, doc.mimetype, doc.bytes.Length);

            this.log.Msg("Loading documents for the key '{0}' complete.", oSignature.DocumentKey);

            return(new SignedDoc {
                HasValue = true, MimeType = doc.mimetype, Content = doc.bytes,
            });
        }         // GetDocuments
Ejemplo n.º 3
0
        }         // Send

        public List <EsignatureStatus> ProcessPending(int?nCustomerID = null)
        {
            if (!this.isReady)
            {
                this.log.Msg("EchoSign cannot process pending - not ready.");
                return(new List <EsignatureStatus>());
            }             // if

            var oSp = new SpLoadPendingEsignatures(nCustomerID, this.db, this.log);

            oSp.Load();

            this.log.Debug(
                "{0} pending signature{1} discovered.",
                oSp.Signatures.Count,
                oSp.Signatures.Count == 1 ? "" : "s"
                );

            var oCompleted = new List <EsignatureStatus>();

            foreach (KeyValuePair <int, Esignature> pair in oSp.Signatures)
            {
                Esignature oSignature = pair.Value;

                int nStatus = GetAgreementStatus(oSignature);

                if (this.terminalStatuses.Contains(nStatus))
                {
                    this.log.Debug(
                        "Terminal status {0} for e-signature {1} (customer {2}).",
                        nStatus, oSignature.ID, oSignature.CustomerID
                        );

                    oCompleted.Add(new EsignatureStatus {
                        CustomerID   = oSignature.CustomerID,
                        EsignatureID = oSignature.ID,
                        Status       = (AgreementStatus)nStatus
                    });
                }         // if
            }             // for each signature

            this.log.Debug(
                "{0} processed, out of them {1} ha{2} completed.",
                Grammar.Number(oSp.Signatures.Count, "pending signature"),
                oCompleted.Count,
                oCompleted.Count == 1 ? "ve" : "s"
                );

            return(oCompleted);
        }         // ProcessPending
Ejemplo n.º 4
0
        }         // GetDocuments

        private int GetAgreementStatus(Esignature oSignature)
        {
            if (this.isUseRestApi)
            {
                return(HandleRestAgreementStatus(oSignature));
            }

            var status = HandleSoapAgreementStatus(oSignature);

            if (status.HasValue)
            {
                return((int)status.Value);
            }

            return(-1);
        }
Ejemplo n.º 5
0
        public void Load()
        {
            ForEachRowSafe((sr, bRowsetStart) => {
                int nEsignatureID = sr["EsignatureID"];

                if (!Signatures.ContainsKey(nEsignatureID))
                {
                    var oSignature = new Esignature(nEsignatureID);
                    sr.Fill(oSignature);
                    Signatures[oSignature.ID] = oSignature;
                }                 // if

                Esigner oSigner = sr.Fill <Esigner>();
                Signatures[nEsignatureID].Signers[oSigner.ID] = oSigner;

                return(ActionResult.Continue);
            });
        }         // Load
Ejemplo n.º 6
0
        }         // GetAgreementStatus

        private AgreementStatus?HandleSoapAgreementStatus(Esignature oSignature)
        {
            this.log.Msg("Loading document info for the key '{0}' started...", oSignature.DocumentKey);

            DocumentInfo oResult;

            try
            {
                oResult = this.echoSign.getDocumentInfo(this.apiKey, oSignature.DocumentKey);
            }
            catch (Exception e)
            {
                this.log.Warn(e, "Failed to load document info for the '{0}'.", oSignature.DocumentKey);
                return(null);
            } // try

            this.log.Debug("Loading document info result:");
            this.log.Debug("Name: {0}", oResult.name);
            this.log.Debug("Status: {0}", oResult.status);
            this.log.Debug(
                "Expiration: {0}",
                oResult.expiration.ToString("MMMM d yyyy H:mm:ss", CultureInfo.InvariantCulture)
                );

            if (oResult.status.HasValue)
            {
                SignedDoc doc = GetDocuments(oSignature);

                oSignature.SetHistoryAndStatus(oResult.events, oResult.participants);

                if (doc.HasValue)
                {
                    var sp = new SpSaveSignedDocument(this.db, this.log)
                    {
                        EsignatureID    = oSignature.ID,
                        StatusID        = (int)oResult.status.Value,
                        DoSaveDoc       = doc.HasValue,
                        MimeType        = doc.MimeType,
                        DocumentContent = doc.Content,
                        SignerStatuses  = oSignature.SignerStatuses,
                        HistoryEvents   = oSignature.HistoryEvents,
                    };

                    try
                    {
                        sp.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        this.log.Alert(e, "Failed to save signed document for the key '{0}'.", oSignature.DocumentKey);
                    } // try
                }
                else
                {
                    this.log.Debug(
                        "Nothing to save for the key '{0}': no documents received from EchoSign.",
                        oSignature.DocumentKey
                        );
                } // if
            }     // if

            this.log.Msg("Loading document info for the key '{0}' complete.", oSignature.DocumentKey);

            return(oResult.status);
        }