Пример #1
0
        public bool TestConnection(string surname, string forename, string dateOfBirth, string postcode)
        {
            //SmartConnect.CardManagerClient client = new SmartConnect.CardManagerClient("WSHttpBinding_ICardManager1");
            //client.Endpoint.Address = new EndpointAddress(new Uri("https://warwickshiretest.smartcitizen.net/cardmanager3/cardmanager.svc"), client.Endpoint.Address.Identity, client.Endpoint.Address.Headers);
            //client.ClientCredentials.UserName.UserName = "******";
            //client.ClientCredentials.UserName.Password = "******";
            //client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode =
            //    System.ServiceModel.Security.X509CertificateValidationMode.None;

            CardholderExistsData     data = new CardholderExistsData();
            CardholderExistsResponse response;

            /*data.Surname = "Test";
             * data.Forename = "Andy";
             * data.DateOfBirth = new DateTime(1945,09,05);
             * data.Postcode = "CV34 4TG";*/
            data.Surname     = surname;
            data.Forename    = forename;
            data.DateOfBirth = DateTime.Parse(dateOfBirth);
            data.Postcode    = postcode;
            try
            {
                string serialized = SerializeObj(data);
                response = CMClient.Test.CheckCardholderExists(data);
                if (log.IsDebugEnabled)
                {
                    log.Debug("Cardholder Found:");
                    log.Debug("Cardholder Exists:" + response.RecordExists.ToString());
                    log.Debug("CardholderId:" + response.UniqueMatchIdentifier.CardholderID);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }


            return(true);
        }
Пример #2
0
        public XmlDocument CheckPassHolderData(string surname, string forename, string dateOfBirth, string postcode, string ISRN)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("Entering");
            }
            logParams(surname, forename, dateOfBirth, postcode, ISRN);
            // Call old method for now...
            //CTSelf_WS self = new CTSelf_WS();
            //return self.CheckPassHolderData(surname, forename, dateOfBirth, postcode, ISRN);

            // Redundant code here to be implemented with SmartCitizen switch.

            if (log.IsDebugEnabled)
            {
                log.Debug("Trimming spaces");
            }
            surname     = surname.Trim();
            forename    = forename.Trim();
            dateOfBirth = dateOfBirth.Trim();
            postcode    = postcode.Trim();
            ISRN        = ISRN.Trim();
            if (log.IsDebugEnabled)
            {
                log.Debug("Spaces Trimmed.");
            }

            XmlDocument responseDoc = new XmlDocument();
            //Parse the DoB String
            DateTime parsedDob;

            if (log.IsDebugEnabled)
            {
                log.Debug("Parsing Date:" + dateOfBirth);
            }
            if (DateTime.TryParse(dateOfBirth, out parsedDob) == false)
            {
                throw new ArgumentException("Date: " + dateOfBirth + " is not a valid Date.");
            }
            //Validating a passholder on SC takes five steps if any of the first three fail, return a 'not found' response.:
            //1. Check Cardholder Exists
            try
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Checking Cardholder Exists");
                }
                CardholderExistsData cardholderExistsData = new CardholderExistsData()
                {
                    Surname = surname, Forename = forename.ToCharArray()[0].ToString(), DateOfBirth = parsedDob, Postcode = postcode
                };
                //CardholderExistsData cardholderExistsData = new CardholderExistsData() { Surname = surname, Forename = forename, DateOfBirth = parsedDob, Postcode = postcode };
                //CardholderExistsData cardholderExistsData = new CardholderExistsData() { Surname = surname, Forename = forename, Postcode = postcode };
                //CardholderExistsData cardholderExistsData = new CardholderExistsData() { Surname = surname, DateOfBirth = parsedDob, Postcode = postcode };
                if (log.IsDebugEnabled)
                {
                    log.Debug("Message sent to SmartCitizen:");
                }
                if (log.IsDebugEnabled)
                {
                    log.Debug(SerializeObj(cardholderExistsData));
                }
                CardholderExistsResponse cardholderExistsResponse = _cmClient.CheckCardholderExists(cardholderExistsData);
                if (log.IsDebugEnabled)
                {
                    log.Debug("Response received from SmartCitizen:");
                }
                if (log.IsDebugEnabled)
                {
                    log.Debug(SerializeObj(cardholderExistsResponse));
                }
                //if there is 1/1 matches, .RecordExists will be true. If there are potential matches, .RecordExists will be false, but there will be items in the NonUniquePotentialMatches enum.
                if (!cardholderExistsResponse.RecordExists && cardholderExistsResponse.NonUniquePotentialMatches == null)
                {
                    throw new ScValidationException(ScValidationException.ScValidationReason.CitizenDataNotFound);
                }

                RecordIdentifier cardHolderUniqueId = null;
                //If there is a match where the initial matches, this is where the data will be...
                if (cardholderExistsResponse.UniqueMatchIdentifier != null)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Single Exact Match found. Using Card Holder ID:" + cardholderExistsResponse.UniqueMatchIdentifier.CardholderID);
                    }
                    cardHolderUniqueId = cardholderExistsResponse.UniqueMatchIdentifier;
                }
                else
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("No exact match of initial only. Parsing through NonUnique matches.");
                    }
                    //If there are any NonUniquePotentialMatehes, this is where the data will be.
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Checking through NonUniquePotential matches to try and match data");
                    }

                    if (cardholderExistsResponse.NonUniquePotentialMatches.Length >= 1)
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("Checking to see if the 'forename' on SmartCitizen is simply an initial.");
                        }
                        if (cardholderExistsResponse.NonUniquePotentialMatches.Length == 1 &&
                            cardholderExistsResponse.NonUniquePotentialMatches[0].Forename.Length == 1)
                        {
                            if (log.IsDebugEnabled)
                            {
                                log.Debug("Record is only an initial in SmartCitizen. Returning match.");
                            }
                            cardHolderUniqueId = cardholderExistsResponse.NonUniquePotentialMatches[0].UniqueIdentifier;
                        }
                        else
                        {
                            //Loop through matches to find forename and check that it completely matches.
                            foreach (
                                CardholderCoreDetails nonUniquePotentialMatch in
                                cardholderExistsResponse.NonUniquePotentialMatches)
                            {
                                if (nonUniquePotentialMatch.Forename.ToLower() == forename.ToLower())
                                {
                                    if (log.IsDebugEnabled)
                                    {
                                        log.Debug("Record matched complete forename with ID:" +
                                                  nonUniquePotentialMatch.UniqueIdentifier.CardholderID);
                                    }
                                    cardHolderUniqueId = nonUniquePotentialMatch.UniqueIdentifier;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (cardHolderUniqueId == null)
                {
                    throw new ScValidationException(ScValidationException.ScValidationReason.MultiplePotentialMatches);
                }

                if (log.IsInfoEnabled)
                {
                    log.Info("Cardholder Exists.");
                }
                if (log.IsDebugEnabled)
                {
                    log.Debug("Output of XML Returned:");
                }
                if (log.IsDebugEnabled)
                {
                    log.Debug(SerializeObj(cardholderExistsResponse));
                }
                if (log.IsDebugEnabled)
                {
                    log.Debug("Checking Card Exists");
                }
                // 2. Check Card Exists
                CheckCardData cardData = new CheckCardData()
                {
                    CardIdentifier = ISRN
                };
                CheckCardResponse cardCheckResponse = _cmClient.CheckCard(cardData);
                if (!cardCheckResponse.CardKnown)
                {
                    throw new ScValidationException(ScValidationException.ScValidationReason.CardDataNotFound);
                }

                if (log.IsInfoEnabled)
                {
                    log.Info("Card Exists.");
                }
                if (log.IsDebugEnabled)
                {
                    log.Debug("Output of XML Returned:");
                }
                if (log.IsDebugEnabled)
                {
                    log.Debug(SerializeObj(cardCheckResponse));
                }
                if (log.IsDebugEnabled)
                {
                    log.Debug("Getting complete Citizen data using unique ID:" + cardHolderUniqueId.CardholderID);
                }

                //3. Check Check supplied card number is correct against that person's record
                GetCardholderResponse cardHolderDetails = _cmClient.GetCardholder(new GetCardholderData()
                {
                    CardholderIdentifier = cardHolderUniqueId
                });
                if (log.IsDebugEnabled)
                {
                    log.Debug("Retrieved Customer record from ID. Output of Raw response:");
                }
                if (log.IsDebugEnabled)
                {
                    log.Debug(SerializeObj(cardHolderDetails));
                }
                if (log.IsInfoEnabled)
                {
                    log.Info("Retrieved Customer Record from ID. Checking ISRN on file matches supplied ISRN");
                }
                if (cardHolderDetails.Identifier.CardID != ISRN)
                {
                    throw new ScValidationException(ScValidationException.ScValidationReason.CardNotMatched);
                }

                if (log.IsDebugEnabled)
                {
                    log.Debug("Passholder data and ISRN match. Returning Customer Data.");
                }

                //4. Return pass holder data:
                responseDoc.Load(appDataPath + "CTSelfPassSearchResponse.xml");
                responseDoc.SelectSingleNode("result/recordId").InnerText =
                    cardHolderDetails.Identifier.CardholderID.ToString();
                responseDoc.SelectSingleNode("result/title").InnerText =
                    cardHolderDetails.CitizenData.XPathSelectElement("Services/Service/Item[@name='TITLE']").Value;
                responseDoc.SelectSingleNode("result/foreName").InnerText     = cardHolderDetails.CitizenData.XPathSelectElement("Services/Service/Item[@name='FORENAME']").Value;
                responseDoc.SelectSingleNode("result/resultsFound").InnerText = "1";
                //Reformat Dob to Firmstep pattern
                DateTime doB;
                if (
                    DateTime.TryParse(
                        cardHolderDetails.CitizenData.XPathSelectElement("Services/Service/Item[@name='DOB']").Value,
                        out doB))
                {
                    responseDoc.SelectSingleNode("result/dob").InnerText = doB.ToString("yyyy-MM-dd");
                }


                string passType =
                    cardHolderDetails.CitizenData.XPathSelectElement("Services/Service[@application='ENCTS']")
                    .Attribute("refinement").Value;


                if (passType.ToLower().Contains("older"))
                {
                    responseDoc.SelectSingleNode("result/passType").InnerText = "Age";
                }
                else
                {
                    responseDoc.SelectSingleNode("result/passType").InnerText           = "Disabled";
                    responseDoc.SelectSingleNode("result/disabilityCategory").InnerText = passType[0].ToString();
                    // Determine whether the pass is temporary or permanent. According to Matt Shaw at SmartCitizen, this comes back in the RENEWREFER item. If it is 'Refer' this is temporary, 'Renew' is permanent.
                    switch (
                        cardHolderDetails.CitizenData.XPathSelectElement(
                            "Services/Service[@application='ENCTS']/Item[@name='RENEWREFER']").Value.ToLower())
                    {
                    case "renew":
                        responseDoc.SelectSingleNode("result/disabledPassType").InnerText = "Permanent";
                        break;

                    case "refer":
                        responseDoc.SelectSingleNode("result/disabledPassType").InnerText = "Temporary";
                        break;
                    }
                }

                DateTime expiryDate;
                if (
                    DateTime.TryParse(
                        cardHolderDetails.CitizenData.XPathSelectElement("Services/Service/Item[@name='EXPIRY DATE']")
                        .Value, out expiryDate))
                {
                    responseDoc.SelectSingleNode("result/expiryDate").InnerText = expiryDate.ToString("yyyy-MM-dd");
                }

                //Gender
                switch (cardHolderDetails.CitizenData.XPathSelectElement("Services/Service/Item[@name='GENDER']").Value)
                {
                case "1":
                    responseDoc.SelectSingleNode("result/gender").InnerText = "M";
                    break;

                case "2":
                    responseDoc.SelectSingleNode("result/gender").InnerText = "F";
                    break;

                default:
                    responseDoc.SelectSingleNode("result/gender").InnerText = "U";
                    break;
                }

                if (log.IsDebugEnabled)
                {
                    log.Debug("Determining if the pass record has a photograph");
                }
                {
                    if (cardHolderDetails.CitizenData.XPathSelectElement(
                            "Services/Service[@application='Photo Id']/Item[@name='PHOTO']") != null)
                    {
                        if (
                            cardHolderDetails.CitizenData.XPathSelectElement(
                                "Services/Service[@application='Photo Id']/Item[@name='PHOTO']").Value.Length > 3)
                        // Check the string is a valid image...
                        {
                            try
                            {
                                byte[] imageBytes = Convert.FromBase64String(
                                    cardHolderDetails.CitizenData.XPathSelectElement(
                                        "Services/Service[@application='Photo Id']/Item[@name='PHOTO']").Value);
                                ImageConverter ic = new ImageConverter();
                                ic.ConvertFrom(imageBytes);
                                responseDoc.SelectSingleNode("result/hasPhoto").InnerText = "true";
                            }
                            catch (Exception ex)
                            {
                                if (log.IsInfoEnabled)
                                {
                                    log.Info("Could not convert image string to a valid image");
                                }
                                if (log.IsDebugEnabled)
                                {
                                    log.Debug(ex.Message);
                                }
                            }
                        }
                    }
                }

                responseDoc.SelectSingleNode("result/searchISRN").InnerText     = ISRN;
                responseDoc.SelectSingleNode("result/searchSurname").InnerText  = surname;
                responseDoc.SelectSingleNode("result/searchPostcode").InnerText = postcode;
            }
            catch (Exception ex)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error(ex.Message);
                }
                return(responseDoc);
            }

            if (log.IsDebugEnabled)
            {
                log.Debug("Returning Pass Data:" + responseDoc.OuterXml);
            }
            if (log.IsDebugEnabled)
            {
                log.Debug("Exiting");
            }
            return(responseDoc);
        }