Ejemplo n.º 1
0
        public async Task <PassportParseResult> ParsePassport(Stream passportImage)
        {
            var result = new PassportParseResult();

            try
            {
                // TODO: Reusing last task's result (if exists) to spare executions during dev -to be removed in deployed
                var task = ocrClient.ListTasks().LastOrDefault() ?? ocrClient.ProcessMrz(passportImage);

                result.TaskId = task.Id.ToString();
                while (task.IsTaskActive())
                {
                    await ThreadTask.Delay(1000);

                    task = ocrClient.GetTaskStatus(task.Id);
                }

                // Sample response file content: /SampleResponse/OcrMrzTaskDocument.xml
                var documentUrl = task.DownloadUrls.Single();
                result.PassportDocument = PassportDocumentInfo.CreateFromDocumentUrl(documentUrl);
            }
            catch (Exception ex)
            {
                result.SetError(ex);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Extracts the passport information from the parsed result.
        /// </summary>
        private PassportInformation ExtractPassportInformation(PassportParseResult passportParseResult)
        {
            var passportDocument = passportParseResult.PassportDocument;
            var passportInfo     = new PassportInformation()
            {
                Gender      = passportDocument.Sex,
                DateOfBirth = passportDocument.BirthDateVerified
                    ? DateTime.ParseExact(passportDocument.BirthDate, "yyMMdd", CultureInfo.InvariantCulture)
                    : default(DateTime?),
                ExpirationDate = passportDocument.ExpiryDateVerified
                    ? DateTime.ParseExact(passportDocument.ExpiryDate, "yyMMdd", CultureInfo.InvariantCulture)
                    : default(DateTime?),
                Firstname      = passportDocument.GivenName,
                Surname        = passportDocument.LastName,
                PassportNumber = passportDocument.DocumentNumber,
                IssuingState   = passportDocument.IssuingCountry,
                Nationality    = passportDocument.Nationality
            };

            return(passportInfo);
        }