timer.ElapseTime(1000);\r
}\r
}\r
+\r
+ /// <summary>\r
+ /// リピートを中断・再開する\r
+ /// </summary>\r
+ [TestMethod]\r
+ public void SuspendRepeat()\r
+ {\r
+ var timer = new MockTimer();\r
+ Message result = null;\r
+ var manager =\r
+ new NotificationManager((t, b, n) => { result = new Message {Title = t, Body = b, Name = n}; }, timer);\r
+ var expected = new Message {Title = "遠征が終わりました", Body = "防空射撃演習", Name = "遠征終了"};\r
+ while (true)\r
+ {\r
+ switch (timer.Elapsed)\r
+ {\r
+ case 0:\r
+ manager.Enqueue("遠征終了", "防空射撃演習", 10);\r
+ PAssert.That(() => expected.Equals(result));\r
+ break;\r
+ case 1000:\r
+ manager.SuspendRepeat();\r
+ break;\r
+ case 11000:\r
+ manager.ResumeRepeat();\r
+ break;\r
+ case 12000:\r
+ PAssert.That(() => expected.Equals(result));\r
+ return;\r
+ default:\r
+ PAssert.That(() => result == null, timer.Elapsed.ToString());\r
+ break;\r
+ }\r
+ result = null;\r
+ timer.ElapseTime(1000);\r
+ }\r
+ }\r
}\r
}
\ No newline at end of file
_notificationQueue.StopRepeat(key);\r
}\r
\r
+ public void SuspendRepeat()\r
+ {\r
+ _notificationQueue.SuspendRepeat();\r
+ }\r
+\r
+ public void ResumeRepeat()\r
+ {\r
+ _notificationQueue.ResumeRepeat();\r
+ }\r
+\r
public string KeyToName(string key) => NotificationConfig.KeyToName(key);\r
\r
private class NotificationConfig\r
private readonly ITimer _timer;\r
private readonly NotificationConfig _notificationConfig = new NotificationConfig();\r
private DateTime _lastRing;\r
+ private bool _suspend;\r
\r
public NotificationQueue(Action<string, string, string> ring, ITimer timer = null)\r
{\r
_queue.RemoveAll(n => n.Key.Substring(0, 4) == key.Substring(0, 4) && n.Schedule != default);\r
}\r
\r
+ public void SuspendRepeat()\r
+ {\r
+ _suspend = true;\r
+ }\r
+\r
+ public void ResumeRepeat()\r
+ {\r
+ _suspend = false;\r
+ }\r
+\r
private void Ring()\r
{\r
var now = _timer.Now;\r
if (now - _lastRing < TimeSpan.FromSeconds(2))\r
return;\r
- var notification = _queue.FirstOrDefault(n => n.Schedule.CompareTo(now) <= 0);\r
+ var notification = _queue.FirstOrDefault(n => n.Schedule.CompareTo(now) <= 0 &&\r
+ !(_suspend && n.Schedule != default));\r
if (notification == null)\r
return;\r
if (notification.Repeat == 0)\r