From 9774f5866ad6b8d0b48eb76b7b3cb3ed55a423a3 Mon Sep 17 00:00:00 2001 From: Kyriakos Sidiropoulos Date: Fri, 18 Oct 2024 14:04:38 +0200 Subject: [PATCH] refa (FileUploader.cs): trivial neutral refactoring to simplify FileUploader_FatalErrorOccurred_() by employing a simple switch-expression (old was: if-conditions) --- .../Shared/FileUploader/FileUploader.cs | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs b/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs index 320c1645..fadf4238 100644 --- a/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs +++ b/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs @@ -418,36 +418,27 @@ void FileUploader_FileUploadProgressPercentageAndDataThroughputChanged_(object s void FileUploader_FatalErrorOccurred_(object sender, FatalErrorOccurredEventArgs ea) { - var isAboutUnauthorized = ea.ErrorCode == EMcuMgrErrorCode.AccessDenied; - if (isAboutUnauthorized) + taskCompletionSource.TrySetException(ea.ErrorCode switch { - taskCompletionSource.TrySetException(new UploadUnauthorizedException( //specific case + EMcuMgrErrorCode.Unknown => new UploadErroredOutRemoteFolderNotFoundException( //specific case remoteFilePath: remoteFilePath, mcuMgrErrorCode: ea.ErrorCode, groupReturnCode: ea.GroupReturnCode, nativeErrorMessage: ea.ErrorMessage - )); - return; - } - - var isAboutFolderNotExisting = ea.ErrorCode == EMcuMgrErrorCode.Unknown; - if (isAboutFolderNotExisting) - { - taskCompletionSource.TrySetException(new UploadErroredOutRemoteFolderNotFoundException( //specific case + ), + EMcuMgrErrorCode.AccessDenied => new UploadUnauthorizedException( //specific case remoteFilePath: remoteFilePath, mcuMgrErrorCode: ea.ErrorCode, groupReturnCode: ea.GroupReturnCode, nativeErrorMessage: ea.ErrorMessage - )); - return; - } - - taskCompletionSource.TrySetException(new UploadErroredOutException( //generic - remoteFilePath: remoteFilePath, - mcuMgrErrorCode: ea.ErrorCode, - groupReturnCode: ea.GroupReturnCode, - nativeErrorMessage: ea.ErrorMessage - )); + ), + _ => new UploadErroredOutException( //generic + remoteFilePath: remoteFilePath, + mcuMgrErrorCode: ea.ErrorCode, + groupReturnCode: ea.GroupReturnCode, + nativeErrorMessage: ea.ErrorMessage + ) + }); } // ReSharper restore AccessToModifiedClosure }