Пример #1
0
 public Boolean VerifyAndCleanAddress(InputStreetAddress inA, out OutputStreetAddress outA)
 {
     /* use settings from config file and process 1 record */
     var iArray = new[] {inA};
     var oArray = VerifyAndCleanAddress(iArray);
     outA = oArray[0];
     return  oArray[0].OkComplete;
 }
        public  DataCleanEvent ValidateAddress(InputStreetAddress input)
        {

            DataCleanEvent e;
            OutputStreetAddress output;
            if (_criteria.ForceValidation == false)
            {
                e = _dataCleanRepository.GetEvent(input.ID);
                if (e != null) return e;
            }

            var b = _dataCleaner.VerifyAndCleanAddress(input, out output);
            e = new DataCleanEvent() {Input = input, DataCleanDate = DateTime.Now, Output = output};
            _dataCleanRepository.SaveEvent(e);
            return e;
        }
 public static InputStreetAddress ToInputStreetAddress(VoucherImportWrapper v)
 {
     var n = new InputStreetAddress();
     n.AddressLine1 = v.AddressLine1;
     n.AddressLine2 = v.AddressLine2;
     n.CompanyName = v.Company;
     n.Country = v.Country;
     n.EmailAddress = v.EmailAddress;
     n.FirstName = v.First;
     n.LastName = v.Last;
     n.City = v.Municipality;
     n.PhoneNumber = v.PhoneNumber;
     n.PostalCode = v.PostalCode;
     n.State = v.Region;
     n.ID = v.ID;
     n.RecordID = v.RecordID;
     return n;
 }
Пример #4
0
            protected override void Execute(Csla.Rules.RuleContext context)
            {
                
                var target = (VoucherEdit)context.Target;
                string firstName = (string)ReadProperty(target, FirstProperty);
                string lastName = (string)ReadProperty(target, LastProperty);
                string companyName = (string)ReadProperty(target, CompanyProperty);
                string address1 = (string)ReadProperty(target, AddressLine1Property);
                string municipality = (string)ReadProperty(target, MunicipalityProperty);
                string postalCode = (string)ReadProperty(target, PostalCodeProperty);

                
                if (!string.IsNullOrEmpty(firstName + lastName + companyName) && !string.IsNullOrEmpty(address1) && !string.IsNullOrEmpty(municipality) && !string.IsNullOrEmpty(postalCode) && target.IsDirty )
                
                {
                        //if a complete address then verify against web service
                        var config = ConfigurationManager.AppSettings;
                    var dataCleanEventFactory =
                        new DataCleanEventFactory(
                            new DataCleaner(config),
                            new DataCleanRespository(), 
                            new DataCleanCriteria()
                            {
                                AutoFixAddressLine1 = false,
                                AutoFixCity = false,
                                AutoFixPostalCode = false,
                                AutoFixState = false,
                                ForceValidation = false
                            });

                    var inputAddress = new InputStreetAddress()
                        {
                            AddressLine1 = target.AddressLine1,
                            AddressLine2 = target.AddressLine2,
                            City = target.Municipality,
                            CompanyName = target.Company,
                            Country = target.Country,
                            FirstName = target.First,
                            FullName = target.FullName,
                            LastName = target.Last,
                            PostalCode = target.PostalCode,
                            State = target.Region
                        };

                    var dataCleanEvent = dataCleanEventFactory.ValidateAddress(inputAddress);

                        if (!dataCleanEvent.Output.OkMailingAddress)
                    {
                            var errStr = string.Empty;
                            foreach (var err in dataCleanEvent.Output.Errors)
                            {
                                context.AddErrorResult(err.LongDescription);
                            }
                            
                        }
                        
                }

            }
 private DataCleanEvent MergeInandOutReq(InputStreetAddress inAddress, DataCleanEvent outEvent)
 {
     var e = new DataCleanEvent
     {
         DataCleanDate = outEvent.DataCleanDate,
         Input = inAddress,
         Output = outEvent.Output
     };
     e.Output.RecordID = e.Input.RecordID;
     return e;
 }
Пример #6
0
        public OutputStreetAddress[] VerifyAndCleanAddress(InputStreetAddress[] inputAddressArray)
        {
            Logger.Info(String.Format("total number of vouchers to clean {0} ", inputAddressArray.Count()));


            var o = new List<OutputStreetAddress>();
            
            int i = 0;
            int arrayOffset = 0;

            if (inputAddressArray.Length <= MaxArraySize)
                return VerifyAndCleanAddressBatch(inputAddressArray).ToArray();
            i = MaxArraySize;
            while (o.Count  < inputAddressArray.Length)
            {
                var l = inputAddressArray.Skip(arrayOffset).Take(i);
                o.AddRange(VerifyAndCleanAddressBatch(l.ToArray()));
                arrayOffset = o.Count() -1 ;
                i = ((inputAddressArray.Length - arrayOffset) < MaxArraySize)
                    ? inputAddressArray.Length - arrayOffset
                    : MaxArraySize;
            }
            return o.ToArray();
        }
Пример #7
0
        protected OutputStreetAddress[] VerifyAndCleanAddressBatch(InputStreetAddress[] inputAddressArray)
        {
            Logger.Info(String.Format("Number of vouchers in batch to clean {0} ", inputAddressArray.Count()));

            if (inputAddressArray.Length > MaxArraySize)
                throw new Exception(String.Format("Too Many Items in Request maximum number is {0}", MaxArraySize));
            _arraysize = inputAddressArray.Length;
            var rra = new RequestRecord[_arraysize];
            var x = 0;
            foreach (var i in inputAddressArray)
                rra[x++] = new RequestRecord(i);
            _req.Records = rra;

            try
            {
                // the transmission results tell us if we got far enough to process records. if it is blank the answer is yes 
                // if we got transmission results we have a broke - connection and or configuration 
                _resp = _action.doContactVerify(_req);

                if (_resp.TransmissionResults.Trim() == "")
                {
                    var o = new OutputStreetAddress[_resp.Records.Length];
                    int i = 0;
                    foreach (var r in _resp.Records)
                    {
                        o[i++] = ResponseToOutputStreetAddressConverter.ProcessResponseRecord(r, _msgDict);
                    }

                    Logger.Info(String.Format("Number of vouchers cleaned {0} ", o.Count()));
                    return o;
                }
                var t = GetTransmissionErrors();
                string exText = null;
                foreach (var a in t)
                    exText += a.ToString() + Environment.NewLine;
                throw new Exception(exText);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                throw;
            }

        }