예제 #1
0
        //public string GetEconomyPdf(SearchFilters searchFilters)
        //{
        //    DateTime sDate = searchFilters.PuDate;
        //    DateTime eDate = searchFilters.DoDate;
        //    EcoBookings s = new EcoBookings(Const.Locations[searchFilters.Location].EcoBoking);
        //    JSourceReader s1 = new JSourceReader();
        //    sDate = sDate.AddDays(1);
        //    eDate = eDate.AddDays(1);
        //    s.InitDate(sDate);

        //    int numOfIterations = (eDate - sDate).Days;

        //    List<string> links = s.GetGeneratedLinksByDate(sDate, eDate);
        //    List<JOffer> minOffers = new List<JOffer>();
        //    Dictionary<string, Dictionary<string, JOffer>> offerMap = new Dictionary<string, Dictionary<string, JOffer>>();

        //    for (int i = 0; i < links.Count; i++)
        //        offerMap.Add(links[i], new Dictionary<string, JOffer>());

        //    List<Thread> threads = new List<Thread>();
        //    for (int i = 0; i < links.Count; i++)
        //    {
        //        JSourceReader reader = new JSourceReader();
        //        List<JOffer> offers = reader.GetBookingOffers(
        //                            reader.GetBookingsSource(links.ElementAt(i), links.ElementAt(i)));

        //        offerMap[links.ElementAt(i)] =
        //                reader.GetMapNorwegian(offers);

        //    }
        //    return CreatePdf(s, offerMap);
        //}

        public string GetExpediaPdf(SearchFilters searchFilters)
        {
            DateTime      sDate = searchFilters.PuDate;
            DateTime      eDate = searchFilters.DoDate;
            Expedia       s     = new Expedia(Const.Locations[searchFilters.Location].EcoBoking);
            JSourceReader s1    = new JSourceReader();

            sDate = sDate.AddDays(1);
            eDate = eDate.AddDays(1);
            s.InitDate(sDate);

            int numOfIterations = (eDate - sDate).Days;

            List <string> links     = s.GetGeneratedLinksByDate(sDate, eDate);
            List <JOffer> minOffers = new List <JOffer>();
            Dictionary <string, Dictionary <string, JOffer> > offerMap = new Dictionary <string, Dictionary <string, JOffer> >();

            for (int i = 0; i < links.Count; i++)
            {
                offerMap.Add(links[i], new Dictionary <string, JOffer>());
            }

            List <Thread> threads = new List <Thread>();

            for (int i = 0; i < links.Count; i++)
            {
                JSourceReader reader = new JSourceReader();
                List <JOffer> offers = reader.GetExpediaOffers(
                    reader.GetExpediaSource(links.ElementAt(i)));

                offerMap[links.ElementAt(i)] =
                    reader.GetMapNorwegian(offers);
            }
            return(CreatePdf(s, offerMap));
        }
예제 #2
0
        public void CalculateTime()
        {
            DateTime           now    = DateTime.Now;
            JSourceReader      reader = new JSourceReader();
            HtmlNodeCollection str    = reader.GetResultGroup("http://www.rentalcars.com/SearchResults.do?enabler=&country=Latvija&doYear=2017&distance=10&ftsEntry=1472408&city=Ryga&driverage=on&doFiltering=false&dropCity=Ryga&dropFtsType=A&ftsAutocomplete=Ryga+Oro+Uostas+(RIX)%2c+Ryga%2c+Latvija&driversAge=30&dropFtsAutocomplete=Ryga+Oro+Uostas+(RIX)%2c+Ryga%2c+Latvija&dropFtsLocationName=Ryga+Oro+Uostas+(RIX)&fromLocChoose=true&filterTo=1000&dropLocationName=Ryga+Oro+Uostas+(RIX)&dropCountryCode=lv&ftsType=A&doMinute=0&countryCode=lv&puYear=2017&puSameAsDo=on&ftsLocationSearch=24281&dropFtsSearch=L&locationName=Ryga+Oro+Uostas+(RIX)&puMinute=0&ftsInput=riga&doDay=1&searchType=&filterFrom=0&coordinates=56.9236%2c23.9711&puMonth=5&dropLocation=24281&dropFtsInput=riga&doHour=10&dropCountry=Latvija&dropCoordinates=56.9236%2c23.9711&ftsLocationName=Ryga+Oro+Uostas+(RIX)&ftsSearch=L&puDay=31&dropFtsLocationSearch=24281&puHour=10&location=24281&dropFtsEntry=1472408&doMonth=6&filterName=CarCategorisationSupplierFilter");

            Console.WriteLine("duration " + (DateTime.Now - now).TotalSeconds);
            Console.ReadLine();
        }
예제 #3
0
        public string GetScannerExcel(SearchFilters searchFilters)
        {
            Scanner  s     = new Scanner(Const.Locations[searchFilters.Location].CarScanner);
            DateTime sDate = searchFilters.PuDate.AddHours(searchFilters.PuTime.Hours).AddMinutes(searchFilters.PuTime.Minutes);
            DateTime eDate = searchFilters.DoDate.AddHours(searchFilters.DoTime.Hours).AddMinutes(searchFilters.DoTime.Minutes);

            s.InitDate(sDate);
            int numOfIterations = (eDate - sDate).Days;

            List <string> links     = s.GetGeneratedLinksByDate(sDate, eDate);
            List <JOffer> minOffers = new List <JOffer>();
            Dictionary <string, Dictionary <string, JOffer> > offerMap = new Dictionary <string, Dictionary <string, JOffer> >();

            for (int i = 0; i < links.Count; i++)
            {
                offerMap.Add(links[i], new Dictionary <string, JOffer>());
            }

            List <Thread> threads = new List <Thread>();

            for (int index = 0; index < links.Count; index++)//--- Start all threads

            {
                Thread thread = new Thread(() =>
                {
                    JSourceReader reader = new JSourceReader();
                    offerMap[Thread.CurrentThread.Name == null ?
                             links.ElementAt(0) :
                             Thread.CurrentThread.Name] =
                        reader.GetMapNorwegian(reader.GetScannerRates(Thread.CurrentThread.Name));
                });
                thread.Name = links.ElementAt(index);
                threads.Add(thread);
                thread.Start();
            }

            //check if threads has done//--- Start all threads
            bool allCompleted = false;

            while (!allCompleted)
            {
                int completed = links.Count;
                for (int i = 0; i < links.Count; i++)
                {
                    if (!threads.ElementAt(i).IsAlive)
                    {
                        --completed;
                    }
                    else
                    {
                        Thread.Sleep(100);
                        break;
                    }
                }
                if (completed == 0)
                {
                    break;
                }
            }


            FileInfo template = new FileInfo(Server.MapPath(@"\Content\ExcelPackageTemplate.xlsx"));
            string   filename = @"\excel\" + s.GetTitle() + s.GetPuMonth() + "-" + s.GetPuDay() + s.GetCity() + ".xlsx";
            FileInfo newFile  = new FileInfo(Server.MapPath(filename));

            using (ExcelPackage excelPackage = new ExcelPackage(newFile, template))
            {
                ExcelWorkbook  myWorkbook  = excelPackage.Workbook;          // Getting the complete workbook...
                ExcelWorksheet myWorksheet = myWorkbook.Worksheets["Rates"]; // Getting the worksheet by its name...

                int      rowNum = 2;
                DateTime doDate = new DateTime(Convert.ToInt32(s.GetPuYear()), Convert.ToInt32(s.GetPuMonth()), Convert.ToInt32(s.GetPuDay()));

                foreach (string link in links)
                {
                    Dictionary <string, JOffer> map = offerMap[link];
                    List <JOffer> offers            = new List <JOffer>();
                    if (map.Count > 0)
                    {
                        foreach (Category item in Const.categories)
                        {
                            if ((map.ContainsKey(item.Name)) && (map[item.Name] != null))
                            {
                                map[item.Name].SetSiteName(link);
                                offers.Add(map[item.Name]);
                            }
                            else
                            {
                                offers.Add(new JOffer());
                            }
                        }
                    }
                    myWorksheet.Cells[rowNum, 1].Value = s.GetPuMonth() + "-" + s.GetPuDay() + "/" + doDate.AddDays(rowNum - 1).Day + "\n" + (rowNum - 1);
                    for (int i = 0; i < offers.Count; i++)
                    {
                        myWorksheet.Cells[rowNum, i + 2].Value = offers.ElementAt(i).GetOffer();
                        myWorksheet.Row(rowNum).Height         = 45;
                    }
                    ++rowNum;
                }
                excelPackage.Save();// Saving the change...
            }
            return(filename);
        }
예제 #4
0
        public string GetScannerPdf(SearchFilters searchFilters)
        {
            Trawler  s     = new Trawler(Const.Locations[searchFilters.Location].CarScanner);
            DateTime sDate = searchFilters.PuDate.AddHours(searchFilters.PuTime.Hours).AddMinutes(searchFilters.PuTime.Minutes);
            DateTime eDate = searchFilters.DoDate.AddHours(searchFilters.DoTime.Hours).AddMinutes(searchFilters.DoTime.Minutes);

            s.InitDate(sDate);


            int numOfIterations = (eDate - sDate).Days;

            List <string> links     = s.GetGeneratedLinksByDate(sDate, eDate);
            List <JOffer> minOffers = new List <JOffer>();

            Dictionary <string, Dictionary <string, JOffer> > offerMap = new Dictionary <string, Dictionary <string, JOffer> >();

            for (int i = 0; i < links.Count; i++)
            {
                offerMap.Add(links[i], new Dictionary <string, JOffer>());
            }


            List <Thread> threads = new List <Thread>();

            //--- Start all threads
            for (int index = 0; index < links.Count; index++)
            {
                Thread thread = new Thread(() =>
                {
                    JSourceReader reader = new JSourceReader();
                    offerMap[Thread.CurrentThread.Name == null ?
                             links.ElementAt(0) :
                             Thread.CurrentThread.Name] =
                        reader.GetMapNorwegian(reader.GetScannerRates(Thread.CurrentThread.Name));
                });
                thread.Name = links.ElementAt(index);
                threads.Add(thread);
                thread.Start();
            }

            //check if threads has done
            Boolean allCompleted = false;

            while (!allCompleted)
            {
                int completed = links.Count;
                for (int i = 0; i < links.Count; i++)
                {
                    if (!threads.ElementAt(i).IsAlive)
                    {
                        --completed;
                    }
                    else
                    {
                        Thread.Sleep(100);
                        break;
                    }
                }
                if (completed == 0)
                {
                    break;
                }
            }
            s.SetTitle("scanner");
            return(CreatePdf(s, offerMap));
        }