Handle operation execution errors in rendering page.
This commit is contained in:
@@ -17,6 +17,7 @@ using Wino.Core.Domain;
|
|||||||
using Wino.Core.Domain.Entities.Mail;
|
using Wino.Core.Domain.Entities.Mail;
|
||||||
using Wino.Core.Domain.Entities.Shared;
|
using Wino.Core.Domain.Entities.Shared;
|
||||||
using Wino.Core.Domain.Enums;
|
using Wino.Core.Domain.Enums;
|
||||||
|
using Wino.Core.Domain.Exceptions;
|
||||||
using Wino.Core.Domain.Interfaces;
|
using Wino.Core.Domain.Interfaces;
|
||||||
using Wino.Core.Domain.Models.MailItem;
|
using Wino.Core.Domain.Models.MailItem;
|
||||||
using Wino.Core.Domain.Models.Menus;
|
using Wino.Core.Domain.Models.Menus;
|
||||||
@@ -42,6 +43,7 @@ public partial class MailRenderingPageViewModel : MailBaseViewModel,
|
|||||||
|
|
||||||
private readonly IMimeFileService _mimeFileService;
|
private readonly IMimeFileService _mimeFileService;
|
||||||
private readonly Core.Domain.Interfaces.IMailService _mailService;
|
private readonly Core.Domain.Interfaces.IMailService _mailService;
|
||||||
|
private readonly IFolderService _folderService;
|
||||||
private readonly IFileService _fileService;
|
private readonly IFileService _fileService;
|
||||||
private readonly IWinoRequestDelegator _requestDelegator;
|
private readonly IWinoRequestDelegator _requestDelegator;
|
||||||
private readonly IContactService _contactService;
|
private readonly IContactService _contactService;
|
||||||
@@ -145,6 +147,7 @@ public partial class MailRenderingPageViewModel : MailBaseViewModel,
|
|||||||
IUnderlyingThemeService underlyingThemeService,
|
IUnderlyingThemeService underlyingThemeService,
|
||||||
IMimeFileService mimeFileService,
|
IMimeFileService mimeFileService,
|
||||||
IMailService mailService,
|
IMailService mailService,
|
||||||
|
IFolderService folderService,
|
||||||
IFileService fileService,
|
IFileService fileService,
|
||||||
IWinoRequestDelegator requestDelegator,
|
IWinoRequestDelegator requestDelegator,
|
||||||
IStatePersistanceService statePersistenceService,
|
IStatePersistanceService statePersistenceService,
|
||||||
@@ -167,6 +170,7 @@ public partial class MailRenderingPageViewModel : MailBaseViewModel,
|
|||||||
_underlyingThemeService = underlyingThemeService;
|
_underlyingThemeService = underlyingThemeService;
|
||||||
_mimeFileService = mimeFileService;
|
_mimeFileService = mimeFileService;
|
||||||
_mailService = mailService;
|
_mailService = mailService;
|
||||||
|
_folderService = folderService;
|
||||||
_fileService = fileService;
|
_fileService = fileService;
|
||||||
_requestDelegator = requestDelegator;
|
_requestDelegator = requestDelegator;
|
||||||
}
|
}
|
||||||
@@ -258,69 +262,92 @@ public partial class MailRenderingPageViewModel : MailBaseViewModel,
|
|||||||
|
|
||||||
private async Task HandleMailOperationAsync(MailOperation operation)
|
private async Task HandleMailOperationAsync(MailOperation operation)
|
||||||
{
|
{
|
||||||
// Toggle theme
|
try
|
||||||
if (operation == MailOperation.DarkEditor || operation == MailOperation.LightEditor)
|
|
||||||
IsDarkWebviewRenderer = !IsDarkWebviewRenderer;
|
|
||||||
else if (operation == MailOperation.SaveAs)
|
|
||||||
{
|
{
|
||||||
await SaveAsAsync();
|
// Toggle theme
|
||||||
}
|
if (operation == MailOperation.DarkEditor || operation == MailOperation.LightEditor)
|
||||||
else if (operation == MailOperation.Print)
|
IsDarkWebviewRenderer = !IsDarkWebviewRenderer;
|
||||||
{
|
else if (operation == MailOperation.SaveAs)
|
||||||
var settings = await _dialogService.ShowPrintDialogAsync();
|
|
||||||
|
|
||||||
if (settings == null) return;
|
|
||||||
|
|
||||||
var printingResult = await DirectPrintFuncAsync.Invoke(settings);
|
|
||||||
|
|
||||||
// TODO: More detailed printing result handling.
|
|
||||||
if (printingResult == PrintingResult.Submitted)
|
|
||||||
{
|
{
|
||||||
_dialogService.InfoBarMessage(Translator.DialogMessage_PrintingSuccessTitle, Translator.DialogMessage_PrintingSuccessMessage, InfoBarMessageType.Success);
|
await SaveAsAsync();
|
||||||
}
|
}
|
||||||
else if (printingResult == PrintingResult.Failed)
|
else if (operation == MailOperation.Print)
|
||||||
{
|
{
|
||||||
_dialogService.InfoBarMessage(Translator.DialogMessage_PrintingFailedTitle, Translator.DialogMessage_PrintingFailedMessage, InfoBarMessageType.Error);
|
var settings = await _dialogService.ShowPrintDialogAsync();
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if (settings == null) return;
|
||||||
else if (operation == MailOperation.ViewMessageSource)
|
|
||||||
{
|
|
||||||
await _dialogService.ShowMessageSourceDialogAsync(initializedMimeMessageInformation.MimeMessage.ToString());
|
|
||||||
}
|
|
||||||
else if (operation == MailOperation.Reply || operation == MailOperation.ReplyAll || operation == MailOperation.Forward)
|
|
||||||
{
|
|
||||||
if (initializedMailItemViewModel == null) return;
|
|
||||||
|
|
||||||
// Create new draft.
|
var printingResult = await DirectPrintFuncAsync.Invoke(settings);
|
||||||
var draftOptions = new DraftCreationOptions()
|
|
||||||
{
|
// TODO: More detailed printing result handling.
|
||||||
Reason = operation switch
|
if (printingResult == PrintingResult.Submitted)
|
||||||
{
|
{
|
||||||
MailOperation.Reply => DraftCreationReason.Reply,
|
_dialogService.InfoBarMessage(Translator.DialogMessage_PrintingSuccessTitle, Translator.DialogMessage_PrintingSuccessMessage, InfoBarMessageType.Success);
|
||||||
MailOperation.ReplyAll => DraftCreationReason.ReplyAll,
|
}
|
||||||
MailOperation.Forward => DraftCreationReason.Forward,
|
else if (printingResult == PrintingResult.Failed)
|
||||||
_ => DraftCreationReason.Empty
|
{
|
||||||
},
|
_dialogService.InfoBarMessage(Translator.DialogMessage_PrintingFailedTitle, Translator.DialogMessage_PrintingFailedMessage, InfoBarMessageType.Error);
|
||||||
ReferencedMessage = new ReferencedMessage()
|
|
||||||
{
|
|
||||||
MimeMessage = initializedMimeMessageInformation.MimeMessage,
|
|
||||||
MailCopy = initializedMailItemViewModel.MailCopy
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
var (draftMailCopy, draftBase64MimeMessage) = await _mailService.CreateDraftAsync(initializedMailItemViewModel.MailCopy.AssignedAccount.Id, draftOptions).ConfigureAwait(false);
|
}
|
||||||
|
else if (operation == MailOperation.ViewMessageSource)
|
||||||
|
{
|
||||||
|
await _dialogService.ShowMessageSourceDialogAsync(initializedMimeMessageInformation.MimeMessage.ToString());
|
||||||
|
}
|
||||||
|
else if (operation == MailOperation.Reply || operation == MailOperation.ReplyAll || operation == MailOperation.Forward)
|
||||||
|
{
|
||||||
|
if (initializedMailItemViewModel == null) return;
|
||||||
|
|
||||||
var draftPreparationRequest = new DraftPreparationRequest(initializedMailItemViewModel.MailCopy.AssignedAccount, draftMailCopy, draftBase64MimeMessage, draftOptions.Reason, initializedMailItemViewModel.MailCopy);
|
// Create new draft.
|
||||||
|
var draftOptions = new DraftCreationOptions()
|
||||||
|
{
|
||||||
|
Reason = operation switch
|
||||||
|
{
|
||||||
|
MailOperation.Reply => DraftCreationReason.Reply,
|
||||||
|
MailOperation.ReplyAll => DraftCreationReason.ReplyAll,
|
||||||
|
MailOperation.Forward => DraftCreationReason.Forward,
|
||||||
|
_ => DraftCreationReason.Empty
|
||||||
|
},
|
||||||
|
ReferencedMessage = new ReferencedMessage()
|
||||||
|
{
|
||||||
|
MimeMessage = initializedMimeMessageInformation.MimeMessage,
|
||||||
|
MailCopy = initializedMailItemViewModel.MailCopy
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
await _requestDelegator.ExecuteAsync(draftPreparationRequest);
|
var (draftMailCopy, draftBase64MimeMessage) = await _mailService.CreateDraftAsync(initializedMailItemViewModel.MailCopy.AssignedAccount.Id, draftOptions).ConfigureAwait(false);
|
||||||
|
|
||||||
|
var draftPreparationRequest = new DraftPreparationRequest(initializedMailItemViewModel.MailCopy.AssignedAccount, draftMailCopy, draftBase64MimeMessage, draftOptions.Reason, initializedMailItemViewModel.MailCopy);
|
||||||
|
|
||||||
|
await _requestDelegator.ExecuteAsync(draftPreparationRequest);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (initializedMailItemViewModel != null)
|
||||||
|
{
|
||||||
|
// All other operations require a mail item.
|
||||||
|
var prepRequest = new MailOperationPreperationRequest(operation, initializedMailItemViewModel.MailCopy);
|
||||||
|
await _requestDelegator.ExecuteAsync(prepRequest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (initializedMailItemViewModel != null)
|
catch (UnavailableSpecialFolderException unavailableSpecialFolderException)
|
||||||
{
|
{
|
||||||
// All other operations require a mail item.
|
_dialogService.InfoBarMessage(Translator.Info_MissingFolderTitle,
|
||||||
var prepRequest = new MailOperationPreperationRequest(operation, initializedMailItemViewModel.MailCopy);
|
string.Format(Translator.Info_MissingFolderMessage, unavailableSpecialFolderException.SpecialFolderType),
|
||||||
await _requestDelegator.ExecuteAsync(prepRequest);
|
InfoBarMessageType.Warning,
|
||||||
|
Translator.SettingConfigureSpecialFolders_Button,
|
||||||
|
() =>
|
||||||
|
{
|
||||||
|
_dialogService.HandleSystemFolderConfigurationDialogAsync(unavailableSpecialFolderException.AccountId, _folderService);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (NotImplementedException)
|
||||||
|
{
|
||||||
|
_dialogService.ShowNotSupportedMessage();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Mail operation execution failed. Operation: {Operation}", operation);
|
||||||
|
_dialogService.InfoBarMessage(Translator.Info_RequestCreationFailedTitle, ex.Message, InfoBarMessageType.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user