/// <summary> /// -- Check de la saisie user de Bccmail et Ccmail -- /// </summary> /// <param name="email"></param> private void ValidateEmail(string email) { // -- $"==> Vérification de email saisie." -- if ((!string.IsNullOrEmpty(email) && !RegexMailUtilities.IsValidEmail(email)) && !RegexMailUtilities.IsValidEmail(email)) { CanContinuousSendMail = false; ErrorMessage = string.Format(ErrorMessageLabels.ImpossibleToSendMailMsg, email); _logger.Error(ErrorMessage); _dialogService.ShowMessage(ErrorMessage, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Yes); } else { _logger.Debug($"==> Poursuite de l'envoie de mail après vérification de l'email [{email}]."); CanContinuousSendMail = true; } }
/// <summary> /// -- Check de la ssisie user de Bccmail et Ccmail -- /// </summary> /// <param name="email"></param> private void ValidateEmail(string email) { // -- $"==> Vérification de email saisie." -- if ((!string.IsNullOrEmpty(email) && !RegexMailUtilities.IsValidEmail(email)) && !RegexMailUtilities.IsValidEmail(email)) { CanContinuousSendMail = false; ErrorMessage = string.Format(ErrorMessageLabels.ImpossibleToSendMailMsg, email); //ErrorMessage = $"Impossoble d'envoyer des mails.\n Assurez-vous que l'adresse : [{email}] saisie soit valide."; _logger.Error(ErrorMessage); _dialogService.ShowMessage(ErrorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Yes); } else { // -- $"==> Poursuite de l'envoie de mail après vérification de l'email." -- CanContinuousSendMail = true; } }
/// <summary> /// -- Feel dictionary -- /// </summary> /// <returns>Dictionary<string, string></returns> private Dictionary <string, string> ConsolidateDataHelper() { ErrorMessage = string.Empty; _logger.Debug($"==> Début consolidation des données dans le dictionaire."); var myDictionnary = new Dictionary <string, string>(); myDictionnary.Clear(); List <string> wrongPathList = new List <string>(); wrongPathList.Clear(); if (_myDataTable.Rows.Count < 1) { ErrorMessage = ErrorMessageLabels.NoDataInDataTableMsg; _logger.Error($"==> {ErrorMessage}."); return(null); } try { _logger.Debug($"==> Début parcours de dataTable. Vérifiaction de la validité de l'email et autre"); for (int i = 0; i < _myDataTable.Rows.Count - 1; i++) { // -- $"==> Récupération de l'email." -- var mail = _myDataTable.Rows[i][0].ToString(); // -- $"==> Récupération du chemin de la fiche de paie." -- var filePath = _myDataTable.Rows[i][1].ToString(); if (!string.IsNullOrWhiteSpace(mail) && !myDictionnary.ContainsKey(mail)) { // -- Check if email is valid -- if (RegexMailUtilities.IsValidEmail(mail)) { // -- Check filePath -- if (!string.IsNullOrWhiteSpace(filePath)) { if (File.Exists(filePath)) { // -- Get file name -- var fileName = Path.GetFileName(filePath); // -- Get userName in email -- string fullName = mail.Split('@')[0]; // -- Get userName in file -- var file = fileName.Split('_')[0]; // -- Check correspondance -- // -- $"==> Rafraichissement du dictionaire." -- if (fullName == file) { myDictionnary.Add(mail, filePath); } } else { ErrorMessage = string.Format(ErrorMessageLabels.CheckFilePathMsg, _myDataTable.Rows[i][1].ToString()); _logger.Error($"==> {ErrorMessage}."); wrongPathList.Add(filePath); } } else { ErrorMessage = string.Format(ErrorMessageLabels.CheckFilePathMsg, _myDataTable.Rows[i][1].ToString()); _logger.Error($"==> {ErrorMessage}"); wrongPathList.Add(filePath); } } } } _logger.Debug($"==> Fin parcours de dataTable. récupération des données dans le dictionaire."); } catch (Exception ex) { ErrorMessage = string.Format(ErrorMessageLabels.AnErreurOccuredMsg, ex.ToString()); _logger.Error($"==> {ErrorMessage}."); throw new Exception(ex.ToString()); } finally { if (!string.IsNullOrWhiteSpace(ErrorMessage)) { StringBuilder stringBuilder = new StringBuilder(); if (wrongPathList.Count > 0) { foreach (var item in wrongPathList) { stringBuilder.Append($"{item} " + Environment.NewLine); } } ErrorMessage = stringBuilder.Length > 0 ? string.Format(ErrorMessageLabels.CheckFilesPathMsg, stringBuilder.ToString()) : ErrorMessage; _dialogService.ShowMessage($"[{ErrorMessage}", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Yes); } } _logger.Debug($"==> Fin consolidation des données dans le dictionaire."); return(myDictionnary); }
/// <summary> /// -- perform all work here -- /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Export_DoWork(object sender, DoWorkEventArgs e) { IsProgressBarVisible = true; IsMainGridEnable = false; // -- -- _logger.Debug($"==> Début appel à la méthode de Vérification de l'email."); ValidateEmail(BccMail); ValidateEmail(CcMail); ValidateEmail(AdminEmail); _logger.Debug($"==> Fin appel à la méthode de Vérification de l'email."); for (int i = 0; i < CountData; i++) { if (bgWorkerExport.CancellationPending == true) { e.Cancel = true; break; } else { // -- Perform a time consuming operation and report progress. -- System.Threading.Thread.Sleep(CountData); #region -- Build any email content -- var item = MyDictionnary.ElementAt(i); var itemKey = item.Key; var itemValue = item.Value; _logger.Debug($"==> Debut vérification du format des champs BCC et CC."); #region -- ******************************************** -- var ed = string.IsNullOrEmpty(bccEmail); var de = RegexMailUtilities.IsValidEmail(bccEmail); var ea = string.IsNullOrEmpty(ccEmail); var ee = RegexMailUtilities.IsValidEmail(ccEmail); if (!string.IsNullOrEmpty(bccEmail) || !string.IsNullOrEmpty(ccEmail)) { } else { if (!RegexMailUtilities.IsValidEmail(bccEmail) || !RegexMailUtilities.IsValidEmail(ccEmail)) { } } //if ((string.IsNullOrEmpty(bccEmail) || !RegexMailUtilities.IsValidEmail(bccEmail)) || // (string.IsNullOrEmpty(ccEmail) || !RegexMailUtilities.IsValidEmail(ccEmail))) //{ // ErrorMessage = "Vérifier le format des champs Bcc, Cc"; // _logger.Error($"==> {ErrorMessage}"); // _dialogService.ShowMessage(ErrorMessage, "ERROR", // MessageBoxButton.OK, // MessageBoxImage.Error, // MessageBoxResult.Yes); // CanContinuousSendMail = false; // break; //} #endregion _logger.Debug($"==> Fin vérification du format des champs BCC et CC."); // -- Send mail -- _logger.Debug($"==> Apple de la méthode de création de mail. [BuildMailBody]"); if (BuildMailBody(itemKey, itemValue, BccMail, CcMail) == false) { _logger.Error($"==> Erreur pendant la construction d mail. [BuildMailBody]"); CanContinuousSendMail = false; break; } #endregion bgWorkerExport.ReportProgress((i + 1) * (100 / CountData)); } } }