Fixed time types

This commit is contained in:
Arthur Grand 2019-09-12 15:44:33 +07:00 committed by GitHub
parent 218544b1b6
commit 64440e4736
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,10 +28,10 @@ namespace TLSharp.Core
private Session _session; private Session _session;
private List<TLDcOption> dcOptions; private List<TLDcOption> dcOptions;
private TcpClientConnectionHandler _handler; private TcpClientConnectionHandler _handler;
private int _requestTimeout; private TimeSpan _requestTimeout;
public TelegramClient(int apiId, string apiHash, public TelegramClient(int apiId, string apiHash,
ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null, int requestTimeout = 5) ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null, double requestTimeout = 5d)
{ {
if (apiId == default(int)) if (apiId == default(int))
throw new MissingApiConfigurationException("API_ID"); throw new MissingApiConfigurationException("API_ID");
@ -44,7 +44,7 @@ namespace TLSharp.Core
_apiHash = apiHash; _apiHash = apiHash;
_apiId = apiId; _apiId = apiId;
_handler = handler; _handler = handler;
_requestTimeout = requestTimeout; _requestTimeout = TimeSpan.FromSeconds(requestTimeout);
_session = Session.TryLoadOrCreateNew(store, sessionUserId); _session = Session.TryLoadOrCreateNew(store, sessionUserId);
_transport = new TcpTransport(_session.DataCenter.Address, _session.DataCenter.Port, _handler); _transport = new TcpTransport(_session.DataCenter.Address, _session.DataCenter.Port, _handler);
@ -116,7 +116,7 @@ namespace TLSharp.Core
var startedAt = DateTime.Now; var startedAt = DateTime.Now;
while(!completed) while(!completed)
{ {
if ((DateTime.Now - startedAt).TotalSeconds > _requestTimeout) if ((DateTime.Now - startedAt) > _requestTimeout)
{ {
throw new Exception("Request Timeout"); throw new Exception("Request Timeout");
} }