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!");
        }
Beispiel #2
0
        public void ParseItemFromDatabaseTest()
        {
            MockChatRoomDatabaseReader mockDatabaseReader = new MockChatRoomDatabaseReader();

            mockDatabaseReader.AddRow("chat901258305184729544", _ParticipantsData);
            ChatRoomInformationReader_Accessor target = new ChatRoomInformationReader_Accessor();

            target.ParseDatabase(mockDatabaseReader);

            ChatRoomInformation expected = new ChatRoomInformation("chat901258305184729544", new string[] { "+15402392304", "+12068189288" });
            ChatRoomInformation actual   = target.ParseItemFromDatabase(mockDatabaseReader);

            Assert.AreEqual(expected, actual);
        }
        public void SetChatRoomPrivacySetting(PersistentChatEndpoint persistentChatEndpoint, Uri roomUri, ChatRoomPrivacy privacySetting)
        {
            Console.WriteLine("\t {0} client {1} SetChatRoomPrivacySetting privacySetting {2}  start", userName, roomUri, privacySetting);
            ChatRoomManagementServices ChatRoomServices = persistentChatEndpoint.PersistentChatServices.ChatRoomManagementServices;

            ChatRoom room = ChatRoomServices.EndGetChatRoom(
                ChatRoomServices.BeginGetChatRoom(roomUri, null, null));
            ChatRoomInformation roomInfo = new ChatRoomInformation(room);

            roomInfo.Privacy = privacySetting;
            ChatRoomServices.EndUpdateChatRoom(
                ChatRoomServices.BeginUpdateChatRoom(roomInfo, null, null));
            Console.WriteLine("\t {0} client {1} SetChatRoomPrivacySetting privacySetting {2} Success", userName, roomUri, privacySetting);
        }
        private List <IContact> LoadChatRoomContacts(ChatRoomInformation chatRoomInfo)
        {
            List <IContact> contacts = new List <IContact>();

            foreach (string phoneNumberValue in chatRoomInfo.Participants)
            {
                IContact contact = GetContactByPhoneNumber(new PhoneNumber(phoneNumberValue));
                if (contact == null)
                {
                    contact = new Contact(Contact.UnknownContactId, null, null, null, new PhoneNumber(phoneNumberValue));
                }

                contacts.Add(contact);
            }

            return(contacts);
        }
        private List<IContact> LoadChatRoomContacts(ChatRoomInformation chatRoomInfo)
        {
            List<IContact> contacts = new List<IContact>();
            foreach (string phoneNumberValue in chatRoomInfo.Participants)
            {
                IContact contact = GetContactByPhoneNumber(new PhoneNumber(phoneNumberValue));
                if (contact == null)
                {
                    contact = new Contact(Contact.UnknownContactId, null, null, null, new PhoneNumber(phoneNumberValue));
                }

                contacts.Add(contact);
            }

            return contacts;
        }
        private static void InitChatRoomInfoItems()
        {
            int chatRoomInfoItemCount = Enum.GetValues(typeof(DummyChatRoomId)).Length;

            ChatRoomInformation[] dummyChatRoomInfoItems = new ChatRoomInformation[chatRoomInfoItemCount];

            {
                DummyChatRoomId chatId       = DummyChatRoomId.ChatRoomA;
                string[]        participants =
                {
                    GetPhoneNumber(DummyPhoneNumberId.ObamaCell),
                    GetPhoneNumber(DummyPhoneNumberId.AnthonyWeinerCell)
                };

                dummyChatRoomInfoItems[(int)chatId] = new ChatRoomInformation("chat901258305184729544", participants);
            }

            {
                DummyChatRoomId chatId       = DummyChatRoomId.ChatRoomB;
                string[]        participants =
                {
                    GetPhoneNumber(DummyPhoneNumberId.TonyWolfCell),
                    GetPhoneNumber(DummyPhoneNumberId.VictoriaWolfCell)
                };

                dummyChatRoomInfoItems[(int)chatId] = new ChatRoomInformation("chat901258305184729566", participants);
            }

            {
                DummyChatRoomId chatId       = DummyChatRoomId.ChatRoomC;
                string[]        participants =
                {
                    GetPhoneNumber(DummyPhoneNumberId.ObamaCell),
                    GetPhoneNumber(DummyPhoneNumberId.HarryLooseTieCell),
                    GetPhoneNumber(DummyPhoneNumberId.AnthonyWeinerCell),
                    GetPhoneNumber(DummyPhoneNumberId.ReliableLarryOffice)
                };

                dummyChatRoomInfoItems[(int)chatId] = new ChatRoomInformation("chat901258305184725792", participants);
            }

            {
                DummyChatRoomId chatId       = DummyChatRoomId.ChatRoomD;
                string[]        participants =
                {
                    GetPhoneNumber(DummyPhoneNumberId.HarryLooseTieCell),
                    GetPhoneNumber(DummyPhoneNumberId.UnknownLawnmower)
                };

                dummyChatRoomInfoItems[(int)chatId] = new ChatRoomInformation("chat901258305184724753", participants);
            }

            foreach (ChatRoomInformation cri in dummyChatRoomInfoItems)
            {
                if (cri == null)
                {
                    throw new ArgumentException("You forgot to initialize a chat room information item.");
                }
            }

            _DummyChatRoomInfoItems = dummyChatRoomInfoItems;
        }