style: more consistent naming removing underscores

There were less places with underscores in field names than
places without them, so we now are consistent with the most
abundant occurrence.
This commit is contained in:
Andres G. Aragoneses 2020-01-31 14:39:19 +08:00 committed by solarin
parent 54781b235f
commit 2d4aa3e8f9
3 changed files with 41 additions and 163 deletions

View file

@ -1,30 +0,0 @@
namespace TLSharp.Core
{
/// <summary>
/// When the Telegram server responds with a set of addresses to connect to, DataCenterIPVersion indicates a preference
/// for how to choose the IP address to connect to
/// </summary>
public enum DataCenterIPVersion
{
/// <summary>
/// Prefers IPv6 addresses if any is passed by Telegram
/// </summary>
Default = 0,
/// <summary>
/// Takes only IPv4 addresses
/// </summary>
OnlyIPv4 = 1,
/// <summary>
/// Takes only IPv6 addresses
/// </summary>
OnlyIPv6 = 2,
/// <summary>
/// Connection to IPv4 addresses is preferred to IPv6 addresses
/// </summary>
PreferIPv4 = 3,
/// <summary>
/// Connection to IPv6 addresses is preferred to IPv4 addresses
/// </summary>
PreferIPv6 = 4,
}
}

View file

@ -48,7 +48,6 @@
<Compile Include="Auth\Step1_PQRequest.cs" />
<Compile Include="Auth\Step2_DHExchange.cs" />
<Compile Include="Auth\Step3_CompleteDHExchange.cs" />
<Compile Include="DataCenterIPVersion.cs" />
<Compile Include="Exceptions\CloudPasswordNeededException.cs" />
<Compile Include="Exceptions\InvalidPhoneCodeException.cs" />
<Compile Include="Exceptions\MissingApiConfigurationException.cs" />

View file

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
@ -24,7 +22,6 @@ using TLAuthorization = TeleSharp.TL.Auth.TLAuthorization;
namespace TLSharp.Core
{
public class TelegramClient : IDisposable
{
private MtProtoSender sender;
@ -34,24 +31,14 @@ namespace TLSharp.Core
private Session session;
private List<TLDcOption> dcOptions;
private TcpClientConnectionHandler handler;
private DataCenterIPVersion dcIpVersion;
public Session Session
{
get { return session; }
}
/// <summary>
/// Creates a new TelegramClient
/// </summary>
/// <param name="apiId">The API ID provided by Telegram. Get one at https://my.telegram.org </param>
/// <param name="apiHash">The API Hash provided by Telegram. Get one at https://my.telegram.org </param>
/// <param name="store">An ISessionStore object that will handle the session</param>
/// <param name="sessionUserId">The name of the session that tracks login info about this TelegramClient connection</param>
/// <param name="handler">A delegate to invoke when a connection is needed and that will return a TcpClient that will be used to connect</param>
/// <param name="dcIpVersion">Indicates the preferred IpAddress version to use to connect to a Telegram server</param>
public TelegramClient(int apiId, string apiHash,
ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null, DataCenterIPVersion dcIpVersion = DataCenterIPVersion.Default)
ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null)
{
if (apiId == default(int))
throw new MissingApiConfigurationException("API_ID");
@ -64,7 +51,6 @@ namespace TLSharp.Core
this.apiHash = apiHash;
this.apiId = apiId;
this.handler = handler;
this.dcIpVersion = dcIpVersion;
session = Session.TryLoadOrCreateNew(store, sessionUserId);
transport = new TcpTransport (session.DataCenter.Address, session.DataCenter.Port, this.handler);
@ -115,21 +101,7 @@ namespace TLSharp.Core
exported = await SendRequestAsync<TLExportedAuthorization>(exportAuthorization, token).ConfigureAwait(false);
}
var dcs = dcOptions.Where(d => d.Id == dcId
&& (
(dcIpVersion == DataCenterIPVersion.Default) // any
|| (d.Ipv6 && dcIpVersion == DataCenterIPVersion.OnlyIPv6) // selects only ipv6 addresses
|| (!d.Ipv6 && dcIpVersion == DataCenterIPVersion.OnlyIPv4) // selects only ipv4 addresses
|| dcIpVersion == DataCenterIPVersion.PreferIPv4 // we can take both types of address
|| dcIpVersion == DataCenterIPVersion.PreferIPv6 // we can take both types of address
)
).OrderBy(d => d.Ipv6);
if (dcs.Count() == 0)
throw new Exception($"Telegram server didn't provide us with any IPAddress that matches your preferences. If you chose OnlyIPvX, try switch to PreferIPvX instead.");
var dc = dcIpVersion == DataCenterIPVersion.PreferIPv4 ? dcs.First() : dcs.Last(); // ipv4 addresses are at the beginning of the list because it was ordered
var dc = dcOptions.First(d => d.Id == dcId);
var dataCenter = new DataCenter (dcId, dc.IpAddress, dc.Port);
transport = new TcpTransport(dc.IpAddress, dc.Port, handler);
@ -434,69 +406,6 @@ namespace TLSharp.Core
.ConfigureAwait(false);
}
/// <summary>
/// Authenticates a Bot
/// </summary>
/// <param name="botAuthToken">The token of the bot to authenticate</param>
/// <param name="token"></param>
/// <returns>The TLUser descriptor</returns>
public async Task<TLUser> MakeAuthBotAsync(string botAuthToken, CancellationToken token = default(CancellationToken))
{
if (String.IsNullOrWhiteSpace(botAuthToken))
{
throw new ArgumentNullException(nameof(botAuthToken));
}
var request = new TLRequestImportBotAuthorization() { BotAuthToken = botAuthToken, ApiId = apiId, ApiHash = apiHash };
await RequestWithDcMigration(request, token).ConfigureAwait(false);
OnUserAuthenticated(((TLUser)request.Response.User));
return ((TLUser)request.Response.User);
}
/// <summary>
/// Gets the full information of a specified chat
/// </summary>
/// <param name="chatId">The ID of the chat we want the info of</param>
/// <param name="token"></param>
/// <returns></returns>
public async Task<TeleSharp.TL.Messages.TLChatFull> GetFullChat(int chatId, CancellationToken token = default(CancellationToken))
{
var req = new TLRequestGetFullChat() { ChatId = chatId };
var fchat = await SendRequestAsync<TeleSharp.TL.Messages.TLChatFull>(req).ConfigureAwait(false);
return fchat;
}
/// <summary>
/// Gets the list of chats opened by the authenticated user.
/// Throws an exception if the authenticated user is a bot.
/// </summary>
/// <param name="token"></param>
/// <returns>The list of chats opened by the authenticated user</returns>
public async Task<TLChats> GetAllChats(CancellationToken token = default(CancellationToken))
{
return await GetAllChats(null, token);
}
/// <summary>
/// Gets the list of chats opened by the authenticated user except the passed ones.
/// Throws an exception if the authenticated user is a bot.
/// </summary>
/// <param name="exceptIds">The IDs of the chats that we don't want to be returned</param>
/// <param name="token"></param>
/// <returns>The list of chats opened by the authenticated user</returns>
public async Task<TLChats> GetAllChats(int[] exceptIds = null, CancellationToken token = default(CancellationToken))
{
var ichats = new TeleSharp.TL.TLVector<int>(); // we can't pass a null argument to the TLRequestGetChats
if (exceptIds != null)
Array.ForEach(exceptIds, x => ichats.Add(x));
var chatInfo = await SendRequestAsync<TLChats>(new TLRequestGetChats() { Id = ichats }).ConfigureAwait(false);
return chatInfo;
}
/// <summary>
/// Serch user or chat. API: contacts.search#11f812d8 q:string limit:int = contacts.Found;
/// </summary>