Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
kichi2004 committed Sep 3, 2021
1 parent 6167ffd commit 2f0a136
Show file tree
Hide file tree
Showing 14 changed files with 930 additions and 744 deletions.
37 changes: 3 additions & 34 deletions EarthquakeLibrary/EEW/EEW.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using EarthquakeLibrary.Core;

namespace EarthquakeLibrary.EEW
Expand Down Expand Up @@ -160,42 +158,13 @@ public enum WarningType
/// 警報
/// </summary>
Warning = 1,
Emergency = 2,
/// <summary>
/// 特別警報
/// </summary>
EmergencyWarning = Warning | Emergency
}

public class EewWatcher
{
/// <summary>
/// EEWWatcherを初期化します。
/// </summary>
/// <param name="interval">取得間隔(秒)</param>
public EewWatcher(ushort interval) : this()
=> this._timer.Interval = interval * 1000;
Emergency = 2,
/// <summary>
/// EEWWatcherを初期化します。
/// 特別警報(警報)
/// </summary>
public EewWatcher()
{
this._timer = new System.Timers.Timer() { Interval = 1000 };
this.SetTime();
this._timer.Elapsed += this.Timer_Elapsed;
}

private System.Timers.Timer _timer;
private int _c;
private DateTime _time;
private void Timer_Elapsed(object sender, EventArgs e)
{
if (this._c == (int)this._timer.Interval / 5 * 18) this.SetTime();

this._c++;
}
public void SetTime()
=> this._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);

EmergencyWarning = Warning | Emergency
}
}
54 changes: 54 additions & 0 deletions EarthquakeLibrary/EEW/EewWatcher.cs
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
}
}
}
}
9 changes: 9 additions & 0 deletions EarthquakeLibrary/EarthquakeLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\EarthquakeLibrary.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="HtmlAgilityPack, Version=1.5.1.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
Expand All @@ -42,6 +43,7 @@
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -50,6 +52,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="EEW\EewWatcher.cs" />
<Compile Include="Information\EarthquakeInformation.cs" />
<Compile Include="Information\InformationType.cs" />
<Compile Include="Information\MessageType.cs" />
<Compile Include="Information\NewEarthquakeInformation.cs" />
<Compile Include="Information\OldEarthquakeInformation.cs" />
<Compile Include="LibCore.cs" />
<Compile Include="EEW\EEW.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Information\Information.cs" />
Expand Down
14 changes: 3 additions & 11 deletions EarthquakeLibrary/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EarthquakeLibrary.Extensions
{
Expand Down Expand Up @@ -38,18 +35,13 @@ public static void ForEachReverse<T>(this IList<T> self, Action<T, int> act)
/// </summary>
public static IEnumerable<T> GetDistinct<T>(this IList<T> self)
{
var uniqueList = new List<T>();
var uniqueList = new HashSet<T>();

foreach (var n in self)
{
if (uniqueList.Contains(n))
{
if (!uniqueList.Add(n))
yield return n;
}
else
{
uniqueList.Add(n);
}

}
}
}
Expand Down
Loading

0 comments on commit 2f0a136

Please sign in to comment.