Example #1
0
        static Dictionary<string, AddressHolder> LoadDropPoints(int Carrier, string Country)
        {
            int countErrors = 0;
            XmlNode errorNode = null;

            Logger.Debug(String.Format("Start to loop the zip codes from {0}", Country));
            Dictionary<string, AddressHolder> dirAddresses = new Dictionary<string, AddressHolder>();
            DropPointService Importer = new DropPointService();
            string[] ziplist =Importer.GetDistinctZipFromCountry(Country, 15).ToArray();
            if(Country.Equals("DK")){
                ziplist = zipcodes;
            }
            foreach (String zip in ziplist)
            {
                try
                {
                    XmlNode xDoc = MakeRequest(CreateRequest(zip));

                    if (xDoc != null)
                    {
                        Console.Write("run " + zip);
                        Console.Write("no found " + xDoc.SelectNodes("//PakkeshopData").Count);
                        foreach (XmlNode d in xDoc.SelectNodes("//PakkeshopData"))
                        {

                            AddressHolder ah = XmlConvertToAddress(d, Carrier);
                            if (!dirAddresses.ContainsKey(ah.DropPointCode))
                            {
                                ah.ZipCode.Add(zip);

                                dirAddresses.Add(ah.DropPointCode, ah);

                            }
                            else
                            {
                                ah = dirAddresses[ah.DropPointCode];
                                if (!ah.Zip.Contains(zip))
                                {
                                    ah.ZipCode.Add(zip);

                                }

                            }

                        }

                    }

                }

                catch (Exception ex)
                {

                    String xml = "";
                    if (errorNode != null)
                        xml = errorNode.OuterXml;
                    String error = string.Format("Import of drop points from carrierId = {0} and Country = {1} go following error: {2}  xml: {3}", Carrier, Country, ex.Message, xml);
                    Logger.Error(error);
                    countErrors++;

                }

            }
            Logger.Debug(String.Format("Number of DropPoint: {0} in Country: {1} and Errors :{2}", dirAddresses.Count, Country, countErrors));
            return dirAddresses;
        }
Example #2
0
        private static void Execute(String Country, int Carrier)
        {
            Dictionary<string, AddressHolder> dirAddress = LoadDropPoints(Carrier, Country);
            if (dirAddress != null && dirAddress.Count > 0)
            {
                DropPointService Importer = new DropPointService();
                int no_records = Importer.CountExistingDropPoints(Country, Carrier);

                if (Math.Abs(no_records - dirAddress.Count) < no_records * 0.1 || no_records == 0 || forceReload)
                {
                    foreach (AddressHolder address in dirAddress.Values)
                    {

                        Importer.AddDropPoint(address);
                        Console.Write("take zip : " + address.Zip);

                    }
                    Logger.Debug(String.Format("Update database with {0} records", Importer.CountListDropPoints()));
                    Importer.SaveToDatabase();
                    Logger.Debug("Update done");

                }
                else
                {
                    String error = String.Format("Import of drop points from carrierId = {0} and Country = {1} is not runned due to mismatch between existing data {2} records and imported data {3} records", Carrier, Country, no_records, dirAddress.Count);
                    Logger.Error(error);
                    SendErrorMail("Import of drop points not executed", error);
                }
            }
        }