mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
TelegramClient ctor: move null checks earlier
This way we avoid creating a FileSessionStore object or initializing the TLContext if API credentials are not supplied, to be on the safe side.
This commit is contained in:
parent
b0b58be25e
commit
a029c33e34
|
|
@ -31,16 +31,17 @@ namespace TLSharp.Core
|
||||||
|
|
||||||
public TelegramClient(int apiId, string apiHash, ISessionStore store = null, string sessionUserId = "session")
|
public TelegramClient(int apiId, string apiHash, ISessionStore store = null, string sessionUserId = "session")
|
||||||
{
|
{
|
||||||
|
if (apiId == default(int))
|
||||||
|
throw new MissingApiConfigurationException("API_ID");
|
||||||
|
if (string.IsNullOrEmpty(apiHash))
|
||||||
|
throw new MissingApiConfigurationException("API_HASH");
|
||||||
|
|
||||||
if (store == null)
|
if (store == null)
|
||||||
store = new FileSessionStore();
|
store = new FileSessionStore();
|
||||||
|
|
||||||
TLContext.Init();
|
TLContext.Init();
|
||||||
_apiHash = apiHash;
|
_apiHash = apiHash;
|
||||||
_apiId = apiId;
|
_apiId = apiId;
|
||||||
if (_apiId == default(int))
|
|
||||||
throw new MissingApiConfigurationException("API_ID");
|
|
||||||
if (string.IsNullOrEmpty(_apiHash))
|
|
||||||
throw new MissingApiConfigurationException("API_HASH");
|
|
||||||
|
|
||||||
_session = Session.TryLoadOrCreateNew(store, sessionUserId);
|
_session = Session.TryLoadOrCreateNew(store, sessionUserId);
|
||||||
_transport = new TcpTransport(_session.ServerAddress, _session.Port);
|
_transport = new TcpTransport(_session.ServerAddress, _session.Port);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue