// Updates the mailbox tree in the specified account with ones from the server. // Also updates the database to reflect the change. public void BeginSyncMailboxList(Account account) { Task.Factory.StartNew(() => { List <Mailbox> localMailboxes = DatabaseManager.GetMailboxes(account.AccountName); ImapClient imapClient = new ImapClient(account); if (imapClient.Connect()) { List <Mailbox> serverMailboxes = imapClient.ListMailboxes(); var comparer = new CompareMailbox(); var localNotServer = localMailboxes.Except(serverMailboxes, comparer).ToList(); var serverNotLocal = serverMailboxes.Except(localMailboxes, comparer).ToList(); if (localNotServer.Count > 0 || serverNotLocal.Count > 0) { account.Mailboxes.Clear(); account.Mailboxes.AddRange(serverMailboxes); if (localNotServer.Count > 0) { DatabaseManager.DeleteMailboxes(localNotServer); } if (serverNotLocal.Count > 0) { DatabaseManager.InsertMailboxes(serverNotLocal); } } imapClient.Disconnect(); } GlobalEventAggregator.Instance.GetEvent <MailboxListSyncFinishedEvent>().Publish(account); }); }
// Updates the mailbox tree in the specified account with ones from the server. // Also updates the database to reflect the change. private void BeginSyncMailboxList(Account account) { Task.Factory.StartNew(() => { List <Mailbox> localMailboxes = DatabaseManager.GetMailboxes(account.AccountName); ImapClient imapClient = new ImapClient(account); if (imapClient.Connect()) { List <Mailbox> serverMailboxes = imapClient.ListMailboxes(); var comparer = new CompareMailbox(); var localNotServer = localMailboxes.Except(serverMailboxes, comparer).ToList(); var serverNotLocal = serverMailboxes.Except(localMailboxes, comparer).ToList(); if (localNotServer.Count > 0 || serverNotLocal.Count > 0) { account.Mailboxes.Clear(); account.Mailboxes.AddRange(serverMailboxes); if (localNotServer.Count > 0) { DatabaseManager.DeleteMailboxes(localNotServer); } if (serverNotLocal.Count > 0) { DatabaseManager.InsertMailboxes(serverNotLocal); } } imapClient.Disconnect(); } while (!Common.Globals.BootStrapperLoaded) { // We don't want to fire this event before the subscribers are ready. // There must be a better way to handle these sort of things. Thread.Sleep(50); } GlobalEventAggregator.Instance.GetEvent <MailboxListSyncFinishedEvent>().Publish(account); }); }
// Updates the mailbox tree in the specified account with ones from the server. // Also updates the database to reflect the change. private void BeginSyncMailboxList(Account account) { Task.Factory.StartNew(() => { List<Mailbox> localMailboxes = DatabaseManager.GetMailboxes(account.AccountName); ImapClient imapClient = new ImapClient(account); if (imapClient.Connect()) { List<Mailbox> serverMailboxes = imapClient.ListMailboxes(); var comparer = new CompareMailbox(); var localNotServer = localMailboxes.Except(serverMailboxes, comparer).ToList(); var serverNotLocal = serverMailboxes.Except(localMailboxes, comparer).ToList(); if (localNotServer.Count > 0 || serverNotLocal.Count > 0) { account.Mailboxes.Clear(); account.Mailboxes.AddRange(serverMailboxes); if (localNotServer.Count > 0) { DatabaseManager.DeleteMailboxes(localNotServer); } if (serverNotLocal.Count > 0) { DatabaseManager.InsertMailboxes(serverNotLocal); } } imapClient.Disconnect(); } while (!Common.Globals.BootStrapperLoaded) { // We don't want to fire this event before the subscribers are ready. // There must be a better way to handle these sort of things. Thread.Sleep(50); } GlobalEventAggregator.Instance.GetEvent<MailboxListSyncFinishedEvent>().Publish(account); }); }