OSDN Git Service

通知のタイトルに通知の種類を表示する
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Thu, 21 Dec 2017 12:00:55 +0000 (21:00 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Sat, 27 Jan 2018 08:33:55 +0000 (17:33 +0900)
KancolleSniffer.Test/NotificationManagerTest.cs
KancolleSniffer/MainForm.cs
KancolleSniffer/NotificationManager.cs

index 316e351..2282c9f 100644 (file)
@@ -89,6 +89,9 @@ namespace KancolleSniffer.Test
 \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
@@ -165,10 +168,10 @@ namespace KancolleSniffer.Test
                         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
@@ -204,10 +207,10 @@ namespace KancolleSniffer.Test
                         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
@@ -245,10 +248,10 @@ namespace KancolleSniffer.Test
                         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
@@ -290,7 +293,7 @@ namespace KancolleSniffer.Test
                         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
@@ -327,7 +330,7 @@ namespace KancolleSniffer.Test
                         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
@@ -366,7 +369,7 @@ namespace KancolleSniffer.Test
                         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
@@ -402,7 +405,7 @@ namespace KancolleSniffer.Test
                         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
@@ -418,5 +421,20 @@ namespace KancolleSniffer.Test
                 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
index c444d32..2331710 100644 (file)
@@ -739,7 +739,7 @@ namespace KancolleSniffer
             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
@@ -792,23 +792,11 @@ namespace KancolleSniffer
                 }\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
@@ -872,7 +860,24 @@ namespace KancolleSniffer
             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
index ccef210..8afa2ad 100644 (file)
@@ -24,12 +24,21 @@ namespace KancolleSniffer
     {\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
@@ -38,14 +47,15 @@ namespace KancolleSniffer
             _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
@@ -201,9 +211,10 @@ namespace KancolleSniffer
             {\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
@@ -336,7 +347,10 @@ namespace KancolleSniffer
                 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
@@ -367,6 +381,7 @@ namespace KancolleSniffer
                                                               !(_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
@@ -374,9 +389,9 @@ namespace KancolleSniffer
                 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