private void LoadAttachments(IEnumerable <MessageAttachment> attachments, ILoadingProgressCallback progressCallback) { foreach (MessageAttachment attachment in attachments) { LoadAttachment(attachment, progressCallback); } }
public ConversationManager(IEnumerable<IContact> contacts, IEnumerable<TextMessage> messages, IEnumerable<ChatRoomInformation> chatInfoItems, IEnumerable<MessageAttachment> attachments, ILoadingProgressCallback progressCallback) { _contactLookupTable = new Dictionary<string, IContact>(); _messageLookupTable = new Dictionary<long, TextMessage>(); List<IConversation> conversationList = LoadConversations(contacts, messages, chatInfoItems, attachments, progressCallback); SetConversationList(conversationList); }
private void LoadAttachments(IEnumerable<MessageAttachment> attachments, ILoadingProgressCallback progressCallback) { foreach (MessageAttachment attachment in attachments) { LoadAttachment(attachment, progressCallback); } }
public AsyncLoadingProgressParams(ILoadingProgressCallback progressCallback, bool mergeConversations, IPhoneDeviceInfo deviceInfo) { LoadingProgressCallback = progressCallback; MergeConversations = mergeConversations; DeviceInfo = deviceInfo; }
public static ConversationManager GetConversationManager(IEnumerable <DummyContactId> dummyContactIds, IEnumerable <DummyPhoneNumberId> messageSetIds, ILoadingProgressCallback progressCallback) { DummyChatRoomId[] dummyChatIds = { }; return(GetConversationManager(dummyContactIds, messageSetIds, dummyChatIds, progressCallback)); }
public AsyncLoadingProgressParams(ILoadingProgressCallback progressCallback, bool mergeConversations, IPhoneDeviceInfo deviceInfo) { LoadingProgressCallback = progressCallback; MergeConversations = mergeConversations; DeviceInfo = deviceInfo; }
protected void SetProgressPhase(ILoadingProgressCallback progressCallback, LoadingPhase loadingPhase) { if (progressCallback == null) { return; } progressCallback.CurrentPhase = loadingPhase; }
protected static void IncrementWorkProgress(ILoadingProgressCallback progressCallback) { if (progressCallback == null) { return; } progressCallback.Increment(1); }
protected static void IncrementWorkProgress(ILoadingProgressCallback progressCallback) { if (progressCallback == null) { return; } progressCallback.Increment(1); }
protected static void CheckForCancel(ILoadingProgressCallback progressCallback) { if (progressCallback == null) { return; } if (progressCallback.IsCancelRequested) { progressCallback.AcceptCancel(); throw new OperationCanceledException(); } }
protected static void CheckForCancel(ILoadingProgressCallback progressCallback) { if (progressCallback == null) { return; } if (progressCallback.IsCancelRequested) { progressCallback.AcceptCancel(); throw new OperationCanceledException(); } }
private void LoadAttachment(MessageAttachment attachment, ILoadingProgressCallback progressCallback) { CheckForCancel(progressCallback); try { TextMessage matchingMessage = _messageLookupTable[attachment.MessageId]; matchingMessage.AddAttachment(attachment); } catch (KeyNotFoundException) { ; } IncrementWorkProgress(progressCallback); }
private void LoadAttachment(MessageAttachment attachment, ILoadingProgressCallback progressCallback) { CheckForCancel(progressCallback); try { TextMessage matchingMessage = _messageLookupTable[attachment.MessageId]; matchingMessage.AddAttachment(attachment); } catch (KeyNotFoundException) { ; } IncrementWorkProgress(progressCallback); }
public static ConversationManager GetConversationManager(IEnumerable <DummyContactId> dummyContactIds, IEnumerable <DummyPhoneNumberId> messageSetIds, IEnumerable <DummyChatRoomId> chatRoomIds, ILoadingProgressCallback progressCallback) { List <Contact> contacts = DummyConversationDataGenerator.GetContacts(dummyContactIds); List <TextMessage> messages = DummyConversationDataGenerator.GetMessages(messageSetIds); messages.AddRange(DummyConversationDataGenerator.GetMessages(chatRoomIds)); List <ChatRoomInformation> chatInfoItems = DummyConversationDataGenerator.GetChatRoomInfoItems(chatRoomIds); List <MessageAttachment> attachments = new List <MessageAttachment>(); return(new ConversationManager(contacts, messages, chatInfoItems, attachments, progressCallback)); }
private static void OnDoWork(object sender, DoWorkEventArgs e) { AsyncLoadingProgressParams workParams = (AsyncLoadingProgressParams)e.Argument; ILoadingProgressCallback progressCallback = workParams.LoadingProgressCallback; bool mergeConversations = workParams.MergeConversations; IPhoneDeviceInfo deviceInfo = workParams.DeviceInfo; try { IConversationManager conversationManager = MainWindowModelBase.LoadConversationManager(progressCallback, deviceInfo, mergeConversations); progressCallback.End(); e.Result = conversationManager; } catch (OperationCanceledException) { e.Cancel = true; } }
private void LoadConversationManagerAsync() { BackgroundWorker backgroundWorker = new BackgroundWorker(); _progressCallback = new LoadingProgressCallback(backgroundWorker); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.WorkerSupportsCancellation = true; backgroundWorker.DoWork += OnDoWork; backgroundWorker.ProgressChanged += OnProgressChanged; backgroundWorker.RunWorkerCompleted += OnWorkerCompleted; _progressDialog = new LoadingProgressDialogView(); _progressDialog.Owner = this; _progressDialog.Cancel += OnCancelProcess; AsyncLoadingProgressParams workParams = new AsyncLoadingProgressParams(_progressCallback, _displayOptions.MergeContacts, _deviceInfo); backgroundWorker.RunWorkerAsync(workParams); _progressDialog.ShowDialog(); }
private void LoadMessages(Dictionary <string, IConversation> conversationHashTable, IEnumerable <TextMessage> messages, ILoadingProgressCallback progressCallback) { SetProgressPhase(progressCallback, LoadingPhase.ReadingMessages); foreach (TextMessage message in messages) { LoadMessage(conversationHashTable, message, progressCallback); } }
private ConversationManager CreateConversationManager(DummyContactId[] contactIds, DummyPhoneNumberId[] messageSetIds, ILoadingProgressCallback progressCallback) { DummyChatRoomId[] chatRoomIds = { }; return CreateConversationManager(contactIds, messageSetIds, chatRoomIds, progressCallback); }
private ConversationManager CreateConversationManager(DummyContactId[] contactIds, DummyPhoneNumberId[] messageSetIds, DummyChatRoomId[] chatRoomIds, ILoadingProgressCallback progressCallback) { if (progressCallback != null) { int messageCount = DummyConversationDataGenerator.GetMessageCount(messageSetIds); int workEstimate = ConversationManager.GetWorkEstimate(contactIds.Length, messageCount, chatRoomIds.Length, 0); progressCallback.Begin(workEstimate); } ConversationManager conversationManager = DummyConversationDataGenerator.GetConversationManager(contactIds, messageSetIds, chatRoomIds, progressCallback); if (progressCallback != null) { progressCallback.End(); } return conversationManager; }
private void LoadChatRoomInformation(Dictionary <string, IConversation> conversationHashTable, IEnumerable <ChatRoomInformation> chatRoomInfoItems, ILoadingProgressCallback progressCallback) { SetProgressPhase(progressCallback, LoadingPhase.ReadingChatInformation); foreach (ChatRoomInformation chatRoomInfo in chatRoomInfoItems) { CheckForCancel(progressCallback); List <IContact> chatContacts = LoadChatRoomContacts(chatRoomInfo); conversationHashTable.Add(chatRoomInfo.ChatId, new ChatConversation(chatContacts)); IncrementWorkProgress(progressCallback); } }
private List<IConversation> LoadConversations(IEnumerable<IContact> contacts, IEnumerable<TextMessage> messages, IEnumerable<ChatRoomInformation> chatInfoItems, IEnumerable<MessageAttachment> attachments, ILoadingProgressCallback progressCallback) { Dictionary<string, IConversation> conversationHashTable = new Dictionary<string, IConversation>(); CheckForCancel(progressCallback); LoadContacts(conversationHashTable, contacts, progressCallback); LoadChatRoomInformation(conversationHashTable, chatInfoItems, progressCallback); LoadMessages(conversationHashTable, messages, progressCallback); LoadAttachments(attachments, progressCallback); CheckForCancel(progressCallback); List<IConversation> finalConversations = new List<IConversation>(conversationHashTable.Values); return finalConversations; }
private ConversationManager CreateConversationManager(DummyContactId[] contactIds, DummyPhoneNumberId[] messageSetIds, DummyChatRoomId[] chatRoomIds, ILoadingProgressCallback progressCallback) { if (progressCallback != null) { int messageCount = DummyConversationDataGenerator.GetMessageCount(messageSetIds); int workEstimate = ConversationManager.GetWorkEstimate(contactIds.Length, messageCount, chatRoomIds.Length, 0); progressCallback.Begin(workEstimate); } ConversationManager conversationManager = DummyConversationDataGenerator.GetConversationManager(contactIds, messageSetIds, chatRoomIds, progressCallback); if (progressCallback != null) { progressCallback.End(); } return(conversationManager); }
private void LoadContact(Dictionary<string, IConversation> conversationHashTable, IContact contact, ILoadingProgressCallback progressCallback) { foreach (PhoneNumber contactPhoneNumber in contact.PhoneNumbers) { CheckForCancel(progressCallback); string strippedNumber = PhoneNumber.Strip(contactPhoneNumber); // // If multiple contacts share a single phone number, the duplicate phone numbers are ignored and // only the first contact seen is associated with the number. // if (!conversationHashTable.ContainsKey(strippedNumber)) { SingleNumberConversation conversation = new SingleNumberConversation(contact); conversationHashTable.Add(strippedNumber, conversation); } if (!_contactLookupTable.ContainsKey(strippedNumber)) { _contactLookupTable[strippedNumber] = contact; } } IncrementWorkProgress(progressCallback); }
private static List <IConversation> CoalesceConversations(IEnumerable <IConversation> unmergedConversations, ILoadingProgressCallback progressCallback) { Dictionary <long, IConversation> hashByContactId = new Dictionary <long, IConversation>(); Dictionary <IContactList, IConversation> hashByContactList = new Dictionary <IContactList, IConversation>(); List <IConversation> unknownContactConversations = new List <IConversation>(); foreach (IConversation conversation in unmergedConversations) { CheckForCancel(progressCallback); if (conversation.AssociatedContacts.Count == 1) { long contactId = conversation.AssociatedContacts[0].ContactId; if (contactId == Contact.UnknownContactId) { unknownContactConversations.Add(conversation); } else if (hashByContactId.ContainsKey(contactId)) { IConversation hashedConversation = hashByContactId[contactId]; hashByContactId.Remove(contactId); IConversation mergedConversation = MergeConversations(hashedConversation, conversation); hashByContactId.Add(contactId, mergedConversation); } else { hashByContactId.Add(contactId, conversation); } } else if (hashByContactList.ContainsKey(conversation.AssociatedContacts)) { IConversation hashedConversation = hashByContactList[conversation.AssociatedContacts]; hashByContactList.Remove(conversation.AssociatedContacts); IConversation mergedConversation = MergeConversations(hashedConversation, conversation); hashByContactList.Add(mergedConversation.AssociatedContacts, mergedConversation); } else { hashByContactList.Add(conversation.AssociatedContacts, conversation); } IncrementWorkProgress(progressCallback); } List <IConversation> mergedConversations = new List <IConversation>(hashByContactId.Values); mergedConversations.AddRange(hashByContactList.Values); mergedConversations.AddRange(unknownContactConversations); return(mergedConversations); }
private void OnWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { if (_conversationManager == null) { Application.Current.Shutdown(); } else if (_progressDialog != null) { _progressDialog.Close(); } } else if (e.Error != null) { _progressDialog.Close(); // // If the database file is unreadable, don't auto-open it. // if (_displayOptions != null) { _phoneSelectOptions.PhoneDataPath = ""; _phoneSelectOptions.Save(); } if (e.Error is DirectoryNotFoundException) { ShowDatabaseErrorDialog(new MissingBackupPathException()); } else if (e.Error is FileNotFoundException) { FileNotFoundException ex = (FileNotFoundException)e.Error; ShowDatabaseErrorDialog(new MissingBackupFileException(ex.FileName, ex)); } else if (e.Error is UnreadableDatabaseFileException) { UnreadableDatabaseFileException ex = (UnreadableDatabaseFileException)e.Error; ShowDatabaseErrorDialog(ex); } else { FailHandler.HandleUnrecoverableFailure(e.Error); } Application.Current.Shutdown(); } else { _conversationManager = (IConversationManager)e.Result; UpdateModels(); PopulateConversationList(); Update(); _progressDialog.Close(); _progressCallback = null; _progressDialog = null; ShowTextsOutOfDateWarningIfNeeded(); } }
private MergingConversationManager CreateMergingConversationManager(DummyContactId[] contactIds, DummyPhoneNumberId[] messageSetIds, ILoadingProgressCallback progressCallback) { if (progressCallback != null) { int workEstimate = ConversationManager.GetWorkEstimate(contactIds.Length, messageSetIds.Length, 0, 0) + MergingConversationManager.GetWorkEstimateByContacts(contactIds.Length); progressCallback.Begin(workEstimate); } ConversationManager conversationManager = DummyConversationDataGenerator.GetConversationManager(contactIds, messageSetIds, progressCallback); if (progressCallback != null) { progressCallback.UpdateRemaining(MergingConversationManager.GetWorkEstimate(conversationManager.ConversationCount)); } MergingConversationManager mergingConversationManager = new MergingConversationManager(conversationManager, progressCallback); if (progressCallback != null) { progressCallback.End(); } return(mergingConversationManager); }
protected void SetProgressPhase(ILoadingProgressCallback progressCallback, LoadingPhase loadingPhase) { if (progressCallback == null) { return; } progressCallback.CurrentPhase = loadingPhase; }
public static IConversationManager LoadConversationManager(ILoadingProgressCallback progressCallback, IPhoneDeviceInfo deviceInfo, bool mergeConversations) { IConversationManager conversationManager = null; using (DatabaseReader contactDatabaseReader = new DatabaseReader(DatabaseFinder.FindContactDatabasePath(deviceInfo.BackupPath))) { ContactReader contactReader = new ContactReader(); contactReader.ParseDatabase(contactDatabaseReader); using (DatabaseReader textDatabaseReader = new DatabaseReader(DatabaseFinder.FindTextMessageDatabasePath(deviceInfo.BackupPath))) { TextMessageReaderBase textMessageReader; IEnumerable<ChatRoomInformation> chatReader; IEnumerable<MessageAttachment> attachments; int chatWorkEstimate; if ((deviceInfo.OsVersion == null) || (deviceInfo.OsVersion.MajorVersion >= 6)) { try { textMessageReader = new TextMessageReaderiOS6(deviceInfo.BackupPath); textMessageReader.ParseDatabase(textDatabaseReader); ChatRoomInformationReaderiOS6 chatRoomInfoReader = new ChatRoomInformationReaderiOS6(); chatRoomInfoReader.ParseDatabase(textDatabaseReader); chatReader = chatRoomInfoReader; attachments = new List<MessageAttachment>(); chatWorkEstimate = chatRoomInfoReader.ItemCountEstimate; } catch (DatabaseQueryException) { textMessageReader = new TextMessageReader(deviceInfo.BackupPath); textMessageReader.ParseDatabase(textDatabaseReader); chatReader = new List<ChatRoomInformation>(); attachments = new List<MessageAttachment>(); chatWorkEstimate = 0; } } else if (deviceInfo.OsVersion.MajorVersion == 5) { textMessageReader = new TextMessageReader2(deviceInfo.BackupPath); textMessageReader.ParseDatabase(textDatabaseReader); ChatRoomInformationReader chatRoomInfoReader = new ChatRoomInformationReader(); chatRoomInfoReader.ParseDatabase(textDatabaseReader); chatReader = chatRoomInfoReader; attachments = new List<MessageAttachment>(); chatWorkEstimate = chatRoomInfoReader.ItemCountEstimate; } else { textMessageReader = new TextMessageReader(deviceInfo.BackupPath); textMessageReader.ParseDatabase(textDatabaseReader); chatReader = new List<ChatRoomInformation>(); attachments = new List<MessageAttachment>(); chatWorkEstimate = 0; } int workEstimate = AllYourTextsLib.Conversation.ConversationManager.GetWorkEstimate(contactReader.ItemCountEstimate, textMessageReader.ItemCountEstimate, chatWorkEstimate, 0); if (mergeConversations) { workEstimate += MergingConversationManager.GetWorkEstimateByContacts(contactReader.ItemCountEstimate); } progressCallback.Begin(workEstimate); conversationManager = new ConversationManager(contactReader, textMessageReader, chatReader, attachments, progressCallback); if (mergeConversations) { conversationManager = new MergingConversationManager(conversationManager, progressCallback); } } } return conversationManager; }
public ConversationManager(IEnumerable <IContact> contacts, IEnumerable <TextMessage> messages, IEnumerable <ChatRoomInformation> chatInfoItems, IEnumerable <MessageAttachment> attachments, ILoadingProgressCallback progressCallback) { _contactLookupTable = new Dictionary <string, IContact>(); _messageLookupTable = new Dictionary <long, TextMessage>(); List <IConversation> conversationList = LoadConversations(contacts, messages, chatInfoItems, attachments, progressCallback); SetConversationList(conversationList); }
public MergingConversationManager(IEnumerable <IConversation> conversationManager, ILoadingProgressCallback progressCallback) { List <IConversation> mergedConversations = CoalesceConversations(conversationManager, progressCallback); SetConversationList(mergedConversations); }
private void LoadMessage(Dictionary <string, IConversation> conversationHashTable, TextMessage message, ILoadingProgressCallback progressCallback) { CheckForCancel(progressCallback); string conversationKey; PhoneNumber messagePhoneNumber = new PhoneNumber(message.Address, message.Country); string phoneNumberStripped = PhoneNumber.Strip(messagePhoneNumber); if (message.ChatId != null) { conversationKey = message.ChatId; } else { conversationKey = phoneNumberStripped; } if (string.IsNullOrEmpty(conversationKey)) { return; } Contact unknownContact = new Contact(Contact.UnknownContactId, null, null, null, messagePhoneNumber); message.Contact = GetContactByPhoneNumber(messagePhoneNumber); if (message.Contact == null) { message.Contact = unknownContact; } else { // // Update the contact's phone number to include country information. // foreach (PhoneNumber contactPhoneNumber in message.Contact.PhoneNumbers) { if (PhoneNumber.NumbersAreEquivalent(contactPhoneNumber, messagePhoneNumber)) { contactPhoneNumber.Country = message.Country; break; } } } IConversation conversation; if (conversationHashTable.ContainsKey(conversationKey)) { conversation = conversationHashTable[conversationKey]; // If The contact is not part of the conversation, add them here. This can happen with "orphaned" chat // messages. if (!message.Contact.Equals(unknownContact) && !conversation.AssociatedContacts.Contains(message.Contact)) { conversation.AssociatedContacts.Add(message.Contact); } } else if (message.ChatId != null) { // It's possible to have "orphaned" chat messages, where they appear in the message database with a chat ID // but the chat ID was not in the chat room database. Handle those here. List <IContact> chatContacts = new List <IContact>(); if (!message.Contact.Equals(unknownContact)) { chatContacts.Add(message.Contact); } conversation = new ChatConversation(chatContacts); conversationHashTable.Add(message.ChatId, conversation); } else { conversation = new SingleNumberConversation(unknownContact); conversationHashTable.Add(conversationKey, conversation); } _messageLookupTable.Add(message.MessageId, message); conversation.AddMessage(message); IncrementWorkProgress(progressCallback); }
private void LoadChatRoomInformation(Dictionary<string, IConversation> conversationHashTable, IEnumerable<ChatRoomInformation> chatRoomInfoItems, ILoadingProgressCallback progressCallback) { SetProgressPhase(progressCallback, LoadingPhase.ReadingChatInformation); foreach (ChatRoomInformation chatRoomInfo in chatRoomInfoItems) { CheckForCancel(progressCallback); List<IContact> chatContacts = LoadChatRoomContacts(chatRoomInfo); conversationHashTable.Add(chatRoomInfo.ChatId, new ChatConversation(chatContacts)); IncrementWorkProgress(progressCallback); } }
private ConversationManager CreateConversationManager(DummyContactId[] contactIds, DummyPhoneNumberId[] messageSetIds, ILoadingProgressCallback progressCallback) { DummyChatRoomId[] chatRoomIds = { }; return(CreateConversationManager(contactIds, messageSetIds, chatRoomIds, progressCallback)); }
private void LoadContacts(Dictionary<string, IConversation> conversationHashTable, IEnumerable<IContact> contacts, ILoadingProgressCallback progressCallback) { SetProgressPhase(progressCallback, LoadingPhase.ReadingContacts); foreach (IContact contact in contacts) { LoadContact(conversationHashTable, contact, progressCallback); } }
private List <IConversation> LoadConversations(IEnumerable <IContact> contacts, IEnumerable <TextMessage> messages, IEnumerable <ChatRoomInformation> chatInfoItems, IEnumerable <MessageAttachment> attachments, ILoadingProgressCallback progressCallback) { Dictionary <string, IConversation> conversationHashTable = new Dictionary <string, IConversation>(); CheckForCancel(progressCallback); LoadContacts(conversationHashTable, contacts, progressCallback); LoadChatRoomInformation(conversationHashTable, chatInfoItems, progressCallback); LoadMessages(conversationHashTable, messages, progressCallback); LoadAttachments(attachments, progressCallback); CheckForCancel(progressCallback); List <IConversation> finalConversations = new List <IConversation>(conversationHashTable.Values); return(finalConversations); }
private void LoadMessage(Dictionary<string, IConversation> conversationHashTable, TextMessage message, ILoadingProgressCallback progressCallback) { CheckForCancel(progressCallback); string conversationKey; PhoneNumber messagePhoneNumber = new PhoneNumber(message.Address, message.Country); string phoneNumberStripped = PhoneNumber.Strip(messagePhoneNumber); if (message.ChatId != null) { conversationKey = message.ChatId; } else { conversationKey = phoneNumberStripped; } if (string.IsNullOrEmpty(conversationKey)) { return; } Contact unknownContact = new Contact(Contact.UnknownContactId, null, null, null, messagePhoneNumber); message.Contact = GetContactByPhoneNumber(messagePhoneNumber); if (message.Contact == null) { message.Contact = unknownContact; } else { // // Update the contact's phone number to include country information. // foreach (PhoneNumber contactPhoneNumber in message.Contact.PhoneNumbers) { if (PhoneNumber.NumbersAreEquivalent(contactPhoneNumber, messagePhoneNumber)) { contactPhoneNumber.Country = message.Country; break; } } } IConversation conversation; if (conversationHashTable.ContainsKey(conversationKey)) { conversation = conversationHashTable[conversationKey]; // If The contact is not part of the conversation, add them here. This can happen with "orphaned" chat // messages. if (!message.Contact.Equals(unknownContact) && !conversation.AssociatedContacts.Contains(message.Contact)) { conversation.AssociatedContacts.Add(message.Contact); } } else if (message.ChatId != null) { // It's possible to have "orphaned" chat messages, where they appear in the message database with a chat ID // but the chat ID was not in the chat room database. Handle those here. List<IContact> chatContacts = new List<IContact>(); if (!message.Contact.Equals(unknownContact)) { chatContacts.Add(message.Contact); } conversation = new ChatConversation(chatContacts); conversationHashTable.Add(message.ChatId, conversation); } else { conversation = new SingleNumberConversation(unknownContact); conversationHashTable.Add(conversationKey, conversation); } _messageLookupTable.Add(message.MessageId, message); conversation.AddMessage(message); IncrementWorkProgress(progressCallback); }
public static ConversationManager GetConversationManager(IEnumerable<DummyContactId> dummyContactIds, IEnumerable<DummyPhoneNumberId> messageSetIds, IEnumerable<DummyChatRoomId> chatRoomIds, ILoadingProgressCallback progressCallback) { List<Contact> contacts = DummyConversationDataGenerator.GetContacts(dummyContactIds); List<TextMessage> messages = DummyConversationDataGenerator.GetMessages(messageSetIds); messages.AddRange(DummyConversationDataGenerator.GetMessages(chatRoomIds)); List<ChatRoomInformation> chatInfoItems = DummyConversationDataGenerator.GetChatRoomInfoItems(chatRoomIds); List<MessageAttachment> attachments = new List<MessageAttachment>(); return new ConversationManager(contacts, messages, chatInfoItems, attachments, progressCallback); }
private void LoadMessages(Dictionary<string, IConversation> conversationHashTable, IEnumerable<TextMessage> messages, ILoadingProgressCallback progressCallback) { SetProgressPhase(progressCallback, LoadingPhase.ReadingMessages); foreach (TextMessage message in messages) { LoadMessage(conversationHashTable, message, progressCallback); } }
private void LoadConversationManagerAsync() { BackgroundWorker backgroundWorker = new BackgroundWorker(); _progressCallback = new LoadingProgressCallback(backgroundWorker); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.WorkerSupportsCancellation = true; backgroundWorker.DoWork += OnDoWork; backgroundWorker.ProgressChanged += OnProgressChanged; backgroundWorker.RunWorkerCompleted += OnWorkerCompleted; _progressDialog = new LoadingProgressDialogView(); _progressDialog.Owner = this; _progressDialog.Cancel += OnCancelProcess; AsyncLoadingProgressParams workParams = new AsyncLoadingProgressParams(_progressCallback, _displayOptions.MergeContacts, _deviceInfo); backgroundWorker.RunWorkerAsync(workParams); _progressDialog.ShowDialog(); }
private MergingConversationManager CreateMergingConversationManager(DummyContactId[] contactIds, DummyPhoneNumberId[] messageSetIds, ILoadingProgressCallback progressCallback) { if (progressCallback != null) { int workEstimate = ConversationManager.GetWorkEstimate(contactIds.Length, messageSetIds.Length, 0, 0) + MergingConversationManager.GetWorkEstimateByContacts(contactIds.Length); progressCallback.Begin(workEstimate); } ConversationManager conversationManager = DummyConversationDataGenerator.GetConversationManager(contactIds, messageSetIds, progressCallback); if (progressCallback != null) { progressCallback.UpdateRemaining(MergingConversationManager.GetWorkEstimate(conversationManager.ConversationCount)); } MergingConversationManager mergingConversationManager = new MergingConversationManager(conversationManager, progressCallback); if (progressCallback != null) { progressCallback.End(); } return mergingConversationManager; }
public static IConversationManager LoadConversationManager(ILoadingProgressCallback progressCallback, IPhoneDeviceInfo deviceInfo, bool mergeConversations) { IConversationManager conversationManager = null; using (DatabaseReader contactDatabaseReader = new DatabaseReader(DatabaseFinder.FindContactDatabasePath(deviceInfo.BackupPath))) { ContactReader contactReader = new ContactReader(); contactReader.ParseDatabase(contactDatabaseReader); using (DatabaseReader textDatabaseReader = new DatabaseReader(DatabaseFinder.FindTextMessageDatabasePath(deviceInfo.BackupPath))) { TextMessageReaderBase textMessageReader; IEnumerable <ChatRoomInformation> chatReader; IEnumerable <MessageAttachment> attachments; int chatWorkEstimate; if ((deviceInfo.OsVersion == null) || (deviceInfo.OsVersion.MajorVersion >= 6)) { try { textMessageReader = new TextMessageReaderiOS6(deviceInfo.BackupPath); textMessageReader.ParseDatabase(textDatabaseReader); ChatRoomInformationReaderiOS6 chatRoomInfoReader = new ChatRoomInformationReaderiOS6(); chatRoomInfoReader.ParseDatabase(textDatabaseReader); chatReader = chatRoomInfoReader; attachments = new List <MessageAttachment>(); chatWorkEstimate = chatRoomInfoReader.ItemCountEstimate; } catch (DatabaseQueryException) { textMessageReader = new TextMessageReader(deviceInfo.BackupPath); textMessageReader.ParseDatabase(textDatabaseReader); chatReader = new List <ChatRoomInformation>(); attachments = new List <MessageAttachment>(); chatWorkEstimate = 0; } } else if (deviceInfo.OsVersion.MajorVersion == 5) { textMessageReader = new TextMessageReader2(deviceInfo.BackupPath); textMessageReader.ParseDatabase(textDatabaseReader); ChatRoomInformationReader chatRoomInfoReader = new ChatRoomInformationReader(); chatRoomInfoReader.ParseDatabase(textDatabaseReader); chatReader = chatRoomInfoReader; attachments = new List <MessageAttachment>(); chatWorkEstimate = chatRoomInfoReader.ItemCountEstimate; } else { textMessageReader = new TextMessageReader(deviceInfo.BackupPath); textMessageReader.ParseDatabase(textDatabaseReader); chatReader = new List <ChatRoomInformation>(); attachments = new List <MessageAttachment>(); chatWorkEstimate = 0; } int workEstimate = AllYourTextsLib.Conversation.ConversationManager.GetWorkEstimate(contactReader.ItemCountEstimate, textMessageReader.ItemCountEstimate, chatWorkEstimate, 0); if (mergeConversations) { workEstimate += MergingConversationManager.GetWorkEstimateByContacts(contactReader.ItemCountEstimate); } progressCallback.Begin(workEstimate); conversationManager = new ConversationManager(contactReader, textMessageReader, chatReader, attachments, progressCallback); if (mergeConversations) { conversationManager = new MergingConversationManager(conversationManager, progressCallback); } } } return(conversationManager); }
public static ConversationManager GetConversationManager(IEnumerable<DummyContactId> dummyContactIds, IEnumerable<DummyPhoneNumberId> messageSetIds, ILoadingProgressCallback progressCallback) { DummyChatRoomId[] dummyChatIds = { }; return GetConversationManager(dummyContactIds, messageSetIds, dummyChatIds, progressCallback); }
private void LoadContacts(Dictionary <string, IConversation> conversationHashTable, IEnumerable <IContact> contacts, ILoadingProgressCallback progressCallback) { SetProgressPhase(progressCallback, LoadingPhase.ReadingContacts); foreach (IContact contact in contacts) { LoadContact(conversationHashTable, contact, progressCallback); } }
private void OnWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { if (_conversationManager == null) { Application.Current.Shutdown(); } else if (_progressDialog != null) { _progressDialog.Close(); } } else if (e.Error != null) { _progressDialog.Close(); // // If the database file is unreadable, don't auto-open it. // if (_displayOptions != null) { _phoneSelectOptions.PhoneDataPath = ""; _phoneSelectOptions.Save(); } if (e.Error is DirectoryNotFoundException) { ShowDatabaseErrorDialog(new MissingBackupPathException()); } else if (e.Error is FileNotFoundException) { FileNotFoundException ex = (FileNotFoundException)e.Error; ShowDatabaseErrorDialog(new MissingBackupFileException(ex.FileName, ex)); } else if (e.Error is UnreadableDatabaseFileException) { UnreadableDatabaseFileException ex = (UnreadableDatabaseFileException)e.Error; ShowDatabaseErrorDialog(ex); } else { FailHandler.HandleUnrecoverableFailure(e.Error); } Application.Current.Shutdown(); } else { _conversationManager = (IConversationManager)e.Result; UpdateModels(); PopulateConversationList(); Update(); _progressDialog.Close(); _progressCallback = null; _progressDialog = null; ShowTextsOutOfDateWarningIfNeeded(); } }
private void LoadContact(Dictionary <string, IConversation> conversationHashTable, IContact contact, ILoadingProgressCallback progressCallback) { foreach (PhoneNumber contactPhoneNumber in contact.PhoneNumbers) { CheckForCancel(progressCallback); string strippedNumber = PhoneNumber.Strip(contactPhoneNumber); // // If multiple contacts share a single phone number, the duplicate phone numbers are ignored and // only the first contact seen is associated with the number. // if (!conversationHashTable.ContainsKey(strippedNumber)) { SingleNumberConversation conversation = new SingleNumberConversation(contact); conversationHashTable.Add(strippedNumber, conversation); } if (!_contactLookupTable.ContainsKey(strippedNumber)) { _contactLookupTable[strippedNumber] = contact; } } IncrementWorkProgress(progressCallback); }