Esempio n. 1
0
        static void Main(string[] args)
        {
            IDictionary <string, string> CheckExists = new Dictionary <string, string>();

            OTAHotelServiceLogic          hotelServiceLogic = new OTAHotelServiceLogic();
            IList <HotelRateRlanCacheDTO> changeItems       = hotelServiceLogic.GetHotelRatePlanCacheChange("2");

            changeItems = changeItems.OrderBy(a => a.HotelCode).ToList();
            foreach (var item in changeItems)
            {
                string hotelId = string.Empty;
                if (CheckExists.ContainsKey(item.HotelCode))
                {
                    hotelId = CheckExists[item.HotelCode];
                }
                else
                {
                    DB_HotelInitilizeLogic logic = new DB_HotelInitilizeLogic();
                    hotelId = logic.GetHotelIdByCode(Convert.ToInt32(item.HotelCode));
                    CheckExists.Add(item.HotelCode, hotelId);
                }
                if (!string.IsNullOrEmpty(hotelId))
                {
                    DB_PriceInitilizeLogic priceLogic = new DB_PriceInitilizeLogic();
                    // string responseXml = hotelServiceLogic.GetHotelRatePlan(item.HotelCode, item.RatePlanCode);
                    priceLogic.Process(hotelId, item.HotelCode, item.RatePlanCode, item.Start, item.End, false);
                    Console.WriteLine(item.HotelCode + "," + item.RatePlanCode);
                }
            }

            Console.Read();
        }
        public void Process(string hotelId, string hotelCode, string ratePlanCode = "", DateTime?startDate = null, DateTime?endDate = null, bool isInitilize = true)
        {
            OTAHotelServiceLogic hotelService = new OTAHotelServiceLogic();
            bool ifNeedUpdateRatePlan         = true;

            //全量获取数据
            if (isInitilize)
            {
                startDate = DateTime.Now;
                endDate   = DateTime.Now.AddDays(28);

                //获取90天数据,分四次获取
                for (int i = 0; i < 4; i++)
                {
                    string xml = hotelService.GetHotelRatePlan(hotelCode, startDate.Value, endDate.Value);
                    ProcessPrice(hotelId, hotelCode, xml, ifNeedUpdateRatePlan, isInitilize);

                    ifNeedUpdateRatePlan = false;

                    startDate = endDate.Value.AddDays(1);
                    endDate   = startDate.Value.AddDays(28);
                }
            }
            else
            {
                ifNeedUpdateRatePlan = false;
                //Update Rate plan Cache
                string xml = hotelService.GetHotelRatePlan(hotelCode, startDate.Value, endDate.Value, ratePlanCode);
                ProcessPrice(hotelId, hotelCode, xml, ifNeedUpdateRatePlan, isInitilize);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            logger.Info("Program Started");

            IList <string> hotelCodeList = new List <string>();

            OTAHotelServiceLogic hotelService = new OTAHotelServiceLogic();
            string hotelXml = hotelService.GetHotelByAreaId(1);


            XmlDocument doc = new XmlDocument();

            doc.LoadXml(hotelXml);

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            nsmgr.AddNamespace("c", "http://www.opentravel.org/OTA/2003/05");

            var nodes  = doc.SelectNodes("c:Property", nsmgr);
            var rsNode = doc.SelectSingleNode("Response/HotelResponse/c:OTA_HotelSearchRS/c:Properties", nsmgr);


            foreach (XmlNode item in rsNode.ChildNodes)
            {
                hotelCodeList.Add(item.Attributes["HotelCode"].Value);
            }

            doc = null;

            Parallel.ForEach(hotelCodeList, obj =>
            {
                Rego:
                try
                {
                    DB_HotelInitilizeLogic hotelLogic = new DB_HotelInitilizeLogic();
                    hotelLogic.ProcessHotel(obj);
                }
                catch (Exception e)
                {
                    logger.Fatal(e.ToString());
                    if (e.Message.ToLower().Contains("timeout"))
                    {
                        goto Rego;
                    }
                }
            });

            //for (int i = 0; i < hotelCodeList.Count; i++)
            //{
            //    DB_HotelInitilizeLogic hotelLogic = new DB_HotelInitilizeLogic();
            //       hotelLogic.ProcessHotel(hotelCodeList[i]);
            //}
        }
Esempio n. 4
0
        public void ProcessHotel(string hotelCode)
        {
            ////read data api
            OTAHotelServiceLogic hotelService = new OTAHotelServiceLogic();

            //string hotelXml = hotelService.GetHotelByAreaId(1);


            //File.AppendAllText("D:\\ttuut.xml", hotelXml);

            //sample xml
            // string hotelXml = System.IO.File.ReadAllText("real.xml");



            //IList<string> hotelCodeList = new List<string>();


            //XmlDocument doc = new XmlDocument();
            //doc.Load(@"D:\\ttuut.xml");

            //XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            //nsmgr.AddNamespace("c", "http://www.opentravel.org/OTA/2003/05");

            //var nodes = doc.SelectNodes("c:Property", nsmgr);
            //var rsNode = doc.SelectSingleNode("Response/HotelResponse/c:OTA_HotelSearchRS/c:Properties", nsmgr);


            //foreach (XmlNode item in rsNode.ChildNodes)
            //{
            //    hotelCodeList.Add(item.Attributes["HotelCode"].Value);
            //}

            //doc = null;


            // Parallel.ForEach(hotelCodeList, obj => {


            logger.Info("Start to Read Data From API ,HotelCode :" + hotelCode);
            var hotelXml = hotelService.GetHotelDetailsByID(hotelCode);

            logger.Info(" Read Data From API ,HotelCode :" + hotelCode + ", Finished");
            //var hotelXml = hotelService.GetHotelDetailsByID("625");
            var root = XRoot.Parse(hotelXml);

            if (hotelXml == null)
            {
                throw new Exception("timeout");
            }


            var hotels = root.Response.HotelResponse[0].OTA_HotelDescriptiveInfoRS.HotelDescriptiveContents[0].HotelDescriptiveContent;


            foreach (var item in hotels)
            {
                TransactionOptions transactionOption = new TransactionOptions();
                transactionOption.Timeout        = new TimeSpan(0, 0, 600000); //no time out
                transactionOption.IsolationLevel = IsolationLevel.ReadUncommitted;
                using (TransactionScope tran = new TransactionScope(TransactionScopeOption.RequiresNew, transactionOption))
                {
                    LoggerHelper(item.HotelCode, "Start to Process");
                    //var hotelCode = item.HotelCode;
                    var hotelId = InsertHotel(item);

                    var hotelinfo = item.HotelInfo[0];

                    if (hotelinfo != null)
                    {
                        var SEG = hotelinfo.CategoryCodes;
                        InsertSEG(hotelId, hotelCode, SEG);

                        var Position = hotelinfo.Position;
                        InsertPosition(hotelId, hotelCode, Position);

                        var Address = hotelinfo.Address;
                        InsertAddress(hotelId, hotelCode, Address);

                        var Services = hotelinfo.Services;
                        InsertServices(hotelId, hotelCode, Services);
                    }

                    var facility = item.FacilityInfo[0];
                    if (facility != null)
                    {
                        var GuestRooms = facility.GuestRooms;
                        InsertGuestRoom(hotelId, hotelCode, GuestRooms);
                    }

                    var policies = item.Policies;
                    InsertPolicies(hotelId, hotelCode, policies);

                    var areas = item.AreaInfo;
                    InsertAreaInfo(hotelId, hotelCode, areas);

                    var affiliation = item.AffiliationInfo;
                    InsertAffiliation(hotelId, hotelCode, affiliation);

                    var multimediadescriptions = item.MultimediaDescriptions;
                    InsertMultimediaDescription(hotelId, hotelCode, multimediadescriptions);


                    // InsertHotelTapExtension(hotelCode, item);
                    DB_PriceInitilizeLogic priceLogic = new DB_PriceInitilizeLogic();
                    priceLogic.Process(hotelId, hotelCode, isInitilize: true);
                    tran.Complete();

                    LoggerHelper(hotelCode, item.HotelName + "Finished");
                }
            }

            //});

            LoggerHelper(null, "ALL Hotel Competed");
            // Console.Read();
        }