public void CalculateMultiDayStatisticsTest()
        {
            DummyContactId[] contactIds = { DummyContactId.ReliableLarry };
            List<Contact> contacts = DummyConversationDataGenerator.GetContacts(contactIds);

            DummyPhoneNumberId[] messageSetIds = { DummyPhoneNumberId.ReliableLarryOffice };
            List<TextMessage> messages = DummyConversationDataGenerator.GetMessages(messageSetIds);
            List<ChatRoomInformation> chatInfoItems = new List<ChatRoomInformation>();

            ConversationManager conversationManager = new ConversationManager(contacts, messages, chatInfoItems, _attachments, null);

            IConversation conversation = conversationManager.GetConversation(0);
            IConversationStatistics statsActual = ConversationStatisticsGenerator.CalculateStatistics(conversation);

            int messagesSentExpected = 5;
            int messagesReceivedExpected = messages.Count - messagesSentExpected;
            int messagesTotalExpected = messages.Count;
            Assert.AreEqual(messagesSentExpected, statsActual.MessagesSent);
            Assert.AreEqual(messagesReceivedExpected, statsActual.MessagesReceived);
            Assert.AreEqual(messagesTotalExpected, statsActual.MessagesExchanged);
            Assert.AreEqual(5, statsActual.DayCount);
        }
        private IConversationManager GetConversationManager(IDisplayOptions diplayOptions)
        {
            IConversationManager conversationManager;

            DummyContactId[] contactIds = { DummyContactId.Davola, DummyContactId.Obama, DummyContactId.NeverTexter, DummyContactId.ReliableLarry };
            DummyPhoneNumberId[] messageSetIds = {DummyPhoneNumberId.DavolaCell,
                                                 DummyPhoneNumberId.DavolaiPhone,
                                                 DummyPhoneNumberId.ObamaCell,
                                                 DummyPhoneNumberId.ReliableLarryOffice,
                                                 DummyPhoneNumberId.UnknownLawnmower,
                                                 DummyPhoneNumberId.UnknownEagle};
            List<Contact> contacts = DummyConversationDataGenerator.GetContacts(contactIds);
            List<ChatRoomInformation> chatInfoItems = new List<ChatRoomInformation>();
            List<TextMessage> messages = DummyConversationDataGenerator.GetMessages(messageSetIds);
            List<MessageAttachment> attachments = new List<MessageAttachment>();

            conversationManager = new ConversationManager(contacts, messages, chatInfoItems, attachments, null);
            if (diplayOptions.MergeContacts)
            {
                conversationManager = new MergingConversationManager(conversationManager, null);
            }

            return conversationManager;
        }
        public static IConversation GetChatConversation(DummyChatRoomId chatRoomId)
        {
            List<IContact> contacts = new List<IContact>();
            List<TextMessage> messages = DummyConversationDataGenerator.GetMessageSet(chatRoomId);
            List<ChatRoomInformation> chatInfoItems = new List<ChatRoomInformation>();
            ChatRoomInformation chatRoomInfo = GetChatRoomInfo(chatRoomId);
            chatInfoItems.Add(chatRoomInfo);
            List<MessageAttachment> attachments = new List<MessageAttachment>();

            foreach (string phoneNumberValue in chatRoomInfo.Participants)
            {
                IContact associatedContact = GetContactByPhoneNumber(phoneNumberValue);
                if (associatedContact != null)
                {
                    contacts.Add(associatedContact);
                }
            }

            ConversationManager conversationManager = new ConversationManager(contacts, messages, chatInfoItems, attachments, null);
            foreach (IConversation conversation in conversationManager)
            {
                if (conversation.MessageCount > 0)
                {
                    return conversation;
                }
            }

            throw new ArgumentException("Shouldn't reach here!");
        }
        public static IConversation GetSingleConversation(DummyPhoneNumberId messageSetId)
        {
            Contact contact = GetAssociatedContact(messageSetId);
            List<Contact> contacts = new List<Contact>(1);
            if (contact != null)
            {
                contacts.Add(contact);
            }
            List<TextMessage> messages = DummyConversationDataGenerator.GetMessageSet(messageSetId);
            List<ChatRoomInformation> chatInfoItems = new List<ChatRoomInformation>();
            List<MessageAttachment> attachments = new List<MessageAttachment>();

            ConversationManager conversationManager = new ConversationManager(contacts, messages, chatInfoItems, attachments, null);

            return conversationManager.GetConversation(0);
        }
        public static IConversation GetMergedConversation(DummyContactId contactId)
        {
            List<Contact> contacts = GetContacts(contactId);

            IEnumerable<TextMessage> messages = GetMessageSet(contactId);

            List<ChatRoomInformation> chatInfoItems = new List<ChatRoomInformation>();

            List<MessageAttachment> attachments = new List<MessageAttachment>();

            ConversationManager conversationManager = new ConversationManager(contacts, messages, chatInfoItems, attachments, null);

            MergingConversationManager megingConversationManager = new MergingConversationManager(conversationManager, null);

            return megingConversationManager.GetConversation(0);
        }
        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;
        }