private async void Logout_Click(object sender, RoutedEventArgs e) { ContentDialog dialog = new ContentDialog { Title = "警告", PrimaryButtonText = "继续", CloseButtonText = "取消", Content = "此操作将注销当前账户\r\r可能需要重新输入相关信息,是否继续?", Background = Application.Current.Resources["DialogAcrylicBrush"] as Brush }; if ((await dialog.ShowAsync()) != ContentDialogResult.Primary) { return; } LoadingText.Text = "正在注销..."; LoadingControl.IsLoading = true; ConnectionCancellation?.Cancel(); await Task.Delay(1000); ConnectionCancellation?.Dispose(); ConnectionCancellation = null; DisplayMode.SelectionChanged -= DisplayMode_SelectionChanged; LastSelectedItem = null; if (EmailProtocolServiceProvider.CheckWhetherInstanceExist()) { EmailProtocolServiceProvider.GetInstance().Dispose(); } EmailService = null; ApplicationData.Current.LocalSettings.Values["EmailStartup"] = null; ApplicationData.Current.RoamingSettings.Values["EmailCredentialName"] = null; ApplicationData.Current.RoamingSettings.Values["EmailCredentialPassword"] = null; ApplicationData.Current.RoamingSettings.Values["EmailIMAPAddress"] = null; ApplicationData.Current.RoamingSettings.Values["EmailIMAPPort"] = null; ApplicationData.Current.RoamingSettings.Values["EmailSMTPAddress"] = null; ApplicationData.Current.RoamingSettings.Values["EmailSMTPPort"] = null; ApplicationData.Current.RoamingSettings.Values["EmailEnableSSL"] = null; ApplicationData.Current.RoamingSettings.Values["EmailCallName"] = null; LoadingControl.IsLoading = false; await Task.Delay(700); EmailAllItemCollection.Clear(); EmailNotSeenItemCollection.Clear(); EmailDisplayCollection?.Clear(); EmailPage.ThisPage.Nav.Navigate(typeof(EmailStartupOne), EmailPage.ThisPage.Nav, new DrillInNavigationTransitionInfo()); NothingDisplayControl.Visibility = Visibility.Visible; }
/// <summary> /// 在将要挂起应用程序执行时调用。 在不知道应用程序 /// 无需知道应用程序会被终止还是会恢复, /// 并让内存内容保持不变。 /// </summary> /// <param name="sender">挂起的请求的源。</param> /// <param name="e">有关挂起请求的详细信息。</param> private void OnSuspending(object sender, SuspendingEventArgs e) { //TODO: 保存应用程序状态并停止任何后台活动 SQLite.GetInstance().Dispose(); if (EmailProtocolServiceProvider.CheckWhetherInstanceExist()) { EmailProtocolServiceProvider.GetInstance().Dispose(); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { EmailService = EmailProtocolServiceProvider.GetInstance(); if (e.Parameter is EmailLoginData data) { EmailService.SetCredential(new System.Net.NetworkCredential(data.EmailAddress, data.Password), data.CallName); KeyValuePair <EmailProtocol, KeyValuePair <string, int> > IMAP = new KeyValuePair <EmailProtocol, KeyValuePair <string, int> >(EmailProtocol.IMAP, new KeyValuePair <string, int>(data.IMAPAddress, data.IMAPPort)); KeyValuePair <EmailProtocol, KeyValuePair <string, int> > SMTP = new KeyValuePair <EmailProtocol, KeyValuePair <string, int> >(EmailProtocol.SMTP, new KeyValuePair <string, int>(data.SMTPAddress, data.SMTPPort)); EmailService.SetEmailServerAddress(new List <KeyValuePair <EmailProtocol, KeyValuePair <string, int> > > { IMAP, SMTP }, data.IsEnableSSL); } }
//点击发送时执行此函数 public async void ThisPage_SendEmailRequested(object sender, SendEmailData e) { EmailPresenter.ThisPage.LoadingActivation(true, "正在发送..."); //根据EmailSendType区分发送的邮件类型 switch (e.SendType) { case EmailSendType.NormalSend: { MimeMessage SendMessage = GetSendMessage(e.To, new MailboxAddress(EmailService.CallName, EmailService.UserName), e.Subject, e.Text, e.Attachments); await EmailProtocolServiceProvider.GetInstance().SendEmailAsync(SendMessage); break; } case EmailSendType.Reply: { MimeMessage message = (EmailPresenter.ThisPage.EmailList.SelectedItem as EmailItem).Message; MimeMessage ReplyMessage = GetReplyMessage(message, new MailboxAddress(EmailService.CallName, EmailService.UserName), e.Attachments, false, e.Text); await EmailProtocolServiceProvider.GetInstance().SendEmailAsync(ReplyMessage); break; } case EmailSendType.ReplyToAll: { MimeMessage message = (EmailPresenter.ThisPage.EmailList.SelectedItem as EmailItem).Message; MimeMessage ReplyMessage = GetReplyMessage(message, new MailboxAddress(EmailService.CallName, EmailService.UserName), e.Attachments, true, e.Text); await EmailProtocolServiceProvider.GetInstance().SendEmailAsync(ReplyMessage); break; } case EmailSendType.Forward: { MimeMessage message = (EmailPresenter.ThisPage.EmailList.SelectedItem as EmailItem).Message; MimeMessage ForwardMessage = GetForwardMessage(message, new MailboxAddress(EmailService.CallName, EmailService.UserName), e.To); await EmailProtocolServiceProvider.GetInstance().SendEmailAsync(ForwardMessage); break; } } await Task.Delay(1000); EmailPresenter.ThisPage.LoadingActivation(false); }
private async void Email_Loaded(object sender, RoutedEventArgs e) { Updating = true; Nav.Navigate(typeof(EmailDetail), null, new DrillInNavigationTransitionInfo()); DisplayMode.SelectionChanged += DisplayMode_SelectionChanged; ConnectionCancellation = new CancellationTokenSource(); await ActivateSyncNotification(true); try { if (EmailService == null) { EmailService = EmailProtocolServiceProvider.GetInstance(); } await EmailService.ConnectAllServiceAsync(ConnectionCancellation); } catch (TaskCanceledException) { await ActivateSyncNotification(false); } catch (OperationCanceledException) { await ActivateSyncNotification(false); } catch (SocketException) { SyncNotification.Dismiss(); await Task.Delay(1000); bool isTemplatePresent = Resources.TryGetValue("NetWorkErrorNotificationTemplate", out object NotificationTemplate); if (isTemplatePresent && NotificationTemplate is DataTemplate template) { SyncNotification.Show(template, 5000); } Updating = false; return; } catch (ImapProtocolException) { SyncNotification.Dismiss(); await Task.Delay(1000); bool isTemplatePresent = Resources.TryGetValue("ProtocolErrorNotificationTemplate", out object NotificationTemplate); if (isTemplatePresent && NotificationTemplate is DataTemplate template) { SyncNotification.Show(template, 5000); } Updating = false; return; } catch (SmtpProtocolException) { SyncNotification.Dismiss(); await Task.Delay(1000); bool isTemplatePresent = Resources.TryGetValue("ProtocolErrorNotificationTemplate", out object NotificationTemplate); if (isTemplatePresent && NotificationTemplate is DataTemplate template) { SyncNotification.Show(template, 5000); } Updating = false; return; } catch (SslHandshakeException) { SyncNotification.Dismiss(); await Task.Delay(1000); bool isTemplatePresent = Resources.TryGetValue("SSLErrorNotificationTemplate", out object NotificationTemplate); if (isTemplatePresent && NotificationTemplate is DataTemplate template) { SyncNotification.Show(template, 5000); } Updating = false; return; } catch (Exception) { SyncNotification.Dismiss(); await Task.Delay(1000); bool isTemplatePresent = Resources.TryGetValue("AuthenticationErrorNotificationTemplate", out object NotificationTemplate); if (isTemplatePresent && NotificationTemplate is DataTemplate template) { SyncNotification.Show(template, 5000); } Updating = false; return; } if (!ConnectionCancellation.IsCancellationRequested) { try { await LoadEmailData(); await ActivateSyncNotification(false); } catch (Exception) { } } Updating = false; }