public void Update(Station_Info obj)
 {
     throw new NotImplementedException();
 }
Пример #2
0
 public void Update(Station_Info obj)
 {
     DbSet.Update(obj);
 }
Пример #3
0
        static void Main(string[] args)
        {
            /*using (var client = new WebClient())
             * {
             *  client.Encoding = Encoding.UTF8;
             *  client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
             *  string html, jsonData;
             *  html = client.DownloadString("https://www.google.com/maps/place/%E5%B0%9A%E9%87%8E%E9%90%B5%E6%9D%BF%E7%87%92/@24.6983017,121.7687086,17z/data=!4m5!3m4!1s0x3467e5cb9754e03f:0x1ed5780d41ffdc12!8m2!3d24.6983017!4d121.7687086?hl=zh-Hant");
             *  int index = html.IndexOf("cacheResponse", html.IndexOf("cacheResponse") + 1);
             *  jsonData = "{\"j\":" + html.Substring(index + 14, html.IndexOf("]);", index) - index - 13) + "}";
             *  //html = client.DownloadString("https://www.google.com/maps/uv?pb=!1s0x3467e5b508667ee3%3A0x8d8393c944e4556e&hl=zh-Hant");
             *  //int index = html.IndexOf("window.APP_OPTIONS=") + 19;
             *  //jsonData = "{\"j\":" + html.Substring(index, html.IndexOf(";window.JS_VERSION=") - index) + "}";
             *  HtmlDocument document = new HtmlDocument();
             *  document.LoadHtml(html);
             *  HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("/html[1]/body[1]/jsl[1]/div[3]/div[8]/div[8]/div[1]/div[2]/div[1]/div[1]/div[1]/button[1]");
             *  foreach (HtmlNode node in nodes)
             *  {
             *      Console.WriteLine(node.InnerText);
             *  }
             * }*/

            /* Get stations' infomation */
            string[] stations = File.ReadAllLines(@"C:\Users\Jack-PC\Desktop\Railway.txt");
            string   area     = "Unknown";
            string   stations_data;
            int      API_COUNT = 0;

            using (var client = new WebClient())
            {
                client.Encoding = Encoding.UTF8;
                client.Headers.Add("content-type", "application/json");
                stations_data = client.DownloadString(Firebase_URL + "Stations" + "/.json");
            }

            foreach (string s in stations)
            {
                if (s[0].Equals('['))
                {
                    area = s.Split('[')[1].Split(']')[0];
                }
                else
                {
                    try
                    {
                        JObject.Parse(stations_data)[area][s]["Name"].ToString();
                    }
                    catch
                    {
                        using (var client = new WebClient())
                        {
                            client.Encoding = Encoding.UTF8;
                            client.Headers.Add("content-type", "application/json");
                            string response = safeHttpRequest(client, Geocoding_URL + "address=" + HttpUtility.UrlEncode(s + "車站") + "&key=" + API_KEY[API_COUNT]);
                            if (JObject.Parse(response)["status"].ToString().Equals("OK"))
                            {
                                Station_Info info = new Station_Info();
                                info.Area      = area;
                                info.Latitude  = JObject.Parse(response)["results"][0]["geometry"]["location"]["lat"].ToString();
                                info.Longitude = JObject.Parse(response)["results"][0]["geometry"]["location"]["lng"].ToString();
                                info.Name      = s;
                                info.ID        = JObject.Parse(response)["results"][0]["place_id"].ToString();
                                response       = client.UploadString(Firebase_URL + "Stations/" + area + "/" + s + "/.json", "PUT", JsonConvert.SerializeObject(info));
                            }
                        }
                    }
                }
            }


            /* Get stores near stations */

            /*using (var client = new WebClient())
             * {
             *  client.Encoding = Encoding.UTF8;
             *  client.Headers.Add("content-type", "application/json");
             *  stations_data = client.DownloadString(Firebase_URL + "Stations" + "/.json");
             * }
             * stations = File.ReadAllLines(@"C:\Users\Jack-PC\Desktop\place.txt");
             * area = "Unknown";
             * using (var client = new WebClient())
             * {
             *  client.Encoding = Encoding.UTF8;
             *  client.Headers.Add("content-type", "application/json");
             *
             *  List<string> storeList = new List<string>();
             *  string response = safeHttpRequest(client, Firebase_URL + "Stores/.json");
             *  try
             *  {
             *      Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(response);
             *      foreach (var value in values)
             *          storeList.Add(value.Key);
             *  }
             *  catch
             *  {
             *
             *  }
             *  foreach (string s in stations)
             *  {
             *      Console.WriteLine();
             *      Console.Write(s);
             *      if (s[0].Equals('['))
             *      {
             *          area = s.Split('[')[1].Split(']')[0];
             *      }
             *      else
             *      {
             *
             *          string pagetoken = "";
             *          for (double k = 0.5; k <= radius / 1000; k += 0.3)
             *              for (int j = 0; j < 9; j++)
             *                  do
             *                  {
             *                      Console.Write(".");
             *                      LatLng latLng = CalculateLatLng(JObject.Parse(stations_data)[area][s]["Latitude"].ToString(), JObject.Parse(stations_data)[area][s]["Longitude"].ToString(), k, direction[j]);
             *                      string location = latLng.Latitude + "," + latLng.Longitude;
             *                      if (pagetoken.Equals(""))
             *                      {
             *                          response = safeHttpRequest(client, Place_Url + "location=" + location + "&rankby=distance" + "&type=restaurant" + "&key=" + API_KEY[API_COUNT]);
             *                          while (JObject.Parse(response)["status"].ToString().Equals("OVER_QUERY_LIMIT"))
             *                          {
             *                              //Console.Write("Please enter new API Key:");
             *                              //API_KEY = Console.ReadLine();
             *                              API_COUNT++;
             *                              if (API_COUNT == 10)
             *                              {
             *                                  Console.WriteLine("NO API KEY!!");
             *                                  Console.Read();
             *                              }
             *                              response = safeHttpRequest(client, Place_Url + "location=" + location + "&rankby=distance" + "&type=restaurant" + "&key=" + API_KEY[API_COUNT]);
             *                          }
             *                      }
             *                      else
             *                      {
             *                          response = safeHttpRequest(client, Place_Url + "pagetoken=" + pagetoken + "&key=" + API_KEY[API_COUNT]);
             *                          while (JObject.Parse(response)["status"].ToString().Equals("OVER_QUERY_LIMIT") || JObject.Parse(response)["status"].ToString().Equals("INVALID_REQUEST"))
             *                          {
             *                              if (JObject.Parse(response)["status"].ToString().Equals("OVER_QUERY_LIMIT"))
             *                              {
             *                                  //Console.Write("Please enter new API Key:");
             *                                  //API_KEY = Console.ReadLine();
             *                                  API_COUNT++;
             *                                  if (API_COUNT == 10)
             *                                  {
             *                                      Console.WriteLine("NO API KEY!!");
             *                                      Console.Read();
             *                                  }
             *                                  response = safeHttpRequest(client, Place_Url + "pagetoken=" + pagetoken + "&key=" + API_KEY[API_COUNT]);
             *                              }
             *                              else
             *                              {
             *                                  Thread.Sleep(1000);
             *                                  response = safeHttpRequest(client, Place_Url + "pagetoken=" + pagetoken + "&key=" + API_KEY[API_COUNT]);
             *                              }
             *                          }
             *                      }
             *                      if (JObject.Parse(response)["status"].ToString().Equals("OK"))
             *                      {
             *                          try { pagetoken = JObject.Parse(response)["next_page_token"].ToString(); }
             *                          catch { pagetoken = ""; }
             *                          foreach (JObject item in JArray.Parse(JObject.Parse(response)["results"].ToString()))
             *                          {
             *                              Store_Info info = new Store_Info();
             *                              info.Near_Station = s;
             *                              info.Latitude = item["geometry"]["location"]["lat"].ToString();
             *                              info.Longitude = item["geometry"]["location"]["lng"].ToString();
             *                              if (Math.Abs(distanceEarth(double.Parse(info.Latitude), double.Parse(info.Longitude),
             *                                              double.Parse(JObject.Parse(stations_data)[area][s]["Latitude"].ToString()),
             *                                              double.Parse(JObject.Parse(stations_data)[area][s]["Longitude"].ToString())) * 1000) > radius)
             *                              {
             *                                  pagetoken = "";
             *                                  break;
             *                              }
             *                              info.Name = item["name"].ToString();
             *                              info.ID = item["place_id"].ToString();
             *                              JArray types = JArray.Parse(item["types"].ToString());
             *                              info.Types = new string[types.Count];
             *                              for (int i = 0; i < types.Count; i++)
             *                                  info.Types[i] = types[i].ToString();
             *
             *                              if (!isStoreExist(storeList, info.ID))
             *                              {
             *                                  client.UploadString(Firebase_URL + "Stores/" + "Stations/" + s + "/" + info.ID + "/.json", "PUT", "0");
             *                                  client.UploadString(Firebase_URL + "Stores/" + info.ID + "/.json", "PUT", JsonConvert.SerializeObject(info));
             *                                  storeList.Add(info.ID);
             *                              }
             *                          }
             *                      }
             *                      else if (JObject.Parse(response)["status"].ToString().Equals("ZERO_RESULTS"))
             *                      {
             *                          Console.WriteLine(JObject.Parse(response)["status"].ToString() + ":" + s);
             *                      }
             *                      else
             *                      {
             *                          Console.WriteLine(JObject.Parse(response)["status"].ToString());
             *                          Console.ReadLine();
             *                      }
             *                  } while (!pagetoken.Equals(""));
             *      }
             *  }
             *
             * }*/
            using (var client = new WebClient())
            {
                client.Encoding = Encoding.UTF8;
                client.Headers.Add("content-type", "application/json");
                string response = safeHttpRequest(client, Firebase_URL + "Stores/.json");
                try
                {
                    Dictionary <string, object> values = JsonConvert.DeserializeObject <Dictionary <string, object> >(response);
                    foreach (var value in values)
                    {
                        if (!value.Key.ToString().Equals("Stations"))
                        {
                            string Lat = "", Lng = "";
                            Dictionary <string, object> info = JsonConvert.DeserializeObject <Dictionary <string, object> >(value.Value.ToString());
                            foreach (var i in info)
                            {
                                if (i.Key.ToString().Equals("Latitude"))
                                {
                                    Lat = i.Value.ToString();
                                }
                                else if (i.Key.ToString().Equals("Longitude"))
                                {
                                    Lng = i.Value.ToString();
                                }
                            }
                            response = safeHttpRequest(client, Geocoding_URL + "latlng=" + Lat + "," + Lng + "&language=en&key=" + API_KEY[API_COUNT]);
                            while (JObject.Parse(response)["status"].ToString().Equals("OVER_QUERY_LIMIT"))
                            {
                                API_COUNT++;
                                if (API_COUNT == 24)
                                {
                                    Console.WriteLine("NO API KEY!!");
                                    Console.Read();
                                }
                                response = safeHttpRequest(client, Geocoding_URL + "latlng=" + Lat + "," + Lng + "&language=en&key=" + API_KEY[API_COUNT]);
                            }
                            JObject r       = JObject.Parse(response);
                            JArray  address = JArray.Parse(r["results"].ToString());
                            client.UploadString(Firebase_URL + "Stores/" + value.Key.ToString() + "/Address_en/.json", "PUT", "\"" + address[0]["formatted_address"].ToString() + "\"");
                        }
                    }
                }
                catch
                {
                }
            }


            Console.ReadLine();
        }
Пример #4
0
 public void Add(Station_Info obj)
 {
     Db.Add(obj);
 }