From b129e655f8182d4b39b59939aeffa5adbe618dd5 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Fri, 21 Oct 2016 23:43:53 +0800 Subject: [PATCH 1/3] build: switch to lower framework version (4.5.2 -> 4.5) This change is good because: a) It's better to target a lower target framework version if the project doesn't necessarily depend on the new features of the newer versions (so, bigger target audience). b) It lets compile the project with implementations of the .NET Framework that are not compatible with 4.5.2. For example, after this change I can successfully build TLSharp with the Mono v4.2.1 that comes in my Ubuntu Linux 16.04.1. --- README.md | 2 +- TLSharp.Core/TLSharp.Core.csproj | 2 +- TeleSharp.Generator/TeleSharp.Generator.csproj | 2 +- TeleSharp.TL/TeleSharp.TL.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4b68f9f..b47b54d 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Library _almost_ ready for production usage. We need contributors to make 1.0.0 To use TLSharp follow next steps: 1. Clone TLSharp from GitHub -1. Compile source with VS2015 +1. Compile source with VS2015 or MonoDevelop 1. Add reference to ```TLSharp.Core.dll``` to your awesome project. # Dependencies diff --git a/TLSharp.Core/TLSharp.Core.csproj b/TLSharp.Core/TLSharp.Core.csproj index de604d1..792a7bb 100644 --- a/TLSharp.Core/TLSharp.Core.csproj +++ b/TLSharp.Core/TLSharp.Core.csproj @@ -9,7 +9,7 @@ Properties TLSharp.Core TLSharp.Core - v4.5.2 + v4.5 512 diff --git a/TeleSharp.Generator/TeleSharp.Generator.csproj b/TeleSharp.Generator/TeleSharp.Generator.csproj index c386fa6..94f3e9b 100644 --- a/TeleSharp.Generator/TeleSharp.Generator.csproj +++ b/TeleSharp.Generator/TeleSharp.Generator.csproj @@ -9,7 +9,7 @@ Properties TeleSharp.Generator TeleSharp.Generator - v4.5.2 + v4.5 512 true diff --git a/TeleSharp.TL/TeleSharp.TL.csproj b/TeleSharp.TL/TeleSharp.TL.csproj index 46e2a18..a6da831 100644 --- a/TeleSharp.TL/TeleSharp.TL.csproj +++ b/TeleSharp.TL/TeleSharp.TL.csproj @@ -9,7 +9,7 @@ Properties TeleSharp.TL TeleSharp.TL - v4.5.2 + v4.5 512 From 77867b44e626aedfba58cf9729100e3cc1a808a8 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Sat, 22 Oct 2016 22:00:15 +0800 Subject: [PATCH 2/3] Use better exception handling Parsing the message of an exception to decide what to do next is a bad practice, because it's easy that the message might be changed by mistake in the future. To enforce the coupling in a stronger way it's better to use exceptions of different type depending on the kind of error, so that we rely on the compiler enforcing the behaviour when doing changes in this error handling areas in the future. This also makes the code a bit more simple and readable. --- TLSharp.Core/Network/MtProtoSender.cs | 15 ++++++++++++--- TLSharp.Core/TelegramClient.cs | 11 ++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/TLSharp.Core/Network/MtProtoSender.cs b/TLSharp.Core/Network/MtProtoSender.cs index f7c4ef2..2d8babf 100644 --- a/TLSharp.Core/Network/MtProtoSender.cs +++ b/TLSharp.Core/Network/MtProtoSender.cs @@ -279,9 +279,7 @@ namespace TLSharp.Core.Network { var resultString = Regex.Match(errorMessage, @"\d+").Value; var dcIdx = int.Parse(resultString); - var exception = new InvalidOperationException($"Your phone number registered to {dcIdx} dc. Please update settings. See https://github.com/sochix/TLSharp#i-get-an-error-migrate_x for details."); - exception.Data.Add("dcId", dcIdx); - throw exception; + throw new MigrationNeededException(dcIdx); } else { @@ -484,4 +482,15 @@ namespace TLSharp.Core.Network return new MemoryStream(new byte[len], 0, len, true, true); } } + + internal class MigrationNeededException : Exception + { + internal int DC { get; private set; } + + internal MigrationNeededException(int dc) + : base ("$Your phone number is registered to a different dc: {dc}. Please migrate.") + { + DC = dc; + } + } } \ No newline at end of file diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 75d0466..40eefaf 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -110,16 +110,9 @@ namespace TLSharp.Core completed = true; } - catch (InvalidOperationException ex) + catch (MigrationNeededException ex) { - if (ex.Message.StartsWith("Your phone number registered to") && ex.Data["dcId"] != null) - { - await ReconnectToDcAsync((int)ex.Data["dcId"]); - } - else - { - throw; - } + await ReconnectToDcAsync(ex.DC); } } From 6c541647261fa396e0313ce4e34260b74309e519 Mon Sep 17 00:00:00 2001 From: Ilya Pirozhenko Date: Sun, 23 Oct 2016 10:59:20 +0300 Subject: [PATCH 3/3] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9f255c2..8afdbc7 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ List of donators: # Contributors * [Afshin Arani](http://aarani.ir) - TLGenerator, and a lot of other usefull things +* [Knocte](https://github.com/knocte) # License