\r
public bool Equals(Message other) =>\r
other != null && Title == other.Title && Body == other.Body && Name == other.Name;\r
+\r
+ public Message Repeat => new Message {Title = "[リピート] " + Title, Body = Body, Name = Name};\r
+ public Message Cont => new Message {Title = "[継続] " + Title, Body = Body, Name = Name};\r
}\r
\r
/// <summary>\r
PAssert.That(() => expected.Equals(result));\r
break;\r
case 2000:\r
- PAssert.That(() => expected.Equals(result));\r
+ PAssert.That(() => expected.Repeat.Equals(result));\r
break;\r
case 4000:\r
- PAssert.That(() => expected.Equals(result));\r
+ PAssert.That(() => expected.Repeat.Equals(result));\r
return;\r
default:\r
PAssert.That(() => result == null, timer.Elapsed.ToString());\r
PAssert.That(() => hakuchi.Equals(result));\r
break;\r
case 7000:\r
- PAssert.That(() => hakuchi.Equals(result), "泊地修理2回目");\r
+ PAssert.That(() => hakuchi.Repeat.Equals(result), "泊地修理2回目");\r
break;\r
case 10000:\r
- PAssert.That(() => ensei.Equals(result), "遠征終了2回目");\r
+ PAssert.That(() => ensei.Repeat.Equals(result), "遠征終了2回目");\r
return;\r
default:\r
PAssert.That(() => result == null, timer.Elapsed.ToString());\r
PAssert.That(() => hakuchi.Equals(result));\r
break;\r
case 4000:\r
- PAssert.That(() => ensei.Equals(result), "遠征終了2回目");\r
+ PAssert.That(() => ensei.Repeat.Equals(result), "遠征終了2回目");\r
break;\r
case 6000:\r
- PAssert.That(() => hakuchi.Equals(result), "泊地修理2回目");\r
+ PAssert.That(() => hakuchi.Repeat.Equals(result), "泊地修理2回目");\r
return;\r
default:\r
PAssert.That(() => result == null, timer.Elapsed.ToString());\r
PAssert.That(() => result == null, "入渠終了2回目はない");\r
break;\r
case 10000:\r
- PAssert.That(() => ensei.Equals(result), "遠征終了2回目");\r
+ PAssert.That(() => ensei.Repeat.Equals(result), "遠征終了2回目");\r
return;\r
default:\r
PAssert.That(() => result == null, timer.Elapsed.ToString());\r
manager.ResumeRepeat();\r
break;\r
case 12000:\r
- PAssert.That(() => expected.Equals(result));\r
+ PAssert.That(() => expected.Repeat.Equals(result));\r
return;\r
default:\r
PAssert.That(() => result == null, timer.Elapsed.ToString());\r
manager.StopRepeat("遠征終了", 1);\r
break;\r
case 12000:\r
- PAssert.That(() => expected2.Equals(result));\r
+ PAssert.That(() => expected2.Repeat.Equals(result));\r
return;\r
default:\r
PAssert.That(() => result == null, timer.Elapsed.ToString());\r
manager.StopRepeat("遠征終了", true);\r
break;\r
case 10000:\r
- PAssert.That(() => expected2.Equals(result));\r
+ PAssert.That(() => expected2.Cont.Equals(result));\r
break;\r
case 11000:\r
manager.StopRepeat("遠征終了", 1);\r
timer.ElapseTime(1000);\r
}\r
}\r
+\r
+ /// <summary>\r
+ /// 予告する\r
+ /// </summary>\r
+ [TestMethod]\r
+ public void PreliminaryNotification()\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
+ manager.Enqueue("遠征終了", 1, "防空射撃演習", 0, true);\r
+ PAssert.That(() => expected.Equals(result));\r
+ }\r
}\r
}
\ No newline at end of file
if (pre == TimeSpan.Zero)\r
return;\r
if (timer.CheckRing(_prev + pre, _now + pre))\r
- _notificationManager.Enqueue(key, fleet, subject);\r
+ SetPreNotification(key, fleet, subject);\r
}\r
\r
private void SetTimerColor(Label label, RingTimer timer, DateTime now)\r
}\r
else if (_config.NotifyConditions.Contains(preNotice[i]))\r
{\r
- _notificationManager.Enqueue("疲労回復" + notice[i], i, "cond" + notice[i]);\r
+ SetPreNotification("疲労回復" + preNotice[i], i, "cond" + notice[i]);\r
}\r
}\r
}\r
\r
- private void SetNotification(string key, string subject)\r
- {\r
- SetNotification(key, 0, subject);\r
- }\r
-\r
- private void SetNotification(string key, int fleet, string subject)\r
- {\r
- var spec = _config.Notifications[_notificationManager.KeyToName(key)];\r
- _notificationManager.Enqueue(key, fleet, subject,\r
- (spec.Flags & _config.NotificationFlags & NotificationType.Repeat) == 0 ? 0 : spec.RepeatInterval);\r
- }\r
-\r
private void UpdateAkashiTimer()\r
{\r
if (_config.UsePresetAkashi)\r
if (skipPreliminary || pre == TimeSpan.Zero)\r
return;\r
if ((msgs = akashi.GetNotice(_prev + pre, _now + pre))[0].Proceeded == "20分経過しました。")\r
- _notificationManager.Enqueue("泊地修理20分経過", 0, msgs[0].Proceeded);\r
+ SetPreNotification("泊地修理20分経過", 0, msgs[0].Proceeded);\r
+ }\r
+\r
+ private void SetNotification(string key, string subject)\r
+ {\r
+ SetNotification(key, 0, subject);\r
+ }\r
+\r
+ private void SetNotification(string key, int fleet, string subject)\r
+ {\r
+ var spec = _config.Notifications[_notificationManager.KeyToName(key)];\r
+ _notificationManager.Enqueue(key, fleet, subject,\r
+ (spec.Flags & _config.NotificationFlags & NotificationType.Repeat) == 0 ? 0 : spec.RepeatInterval);\r
+ }\r
+\r
+ private void SetPreNotification(string key, int fleet, string subject)\r
+ {\r
+ _notificationManager.Enqueue(key, fleet, subject, 0, true);\r
}\r
\r
private void UpdateRepairList()\r
{\r
private readonly NotificationQueue _notificationQueue;\r
\r
+ private enum Mode\r
+ {\r
+ Normal,\r
+ Repeat,\r
+ Cont,\r
+ Preliminary\r
+ }\r
+\r
private class Notification\r
{\r
public string Key { get; set; }\r
public int Fleet { get; set; }\r
public string Subject { get; set; }\r
public int Repeat { get; set; }\r
+ public Mode Mode { get; set; }\r
public DateTime Schedule { get; set; }\r
}\r
\r
_notificationQueue = new NotificationQueue(ring, timer);\r
}\r
\r
- public void Enqueue(string key, int fleet, string subject, int repeat = 0)\r
+ public void Enqueue(string key, int fleet, string subject, int repeat = 0, bool preliminary = false)\r
{\r
_notificationQueue.Enqueue(new Notification\r
{\r
Key = key,\r
Fleet = fleet,\r
Subject = subject,\r
- Repeat = repeat\r
+ Repeat = repeat,\r
+ Mode = preliminary ? Mode.Preliminary : Mode.Normal\r
});\r
}\r
\r
{\r
LoadConfig();\r
var format = _config.TryGetValue(notification.Key, out Message value) ? value : _default[notification.Key];\r
+ var prefix = new[] {"", "[リピート] ", "[継続] ", "[予告] "}[(int)notification.Mode];\r
return new Message\r
{\r
- Title = ProcessFormatString(format.Title, notification.Fleet, notification.Subject),\r
+ Title = prefix + ProcessFormatString(format.Title, notification.Fleet, notification.Subject),\r
Body = ProcessFormatString(format.Body, notification.Fleet, notification.Subject),\r
Name = KeyToName(notification.Key)\r
};\r
else\r
{\r
foreach (var n in _queue.Where(n => IsMatch(n, key)))\r
+ {\r
n.Subject = "";\r
+ n.Mode = Mode.Cont;\r
+ }\r
}\r
}\r
\r
!(_suspend && n.Schedule != default));\r
if (notification == null)\r
return;\r
+ var message = _notificationConfig.GenerateMessage(notification);\r
if (notification.Repeat == 0)\r
{\r
_queue.Remove(notification);\r
else\r
{\r
notification.Schedule = _timer.Now + TimeSpan.FromSeconds(notification.Repeat);\r
+ if (notification.Mode == Mode.Normal)\r
+ notification.Mode = Mode.Repeat;\r
}\r
- var message =\r
- _notificationConfig.GenerateMessage(notification);\r
_ring(message.Title, message.Body, message.Name);\r
_lastRing = now;\r
}\r