From ae9942e892cf9fae3ec61cfcf2f90914d2e60561 Mon Sep 17 00:00:00 2001 From: Kyriakos Sidiropoulos Date: Fri, 18 Oct 2024 14:22:04 +0200 Subject: [PATCH] clean (FileDownloader.cs, FileUploader.cs): we now increase suspiciousTransportFailuresCount if and only if we're not dealing with a show-stopper error --- .../Shared/FileDownloader/FileDownloader.cs | 10 +++++----- .../Shared/FileUploader/FileUploader.cs | 16 +++++++--------- .../FirmwareInstaller/FirmwareInstaller.cs | 6 +++--- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Laerdal.McuMgr/Shared/FileDownloader/FileDownloader.cs b/Laerdal.McuMgr/Shared/FileDownloader/FileDownloader.cs index 3d7c21b2..94e7f683 100644 --- a/Laerdal.McuMgr/Shared/FileDownloader/FileDownloader.cs +++ b/Laerdal.McuMgr/Shared/FileDownloader/FileDownloader.cs @@ -267,11 +267,6 @@ public async Task DownloadAsync( } catch (DownloadErroredOutException ex) { - if (fileDownloadProgressEventsCount <= 10) - { - suspiciousTransportFailuresCount++; - } - if (ex is DownloadErroredOutRemoteFileNotFoundException) //order no point to retry if the remote file is not there { //OnStateChanged(new StateChangedEventArgs(newState: EFileDownloaderState.Error)); //noneed already done in native code @@ -283,6 +278,11 @@ public async Task DownloadAsync( //OnStateChanged(new StateChangedEventArgs(newState: EFileDownloaderState.Error)); //noneed already done in native code throw new AllDownloadAttemptsFailedException(remoteFilePath, maxTriesCount, innerException: ex); } + + if (fileDownloadProgressEventsCount <= 10) + { + suspiciousTransportFailuresCount++; + } if (sleepTimeBetweenRetriesInMs > 0) //order { diff --git a/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs b/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs index fadf4238..00cabb74 100644 --- a/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs +++ b/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs @@ -314,17 +314,17 @@ public async Task UploadAsync( } catch (UploadErroredOutException ex) //errors with code in_value(3) and even UnauthorizedException happen all the time in android when multiuploading files { - if (fileUploadProgressEventsCount <= 10) - { - suspiciousTransportFailuresCount++; - } - if (ex is UploadErroredOutRemoteFolderNotFoundException) //order no point to retry if any of the remote parent folders are not there throw; if (++triesCount > maxTriesCount) //order throw new AllUploadAttemptsFailedException(remoteFilePath, maxTriesCount, innerException: ex); + if (fileUploadProgressEventsCount <= 10) + { + suspiciousTransportFailuresCount++; + } + if (sleepTimeBetweenRetriesInMs > 0) //order { await Task.Delay(sleepTimeBetweenRetriesInMs); @@ -369,8 +369,7 @@ void FileUploader_FileUploaded_(object _, FileUploadedEventArgs ea_) taskCompletionSource.TrySetResult(true); } - // ReSharper disable AccessToModifiedClosure - void FileUploader_StateChanged_(object _, StateChangedEventArgs ea_) + void FileUploader_StateChanged_(object _, StateChangedEventArgs ea_) // ReSharper disable AccessToModifiedClosure { switch (ea_.NewState) { @@ -409,7 +408,7 @@ void FileUploader_StateChanged_(object _, StateChangedEventArgs ea_) //00 we first wait to allow the cancellation to be handled by the underlying native code meaning that we should see OnCancelled() // getting called right above but if that takes too long we give the killing blow by calling OnCancelled() manually here - } + } // ReSharper restore AccessToModifiedClosure void FileUploader_FileUploadProgressPercentageAndDataThroughputChanged_(object sender, FileUploadProgressPercentageAndDataThroughputChangedEventArgs ea) { @@ -440,7 +439,6 @@ void FileUploader_FatalErrorOccurred_(object sender, FatalErrorOccurredEventArgs ) }); } - // ReSharper restore AccessToModifiedClosure } if (isCancellationRequested) //vital diff --git a/Laerdal.McuMgr/Shared/FirmwareInstaller/FirmwareInstaller.cs b/Laerdal.McuMgr/Shared/FirmwareInstaller/FirmwareInstaller.cs index cad24d59..bc22da01 100644 --- a/Laerdal.McuMgr/Shared/FirmwareInstaller/FirmwareInstaller.cs +++ b/Laerdal.McuMgr/Shared/FirmwareInstaller/FirmwareInstaller.cs @@ -234,13 +234,13 @@ public async Task InstallAsync( } catch (FirmwareInstallationUploadingStageErroredOutException ex) //we only want to retry if the errors are related to the upload part of the process { + if (++triesCount > maxTriesCount) //order + throw new AllFirmwareInstallationAttemptsFailedException(maxTriesCount, innerException: ex); + if (_fileUploadProgressEventsCount <= 10) { suspiciousTransportFailuresCount++; } - - if (++triesCount > maxTriesCount) //order - throw new AllFirmwareInstallationAttemptsFailedException(maxTriesCount, innerException: ex); if (sleepTimeBetweenRetriesInMs > 0) //order {