コード例 #1
0
        private void SelectApplicationBar()
        {
            string pivotResource;

            switch (this.ConversationPagePivot.SelectedIndex)
            {
            case 0:
                pivotResource = "MessagesAppBar";
                break;

            case 1:
                ConversationMessagesViewModel vm = (ConversationMessagesViewModel)this.DataContext;

                if (vm.IsGroup)
                {
                    pivotResource = "ContactDetailsAppBar";
                }
                else
                {
                    pivotResource = null;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            this.ApplicationBar = pivotResource == null ? null : (ApplicationBar)this.Resources[pivotResource];
        }
コード例 #2
0
        public IActionResult Messages([FromRoute] int id)
        {
            List <Message> ConversationMessages = context.Message.Where(m => m.ConversationRoomName == Convert.ToString(id)).ToList();

            ConversationMessagesViewModel model = new ConversationMessagesViewModel(context);

            model.UserStyle           = context.Style.Where(s => s.UserId == ActiveUser.Instance.User.UserId).SingleOrDefault();
            model.Messages            = ConversationMessages.OrderByDescending(cm => cm.MessageSentDate).ToList();
            model.CurrentConversation = context.Conversation.Where(c => c.ConversationRoomName == Convert.ToString(id)).SingleOrDefault();

            return(View(model));
        }
コード例 #3
0
        private void GroupMember_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Get item of LongListSelector.
            List <UserControl> listItems = new List <UserControl>();

            GetItemsRecursive <UserControl>(GroupMemberListSelector, ref listItems);

            // Selected.
            if (e.AddedItems.Count > 0 && e.AddedItems[0] != null)
            {
                foreach (UserControl userControl in listItems)
                {
                    if (e.AddedItems[0].Equals(userControl.DataContext))
                    {
                        VisualStateManager.GoToState(userControl, "Selected", true);
                    }
                }
            }

            // Unselected.
            if (e.RemovedItems.Count > 0 && e.RemovedItems[0] != null)
            {
                foreach (UserControl userControl in listItems)
                {
                    if (e.RemovedItems[0].Equals(userControl.DataContext))
                    {
                        VisualStateManager.GoToState(userControl, "Normal", true);
                    }
                }
            }

            ConversationMessagesViewModel vm = (ConversationMessagesViewModel)this.DataContext;

            if (this.GroupMemberListSelector.SelectedItem != null)
            {
                this.ApplicationBar = (ApplicationBar)this.Resources["RemoveMemberAppBar"];
            }

            if (this.GroupMemberListSelector.SelectedItem == null)
            {
                this.SelectApplicationBar();
            }
        }
コード例 #4
0
        public void HandlePushNotificationTest()
        {
            for (int i = 0; i < this.conversationMessages.Count; i++)
            {
                for (int j = 0; j < this.conversationMessages[i].Count; j++)
                {
                    MockServiceProxy serviceProxy = new MockServiceProxy()
                    {
                        Messages = this.conversationMessages[i][j].m_Item2
                    };
                    MockUserSettings userSettings = new MockUserSettings();
                    userSettings.Save(owners[i]);

                    UserModel recipient = null;
                    foreach (UserModel user in this.conversationMessages[i][j].m_Item1.ConversationParticipants)
                    {
                        if (!user.Equals(userSettings.Me))
                        {
                            recipient = user;
                        }
                    }

                    ConversationMessagesViewModel messages = new ConversationMessagesViewModel(serviceProxy, userSettings, this.conversationMessages[i][j].m_Item1.ConversationId, recipient);

                    messages.LoadMessagesForConversations();

                    Random random = new Random((int)DateTime.Now.Ticks);
                    long   existingConversationId     = this.conversationMessages[i][j].m_Item2.Count > 0 ? this.conversationMessages[i][j].m_Item2[0].ConversationId : long.MaxValue;
                    int    existingConversationUserId = this.conversationMessages[i][j].m_Item2.Count > 0 ? this.conversationMessages[i][j].m_Item2[0].Sender.Id : random.Next(1000, 2000);

                    PushNotificationEvent pushEvent = new PushNotificationEvent(this, (long)2000, existingConversationId, "test", DateTime.Now.Ticks, "ConversationMessagesHandlePushNotificationTest" + i.ToString(), existingConversationUserId);

                    int messageCountBeforePush = messages.Messages.Count;
                    NotifyCollectionChangedTester <MessageModel> collectionChangedTester = new NotifyCollectionChangedTester <MessageModel>(messages.Messages);
                    Messenger.Default.Send <PushNotificationEvent>(pushEvent);

                    Assert.AreEqual(1, collectionChangedTester.Count, "Collection changed event was not generated");
                    Assert.AreEqual(messageCountBeforePush + 1, messages.Messages.Count, "Push notification was not handled properly");
                }
            }
        }
コード例 #5
0
        public void CreateConversationMessagesViewModelTest()
        {
            for (int i = 0; i < this.conversationMessages.Count; i++)
            {
                for (int j = 0; j < this.conversationMessages[i].Count; j++)
                {
                    MockServiceProxy serviceProxy = new MockServiceProxy()
                    {
                        Messages = this.conversationMessages[i][j].m_Item2
                    };
                    MockDataContextWrapper dataContext = new MockDataContextWrapper(new MockDatabase()
                    {
                    });
                    MockUserSettings userSettings = new MockUserSettings();
                    userSettings.Save(owners[i]);

                    UserModel recipient = null;
                    foreach (UserModel user in this.conversationMessages[i][j].m_Item1.ConversationParticipants)
                    {
                        if (!user.Equals(userSettings.Me))
                        {
                            recipient = user;
                        }
                    }

                    ConversationMessagesViewModel messages = new ConversationMessagesViewModel(serviceProxy, dataContext, userSettings, this.conversationMessages[i][j].m_Item1.ConversationId, recipient);
                    NotifyPropertyChangedTester   propertyChangedTester = new NotifyPropertyChangedTester(messages);
                    NotifyCollectionChangedTester <MessageModel> collectionChangedTester = new NotifyCollectionChangedTester <MessageModel>(messages.Messages);
                    messages.LoadMessagesForConversations();

                    Assert.AreEqual(1, propertyChangedTester.Changes.Count, "IsLoaded property changed event was not generated");
                    propertyChangedTester.AssertChange(0, "IsLoading");

                    Assert.AreEqual(this.conversationMessages[i][j].m_Item2.Count, collectionChangedTester.Count, "Number of messages in notify collection changed doesn't match");
                }
            }
        }
コード例 #6
0
        async protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (this.DataContext == null)
            {
                Guid   conversationId;
                string senderName = null;

                base.OnNavigatedTo(e);
                conversationId = Guid.Parse(NavigationContext.QueryString["conversationId"]);

                if (NavigationContext.QueryString.ContainsKey("recipientName"))
                {
                    senderName = NavigationContext.QueryString["recipientName"];
                }

                Guid messageId = Guid.Empty;
                if (NavigationContext.QueryString.ContainsKey("messageId"))
                {
                    messageId = Guid.Parse(NavigationContext.QueryString["messageId"]);
                }

                int recipient = -1;
                if (NavigationContext.QueryString.ContainsKey("recipientId"))
                {
                    recipient = Int32.Parse(NavigationContext.QueryString["recipientId"]);
                }

                bool?isGroup = null;
                if (NavigationContext.QueryString.ContainsKey("isGroup"))
                {
                    isGroup = Boolean.Parse(NavigationContext.QueryString["isGroup"]);
                }

                int pivot = 0;
                if (NavigationContext.QueryString.ContainsKey("pivot"))
                {
                    pivot = Int32.Parse(NavigationContext.QueryString["pivot"]);
                }

                if (messageId != Guid.Empty)
                {
                    //DataSync.Instance.SyncMessageId(conversationId, messageId);
                }

                // Before the messages are loaded, ensure that the scroll handler is set correctly.
                var scrollToEndHandler = new System.Collections.Specialized.NotifyCollectionChangedEventHandler(
                    (s1, e1) =>
                {
                    if (this.messagesListBox.ItemsSource.Count > 0)
                    {
                        this.messagesListBox.UpdateLayout();
                        object lastItem = this.messagesListBox.ItemsSource[this.messagesListBox.ItemsSource.Count - 1];
                        this.messagesListBox.ScrollTo(lastItem);
                    }
                });


                //INotifyCollectionChanged listItems = this.messagesListBox.ItemsSource as INotifyCollectionChanged;
                //listItems.CollectionChanged += scrollToEndHandler;

                UserModel recipientUser = DataSync.Instance.GetUser(recipient);
                if (recipientUser == null)
                {
                    UserType userType = isGroup.HasValue && isGroup.Value ? UserType.Group : UserType.User;
                    recipientUser = new Models.UserModel()
                    {
                        Id = recipient, Name = senderName, UserType = userType
                    };
                }

                // Create the viewmodel and load the messages
                ConversationMessagesViewModel cvm = new ConversationMessagesViewModel(conversationId, recipientUser, isGroup);
                this.DataContext = cvm;
                cvm.LoadMessagesForConversations();

                if (cvm.IsGroup && cvm.Recipient != null && !cvm.Recipient.IsGroupMember)
                {
                    MessageBox.Show(Strings.NotAGroupMember);
                }

                // Bind the list items to a collection view source
                // This helps in sorting the messages based on post time
                // without having to maintain the list in the view model in a sorted order
                CollectionViewSource messageCollection = new CollectionViewSource();
                messageCollection.Source = ((ConversationMessagesViewModel)this.DataContext).Messages;
                System.ComponentModel.SortDescription sort = new System.ComponentModel.SortDescription("PostDateTime", System.ComponentModel.ListSortDirection.Ascending);
                messageCollection.SortDescriptions.Add(sort);
                messagesListBox.ItemsSource = ((ConversationMessagesViewModel)this.DataContext).Messages;
                this.ConversationPagePivot.SelectedIndex = pivot;

                (Application.Current as App).watcher.PositionChanged += watcher_PositionChanged;
                (Application.Current as App).watcher.StatusChanged   += watcher_StatusChanged;
                (Application.Current as App).Currentlocation          = await(Application.Current as App).watcher.GetGeopositionAsync();
            }
        }
コード例 #7
0
        public void SendNewMessageTest()
        {
            for (int i = 0; i < this.conversationMessages.Count; i++)
            {
                for (int j = 0; j < this.conversationMessages[i].Count; j++)
                {
                    MockServiceProxy serviceProxy = new MockServiceProxy()
                    {
                        Messages = this.conversationMessages[i][j].m_Item2
                    };
                    MockUserSettings userSettings = new MockUserSettings();
                    userSettings.Save(owners[i]);

                    UserModel recipient = null;
                    foreach (UserModel user in this.conversationMessages[i][j].m_Item1.ConversationParticipants)
                    {
                        if (!user.Equals(userSettings.Me))
                        {
                            recipient = user;
                        }
                    }

                    ConversationMessagesViewModel messages = new ConversationMessagesViewModel(serviceProxy, userSettings, this.conversationMessages[i][j].m_Item1.ConversationId, recipient);

                    messages.LoadMessagesForConversations();

                    NotifyCollectionChangedTester <MessageModel> collectionChangedTester = new NotifyCollectionChangedTester <MessageModel>(messages.Messages);

                    /*************************************************
                    * SendMessage chat heads enabled
                    * ***********************************************/

                    int messageCountBeforeNewMessage = messages.Messages.Count;

                    // Send a new message.
                    // The mock proxy will invoke the callback immediately
                    messages.SendNewMessage("SendNewMessageTest message chatheads disabled" + DateTime.Now.Ticks);

                    Assert.AreEqual(1, collectionChangedTester.Count, "Collection changed event was not generated");
                    Assert.AreEqual(messageCountBeforeNewMessage + 1, messages.Messages.Count, "New message was not added to the collection");

                    /*************************************************
                    * SendMessage chat heads enabled
                    * ***********************************************/

                    // Send another message but this time with chatheads enabled.
                    // Ensure that quit application event is generated.
                    messageCountBeforeNewMessage = messages.Messages.Count;
                    userSettings.ChatHeadEnabled = true;
                    bool quitEventGenerated = false;
                    collectionChangedTester.Count = 0;
                    Messenger.Default.Register <QuitApplicationEvent>(this, (QuitApplicationEvent e) => { quitEventGenerated = true; });

                    messages.SendNewMessage("SendNewMessageTest message chatheads disabled" + DateTime.Now.Ticks);

                    Assert.AreEqual(1, collectionChangedTester.Count, "IsLoaded property changed event was not generated");
                    Assert.AreEqual(messageCountBeforeNewMessage + 1, messages.Messages.Count, "New messaged was not added to the collection");

                    /*************************************************
                    * SendMessage simulate failure
                    * ***********************************************/
                    // Remember the count before new message
                    messageCountBeforeNewMessage = messages.Messages.Count;

                    // Set chat heads to enabled to true and
                    userSettings.ChatHeadEnabled = true;
                    // Simulate failure to true
                    serviceProxy.SimulateSendMessageFailure = true;

                    // Set quitEventGenerated to false
                    quitEventGenerated = false;

                    collectionChangedTester.Count = 0;
                    Messenger.Default.Register <QuitApplicationEvent>(this, (QuitApplicationEvent e) => { quitEventGenerated = true; });

                    messages.SendNewMessage("SendNewMessageTest message chatheads disabled" + DateTime.Now.Ticks);

                    Assert.AreEqual(0, collectionChangedTester.Count, "IsLoaded property changed event was not generated");
                    Assert.AreEqual(messageCountBeforeNewMessage, messages.Messages.Count, "New messaged was not added to the collection");
                    Assert.AreEqual(false, quitEventGenerated, "Quit Application event was not generated");
                }
            }
        }