From f282d270ae65aea6259027c53bf61fe1e0777eaa Mon Sep 17 00:00:00 2001
From: Wizou <11647984+wiz0u@users.noreply.github.com>
Date: Thu, 24 Feb 2022 16:44:27 +0100
Subject: [PATCH] Retry API call once on error -503 Timeout
---
EXAMPLES.md | 5 +----
src/Client.cs | 9 ++++++++-
src/Session.cs | 2 +-
src/TL.Schema.cs | 2 +-
4 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/EXAMPLES.md b/EXAMPLES.md
index d29ae3e..ffeab06 100644
--- a/EXAMPLES.md
+++ b/EXAMPLES.md
@@ -371,10 +371,7 @@ If you are not in a Console app or don't want the logs on screen, you can redire
// • Log to VS Output debugging pane in addition to default Console screen logging:
WTelegram.Helpers.Log += (lvl, str) => System.Diagnostics.Debug.WriteLine(str);
-// • Log to file in replacement of default Console screen logging:
-WTelegram.Helpers.Log = (lvl, str) => File.AppendAllText("WTelegram.log", str + Environment.NewLine);
-
-// • More efficient example with a static variable and detailed logging to file:
+// • Log to file in replacement of default Console screen logging, using this static variable:
static StreamWriter WTelegramLogs = new StreamWriter("WTelegram.log", true, Encoding.UTF8) { AutoFlush = true };
...
WTelegram.Helpers.Log = (lvl, str) => WTelegramLogs.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} [{"TDIWE!"[lvl]}] {str}");
diff --git a/src/Client.cs b/src/Client.cs
index 7750bc7..4fba0b5 100644
--- a/src/Client.cs
+++ b/src/Client.cs
@@ -40,6 +40,8 @@ namespace WTelegram
public int FloodRetryThreshold { get; set; } = 60;
/// Number of seconds between each keep-alive ping. Increase this if you have a slow connection or you're debugging your code
public int PingInterval { get; set; } = 60;
+ /// Size of chunks when uploading/downloading files. Reduce this if you don't have much memory
+ public int FilePartSize { get; set; } = 512 * 1024;
/// Is this Client instance the main or a secondary DC session
public bool IsMainDC => (_dcSession?.DataCenter?.id ?? 0) == _session.MainDC;
/// Has this Client established connection been disconnected?
@@ -68,7 +70,6 @@ namespace WTelegram
private Task _connecting;
private CancellationTokenSource _cts;
private int _reactorReconnects = 0;
- private const int FilePartSize = 512 * 1024;
private const string ConnectionShutDown = "Could not read payload length : Connection shut down";
private readonly SemaphoreSlim _parallelTransfers = new(10); // max parallel part uploads/downloads
private readonly SHA256 _sha256 = SHA256.Create();
@@ -840,6 +841,7 @@ namespace WTelegram
var tcs = new TaskCompletionSource