From 7ea86b3dd2fad3d2ef7ca5ed655dd36a0899c078 Mon Sep 17 00:00:00 2001 From: UAVXP Date: Mon, 4 Nov 2019 12:43:14 +0200 Subject: [PATCH] TelegramChatsStorage logging --- MedocUpdates/TelegramChatsStorage.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/MedocUpdates/TelegramChatsStorage.cs b/MedocUpdates/TelegramChatsStorage.cs index b02060b..b6ac1d8 100644 --- a/MedocUpdates/TelegramChatsStorage.cs +++ b/MedocUpdates/TelegramChatsStorage.cs @@ -30,7 +30,10 @@ public static bool Save() // Checking again if (!File.Exists(m_storageFilePath)) + { + Log.Write(LogLevel.NORMAL, "TelegramChatsStorage: Save(): Cannot create chatID storage file"); return false; + } string chatIDsFileStr = ""; foreach(long chatID in m_TelegramChatIDs) @@ -39,8 +42,11 @@ public static bool Save() } File.WriteAllText(m_storageFilePath, chatIDsFileStr); - if (!File.Exists(m_storageFilePath)) + if (!File.Exists(m_storageFilePath)) // TODO: Check for file size instead of availability + { + Log.Write(LogLevel.NORMAL, "TelegramChatsStorage: Save(): Storage file is gone in the middle of writing"); return false; // And here we're going to fail + } return true; } @@ -48,19 +54,31 @@ public static bool Save() public static bool Restore() { if (!File.Exists(m_storageFilePath)) + { + Log.Write(LogLevel.NORMAL, "TelegramChatsStorage: Restore(): Cannot restore - storage file doesn't exist"); return false; + } string chatIDsStr = File.ReadAllText(m_storageFilePath); if(chatIDsStr.Trim().Length <= 0) + { + Log.Write(LogLevel.NORMAL, "TelegramChatsStorage: Restore(): Cannot restore - storage file is empty. Using the empty list instead"); return false; + } string[] userIDsStr = chatIDsStr.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries); if(userIDsStr.Length <= 0) + { + Log.Write(LogLevel.NORMAL, "TelegramChatsStorage: Restore(): Cannot restore - parsing error"); return false; + } long[] userIDs = Array.ConvertAll(userIDsStr, long.Parse); if(userIDs.Length <= 0) + { + Log.Write(LogLevel.NORMAL, "TelegramChatsStorage: Restore(): Cannot restore - convertation error"); return false; + } m_TelegramChatIDs.AddRange(userIDs); return true;