//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)); }
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); }
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)); }