Exemplo n.º 1
0
        public void ReadXmlFileTests()
        {
            SerializeOperaionsXML ser = new SerializeOperaionsXML();

            SearchResult list = ser.ReadXml();

            Assert.IsNotNull(list);
        }
        /// Returns HotelResponse object which contains hotels by city name search
        public HotelResponse GetHotels()
        {
            /*   database code
             * HotelResponse hotelResponse = new HotelResponse();
             * HotelOperations hotelOperations = new HotelOperations();
             * try
             * {
             *     ParseHotel hotelParse = new ParseHotel();
             *     hotelResponse.Hotels = hotelParse.Parse(hotelOperations.SearchByCity(CityName));
             *
             * }
             * catch (Exception exception)
             * {
             *     hotelResponse.HotelStatus.IsFailed = true;
             *     hotelResponse.HotelStatus.Errors.Add(exception.ToString());
             * }
             * return hotelResponse;
             */
            //xml code
            //xml read and parse
            List <Task> tasks = new List <Task>();


            HotelResponse          hotelResponse         = new HotelResponse();
            SerializeOperaionsXML  serializeOperaionsXML = new SerializeOperaionsXML();
            SerializeJsonProvider2 serjson2       = new SerializeJsonProvider2();
            TranslateHotel         translateHotel = new TranslateHotel();

            var xmlReadtask = Task.Run(() => serializeOperaionsXML.ReadXml());

            tasks.Add(xmlReadtask);
            var jsonReadtask = Task.Run(() => serjson2.ReadJson());

            tasks.Add(jsonReadtask);
            Console.WriteLine("waiting for 20 sec ");
            Task.WaitAll(tasks.ToArray(), 20000);

            if (tasks[tasks.IndexOf(xmlReadtask)].IsCompleted && !tasks[tasks.IndexOf(xmlReadtask)].IsFaulted)
            {
                hotelResponse.Hotels = translateHotel.XMLHotel(xmlReadtask.Result);
            }
            if (tasks[tasks.IndexOf(jsonReadtask)].IsCompleted && !tasks[tasks.IndexOf(jsonReadtask)].IsFaulted)
            {
                hotelResponse.Hotels.AddRange(translateHotel.JSONProviderTwoHotel(jsonReadtask.Result));
            }

            return(hotelResponse);
        }