void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e) { switch (e.Mode) { case Microsoft.Win32.PowerModes.StatusChange: case Microsoft.Win32.PowerModes.Suspend: break; case Microsoft.Win32.PowerModes.Resume: lastPosition = null; lastValidPosition = null; userLocation = null; prevLocation = null; myLocation = null; lastPostTime = new DateTime(); lastNMEATime = new DateTime(); break; } }
private bool getImakoko() { WebRequest req = WebRequest.Create("http://imakoko-gps.appspot.com/api/latest?user=all"); try { WebResponse res = req.GetResponse(); Encoding enc = Encoding.GetEncoding("UTF-8"); using (Stream st = res.GetResponseStream()) using (StreamReader sr = new StreamReader(st, enc)) { myLocation = null; Dictionary<string, Dictionary<string, string>> userInfo = new Dictionary<string, Dictionary<string, string>>(); string ret = sr.ReadToEnd(); if (ret.StartsWith("(")) { ret = ret.Substring(1); } if (ret.EndsWith(")")) { ret = ret.Substring(0, ret.Length - 1); } prevLocation = userLocation; userLocation = JsonConvert.DeserializeObject<LatestPoints>(ret); if (userLocation.result == 1) { myLocation = findUser(userLocation.points, Properties.Settings.Default.User); //myLocation = userLocation.points[0]; #if DEBUG myLocation = new ImakokoPoint(); myLocation.lat = 35.65722; myLocation.lon = 139.27204; myLocation.dir = 0.0; #endif if (myLocation != null) { // 近接情報から自分を取り除く List<ImakokoPoint> list = new List<ImakokoPoint>(userLocation.points); list.Remove(myLocation); userLocation.points = list.ToArray(); foreach (ImakokoPoint p in userLocation.points) { Util.GetKyoriHoui(myLocation.lon, myLocation.lat, p.lon, p.lat, out p.distance, out p.direction); p.n_direction = (p.direction - p.dir + 360.0) % 360.0; Dictionary<string, string> GPSData = new Dictionary<string, string>(); GPSData.Add(USER, p.user); GPSData.Add(LATI, p.lat.HasValue ? p.lat.ToString() : "0.0"); GPSData.Add(LONG, p.lon.HasValue ? p.lon.ToString() : "0.0"); GPSData.Add(HEADING, p.dir.HasValue ? p.dir.ToString() : "0.0"); GPSData.Add(DIST, p.distance.ToString()); GPSData.Add(N_DIRECTION, p.direction.ToString()); GPSData.Add(DIRECTION, p.n_direction.ToString()); userInfo.Add(p.user, GPSData); } foreach (PluginBase p in pluginManager.LoadedPlugins) { ImacocoNowPlugin plugin = (ImacocoNowPlugin)p; ThreadStart ts = () => { plugin.OnGetUserLocation(userInfo); }; Thread t = new Thread(ts); t.IsBackground = true; t.Start(); } SetStatusText("近接ユーザーの情報を取得しました"); updateAlert = true; return true; } } } } catch (Exception e) { SetStatusText("近接ユーザー情報の取得に失敗しました"); } return false; }