Ejemplo n.º 1
0
        public void OnIdCaptured(IdCapture mode, IdCaptureSession session, IFrameData data)
        {
            CapturedId capturedId = session.NewlyCapturedId;

            // This callback may be executed on an arbitrary thread. We post to switch back
            // to the main thread.
            this.view.Post(() =>
            {
                string message = string.Empty;

                // The recognized fields of the captured Id can vary based on the capturedResultType.
                if (capturedId.CapturedResultType == CapturedResultType.AamvaBarcodeResult)
                {
                    message = GetDescriptionForAamvaBarcodeResult(capturedId);
                }
                else if (capturedId.CapturedResultType == CapturedResultType.VizResult)
                {
                    message = GetDescriptionForViz(capturedId);
                }
                else
                {
                    message = GetDescriptionForCapturedId(capturedId);
                }

                this.ShowAlert(Resource.String.captured_id_title, message);
            });
        }
Ejemplo n.º 2
0
        private static string GetDescriptionForViz(CapturedId result)
        {
            StringBuilder builder = new StringBuilder();

            AppendDescriptionForCapturedId(result, builder);

            VizResult viz = result.Viz;

            AppendField(builder, "Issuing Authority: ", viz.IssuingAuthority);
            AppendField(builder, "Issuing Jurisdiction: ", viz.IssuingJurisdiction);
            AppendField(builder, "Issuing Jurisdiction ISO: ", viz.IssuingJurisdictionIso);
            AppendField(builder, "Additional Name Information: ", viz.AdditionalNameInformation);
            AppendField(builder, "Additional Address Information: ", viz.AdditionalAddressInformation);
            AppendField(builder, "Place of Birth: ", viz.PlaceOfBirth);
            AppendField(builder, "Race: ", viz.Race);
            AppendField(builder, "Religion: ", viz.Religion);
            AppendField(builder, "Profession: ", viz.Profession);
            AppendField(builder, "Marital Status: ", viz.MaritalStatus);
            AppendField(builder, "Residential Status: ", viz.ResidentialStatus);
            AppendField(builder, "Employer: ", viz.Employer);
            AppendField(builder, "Personal Id Number: ", viz.PersonalIdNumber);
            AppendField(builder, "Document Additional Number: ", viz.DocumentAdditionalNumber);

            return(builder.ToString());
        }
Ejemplo n.º 3
0
        private static string GetDescriptionForCapturedId(CapturedId result)
        {
            StringBuilder builder = new StringBuilder();

            AppendDescriptionForCapturedId(result, builder);

            return(builder.ToString());
        }
        private static string GetDescriptionForMrzResult(CapturedId result)
        {
            StringBuilder builder = new StringBuilder();

            AppendDescriptionForCapturedId(result, builder);

            MrzResult mrzResult = result.Mrz;

            AppendField(builder, "Document Code: ", mrzResult.DocumentCode);
            AppendField(builder, "Names Are Truncated: ", mrzResult.NamesAreTruncated ? "Yes" : "No");
            AppendField(builder, "Optional: ", mrzResult.Optional ?? "<empty>");
            AppendField(builder, "Optional 1: ", mrzResult.Optional1 ?? "<empty>");

            return(builder.ToString());
        }
        private static string GetDescriptionForUsUniformedServicesBarcodeResult(CapturedId result)
        {
            StringBuilder builder = new StringBuilder();

            AppendDescriptionForCapturedId(result, builder);

            UsUniformedServicesBarcodeResult ususBarcodeResult = result.UsUniformedServicesBarcode;

            AppendField(builder, "Version: ", ususBarcodeResult.Version);
            AppendField(builder, "Sponsor Flag: ", ususBarcodeResult.SponsorFlag);
            AppendField(builder, "Person Designator Document: ", ususBarcodeResult.PersonDesignatorDocument);
            AppendField(builder, "Family Sequence Number: ", ususBarcodeResult.FamilySequenceNumber);
            AppendField(builder, "Deers Dependent Suffix Code: ", ususBarcodeResult.DeersDependentSuffixCode);
            AppendField(builder, "Deers Dependent Suffix Description: ", ususBarcodeResult.DeersDependentSuffixDescription);
            AppendField(builder, "Height: ", ususBarcodeResult.Height);
            AppendField(builder, "Weight: ", ususBarcodeResult.Weight);
            AppendField(builder, "Hair Color: ", ususBarcodeResult.HairColor);
            AppendField(builder, "Eye Color: ", ususBarcodeResult.EyeColor);
            AppendField(builder, "Direct Care Flag Code: ", ususBarcodeResult.DirectCareFlagCode);
            AppendField(builder, "Direct Care Flag Description: ", ususBarcodeResult.DirectCareFlagDescription);
            AppendField(builder, "Civilian Health Care Flag Code: ", ususBarcodeResult.CivilianHealthCareFlagCode);
            AppendField(builder, "Civilian Health Care Flag Description: ", ususBarcodeResult.CivilianHealthCareFlagDescription);
            AppendField(builder, "Commissary Flag Code: ", ususBarcodeResult.CommissaryFlagCode);
            AppendField(builder, "Commissary Flag Description: ", ususBarcodeResult.CommissaryFlagDescription);
            AppendField(builder, "MWR Flag Code: ", ususBarcodeResult.MwrFlagCode);
            AppendField(builder, "MWR Flag Description: ", ususBarcodeResult.MwrFlagDescription);
            AppendField(builder, "Exchange Flag Code: ", ususBarcodeResult.ExchangeFlagCode);
            AppendField(builder, "Exchange Flag Description: ", ususBarcodeResult.ExchangeFlagDescription);
            AppendField(builder, "Champus Effective Date: ", ususBarcodeResult.ChampusEffectiveDate?.ToString() ?? "<empty>");
            AppendField(builder, "Champus Expiry Date: ", ususBarcodeResult.ChampusExpiryDate?.ToString() ?? "<empty>");
            AppendField(builder, "Form Number: ", ususBarcodeResult.FormNumber);
            AppendField(builder, "Security Code: ", ususBarcodeResult.SecurityCode);
            AppendField(builder, "Service Code: ", ususBarcodeResult.ServiceCode);
            AppendField(builder, "Status Code: ", ususBarcodeResult.StatusCode);
            AppendField(builder, "Status Code Description: ", ususBarcodeResult.StatusCodeDescription);
            AppendField(builder, "Branch Of Service: ", ususBarcodeResult.BranchOfService);
            AppendField(builder, "Rank: ", ususBarcodeResult.Rank);
            AppendField(builder, "Pay Grade: ", ususBarcodeResult.PayGrade ?? "<empty>");
            AppendField(builder, "Sponsor Name: ", ususBarcodeResult.SponsorName ?? "<empty>");
            AppendField(builder, "Sponsor Person Designator Identifier: ", ususBarcodeResult.SponsorPersonDesignatorIdentifier);
            AppendField(builder, "Relationship Code: ", ususBarcodeResult.RelationshipCode ?? "<empty>");
            AppendField(builder, "Relationship Description: ", ususBarcodeResult.RelationshipDescription ?? "<empty>");
            AppendField(builder, "Geneva Convention Category: ", ususBarcodeResult.GenevaConventionCategory ?? "<empty>");
            AppendField(builder, "Blood Type: ", ususBarcodeResult.BloodType ?? "<empty>");

            return(builder.ToString());
        }
Ejemplo n.º 6
0
 private static void AppendDescriptionForCapturedId(CapturedId result, StringBuilder builder)
 {
     AppendField(builder, "Result Type: ", result.CapturedResultType.ToString());
     AppendField(builder, "Document Type: ", result.DocumentType.ToString());
     AppendField(builder, "First Name: ", result.FirstName);
     AppendField(builder, "Last Name: ", result.LastName);
     AppendField(builder, "Full Name: ", result.FullName);
     AppendField(builder, "Sex: ", result.Sex);
     AppendField(builder, "Date of Birth: ", result.DateOfBirth);
     AppendField(builder, "Nationality: ", result.Nationality);
     AppendField(builder, "Address: ", result.Address);
     AppendField(builder, "Issuing Country ISO: ", result.IssuingCountryIso);
     AppendField(builder, "Issuing Country: ", result.IssuingCountry);
     AppendField(builder, "Document Number: ", result.DocumentNumber);
     AppendField(builder, "Date of Expiry: ", result.DateOfExpiry);
     AppendField(builder, "Date of Issue: ", result.DateOfIssue);
 }
Ejemplo n.º 7
0
        private static string GetDescriptionForAamvaBarcodeResult(CapturedId result)
        {
            StringBuilder builder = new StringBuilder();

            AppendDescriptionForCapturedId(result, builder);

            AamvaBarcodeResult aamvaBarcode = result.AamvaBarcode;

            AppendField(builder, "AAMVA Version: ", aamvaBarcode.AamvaVersion);
            AppendField(builder, "Jurisdiction Version: ", aamvaBarcode.JurisdictionVersion);
            AppendField(builder, "IIN: ", aamvaBarcode.IIN);
            AppendField(builder, "Issuing Jurisdiction: ", aamvaBarcode.IssuingJurisdiction);
            AppendField(builder, "Issuing Jurisdiction ISO: ", aamvaBarcode.IssuingJurisdictionIso);
            AppendField(builder, "Eye Color: ", aamvaBarcode.EyeColor);
            AppendField(builder, "Hair Color: ", aamvaBarcode.HairColor);
            AppendField(builder, "Height (inch): ", aamvaBarcode.HeightInch);
            AppendField(builder, "Height (cm): ", aamvaBarcode.HeightCm);
            AppendField(builder, "Weight (lbs): ", aamvaBarcode.WeightLbs);
            AppendField(builder, "Weight (kg): ", aamvaBarcode.WeightKg);
            AppendField(builder, "Place Of Birth: ", aamvaBarcode.PlaceOfBirth);
            AppendField(builder, "Race: ", aamvaBarcode.Race);
            AppendField(builder, "Document Discriminator Number: ", aamvaBarcode.DocumentDiscriminatorNumber);
            AppendField(builder, "Vehicle Class: ", aamvaBarcode.VehicleClass);
            AppendField(builder, "Restrictions Code: ", aamvaBarcode.RestrictionsCode);
            AppendField(builder, "Endorsements Code: ", aamvaBarcode.EndorsementsCode);
            AppendField(builder, "Card Revision Date: ", aamvaBarcode.CardRevisionDate);
            AppendField(builder, "Middle Name: ", aamvaBarcode.MiddleName);
            AppendField(builder, "Driver Name Suffix: ", aamvaBarcode.DriverNameSuffix);
            AppendField(builder, "Driver Name Prefix: ", aamvaBarcode.DriverNamePrefix);
            AppendField(builder, "Last Name Truncation: ", aamvaBarcode.LastNameTruncation);
            AppendField(builder, "First Name Truncation: ", aamvaBarcode.FirstNameTruncation);
            AppendField(builder, "Middle Name Truncation: ", aamvaBarcode.MiddleNameTruncation);
            AppendField(builder, "Alias Family Name: ", aamvaBarcode.AliasFamilyName);
            AppendField(builder, "Alias Given Name: ", aamvaBarcode.AliasGivenName);
            AppendField(builder, "Alias Suffix Name: ", aamvaBarcode.AliasSuffixName);

            return(builder.ToString());
        }
        public void OnIdCaptured(IdCapture idCapture, IdCaptureSession session, IFrameData frameData)
        {
            try
            {
                CapturedId capturedId = session.NewlyCapturedId;

                string message = string.Empty;

                // The recognized fields of the captured Id can vary based on the capturedResultType.
                if (capturedId.CapturedResultType == CapturedResultType.MrzResult)
                {
                    message = GetDescriptionForMrzResult(capturedId);
                }
                else if (capturedId.CapturedResultType == CapturedResultType.AamvaBarcodeResult)
                {
                    message = GetDescriptionForAamvaBarcodeResult(capturedId);
                }
                else if (capturedId.CapturedResultType == CapturedResultType.VizResult)
                {
                    message = GetDescriptionForViz(capturedId);
                }
                else if (capturedId.CapturedResultType == CapturedResultType.UsUniformedServicesBarcodeResult)
                {
                    message = GetDescriptionForUsUniformedServicesBarcodeResult(capturedId);
                }
                else
                {
                    message = GetDescriptionForCapturedId(capturedId);
                }

                this.ShowResult(message);
            }
            finally
            {
                frameData.Dispose();
            }
        }
Ejemplo n.º 9
0
        private async Task <TcpClientTermination> AcceptAsync(
            TcpClient client,
            CapturedId capturedId,
            QbservableServiceOptions options,
            Func <IQbservableProtocol, IParameterizedQbservableProvider> providerFactory,
            CancellationToken cancel)
        {
            Contract.Requires(client != null);
            Contract.Requires(capturedId != null);
            Contract.Requires(options != null);
            Contract.Requires(providerFactory != null);

            ReceivingConnection(idOverride: capturedId.Value);

            // These default settings enable a proper graceful shutdown. DisconnectAsync is used instead of Close on the server-side to request
            // that the client terminates the connection ASAP. This is important because it prevents the server-side socket from going into a
            // TIME_WAIT state rather than the client. The linger option is meant to ensure that any outgoing data, such as an exception, is
            // completely transmitted to the client before the socket terminates. The seconds specified is arbitrary, though chosen to be large
            // enough to transfer any remaining data successfully and small enough to cause a timely disconnection. A custom prepareSocket
            // implementation can always change it via SetSocketOption, if necessary.
            //
            // https://msdn.microsoft.com/en-us/library/system.net.sockets.socket.disconnect(v=vs.110).aspx
            client.LingerState.Enabled    = true;
            client.LingerState.LingerTime = LingerTimeInSeconds;

            prepareSocket(client.Client);

            var watch = Stopwatch.StartNew();

            var localEndPoint  = client.Client.LocalEndPoint;
            var remoteEndPoint = client.Client.RemoteEndPoint;

            var exceptions     = new List <ExceptionDispatchInfo>();
            var shutdownReason = QbservableProtocolShutdownReason.None;

            try
            {
                using (var stream = new NetworkStream(client.Client, ownsSocket: false))
                    using (var protocol = await NegotiateServerAsync(capturedId.Value, stream, formatterFactory(), options, cancel).ConfigureAwait(false))
                    {
                        capturedId.Value = protocol.ClientId;

                        var provider = providerFactory(protocol);

                        ReceivedConnection(idOverride: capturedId.Value);

                        try
                        {
                            await protocol.ExecuteServerAsync(provider).ConfigureAwait(false);
                        }
                        catch (OperationCanceledException)
                        {
                        }
                        catch (Exception ex)
                        {
                            exceptions.Add(ExceptionDispatchInfo.Capture(ex));
                        }
                        finally
                        {
                            shutdownReason = protocol.ShutdownReason;
                        }

                        var protocolExceptions = protocol.Exceptions;

                        if (protocolExceptions != null)
                        {
                            foreach (var exception in protocolExceptions)
                            {
                                exceptions.Add(exception);
                            }
                        }
                    }
            }
            catch (OperationCanceledException)
            {
                shutdownReason = QbservableProtocolShutdownReason.ProtocolNegotiationCanceled;
            }
            catch (Exception ex)
            {
                shutdownReason = QbservableProtocolShutdownReason.ProtocolNegotiationError;

                exceptions.Add(ExceptionDispatchInfo.Capture(ex));
            }

            return(new TcpClientTermination(localEndPoint, remoteEndPoint, watch.Elapsed, shutdownReason, exceptions));
        }
Ejemplo n.º 10
0
        private async Task <WebSocketClientTermination> AcceptAsync(
            HttpListenerWebSocketContext context,
            CapturedId capturedId,
            CapturedShutdownReason capturedShutdownReason,
            QbservableServiceOptions options,
            Func <IQbservableProtocol, IParameterizedQbservableProvider> providerFactory,
            CancellationToken cancel)
        {
            Contract.Requires(context != null);
            Contract.Requires(capturedId != null);
            Contract.Requires(capturedShutdownReason != null);
            Contract.Requires(options != null);
            Contract.Requires(providerFactory != null);

            ReceivingConnection(idOverride: capturedId.Value);

            prepareSocket(context.WebSocket);

            var watch = Stopwatch.StartNew();

            var exceptions     = new List <ExceptionDispatchInfo>();
            var shutdownReason = QbservableProtocolShutdownReason.None;

            try
            {
                using (var stream = new WebSocketStream(context.WebSocket))
                    using (var protocol = await NegotiateServerAsync(capturedId.Value, stream, formatterFactory(), options, cancel).ConfigureAwait(false))
                    {
                        capturedId.Value = protocol.ClientId;

                        var provider = providerFactory(protocol);

                        ReceivedConnection(idOverride: capturedId.Value);

                        try
                        {
                            await protocol.ExecuteServerAsync(provider).ConfigureAwait(false);
                        }
                        catch (OperationCanceledException)
                        {
                        }
                        catch (Exception ex)
                        {
                            exceptions.Add(ExceptionDispatchInfo.Capture(ex));
                        }
                        finally
                        {
                            shutdownReason = protocol.ShutdownReason;
                        }

                        var protocolExceptions = protocol.Exceptions;

                        if (protocolExceptions != null)
                        {
                            foreach (var exception in protocolExceptions)
                            {
                                exceptions.Add(exception);
                            }
                        }
                    }
            }
            catch (OperationCanceledException)
            {
                shutdownReason = QbservableProtocolShutdownReason.ProtocolNegotiationCanceled;
            }
            catch (Exception ex)
            {
                shutdownReason = QbservableProtocolShutdownReason.ProtocolNegotiationError;

                exceptions.Add(ExceptionDispatchInfo.Capture(ex));
            }
            finally
            {
                capturedShutdownReason.Value = shutdownReason;
            }

            return(new WebSocketClientTermination(Uri, context.Origin, watch.Elapsed, shutdownReason, exceptions));
        }