-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
930 additions
and
744 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Net; | ||
using System.Timers; | ||
|
||
namespace EarthquakeLibrary.EEW | ||
{ | ||
/// <summary> | ||
/// 緊急地震速報の監視を行うクラスです。 | ||
/// </summary> | ||
public class EewWatcher | ||
{ | ||
/// <summary> | ||
/// EEWWatcherを初期化します。 | ||
/// </summary> | ||
/// <param name="interval">取得間隔(秒)</param> | ||
public EewWatcher(ushort interval) : this() | ||
=> _timer.Interval = interval * 1000; | ||
/// <summary> | ||
/// EEWWatcherを初期化します。 | ||
/// </summary> | ||
public EewWatcher() | ||
{ | ||
_timer = new Timer { Interval = 1000 }; | ||
SetTime(); | ||
_timer.Elapsed += Timer_Elapsed; | ||
} | ||
|
||
private Timer _timer; | ||
private int _c; | ||
private DateTime _time; | ||
private void Timer_Elapsed(object sender, EventArgs e) | ||
{ | ||
if (_c == (int)_timer.Interval / 5 * 18) SetTime(); | ||
|
||
_c++; | ||
} | ||
/// <summary> | ||
/// 時刻を修正します。 | ||
/// </summary> | ||
public void SetTime() | ||
{ | ||
try | ||
{ | ||
_time = DateTime.ParseExact(new WebClient().DownloadString("http://ntp-a1.nict.go.jp/cgi-bin/time"), | ||
"ddd MMM dd HH:mm:ss yyyy JST\n", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None); | ||
} | ||
catch | ||
{ | ||
// Do nothing now | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.