Пример #1
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();
        }
Пример #2
0
        public string GetRentalPdf(SearchFilters searchFilters)
        {
            DateTime sDate = (DateTime)searchFilters.PuDate;
            DateTime eDate = searchFilters.DoDate;

            Rental s = new Rental(Const.Locations[searchFilters.Location].Rental);

            s.SetTime(searchFilters.PuTime.Hours, searchFilters.PuTime.Minutes, searchFilters.DoTime.Hours, 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.GetMap(reader.ExtractOffers(reader.GetResultGroup(Thread.CurrentThread.Name)));
                });
                thread.Name = links.ElementAt(index);
                threads.Add(thread);
                thread.Start();
            }

            //check if thread 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(300);
                        break;
                    }
                }
                if (completed == 0)
                {
                    break;
                }
            }
            return(CreatePdf(s, offerMap));
        }
Пример #3
0
        public string GetRentalExcel(SearchFilters searchFilters)
        {
            DateTime sDate = (DateTime)searchFilters.PuDate;
            DateTime eDate = searchFilters.DoDate;

            Rental s = new Rental(Const.Locations[searchFilters.Location].Rental);

            s.SetTime(searchFilters.PuTime.Hours, searchFilters.PuTime.Minutes, searchFilters.DoTime.Hours, 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.GetMap(reader.ExtractOffers(reader.GetResultGroup(Thread.CurrentThread.Name)));
                });
                thread.Name = links.ElementAt(index);
                threads.Add(thread);
                thread.Start();
            }

            //check if thread 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(300);
                        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))
            {
                // Getting the complete workbook...
                ExcelWorkbook myWorkbook = excelPackage.Workbook;

                // Getting the worksheet by its name...
                ExcelWorksheet myWorksheet = myWorkbook.Worksheets["Rates"];
                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))
                            {
                                if (map[item.Name] != null)
                                {
                                    map[item.Name].SetSiteName(link);
                                    offers.Add(map[item.Name]);
                                }
                            }
                            else
                            {
                                offers.Add(new JOffer());
                            }
                        }
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Map count 0");
                    }

                    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         = 35;
                    }
                    ++rowNum;
                }
                excelPackage.Save();// Saving the change...
                return(filename);
            }
        }