public PlaceDetails(String name, String placeid, String address, String phonenumber, float rating, ListOpeningHours opening_hours, List <String> types, String url) { this.name = name; this.placeid = placeid; this.address = address; this.phonenumber = phonenumber; this.rating = rating; this.opening_hours = opening_hours; this.types = types; this.url = url; }
public ItineraryData(RadarSearch radarsearch, PlaceDetails placedetails, PlacePhoto placephoto, String city = "", String country = "") { opening_hours = new ListOpeningHours(); latitude = radarsearch.latitude; longitude = radarsearch.longitude; this.city = city; this.country = country; name = placedetails.name; placeid = placedetails.placeid; address = placedetails.address; phonenumber = placedetails.phonenumber; rating = placedetails.rating; opening_hours = placedetails.opening_hours; byte idx = 0; Sunday = (opening_hours[idx].close == "0" && opening_hours[idx].open == "0") ? "Closed" : opening_hours[idx].open + "-" + opening_hours[idx].close; idx++; Monday = (opening_hours[idx].close == "0" && opening_hours[idx].open == "0") ? "Closed" : opening_hours[idx].open + "-" + opening_hours[idx].close; idx++; Tuesday = (opening_hours[idx].close == "0" && opening_hours[idx].open == "0") ? "Closed" : opening_hours[idx].open + "-" + opening_hours[idx].close; idx++; Wednesday = (opening_hours[idx].close == "0" && opening_hours[idx].open == "0") ? "Closed" : opening_hours[idx].open + "-" + opening_hours[idx].close; idx++; Thursday = (opening_hours[idx].close == "0" && opening_hours[idx].open == "0") ? "Closed" : opening_hours[idx].open + "-" + opening_hours[idx].close; idx++; Friday = (opening_hours[idx].close == "0" && opening_hours[idx].open == "0") ? "Closed" : opening_hours[idx].open + "-" + opening_hours[idx].close; idx++; Saturday = (opening_hours[idx].close == "0" && opening_hours[idx].open == "0") ? "Closed" : opening_hours[idx].open + "-" + opening_hours[idx].close; idx++; types = ""; foreach (String type in placedetails.types) { types += type + ";"; } url = placedetails.url; photo_name = placephoto.name; extension = placephoto.extension; dir = placephoto.dir; this.timestamp = DateTime.Now.ToString(); }
private async void button1_ClickAsync(object sender, EventArgs e) { if (MessageBox.Show("Are You Sure to Proceed ?", "Confirmation Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (checkInput()) { progressBar1.Value = 0; richTextBox1.Clear(); arrRadarSearch.Clear(); arrPlaceDetails.Clear(); arrData.Clear(); country = cbCountry.Text; city = cbCity.Text; latitude = cbCity.SelectedValue.ToString().Split(';')[0]; longitude = cbCity.SelectedValue.ToString().Split(';')[1]; types = getAllTypes(); radius = ((int)numericUpDownRadius.Value).ToString(); offset = (int)numericUpDownOffset.Value; limit = (int)numericUpDownLimit.Value; try { groupBox1.Enabled = false; //radarsearch //lookingForConnectionAsync(); String radarsearchResult = await doTaskAsync(RadarSearch.getRadarSearchQuery(apiKey, latitude, longitude, types, radius)); String dir_log = getDateTimeDirectory(); String dir = dir_log + "_" + city + "_" + types + "_" + radius; Directory.CreateDirectory("Images/" + dir); JObject radarsearchJSON = JObject.Parse(radarsearchResult); String radarsearchStatus = (String)radarsearchJSON["status"]; if (radarsearchStatus == "OK") { JArray radarsearchArray = (JArray)radarsearchJSON["results"]; if (checkBox1.Checked && offset == 0) { progressBar1.Maximum = radarsearchArray.Count * 3; } else { progressBar1.Maximum = radarsearchArray.Count + (limit * 2); } foreach (var item in radarsearchArray) { String radarsearchLatitude = (String)item["geometry"]["location"]["lat"]; String radarsearchLongitude = (String)item["geometry"]["location"]["lng"]; String radarsearchPlaceID = (String)item["place_id"]; RadarSearch radarsearchObj = new RadarSearch(radarsearchLatitude, radarsearchLongitude, radarsearchPlaceID); arrRadarSearch.Add(radarsearchObj); //Console.WriteLine(radarsearchObj); progressBar1.Value++; } richTextBox1.AppendText("Starting fetch " + arrRadarSearch.Count.ToString() + " items...\n"); //placedetails byte idx = 0; if (checkBox1.Checked) { limit = radarsearchArray.Count - offset; } String placedetailsStatus = ""; do { if (offset + limit > radarsearchArray.Count) { richTextBox1.AppendText("Invalid Input...\n"); break; } String placeid = arrRadarSearch[idx + offset].place_id; //lookingForConnectionAsync(); String placedetailsResult = await doTaskAsync(PlaceDetails.getPlaceDetailsQuery(apiKey, placeid)); JObject placedetailsJSON = JObject.Parse(placedetailsResult); placedetailsStatus = (String)placedetailsJSON["status"]; if (placedetailsStatus == "OK") { try { String placedetailsName = (String)placedetailsJSON["result"]["name"]; String placedetailsAddress = (String)placedetailsJSON["result"]["formatted_address"]; String placedetailsPhoneNumber = (String)placedetailsJSON["result"]["international_phone_number"]; String placedetailsURL = (String)placedetailsJSON["result"]["url"]; float placedetailsRating = (float)placedetailsJSON["result"]["rating"]; JArray placedetailsOpeningHoursArray; ListOpeningHours placedetailsOpeningHours = new ListOpeningHours(); try { placedetailsOpeningHoursArray = (JArray)placedetailsJSON["result"]["opening_hours"]["periods"]; foreach (var openinghours in placedetailsOpeningHoursArray) { int day_index = (int)openinghours["close"]["day"]; String close = (String)openinghours["close"]["time"]; String open = (String)openinghours["open"]["time"]; placedetailsOpeningHours[day_index].close = close; placedetailsOpeningHours[day_index].open = open; } } catch (Exception) { placedetailsOpeningHoursArray = null; for (int i = 0; i < placedetailsOpeningHours.Count; i++) { placedetailsOpeningHours[i].open = "0000"; placedetailsOpeningHours[i].close = "2400"; } } JArray placedetailsArray = (JArray)placedetailsJSON["result"]["types"]; List <String> placedetailsTypes = new List <String>(); foreach (var type in placedetailsArray) { placedetailsTypes.Add((String)type); } //photo String photoreference; PlacePhoto photo; try { photoreference = (String)placedetailsJSON["result"]["photos"][0]["photo_reference"]; //Console.WriteLine(photoreference); //Console.WriteLine(PlacePhoto.getPlacePhotoQuery(apiKey, photoreference)); photo = new PlacePhoto(placeid, dir); String save_directory = "Images/" + dir + "/" + placeid + ".jpg"; //lookingForConnectionAsync(); PlacePhoto.SaveImage(apiKey, photoreference, save_directory); progressBar1.Value++; } catch (Exception) { Console.WriteLine("No Photos"); photo = new PlacePhoto(); progressBar1.Value++; } PlaceDetails placedetailsOBJ = new PlaceDetails(placedetailsName, placeid, placedetailsAddress, placedetailsPhoneNumber, placedetailsRating, placedetailsOpeningHours, placedetailsTypes, placedetailsURL); arrPlaceDetails.Add(placedetailsOBJ); //Console.WriteLine(placedetailsOBJ); ItineraryData data = new ItineraryData(arrRadarSearch[idx + offset], placedetailsOBJ, photo, city, country); arrData.Add(data); richTextBox1.AppendText("Success fetch item - " + (idx + offset).ToString() + "...\n"); } catch (Exception ex) { Console.WriteLine(ex.Message); //progressBar1.Value++; richTextBox1.AppendText("Fail fetch item - " + (idx + offset).ToString() + "...\n"); } } else { break; } progressBar1.Value++; ++idx; } while (idx < limit && placedetailsStatus == "OK"); } //foreach (ItineraryData item in arrData) //{ // Console.WriteLine(item); //} exportCSV("Result/" + dir + ".csv", arrData); savetoLog(dir_log, city, country, arrRadarSearch.Count.ToString(), offset, limit, types, radius); progressBar1.Value = progressBar1.Maximum; richTextBox1.AppendText("Done...\n"); System.Media.SoundPlayer player = new System.Media.SoundPlayer("alert.wav"); player.Play(); } catch (Exception) { richTextBox1.AppendText("No Connection...\n"); } } else { MessageBox.Show("Invalid Input!!"); } } groupBox1.Enabled = true; setListBoxTypes(); }
private async void button1_ClickAsync(object sender, EventArgs e) { button1.Enabled = false; String placeid = textBox1.Text; textBox1.Clear(); richTextBox1.Clear(); //lookingForConnectionAsync(); String placedetailsResult = await doTaskAsync(PlaceDetails.getPlaceDetailsQuery(apiKey, placeid)); JObject placedetailsJSON = JObject.Parse(placedetailsResult); String placedetailsStatus = (String)placedetailsJSON["status"]; if (placedetailsStatus == "OK") { try { String placedetailsName = (String)placedetailsJSON["result"]["name"]; String placedetailsAddress = (String)placedetailsJSON["result"]["formatted_address"]; String placedetailsPhoneNumber = (String)placedetailsJSON["result"]["international_phone_number"]; String placedetailsURL = (String)placedetailsJSON["result"]["url"]; float placedetailsRating = (float)placedetailsJSON["result"]["rating"]; JArray placedetailsOpeningHoursArray; ListOpeningHours placedetailsOpeningHours = new ListOpeningHours(); try { placedetailsOpeningHoursArray = (JArray)placedetailsJSON["result"]["opening_hours"]["periods"]; foreach (var openinghours in placedetailsOpeningHoursArray) { int day_index = (int)openinghours["close"]["day"]; String close = (String)openinghours["close"]["time"]; String open = (String)openinghours["open"]["time"]; placedetailsOpeningHours[day_index].close = close; placedetailsOpeningHours[day_index].open = open; } } catch (Exception) { placedetailsOpeningHoursArray = null; for (int i = 0; i < placedetailsOpeningHours.Count; i++) { placedetailsOpeningHours[i].open = "0000"; placedetailsOpeningHours[i].close = "2400"; } } JArray placedetailsArray = (JArray)placedetailsJSON["result"]["types"]; List <String> placedetailsTypes = new List <String>(); foreach (var type in placedetailsArray) { placedetailsTypes.Add((String)type); } PlaceDetails placedetailsOBJ = new PlaceDetails(placedetailsName, placeid, placedetailsAddress, placedetailsPhoneNumber, placedetailsRating, placedetailsOpeningHours, placedetailsTypes, placedetailsURL); richTextBox1.AppendText(placedetailsOBJ.ToString()); } catch (Exception ex) { Console.WriteLine(ex.Message); } } button1.Enabled = true; }