Exemplo n.º 1
0
        //public string GetVehicleRentPdf(SearchFilters searchFilters)
        //{
        //    DateTime sDate = searchFilters.PuDate.AddHours(searchFilters.PuTime.Hours).AddMinutes(searchFilters.PuTime.Minutes);
        //    DateTime eDate = searchFilters.DoDate.AddHours(searchFilters.DoTime.Hours).AddMinutes(searchFilters.DoTime.Minutes);

        //    Vehicle s = new Vehicle(Const.Locations[searchFilters.Location].EcoBoking);
        //    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>());


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

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

        //    }

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

        public string GetCarTrawlerExcel(SearchFilters searchFilters)
        {
            DateTime sDate = searchFilters.PuDate.AddHours(searchFilters.PuTime.Hours).AddMinutes(searchFilters.PuTime.Minutes);
            DateTime eDate = searchFilters.DoDate.AddHours(searchFilters.DoTime.Hours).AddMinutes(searchFilters.DoTime.Minutes);

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

            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.GetNorwRates(Thread.CurrentThread.Name));
                });
                thread.Name = links.ElementAt(index);
                threads.Add(thread);
                thread.Start();
            }

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

            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);
        }
Exemplo n.º 2
0
        public Dictionary <string, Dictionary <string, JOffer> > GetCarTrawlerRates(SearchFilters searchFilters)
        {
            searchFilters.PuDate = searchFilters.PuDate.AddHours(searchFilters.PuTime.Hours).AddMinutes(searchFilters.PuTime.Minutes);
            searchFilters.DoDate = searchFilters.DoDate.AddHours(searchFilters.DoTime.Hours).AddMinutes(searchFilters.DoTime.Minutes);

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

            s.InitDate(searchFilters.PuDate);



            int numOfIterations = (searchFilters.DoDate - searchFilters.PuDate).Days;

            List <string> links     = s.GetGeneratedLinksByDate(searchFilters.PuDate, searchFilters.DoDate);
            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.GetNorwRates(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;
                }
            }

            return(offerMap);
        }