From 12ff50c53110d5ae0ae06cbfff1655d96fc7292e Mon Sep 17 00:00:00 2001 From: Soultan Date: Mon, 4 Jul 2022 15:40:05 +0200 Subject: [PATCH 1/5] code cleaning --- DropboxSync.UIL/BrokerEventListener.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/DropboxSync.UIL/BrokerEventListener.cs b/DropboxSync.UIL/BrokerEventListener.cs index 3a3b2a9..4a1736e 100644 --- a/DropboxSync.UIL/BrokerEventListener.cs +++ b/DropboxSync.UIL/BrokerEventListener.cs @@ -229,16 +229,6 @@ private void ReceiveMessage(ReceiverLink receiver, CancellationToken cancellatio SendToFailedQueue(textMessage, brokerEvent); } - // if (EventRedirection(brokerEvent, textMessage)) - // { - // // When a message is successfully treated, a ACK is sent to notify the broker - // _logger.LogInformation("{date} | Event {eventName} treated with success!", DateTime.Now, eventModel.EventName); - // } - // else - // { - // SendToFailedQueue(textMessage, brokerEvent); - // } - receiver.Accept(message); } } @@ -341,7 +331,6 @@ public void CheckFailedQueue() BrokerEvent eventType = (BrokerEvent)brokerEventParseResult; - // bool redirectionResult = Task.Run(() => EventRedirection(eventType, failedEvent.MessageJson)).Result; bool redirectionResult = Task.Run(() => _eventManagerLocator.RedirectToManager(failedEvent.MessageJson)).Result; From 80d047d4e8546b81b4d4ef4e445c8f8278e60aa1 Mon Sep 17 00:00:00 2001 From: Soultan Date: Fri, 8 Jul 2022 12:20:59 +0200 Subject: [PATCH 2/5] removed develop branch from docker-image action --- .github/workflows/docker-image.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 9340a3e..0a58efa 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -4,7 +4,6 @@ on: push: branches: - 'main' - - 'develop' jobs: docker: From 3b6027291090870ea46139b08a8aab545a6f60cd Mon Sep 17 00:00:00 2001 From: Soultan Date: Wed, 20 Jul 2022 10:10:46 +0200 Subject: [PATCH 3/5] cleaned code and added try catch during dossier creation --- DropboxSync.BLL/Services/DropboxService.cs | 69 +++++++++++++--------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/DropboxSync.BLL/Services/DropboxService.cs b/DropboxSync.BLL/Services/DropboxService.cs index 4540d93..1a022b6 100644 --- a/DropboxSync.BLL/Services/DropboxService.cs +++ b/DropboxSync.BLL/Services/DropboxService.cs @@ -119,7 +119,7 @@ public DropboxService(ILogger logger) _dropboxClient = new DropboxClient(_dropboxConfig.AccessToken); - if (!CheckDropboxClient()) throw new Exception($"An error occured during Dropbox Client checkout. Please read the precedent " + + if (!CheckDropboxClient()) throw new Exception($"An error occurred during Dropbox Client checkout. Please read the precedent " + $"logs to understand the error"); if (!AsyncHelper.RunSync(VerifyRootFolder)) throw new DropboxRootFolderMissingException(nameof(ROOT_FOLDER)); @@ -157,9 +157,9 @@ public async Task SaveUnprocessedFileAsync(string fileName, Da string dropboxId = dropboxUploadResult.Id.Substring(dropboxUploadResult.Id.IndexOf(':') + 1); - DropboxSavedFile finalOuput = new DropboxSavedFile(dropboxId, dropboxUploadResult.PathDisplay); + DropboxSavedFile finalOutput = new DropboxSavedFile(dropboxId, dropboxUploadResult.PathDisplay); - return finalOuput; + return finalOutput; } /// @@ -175,19 +175,29 @@ public async Task CreateDossierAsync(string dossierName, DateTime createdA string completeFolder = GenerateDossierFolderPath(createdAt.Year, dossierName); - CreateFolderResult createFolderResult = await _dropboxClient.Files.CreateFolderV2Async(completeFolder); + try + { + CreateFolderResult createFolderResult = await _dropboxClient.Files.CreateFolderV2Async(completeFolder); + + if (!createFolderResult.Metadata.IsFolder) + { + _logger.LogError("{date} | Something was created but not a folder at path {dropboxPath}", + DateTime.Now, createFolderResult.Metadata.PathDisplay); + return false; + } + + _logger.LogInformation("{date} | Successfully created folder for dossier \"{dossierName}\" at path {dropboxFolderPath}", + DateTime.Now, dossierName, createFolderResult.Metadata.PathDisplay); - if (!createFolderResult.Metadata.IsFolder) + return true; + } + catch (Exception e) { - _logger.LogError("{date} | Something was created but not a folder at path {dropboxPath}", - DateTime.Now, createFolderResult.Metadata.PathDisplay); + _logger.LogError("{date} | An exception was throw during Dossier creation! : {e}", + DateTime.Now, e.Message); + return false; } - - _logger.LogInformation("{date} | Successfully created folder for dossier \"{dossierName}\" at path {dropboxFolderPath}", - DateTime.Now, dossierName, createFolderResult.Metadata.PathDisplay); - - return true; } /// @@ -609,7 +619,9 @@ private string GenerateDossierFolderPath(int year, string dossierName) /// File creation year /// Dossier name /// File type - /// Dropbox's absolute path to the folder in dossier named + /// + /// Dropbox's absolute path to the folder in dossier named + /// /// /// /// @@ -630,8 +642,8 @@ private string GenerateDossierFolderPath(int year, string dossierName, FileTypes } /// - /// Generate a name for the file to save in Dropbox. The name is composed of the the date and the filename seperated by - /// . If at date 2022-10-22 at 18:42 a file with name MyFilesName.pdf + /// Generate a name for the file to save in Dropbox. The name is composed of the the date and the filename separated by + /// . If at date 2022-10-22 at 18:42 a file with name MyFilesName.pdf /// is created, then the generated name would look like this. /// /// 2022.10.22 1842-MyFilesName.pdf @@ -639,12 +651,12 @@ private string GenerateDossierFolderPath(int year, string dossierName, FileTypes /// /// File's complete name. The filename must respect the Regex /// - /// + /// /// /// /// /// - private string GenerateDropboxFileName(string fileName, DateTime createdAt, char seperator = '-') + private string GenerateDropboxFileName(string fileName, DateTime createdAt, char separator = '-') { fileName = fileName.Trim(); @@ -652,7 +664,7 @@ private string GenerateDropboxFileName(string fileName, DateTime createdAt, char if (fileName.StringMatchFileRegEx()) throw new InvalidFileNameException(nameof(fileName)); if (createdAt > DateTime.Now) throw new ArgumentOutOfRangeException(nameof(DateTime)); - return string.Join(seperator, createdAt.ToString("yyyy.MM.dd HHmm"), fileName); + return string.Join(separator, createdAt.ToString("yyyy.MM.dd HHmm"), fileName); } /// @@ -736,11 +748,11 @@ private async Task VerifyRootFolder() return false; } - bool firstOccurence = true; + bool firstOccurrence = true; do { - if (!firstOccurence) listFolderResult = await _dropboxClient.Files.ListFolderContinueAsync(listFolderResult.Cursor); + if (!firstOccurrence) listFolderResult = await _dropboxClient.Files.ListFolderContinueAsync(listFolderResult.Cursor); foreach (Metadata file in listFolderResult.Entries) { @@ -774,7 +786,8 @@ private async Task VerifyRootFolder() } /// - /// Verify if the folder at full dropbox path exist in Dropbox. If + /// Verify if the folder at full dropbox path exist in Dropbox. + /// If /// is true then the folder is created. /// /// @@ -785,8 +798,8 @@ private async Task VerifyRootFolder() /// /// If true, creates the folder at the researched destination /// - /// null if listing at path failed or if folder isn't found and is false. - /// Otherwise returns the Dropbox's required folder's path. + /// null if listing at path failed or if folder isn't found and + /// is false. Otherwise returns the Dropbox's required folder's path. /// /// private async Task VerifyFolderExist(string folderFullPath, bool createIfDontExist = false) @@ -800,18 +813,18 @@ private async Task VerifyRootFolder() return null; } - bool firstOccurence = true; + bool firstOccurrence = true; do { - if (!firstOccurence) listFolderResult = await _dropboxClient.Files.ListFolderContinueAsync(listFolderResult.Cursor); + if (!firstOccurrence) listFolderResult = await _dropboxClient.Files.ListFolderContinueAsync(listFolderResult.Cursor); foreach (Metadata metadata in listFolderResult.Entries) { if (metadata.IsFolder && metadata.PathDisplay.Equals(folderFullPath)) return metadata.AsFolder.PathDisplay; } - firstOccurence = false; + firstOccurrence = false; } while (listFolderResult.HasMore); @@ -870,11 +883,11 @@ private bool CheckDropboxClient() } catch (Exception e) { - _logger.LogError(e, "{date} | An exception occured during Dropbox SDK checkout.", DateTime.Now); + _logger.LogError(e, "{date} | An exception occurred during Dropbox SDK checkout.", DateTime.Now); return false; } - _logger.LogWarning("{date} | Something wrong happened during echo check. More informations are needed", DateTime.Now); + _logger.LogWarning("{date} | Something wrong happened during echo check. More information are needed", DateTime.Now); return false; } From dc33d2775e83ffca21dac9e3084a9e2054d0dfa8 Mon Sep 17 00:00:00 2001 From: Soultan Date: Wed, 20 Jul 2022 10:12:51 +0200 Subject: [PATCH 4/5] catch ApiException during folder creation --- DropboxSync.BLL/Services/DropboxService.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DropboxSync.BLL/Services/DropboxService.cs b/DropboxSync.BLL/Services/DropboxService.cs index 1a022b6..7c7a606 100644 --- a/DropboxSync.BLL/Services/DropboxService.cs +++ b/DropboxSync.BLL/Services/DropboxService.cs @@ -191,6 +191,11 @@ public async Task CreateDossierAsync(string dossierName, DateTime createdA return true; } + catch (ApiException e) + { + _logger.LogError("{date} | The Dossier folder creation failed : {e}", DateTime.Now, e.Message); + return false; + } catch (Exception e) { _logger.LogError("{date} | An exception was throw during Dossier creation! : {e}", From fcd1c51af86f800ba367e747be887ecd2c91d4e0 Mon Sep 17 00:00:00 2001 From: Soultan Date: Wed, 20 Jul 2022 10:14:32 +0200 Subject: [PATCH 5/5] added more informations in logging --- DropboxSync.BLL/Services/DropboxService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DropboxSync.BLL/Services/DropboxService.cs b/DropboxSync.BLL/Services/DropboxService.cs index 7c7a606..d43209f 100644 --- a/DropboxSync.BLL/Services/DropboxService.cs +++ b/DropboxSync.BLL/Services/DropboxService.cs @@ -193,7 +193,8 @@ public async Task CreateDossierAsync(string dossierName, DateTime createdA } catch (ApiException e) { - _logger.LogError("{date} | The Dossier folder creation failed : {e}", DateTime.Now, e.Message); + _logger.LogError("{date} | The Dossier folder creation failed, please use another name : {e}", + DateTime.Now, e.Message); return false; } catch (Exception e)