IDScan.net

    Show / Hide Table of Contents

    Sample Application the Uses the Authentication SDK

    Initialization and Configuration

    • The first step is to create a Settings object and then to set the SdkDataDirectoryPath field.

    • The second step is to create a ValidationService object and passing in to it's constructor the Settings object created in the previous step.

    • Now you are ready to make use of the library.

    Warning

    IValidationService implements the IDisposable interface. So the SDK must be initialized only once at startup and then disposed of when no longer being used.

    Basic Sample

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.Threading.Tasks;
    using IDScanNet.Validation;
    using IDScanNet.Validation.SDK;
    
    namespace TestApp
    {
        public class Program
        {
            private static ValidationService _validationService;
    
            static async Task Main(string[] args)
            {
                //Init ValidationService
                await Init();
                //Validate valid document
                await Validate("Valid");
                //Validate fake by UV
                await Validate("UVFailed");
                //Validate fake RawString
                await Validate("FakeByRawString");
                //Validate face
                await Validate("Face");
                Console.ReadLine();
            }
    
    
            private static async Task Init()
            {
                Directory.CreateDirectory("Validation Logs");
                //Simple validation settings
                var validationServiceSettings = new ValidationServiceSettings
                {
                    //Set logging directory(default is c:\Users\Public\Documents\IDScan.net\Validation.SDK\Logs\)
                    LoggingDirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Validation Logs"),
                    HostDataDirectoryPath = @"C:\ProgramData\IDScan.net\IDScanNet.Validation.SDK.Data",
                    //Advanced validation settings:
                    //Host - pipe name for connection. If it's not stated, then the default one will be used
                    //Port - ignore this for now, as it would be required sometime in the future
                    HostDirectoryPath = @"C:\Program Files (x86)\IDScan.net\IDScanNet.Validation.SDK\Host"
                    //HostDataDirectoryPath - folder with data-files; can be substituted with a different value in case it's part of an app and data-files are somewhere close
                };
    
                _validationService = new ValidationService(validationServiceSettings);
    
                //Fired when the document processing stage is changed
                _validationService.ProcessingStageChanged += (sender, s) =>
                {
                    Console.WriteLine(s.Status);
                };
                //Fired when the error has occurred
                _validationService.ErrorReceived += (sender, s) =>
                {
                    Console.WriteLine(s.ToString());
                };
                //Fired when the processing of the document captured with the device is completed
                _validationService.DeviceProcessingCompleted += Service_DeviceProcessingCompleted;
    
                //Asynchronously initialize validation service
                await _validationService.InitializeAsync();
            }
    
            private static async Task Validate(String folder)
            {
                Console.WriteLine("----------------------------------------------------------------------------------------");
                Console.WriteLine($"Validate {folder}:");
                Stopwatch sw = Stopwatch.StartNew();
    
                //Create a new validation request
                var request = new ValidationRequest();
                request.Id = Guid.NewGuid();
                request.Scan = new ScanResult();
                var documentPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, folder);
    
                //Set RawString with a RawDataSource type
                var file = Directory.GetFiles(documentPath, "Pdf417RawData.txt").FirstOrDefault();
                if (file != null)
                    request.Scan.RawItems = new Dictionary<RawDataSource, RawData>
                {
                    {
                        RawDataSource.PDF417, new RawData
                        {
                            RawString = await File.ReadAllTextAsync(file)
                        }
                    }
                };
                //Set Images by ImageType
                request.Scan.ScannedImages = new Dictionary<ImageType, byte[]>();
    
                request.Scan.ScannedImages.Add(ImageType.ColorFront, await File.ReadAllBytesAsync(Path.Combine(documentPath, "Normal.jpg")));
                request.Scan.ScannedImages.Add(ImageType.ColorBack, await File.ReadAllBytesAsync(Path.Combine(documentPath, "NormalBack.jpg")));
                file = Directory.GetFiles(documentPath, "UV.*").FirstOrDefault();
                if (file != null)
                     request.Scan.ScannedImages.Add(ImageType.UVFront, await File.ReadAllBytesAsync(file));
                
                file = Directory.GetFiles(documentPath, "UVBack.*").FirstOrDefault();
                if (file != null)
                    request.Scan.ScannedImages.Add(ImageType.UVBack, await File.ReadAllBytesAsync(file));
    
                file = Directory.GetFiles(documentPath, "IR.*").FirstOrDefault();
                if (file != null)
                    request.Scan.ScannedImages.Add(ImageType.IRFront, await File.ReadAllBytesAsync(file));
    
                file = Directory.GetFiles(documentPath, "IRBack.*").FirstOrDefault();
                if (file != null)
                    request.Scan.ScannedImages.Add(ImageType.IRBack, await File.ReadAllBytesAsync(file));
    
                file = Directory.GetFiles(documentPath, "Face.*").FirstOrDefault();
                if (file != null)
                    request.Scan.ScannedImages.Add(ImageType.CameraFace, await File.ReadAllBytesAsync(file));
    
                
                //Asynchronously validate document
                ValidationResponse result = await _validationService.ProcessAsync(request);
    
                Console.WriteLine();
              
                if (result.Result != null)
                {
                    sw.Stop();
                    Console.WriteLine($"Validation Result for {folder} ElapsedMilliseconds: {sw.ElapsedMilliseconds}:");
              
                    // AuthenticationTests include UV, IR, Void validations
                    foreach (var testResult in result.Result.AuthenticationTests)
                    {
                        Console.WriteLine(
                            $"{testResult.Name} - {testResult.Type} {testResult.Status} {testResult.Confidence}");
                    }
                    //CrossMatch RawString and OCR
                    foreach (var testResult in result.Result.CrossMatchTests)
                    {
                        Console.WriteLine(
                            $"{testResult.Name} - {testResult.Type} {testResult.Status} {testResult.Confidence}");
                        if (testResult.CrossMatches != null)
                            foreach (var match in testResult.CrossMatches)
                            {
                                Console.WriteLine(
                                    $"      {match.FieldName} - {match.Item1.DataSource} = {match.Item1.Value};  {match.Item2.DataSource} = {match.Item2.Value} Confidence = {testResult.Confidence}");
                            }
                    }
    
                    //RawString test
                    foreach (var testResult in result.Result.DataValidationTests)
                    {
                        Console.WriteLine(
                            $"{testResult.Name} - {testResult.Type} {testResult.Status} ");
                    }
                }
                //Final validation result
                Console.WriteLine("Validation status = " + result.Result?.Status);
                Console.WriteLine();
            }
    
            private static void Service_DeviceProcessingCompleted(object sender, ValidationResponse e)
            {
                var d = e.Document;
            }
        }
    }
    

    A sample project can be found on Github

    Validation Result

    Validation tests results contain:

    • Validation Status:
    • public ValidationStatus Status { get; set; }
      Error Validation skipped with errors. Error occurred during validation.
      Failed Validation failed.
      Passed Validation passed.
      Skipped Validation not executed (expected behavior).
      Warning Validation skipped with warnings. Suspecious behavior, notify user about details.
    • AuthenticationTests contains:
    • Processed Images: public ImageValidationData ImageData { get; set; }
      Confidence score from 0 to 1: public float? Confidence { get; set; }
    • CrossMatchTestResult contains:
    • The list of fields to be compared from the barcode and those gotten from using OCR: public List CrossMatches { get; set; }
      Confidence score from 0 to 1: public float? Confidence { get; set; }
      Processed Images: public ImageValidationData ImageData { get; set; }/
    Back to top IDScan.net IDScan.net GitHub