mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
Changed session store to return null when couldn't load instead of exception.
This commit is contained in:
parent
29568bef11
commit
f98540bd7f
|
|
@ -24,7 +24,11 @@ namespace TLSharp.Core
|
||||||
|
|
||||||
public Session Load(string sessionUserId)
|
public Session Load(string sessionUserId)
|
||||||
{
|
{
|
||||||
using (var stream = new FileStream($"{sessionUserId}.dat", FileMode.Open))
|
var sessionFileName = $"{sessionUserId}.dat";
|
||||||
|
if (!File.Exists(sessionFileName))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
using (var stream = new FileStream(sessionFileName, FileMode.Open))
|
||||||
{
|
{
|
||||||
var buffer = new byte[2048];
|
var buffer = new byte[2048];
|
||||||
stream.Read(buffer, 0, 2048);
|
stream.Read(buffer, 0, 2048);
|
||||||
|
|
@ -43,7 +47,7 @@ namespace TLSharp.Core
|
||||||
|
|
||||||
public Session Load(string sessionUserId)
|
public Session Load(string sessionUserId)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,15 +155,7 @@ namespace TLSharp.Core
|
||||||
|
|
||||||
public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId)
|
public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId)
|
||||||
{
|
{
|
||||||
Session session;
|
return store.Load(sessionUserId) ?? new Session(store)
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
session = store.Load(sessionUserId);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
session = new Session(store)
|
|
||||||
{
|
{
|
||||||
Id = GenerateRandomUlong(),
|
Id = GenerateRandomUlong(),
|
||||||
SessionUserId = sessionUserId,
|
SessionUserId = sessionUserId,
|
||||||
|
|
@ -168,9 +164,6 @@ namespace TLSharp.Core
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ulong GenerateRandomUlong()
|
private static ulong GenerateRandomUlong()
|
||||||
{
|
{
|
||||||
var random = new Random();
|
var random = new Random();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue