TLSharp/TLSharp.Core/Requests/MTProtoRequest.cs

47 lines
1.2 KiB
C#
Raw Normal View History

2015-09-28 04:01:17 +02:00
using System;
using System.IO;
namespace TLSharp.Core.Requests
{
2016-04-18 12:50:57 +02:00
public abstract class MTProtoRequest
{
public MTProtoRequest()
{
Sended = false;
}
2015-09-28 04:01:17 +02:00
2016-04-18 12:50:57 +02:00
public long MessageId { get; set; }
public int Sequence { get; set; }
2015-09-28 04:01:17 +02:00
2016-04-18 12:50:57 +02:00
public bool Dirty { get; set; }
2015-09-28 04:01:17 +02:00
2016-04-18 12:50:57 +02:00
public bool Sended { get; private set; }
public DateTime SendTime { get; private set; }
public bool ConfirmReceived { get; set; }
public abstract void OnSend(BinaryWriter writer);
public abstract void OnResponse(BinaryReader reader);
public abstract void OnException(Exception exception);
public abstract bool Confirmed { get; }
public abstract bool Responded { get; }
2015-09-28 04:01:17 +02:00
2016-04-18 12:50:57 +02:00
public virtual void OnSendSuccess()
{
SendTime = DateTime.Now;
Sended = true;
}
2015-09-28 04:01:17 +02:00
2016-04-18 12:50:57 +02:00
public virtual void OnConfirm()
{
ConfirmReceived = true;
}
2015-09-28 04:01:17 +02:00
2016-04-18 12:50:57 +02:00
public bool NeedResend
{
get
{
return Dirty || (Confirmed && !ConfirmReceived && DateTime.Now - SendTime > TimeSpan.FromSeconds(3));
}
}
}
2015-09-28 04:01:17 +02:00
}