2024-04-18 01:44:37 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
|
using Windows.UI.Xaml.Navigation;
|
|
|
|
|
|
using Wino.Core.Domain.Entities;
|
2024-06-17 02:16:06 +02:00
|
|
|
|
using Wino.Core.Domain.Exceptions;
|
2024-06-07 23:58:51 +02:00
|
|
|
|
using Wino.Core.Domain.Interfaces;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
using Wino.Core.Domain.Models.AutoDiscovery;
|
2024-08-05 00:36:26 +02:00
|
|
|
|
using Wino.Messaging.Client.Mails;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Wino.Views.ImapSetup
|
|
|
|
|
|
{
|
|
|
|
|
|
public sealed partial class TestingImapConnectionPage : Page
|
|
|
|
|
|
{
|
2024-06-17 02:16:06 +02:00
|
|
|
|
private IImapTestService _imapTestService = App.Current.Services.GetService<IImapTestService>();
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
|
|
|
|
|
public TestingImapConnectionPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task TryTestConnectionAsync(CustomServerInformation serverInformation)
|
|
|
|
|
|
{
|
|
|
|
|
|
await Task.Delay(1000);
|
|
|
|
|
|
|
|
|
|
|
|
await _imapTestService.TestImapConnectionAsync(serverInformation);
|
|
|
|
|
|
|
|
|
|
|
|
// All success. Finish setup with validated server information.
|
|
|
|
|
|
|
|
|
|
|
|
WeakReferenceMessenger.Default.Send(new ImapSetupDismissRequested(serverInformation));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override async void OnNavigatedTo(NavigationEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnNavigatedTo(e);
|
|
|
|
|
|
|
2024-06-17 02:16:06 +02:00
|
|
|
|
// We can only go back to this page from failed connection page.
|
|
|
|
|
|
// We must go back once again in that case to actual setup dialog.
|
|
|
|
|
|
if (e.NavigationMode == NavigationMode.Back)
|
|
|
|
|
|
{
|
|
|
|
|
|
WeakReferenceMessenger.Default.Send(new ImapSetupBackNavigationRequested());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2024-06-17 02:16:06 +02:00
|
|
|
|
// Test connection
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2024-06-17 02:16:06 +02:00
|
|
|
|
CustomServerInformation serverInformationToTest = null;
|
|
|
|
|
|
AutoDiscoverySettings autoDiscoverySettings = null;
|
|
|
|
|
|
|
|
|
|
|
|
// Discovery settings are passed.
|
|
|
|
|
|
// Create server information out of the discovery settings.
|
|
|
|
|
|
if (e.Parameter is AutoDiscoverySettings parameterAutoDiscoverySettings)
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2024-06-17 02:16:06 +02:00
|
|
|
|
autoDiscoverySettings = parameterAutoDiscoverySettings;
|
|
|
|
|
|
serverInformationToTest = autoDiscoverySettings.ToServerInformation();
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
2024-06-17 02:16:06 +02:00
|
|
|
|
else if (e.Parameter is CustomServerInformation customServerInformation)
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2024-06-17 02:16:06 +02:00
|
|
|
|
// Only server information is passed.
|
|
|
|
|
|
serverInformationToTest = customServerInformation;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
2024-06-17 02:16:06 +02:00
|
|
|
|
|
2024-04-18 01:44:37 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-06-17 02:16:06 +02:00
|
|
|
|
await TryTestConnectionAsync(serverInformationToTest);
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2024-06-17 02:16:06 +02:00
|
|
|
|
string protocolLog = ex is ImapClientPoolException clientPoolException ? clientPoolException.ProtocolLog : string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
var failurePackage = new ImapConnectionFailedPackage(ex, protocolLog, autoDiscoverySettings);
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2024-06-17 02:16:06 +02:00
|
|
|
|
WeakReferenceMessenger.Default.Send(new ImapSetupBackNavigationRequested(typeof(ImapConnectionFailedPage), failurePackage));
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|