mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
Requests refactoring (#900)
* Remove unused requests. * Move PingRequest and AckRequest to TLSharp.Core.Network.Requests.
This commit is contained in:
parent
8729b7d85b
commit
7230b9b509
|
|
@ -11,7 +11,7 @@ using TLSharp.Core.Exceptions;
|
|||
using TLSharp.Core.MTProto;
|
||||
using TLSharp.Core.MTProto.Crypto;
|
||||
using TLSharp.Core.Network.Exceptions;
|
||||
using TLSharp.Core.Requests;
|
||||
using TLSharp.Core.Network.Requests;
|
||||
using TLSharp.Core.Utils;
|
||||
|
||||
namespace TLSharp.Core.Network
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using TeleSharp.TL;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
namespace TLSharp.Core.Network.Requests
|
||||
{
|
||||
public class AckRequest : TeleSharp.TL.TLMethod
|
||||
public class AckRequest : TLMethod
|
||||
{
|
||||
private readonly List<ulong> _msgs;
|
||||
|
||||
|
|
@ -36,6 +36,7 @@ namespace TLSharp.Core.Requests
|
|||
}
|
||||
|
||||
public override bool Confirmed => false;
|
||||
|
||||
public override bool Responded { get; }
|
||||
|
||||
public override int Constructor
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using TeleSharp.TL;
|
||||
using TLSharp.Core.Utils;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
namespace TLSharp.Core.Network.Requests
|
||||
{
|
||||
public class PingRequest : TeleSharp.TL.TLMethod
|
||||
public class PingRequest : TLMethod
|
||||
{
|
||||
public PingRequest()
|
||||
{
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using TLSharp.Core.MTProto;
|
||||
using TeleSharp.TL;
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class AuthSendCodeRequest : MTProtoRequest
|
||||
{
|
||||
|
||||
public bool _phoneRegistered;
|
||||
public string _phoneCodeHash;
|
||||
public SendCodeArgs args=new SendCodeArgs();
|
||||
public AuthSendCodeRequest(string phoneNumber, int smsType, int apiId, string apiHash, string langCode)
|
||||
{
|
||||
|
||||
args.phone_number = phoneNumber;
|
||||
args.api_id = apiId;
|
||||
args.api_hash = apiHash;
|
||||
args.allow_flashcall = false;
|
||||
args.current_number = true;
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(0x86AEF0EC);
|
||||
writer.Write(0);
|
||||
Serializers.String.write(writer, args.phone_number);
|
||||
writer.Write(args.api_id.Value);
|
||||
Serializers.String.write(writer, args.api_hash);
|
||||
}
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
|
||||
var s = Deserializer.Deserialize(typeof(SentCode), reader);
|
||||
_phoneRegistered = ((SentCode)s).phone_registered;
|
||||
_phoneCodeHash = ((SentCode)s).phone_code_hash;
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Confirmed => true;
|
||||
public override bool Responded { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using TeleSharp.TL;
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class AuthSignInRequest : MTProtoRequest
|
||||
{
|
||||
private SignInArgs args = new SignInArgs();
|
||||
public User user;
|
||||
public int SessionExpires;
|
||||
|
||||
public AuthSignInRequest(string phoneNumber, string phoneCodeHash, string code)
|
||||
{
|
||||
args.phone_number = phoneNumber;
|
||||
args.phone_code_hash = phoneCodeHash;
|
||||
args.phone_code = code;
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
Serializer.Serialize(args, typeof(SignInArgs), writer);
|
||||
}
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
var auth = (Authorization)Deserializer.Deserialize(typeof(Authorization), reader);
|
||||
user = auth.user;
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Confirmed => true;
|
||||
public override bool Responded { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using TeleSharp.TL;
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class DownloadFileRequest : MTProtoRequest
|
||||
{
|
||||
private GetFileArgs args = new GetFileArgs();
|
||||
public TeleSharp.TL.File file;
|
||||
|
||||
public DownloadFileRequest(InputFileLocation loc,int offset=0,int limit=0)
|
||||
{
|
||||
args.location = loc;
|
||||
args.offset = offset;
|
||||
args.limit = limit;
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
Serializer.Serialize(args, typeof(InputFileLocation), writer);
|
||||
}
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
file = (TeleSharp.TL.File)Deserializer.Deserialize(typeof(TeleSharp.TL.File), reader);
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Confirmed => true;
|
||||
public override bool Responded { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using TeleSharp.TL;
|
||||
using TLSharp.Core.MTProto;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public class InitConnectionRequest : MTProtoRequest
|
||||
{
|
||||
public InvokeWithLayerArgs invokeWithLayer { get; set; }
|
||||
public InitConnectionArgs initConn { get; set; }
|
||||
public GetConfigArgs getConfig { get; set; }
|
||||
public TeleSharp.TL.Config Configs { get; set; }
|
||||
|
||||
public InitConnectionRequest(int apiId)
|
||||
{
|
||||
invokeWithLayer = new InvokeWithLayerArgs();
|
||||
initConn = new InitConnectionArgs();
|
||||
invokeWithLayer.layer = 53;
|
||||
initConn.api_id = apiId;
|
||||
initConn.app_version = "1.0-SNAPSHOT";
|
||||
initConn.lang_code = "en";
|
||||
initConn.system_version = "WinPhone 8.0";
|
||||
initConn.device_model = "WinPhone Emulator";
|
||||
initConn.query = new GetConfigArgs();
|
||||
invokeWithLayer.query = initConn;
|
||||
}
|
||||
|
||||
public override void OnSend(BinaryWriter writer)
|
||||
{
|
||||
Serializer.Serialize(invokeWithLayer, invokeWithLayer.GetType(), writer);
|
||||
}
|
||||
|
||||
|
||||
public override void OnResponse(BinaryReader reader)
|
||||
{
|
||||
Configs = (TeleSharp.TL.Config)Deserializer.Deserialize(typeof(TeleSharp.TL.Config), reader);
|
||||
}
|
||||
|
||||
public override void OnException(Exception exception)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Responded
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override void OnSendSuccess()
|
||||
{
|
||||
|
||||
}
|
||||
public override bool Confirmed => true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace TLSharp.Core.Requests
|
||||
{
|
||||
public abstract class MTProtoRequest
|
||||
{
|
||||
public MTProtoRequest()
|
||||
{
|
||||
Sended = false;
|
||||
}
|
||||
|
||||
public long MessageId { get; set; }
|
||||
public int Sequence { get; set; }
|
||||
|
||||
public bool Dirty { get; set; }
|
||||
|
||||
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; }
|
||||
|
||||
public virtual void OnSendSuccess()
|
||||
{
|
||||
SendTime = DateTime.Now;
|
||||
Sended = true;
|
||||
}
|
||||
|
||||
public virtual void OnConfirm()
|
||||
{
|
||||
ConfirmReceived = true;
|
||||
}
|
||||
|
||||
public bool NeedResend
|
||||
{
|
||||
get
|
||||
{
|
||||
return Dirty || (Confirmed && !ConfirmReceived && DateTime.Now - SendTime > TimeSpan.FromSeconds(3));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -71,8 +71,8 @@
|
|||
<Compile Include="Network\TcpTransport.cs" />
|
||||
<Compile Include="Network\Exceptions\UserMigrationException.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Requests\AckRequest.cs" />
|
||||
<Compile Include="Requests\PingRequest.cs" />
|
||||
<Compile Include="Network\Requests\AckRequest.cs" />
|
||||
<Compile Include="Network\Requests\PingRequest.cs" />
|
||||
<Compile Include="Utils\UploadHelper.cs" />
|
||||
<Compile Include="Session.cs" />
|
||||
<Compile Include="TelegramClient.cs" />
|
||||
|
|
@ -88,6 +88,7 @@
|
|||
<Name>TeleSharp.TL</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ using TLSharp.Core;
|
|||
using TLSharp.Core.Exceptions;
|
||||
using TLSharp.Core.Network;
|
||||
using TLSharp.Core.Network.Exceptions;
|
||||
using TLSharp.Core.Requests;
|
||||
using TLSharp.Core.Utils;
|
||||
|
||||
namespace TLSharp.Tests
|
||||
|
|
|
|||
Loading…
Reference in a new issue