Requests refactoring

Remove unused requests.
Move PingRequest to TLSharp.Core.Network.Requests.
Move AckRequest to TLSharp.Core.Network.Requests.
Add TeleSharp.TL using to PingRequest.
Add TeleSharp.TL using to AckRequest.
This commit is contained in:
CheshireCaat 2020-01-25 01:09:41 +03:00
parent 8729b7d85b
commit 3ed51c14a9
10 changed files with 9 additions and 235 deletions

View file

@ -11,7 +11,7 @@ using TLSharp.Core.Exceptions;
using TLSharp.Core.MTProto; using TLSharp.Core.MTProto;
using TLSharp.Core.MTProto.Crypto; using TLSharp.Core.MTProto.Crypto;
using TLSharp.Core.Network.Exceptions; using TLSharp.Core.Network.Exceptions;
using TLSharp.Core.Requests; using TLSharp.Core.Network.Requests;
using TLSharp.Core.Utils; using TLSharp.Core.Utils;
namespace TLSharp.Core.Network namespace TLSharp.Core.Network

View file

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using TeleSharp.TL; 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; private readonly List<ulong> _msgs;
@ -36,6 +36,7 @@ namespace TLSharp.Core.Requests
} }
public override bool Confirmed => false; public override bool Confirmed => false;
public override bool Responded { get; } public override bool Responded { get; }
public override int Constructor public override int Constructor

View file

@ -1,12 +1,11 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using TeleSharp.TL; using TeleSharp.TL;
using TLSharp.Core.Utils; 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() public PingRequest()
{ {

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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;
}
}

View file

@ -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));
}
}
}
}

View file

@ -71,8 +71,8 @@
<Compile Include="Network\TcpTransport.cs" /> <Compile Include="Network\TcpTransport.cs" />
<Compile Include="Network\Exceptions\UserMigrationException.cs" /> <Compile Include="Network\Exceptions\UserMigrationException.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Requests\AckRequest.cs" /> <Compile Include="Network\Requests\AckRequest.cs" />
<Compile Include="Requests\PingRequest.cs" /> <Compile Include="Network\Requests\PingRequest.cs" />
<Compile Include="Utils\UploadHelper.cs" /> <Compile Include="Utils\UploadHelper.cs" />
<Compile Include="Session.cs" /> <Compile Include="Session.cs" />
<Compile Include="TelegramClient.cs" /> <Compile Include="TelegramClient.cs" />
@ -88,6 +88,7 @@
<Name>TeleSharp.TL</Name> <Name>TeleSharp.TL</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.

View file

@ -13,7 +13,6 @@ using TLSharp.Core;
using TLSharp.Core.Exceptions; using TLSharp.Core.Exceptions;
using TLSharp.Core.Network; using TLSharp.Core.Network;
using TLSharp.Core.Network.Exceptions; using TLSharp.Core.Network.Exceptions;
using TLSharp.Core.Requests;
using TLSharp.Core.Utils; using TLSharp.Core.Utils;
namespace TLSharp.Tests namespace TLSharp.Tests