Skip to content

Commit ed34339

Browse files
committed
Merge branch 'develop' of https://github.com/mateof/TelegramFileManager into develop
2 parents 9d8e3cb + f6884d9 commit ed34339

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

TelegramDownloader/Models/DownloadModel.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,14 @@ public class DownloadModel
128128
public Callbacks callbacks { get; set; }
129129

130130
public long _size { get; set; }
131-
public long _transmitted { get; set; }
131+
public long _transmitted { get; set; } = 0;
132132

133133
public string _sizeString { get; set; }
134134
public string _transmittedString { get; set; }
135135

136136
public IPeerInfo channel { get; set; }
137137
public string channelName { get; set; }
138138
public int progress { get; set; }
139-
public long accumulatedSize { get; set; } = 0;
140139
public TransactionInfoService tis { get; set; }
141140

142141

@@ -157,8 +156,7 @@ public void ProgressCallback(long transmitted, long totalSize)
157156
tis.deleteDownloadInList(this);
158157
throw new Exception($"Paused {name}");
159158
}
160-
tis.addDownloadBytes(transmitted - accumulatedSize);
161-
accumulatedSize = transmitted;
159+
tis.addDownloadBytes(transmitted - _transmitted);
162160
_transmitted = transmitted;
163161
_sizeString = HelperService.SizeSuffix(totalSize);
164162
_transmittedString = HelperService.SizeSuffix(transmitted);
@@ -204,23 +202,21 @@ public class UploadModel
204202
public string path { get; set; }
205203

206204
public long _size { get; set; }
207-
public long _transmitted { get; set; }
205+
public long _transmitted { get; set; } = 0;
208206

209207
public string _sizeString { get; set; }
210208
public string _transmittedString { get; set; }
211209
public string chatName { get; set; }
212210
public IPeerInfo channel { get; set; }
213211
public int progress { get; set; }
214212
public Thread thread { get; set; }
215-
public long accumulatedSize { get; set; } = 0;
216213
public TransactionInfoService tis { get; set; }
217214

218215
public virtual void ProgressCallback(long transmitted, long totalSize)
219216
{
220217
if (state == StateTask.Canceled)
221218
throw new Exception($"Canceled {name}");
222-
tis.addUploadBytes(transmitted - accumulatedSize);
223-
accumulatedSize = transmitted;
219+
tis.addUploadBytes(transmitted - _transmitted);
224220
_transmitted = transmitted;
225221
_sizeString = HelperService.SizeSuffix(totalSize);
226222
_transmittedString = HelperService.SizeSuffix(transmitted);

TelegramDownloader/Services/TransactionInfoService.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Timers;
2+
using TelegramDownloader.Data;
23
using TelegramDownloader.Models;
34
using TelegramDownloader.Pages.Modals;
45
using TL;
@@ -8,7 +9,7 @@ namespace TelegramDownloader.Services
89
{
910
public class TransactionInfoService
1011
{
11-
private Timer aTimer;
12+
1213

1314
public bool isPauseDownloads = false;
1415
public event EventHandler<EventArgs> EventChanged;
@@ -27,6 +28,13 @@ public class TransactionInfoService
2728
private static Mutex DownloadBytesMutex = new Mutex();
2829
private static Mutex UploadBytesMutex = new Mutex();
2930

31+
private Timer aTimer;
32+
private readonly ILogger<IFileService> _logger;
33+
34+
public TransactionInfoService(ILogger<IFileService> logger)
35+
{
36+
_logger = logger;
37+
}
3038
public bool isWorking()
3139
{
3240
if (!(downloadModels.Where(x => x.state == StateTask.Working).Count() > 0
@@ -35,6 +43,7 @@ public bool isWorking()
3543
stopTimer();
3644
return false;
3745
}
46+
startTimer();
3847
return true;
3948
}
4049

@@ -76,12 +85,14 @@ public void stopTimer()
7685

7786
private void OnTimedEvent(Object source, ElapsedEventArgs e)
7887
{
79-
Console.WriteLine("El evento Elapsed se disparó a las {0:HH:mm:ss.fff}", e.SignalTime);
88+
_logger.LogInformation("El evento Elapsed se disparó a las {0:HH:mm:ss.fff}", e.SignalTime);
89+
_logger.LogInformation("Upload: {0}, download: {1}", bytesUploaded, bytesDownloaded);
8090
if (bytesDownloaded > 0)
8191
setDownloadSpeed(HelperService.SizeSuffixPerTime(bytesDownloaded));
8292
if (bytesUploaded > 0)
8393
setUploadSpeed(HelperService.SizeSuffixPerTime(bytesUploaded));
8494
resetDownloadBytes();
95+
resetUploadBytes();
8596
}
8697

8798
public async Task addDownloadBytes(long bytes)
@@ -93,6 +104,7 @@ public async Task addDownloadBytes(long bytes)
93104

94105
public async Task addUploadBytes(long bytes)
95106
{
107+
_logger.LogInformation("Add bytes to upload {0}", bytes);
96108
UploadBytesMutex.WaitOne();
97109
bytesUploaded += bytes;
98110
UploadBytesMutex.ReleaseMutex();
@@ -120,6 +132,7 @@ public void setDownloadSpeed(String speed)
120132

121133
public void setUploadSpeed(String speed)
122134
{
135+
_logger.LogInformation("Set bytes speed upload {0}", speed);
123136
uploadSpeed = speed;
124137
TaskEventChanged.Invoke(null, EventArgs.Empty);
125138
}
@@ -189,8 +202,8 @@ public async Task CheckPendingDownloads()
189202
DownloadModel dm = pendingDownloadModels.FirstOrDefault();
190203
downloadModels.Insert(0, dm);
191204
pendingDownloadModels.Remove(dm);
192-
dm.RetryCallback();
193205
startTimer();
206+
dm.RetryCallback();
194207
}
195208
PendingDownloadMutex.ReleaseMutex();
196209
EventChanged?.Invoke(this, new EventArgs());
@@ -205,8 +218,8 @@ public async Task CheckPendingUploadInfoTasks()
205218
{
206219
InfoDownloadTaksModel idt = infoDownloadTaksModel.Where(x => x.state == StateTask.Pending).OrderBy(x => x.creationDate).FirstOrDefault();
207220
idt.state = StateTask.Working;
208-
idt.RetryCallback();
209221
startTimer();
222+
idt.RetryCallback();
210223
}
211224
PendingUploadInfoTaskMutex.ReleaseMutex();
212225
EventChanged?.Invoke(this, new EventArgs());

0 commit comments

Comments
 (0)