OSDN Git Service

サーバー関連のエラーをダイアログに表示する
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Thu, 29 Oct 2015 12:12:45 +0000 (21:12 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Thu, 29 Oct 2015 15:31:07 +0000 (00:31 +0900)
KancolleSniffer/MainForm.cs

index 3493391..6f159d1 100644 (file)
@@ -92,8 +92,8 @@ namespace KancolleSniffer
                 return;\r
             if (response == null || !response.StartsWith("svdata="))\r
             {\r
-                WriteDebugLog(url, request, response ?? "(null)");\r
-                ShowServerError();\r
+                WriteDebugLog(url, request, response);\r
+                ShowServerError(url, request, response);\r
                 return;\r
             }\r
             response = response.Remove(0, "svdata=".Length);\r
@@ -101,17 +101,24 @@ namespace KancolleSniffer
             {\r
                 var json = DynamicJson.Parse(response);\r
                 WriteDebugLog(url, request, json.ToString());\r
-                UpdateInfo(_sniffer.Sniff(url, request, json));\r
+                var update = _sniffer.Sniff(url, request, json);\r
+                if (update == Sniffer.Update.Error)\r
+                {\r
+                    ShowServerError(url, request, json);\r
+                    return;\r
+                }\r
+                UpdateInfo(update);\r
             }\r
             catch (XmlException)\r
             {\r
                 WriteDebugLog(url, request, response);\r
-                ShowServerError();\r
+                ShowServerError(url, request, response);\r
             }\r
-            catch (RuntimeBinderException)\r
+            catch (RuntimeBinderException e)\r
             {\r
-                labelLogin.Text = "現在の艦これに対応していません。\n新しいバージョンを利用してください。";\r
-                labelLogin.Visible = true;\r
+                if (_errorDialog.ShowDialog(this,\r
+                    "このバージョンは現在の艦これに対応していません。\n新しいバージョンを利用してください。", e.ToString()) == DialogResult.Abort)\r
+                    Application.Exit();\r
             }\r
             catch (LogIOException e)\r
             {\r
@@ -124,17 +131,24 @@ namespace KancolleSniffer
         {\r
             if (_debugLogFile != null)\r
             {\r
-                File.AppendAllText(_debugLogFile, $"url: {url}\nrequest: {request}\nresponse: {response}\n");\r
+                File.AppendAllText(_debugLogFile, SessionString(url, request, response));\r
             }\r
         }\r
 \r
-        private void UpdateInfo(Sniffer.Update update)\r
+        private void ShowServerError(string url, string request, string response)\r
         {\r
-            if (update == Sniffer.Update.Error)\r
-            {\r
-                ShowServerError();\r
+            if (_errorDialog.Visible)\r
                 return;\r
-            }\r
+            if (_errorDialog.ShowDialog(this, "サーバーからの応答が異常です。",\r
+                SessionString(url, request, response)) == DialogResult.Abort)\r
+                Application.Exit();\r
+        }\r
+\r
+        private string SessionString(string url, string request, string response)\r
+            => $"url: {url}\nrequest: {request}\nresponse: {(response ?? "(null)")}\n";\r
+\r
+        private void UpdateInfo(Sniffer.Update update)\r
+        {\r
             if (update == Sniffer.Update.Start)\r
             {\r
                 labelLogin.Visible = false;\r
@@ -159,12 +173,6 @@ namespace KancolleSniffer
                 UpdateBattleInfo();\r
         }\r
 \r
-        private void ShowServerError()\r
-        {\r
-            labelLogin.Text = "サーバーからの応答が異常です。";\r
-            labelLogin.Visible = true;\r
-        }\r
-\r
         private void MainForm_Load(object sender, EventArgs e)\r
         {\r
             _config.Load();\r