From 20168d59c3a0f3de8a41cfbf6b89a89de6658285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=85=D9=8F=D8=B9=D9=8E=D8=A7=D8=B0=20=D8=A7=D9=84=D9=82?= =?UTF-8?q?=D9=8E=D8=B1=D9=92=D9=86=D9=90=D9=8A?= <60256639+Muaath5@users.noreply.github.com> Date: Sun, 14 Feb 2021 12:05:57 +0300 Subject: [PATCH 1/2] Support deleting session --- src/TgSharp.Core/FileSessionStore.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/TgSharp.Core/FileSessionStore.cs b/src/TgSharp.Core/FileSessionStore.cs index 071656df..2f10853a 100644 --- a/src/TgSharp.Core/FileSessionStore.cs +++ b/src/TgSharp.Core/FileSessionStore.cs @@ -48,6 +48,14 @@ public Session Load (string sessionUserId) } } + public void Delete (Session session) + { + string sessionFileName = $"{session.SessionUserId}.dat"; + var sessionPath = basePath == null ? sessionFileName : + Path.Combine (basePath.FullName, sessionFileName); + File.Delete(sessionFileName); + } + public static Session FromBytes (byte [] buffer, ISessionStore store, string sessionUserId) { using (var stream = new MemoryStream (buffer)) From 8de18b08912b198f85c6e3fea27cb77ba2c2dbcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D9=85=D8=B9=D8=A7=D8=B0=20=D8=A7=D9=84=D9=82=D8=B1=D9=86?= =?UTF-8?q?=D9=8A?= Date: Mon, 17 May 2021 22:10:14 +0300 Subject: [PATCH 2/2] Check if file exists before deleting file --- src/TgSharp.Core/FileSessionStore.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/TgSharp.Core/FileSessionStore.cs b/src/TgSharp.Core/FileSessionStore.cs index 2f10853a..cda49b16 100644 --- a/src/TgSharp.Core/FileSessionStore.cs +++ b/src/TgSharp.Core/FileSessionStore.cs @@ -53,7 +53,15 @@ public void Delete (Session session) string sessionFileName = $"{session.SessionUserId}.dat"; var sessionPath = basePath == null ? sessionFileName : Path.Combine (basePath.FullName, sessionFileName); - File.Delete(sessionFileName); + + if (File.Exists(sessionPath)) + { + File.Delete(sessionFileName); + } + else + { + // No throwing exception if not exists + } } public static Session FromBytes (byte [] buffer, ISessionStore store, string sessionUserId)