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:
Andres G. Aragoneses 2016-10-30 22:31:00 +08:00
parent b0b58be25e
commit a029c33e34

View file

@ -31,16 +31,17 @@ namespace TLSharp.Core
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)
store = new FileSessionStore();
TLContext.Init();
_apiHash = apiHash;
_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);
_transport = new TcpTransport(_session.ServerAddress, _session.Port);