Example #1
0
        public AuthenticationResults ParseAndSave_ForBackfill(string xml, long serviceLogId, DateTime serviceLogInsertDate, string key)
        {
            var result = new AuthenticationResults();
            ProcessConfigResponseType r = GetRequestFromXml(xml);

            result.Parse(r);

            SaveAmlData(key, serviceLogId, serviceLogInsertDate, result);

            return(result);
        }
Example #2
0
        //-----------------------------------------------------------------------------------
        public AuthenticationResults Authenticate(string foreName, string middleName, string surname, string gender, DateTime birth, string addressLine1, string addressLine2, string addressLine3, string town, string county, string postCode, int customerId, bool checkInCacheOnly = false, string xmlForDebug = "")
        {
            var result = new AuthenticationResults();

            string key = string.Format("{0}_{1}_{2}_{3}", foreName, middleName, surname, postCode);

            if (string.IsNullOrEmpty(xmlForDebug))
            {
                Log.DebugFormat("Checking key '{0}' in cache...", key);

                var cachedResult = amlResultsRepository.GetAll().FirstOrDefault(aml => aml.LookupKey == key && aml.IsActive);

                bool foundInCache = cachedResult != null;
                if (foundInCache)
                {
                    Log.DebugFormat("Will use cache value for key '{0}'", key);

                    result.AuthenticationIndex = cachedResult.AuthenticationIndex;
                    result.AuthIndexText       = cachedResult.AuthIndexText;
                    result.NumPrimDataItems    = cachedResult.NumPrimDataItems;
                    result.NumPrimDataSources  = cachedResult.NumPrimDataSources;
                    result.NumSecDataItems     = cachedResult.NumSecDataItems;
                    result.StartDateOldestPrim = cachedResult.StartDateOldestPrim;
                    result.StartDateOldestSec  = cachedResult.StartDateOldestSec;
                    result.ReturnedHRPCount    = cachedResult.HighRiskRules.Count;
                    if (result.ReturnedHRPCount == 0)
                    {
                        result.ReturnedHRP = new ReturnedHRPType[0];
                    }
                    else
                    {
                        result.ReturnedHRP = cachedResult.HighRiskRules.Select(rule => new ReturnedHRPType {
                            HighRiskPolRuleID = rule.RuleId, HighRiskPolRuleText = rule.RuleText
                        }).ToArray();
                    }
                    result.Error = cachedResult.Error;

                    return(result);
                }
            }
            if (checkInCacheOnly)
            {
                return(null);
            }

            Log.DebugFormat("Request AML A service for key '{0}'", key);
            var address = FillAddress(addressLine1, addressLine2, addressLine3, town, county, postCode);
            //AML A
            var execRequest = new ExecuteRequestType
            {
                EIHHeader = new EIHHeaderType
                {
                    ClientUser  = "******",
                    ReferenceId = "1234"
                },
                ResponseType           = ResponseType.Detail,
                ProcessConfigReference = new ProcessConfigReferenceType {
                    ItemElementName = ItemChoiceType.ProcessConfigName, Item = "AML A"
                },
                Consent      = ConsentType.Yes,
                PersonalData = new PersonalDataType
                {
                    Name = new NameType
                    {
                        Forename   = foreName,
                        MiddleName = middleName,
                        Surname    = surname
                    },
                    BirthDate          = birth,
                    BirthDateSpecified = true,
                    GenderSpecified    = true
                },
                Addresses = new[] { address }
            };

            execRequest.PersonalData.Gender = gender == "M" ? GenderType.Male : GenderType.Female;

            try
            {
                ProcessConfigResponseType r;
                if (string.IsNullOrEmpty(xmlForDebug))
                {
                    try
                    {
                        r = MakeRequest(execRequest);
                    }
                    catch (AuthenticationException exception)
                    {
                        result.Error = exception.Message;
                        return(result);
                    }
                }
                else
                {
                    r = GetRequestFromXml(xmlForDebug);
                }
                var res = Utils.WriteLog(execRequest, r, ExperianServiceType.Aml, customerId);

                result.Parse(r);

                SaveAmlData(key, res.ServiceLog.Id, res.ServiceLog.InsertDate, result);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
                result.Error = exception.Message;
                Utils.WriteLog(execRequest, string.Format("Excecption: {0}", exception.Message), ExperianServiceType.Aml, customerId);
            }

            return(result);
        }
Example #3
0
        private void SaveAmlData(string key, long serviceLogId, DateTime serviceLogInsertDate, AuthenticationResults result)
        {
            var amlResult = new AmlResults
            {
                LookupKey              = key,
                ServiceLogId           = serviceLogId,
                Created                = serviceLogInsertDate,
                AuthenticationDecision = result.AuthenticationDecision,
                AuthenticationIndex    = result.AuthenticationIndex,
                AuthIndexText          = result.AuthIndexText,
                NumPrimDataItems       = result.NumPrimDataItems,
                NumPrimDataSources     = result.NumPrimDataSources,
                NumSecDataItems        = result.NumSecDataItems,
                StartDateOldestPrim    = result.StartDateOldestPrim,
                StartDateOldestSec     = result.StartDateOldestSec,
                Error    = result.Error,
                IsActive = true
            };

            if (result.ReturnedHRP != null && result.ReturnedHRP.Length != 0)
            {
                List <AmlResultsHighRiskRules> highRiskRules =
                    result.ReturnedHRP.Select(
                        rule =>
                        new AmlResultsHighRiskRules
                {
                    RuleId    = rule.HighRiskPolRuleID,
                    RuleText  = rule.HighRiskPolRuleText,
                    AmlResult = amlResult
                }).ToList();

                amlResult.HighRiskRules = new HashedSet <AmlResultsHighRiskRules>(highRiskRules);
            }

            var prevActiveAmlResult = amlResultsRepository.GetAll().FirstOrDefault(x => x.LookupKey == key && x.IsActive);

            if (prevActiveAmlResult != null)
            {
                prevActiveAmlResult.IsActive = false;
                amlResultsRepository.SaveOrUpdate(prevActiveAmlResult);
            }

            amlResultsRepository.SaveOrUpdate(amlResult);
        }
Example #4
0
        //-----------------------------------------------------------------------------------
        public AuthenticationResults AuthenticateForcedWithCustomAddress(string foreName, string middleName, string surname, string gender, DateTime birth,
                                                                         string houseNumber, string houseName, string street, string district,
                                                                         string town, string county, string postCode, int customerId, string xmlForDebug = "")
        {
            var result = new AuthenticationResults();

            string key = string.Format("{0}_{1}_{2}_{3}", foreName, middleName, surname, postCode);

            Log.DebugFormat("Request AML A service for key '{0}'", key);
            var address = new AddressType
            {
                AddressStatus = AddressStatusType.Current,
                TypeOfAddress = TypeOfAddressType.UK,
                AddressDetail = new AddressDetailType
                {
                    PostCode    = postCode,
                    HouseNumber = houseNumber,
                    HouseName   = houseName,
                    Address1    = street,
                    Address2    = district,
                    Address3    = town,
                    Address4    = county,
                    Country     = "GB"
                }
            };

            //AML A
            var execRequest = new ExecuteRequestType
            {
                EIHHeader = new EIHHeaderType
                {
                    ClientUser  = "******",
                    ReferenceId = "1234"
                },
                ResponseType           = ResponseType.Detail,
                ProcessConfigReference = new ProcessConfigReferenceType {
                    ItemElementName = ItemChoiceType.ProcessConfigName, Item = "AML A"
                },
                Consent      = ConsentType.Yes,
                PersonalData = new PersonalDataType
                {
                    Name = new NameType
                    {
                        Forename   = foreName,
                        MiddleName = middleName,
                        Surname    = surname
                    },
                    BirthDate          = birth,
                    BirthDateSpecified = true,
                    GenderSpecified    = true
                },
                Addresses = new[] { address }
            };

            execRequest.PersonalData.Gender = gender == "M" ? GenderType.Male : GenderType.Female;

            bool hadException           = false;
            ProcessConfigResponseType r = null;

            try
            {
                if (string.IsNullOrEmpty(xmlForDebug))
                {
                    try
                    {
                        r = MakeRequest(execRequest);
                    }
                    catch (AuthenticationException exception)
                    {
                        result.Error = exception.Message;
                        return(result);
                    }
                }
                else
                {
                    r = GetRequestFromXml(xmlForDebug);
                }
            }
            catch (Exception exception)
            {
                hadException = true;
                Log.Error(exception);
                result.Error = exception.Message;
            }

            try
            {
                if (hadException)
                {
                    Utils.WriteLog(execRequest, string.Format("Excecption: {0}", result.Error), ExperianServiceType.Aml, customerId);
                }
                else
                {
                    var writelog = Utils.WriteLog(execRequest, r, ExperianServiceType.Aml, customerId);

                    result.Parse(r);

                    SaveAmlData(key, writelog.ServiceLog.Id, writelog.ServiceLog.InsertDate, result);
                }
            }
            catch (Exception e)
            {
                Log.ErrorFormat("Exception while saving aml data: {0}", e);
            }

            return(result);
        }