diff --git a/DropboxSync.BLL/Services/DropboxService.cs b/DropboxSync.BLL/Services/DropboxService.cs index 4540d93..d43209f 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,35 @@ 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) + 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); + + return true; + } + catch (ApiException e) { - _logger.LogError("{date} | Something was created but not a folder at path {dropboxPath}", - DateTime.Now, createFolderResult.Metadata.PathDisplay); + _logger.LogError("{date} | The Dossier folder creation failed, please use another name : {e}", + DateTime.Now, e.Message); return false; } + catch (Exception e) + { + _logger.LogError("{date} | An exception was throw during Dossier creation! : {e}", + DateTime.Now, e.Message); - _logger.LogInformation("{date} | Successfully created folder for dossier \"{dossierName}\" at path {dropboxFolderPath}", - DateTime.Now, dossierName, createFolderResult.Metadata.PathDisplay); - - return true; + return false; + } } /// @@ -609,7 +625,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 +648,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 +657,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 +670,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 +754,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 +792,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 +804,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 +819,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 +889,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; } 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;