Inheritance: MessengR.Client.Common.ViewModelBase
 public ContactViewModel(User user, ContactViewModel parent)
 {
     User = user;
     IsOnline = user.Online;
     Status = user.Online ? "Online" : "Offline";
     _parent = parent;
 }
Beispiel #2
0
 public MockMainViewModel()
 {
     Me = new ContactViewModel { User = new User { Email = "*****@*****.**", Name = "user", Online = true }, IsOnline = true, Status = "Online" };
     Conversations = new ObservableCollection<ContactViewModel>();
     Conversations.Add(new ContactViewModel { User = new User { Email = "*****@*****.**", Name = "user1", Online = true }, IsOnline = true, Status = "Online", Message = new Message { Id = -1, DateReceived = DateTime.Now.AddMinutes(-2), Value = "and the text box for your message needs to wrap not continue on", From = "user", To = "user1", IsMine = true, Initiator = new User { Email = "*****@*****.**", Name = "user", Online = true }, Contact = new User { Email = "*****@*****.**", Name = "user1", Online = true } } });
     Conversations.Add(new ContactViewModel { User = new User { Email = "*****@*****.**", Name = "user2", Online = false }, IsOnline = false, Status = "Offline", Message = new Message { Id = -1, DateReceived = DateTime.Now.AddMinutes(-2), Value = "Test Message 2", From = "user", To = "user2", IsMine = true, Initiator = new User { Email = "*****@*****.**", Name = "user", Online = true }, Contact = new User { Email = "*****@*****.**", Name = "user2", Online = false } } });
     Conversations.Add(new ContactViewModel { User = new User { Email = "*****@*****.**", Name = "user3", Online = true }, IsOnline = true, Status = "Online", Message = new Message { Id = -1, DateReceived = DateTime.Now.AddMinutes(-2), Value = "Test Message 3", From = "user", To = "user3", IsMine = true, Initiator = new User { Email = "*****@*****.**", Name = "user", Online = true }, Contact = new User { Email = "*****@*****.**", Name = "user3", Online = true } } });
     Conversations.Add(new ContactViewModel { User = new User { Email = "*****@*****.**", Name = "user4", Online = false }, IsOnline = false, Status = "Offline", Message = new Message { Id = -1, DateReceived = DateTime.Now.AddMinutes(-2), Value = "Test Message 4", From = "user", To = "user4", IsMine = true, Initiator = new User { Email = "*****@*****.**", Name = "user", Online = true }, Contact = new User { Email = "*****@*****.**", Name = "user4", Online = false } } });
     Contacts = new ObservableCollection<ContactViewModel>();
     Contacts.Add(new ContactViewModel { User = new User { Email = "*****@*****.**", Name = "user1", Online = true }, IsOnline = true, Status = "Online" });
     Contacts.Add(new ContactViewModel { User = new User { Email = "*****@*****.**", Name = "user2", Online = false }, IsOnline = false, Status = "Offline" });
     Contacts.Add(new ContactViewModel { User = new User { Email = "*****@*****.**", Name = "user3", Online = true }, IsOnline = true, Status = "Online" });
     Contacts.Add(new ContactViewModel { User = new User { Email = "*****@*****.**", Name = "user4", Online = false }, IsOnline = false, Status = "Offline" });
 }
Beispiel #3
0
        private void InitializeConnection(string url, Cookie authCookie)
        {
            _connection = new HubConnection(url) { CookieContainer = new CookieContainer() };
            _connection.CookieContainer.Add(authCookie);

            // Get a reference to the chat proxy
            _chat = new Chat(_connection);

            // Start the connection
            _connection.Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    // Show a connection error here
                }
                else
                {
                    _chat.GetUser(Name).ContinueWith(getUserTask =>
                    {
                        if (getUserTask.IsFaulted)
                        { }
                        else
                        {
                            if (getUserTask.Result != null)
                            {
                                Me = new ContactViewModel(getUserTask.Result);
                                Me.OpenChatEvent += OnOpenChat;

                                _chat.GetConversations(Me.User).ContinueWith(getConversationTask =>
                                {
                                    if (getConversationTask.IsFaulted)
                                    {
                                        Debug.WriteLine("GetConversations Failed: " + getConversationTask.Status);
                                    }
                                    else
                                    {
                                        var conversations =  from Message message in getConversationTask.Result
                                                             select new ContactViewModel(message.Contact, message, Me);
                                        Conversations = new ObservableCollection<ContactViewModel>(conversations);
                                        Debug.WriteLine("Conversations Count: " + conversations.Count());
                                    }
                                });

                                // Get a list of users and add it to the view model
                                _chat.GetUsers().ContinueWith(getUsersTask =>
                                {
                                    if (getUsersTask.IsFaulted)
                                    {
                                        // Show a connection error here
                                    }
                                    else
                                    {
                                        // Exclude current user from Contact list
                                        var contacts = from User user in getUsersTask.Result
                                                       where !user.Name.Equals(Me.User.Name, StringComparison.OrdinalIgnoreCase)
                                                       select new ContactViewModel(user, Me);

                                        Contacts = new ObservableCollection<ContactViewModel>(contacts);
                                        Debug.WriteLine("Contacts Count: " + contacts.Count());
                                    }
                                });
                            }
                        }
                    });
                }
            });

            // Fire events on the ui thread
            _chat.UserOffline += user => _syncContext.Post(_ => OnUserStatusChange(user), null);
            _chat.UserOnline += user => _syncContext.Post(_ => OnUserStatusChange(user), null);
            _chat.Message += message => _syncContext.Post(_ => OnMessage(message), null);
        }
Beispiel #4
0
 public MockMainViewModel()
 {
     Me = new ContactViewModel {
         User = new User {
             Email = "*****@*****.**", Name = "user", Online = true
         }, IsOnline = true, Status = "Online"
     };
     Conversations = new ObservableCollection <ContactViewModel>();
     Conversations.Add(new ContactViewModel {
         User = new User {
             Email = "*****@*****.**", Name = "user1", Online = true
         }, IsOnline = true, Status = "Online", Message = new Message {
             Id = -1, DateReceived = DateTime.Now.AddMinutes(-2), Value = "and the text box for your message needs to wrap not continue on", From = "user", To = "user1", IsMine = true, Initiator = new User {
                 Email = "*****@*****.**", Name = "user", Online = true
             }, Contact = new User {
                 Email = "*****@*****.**", Name = "user1", Online = true
             }
         }
     });
     Conversations.Add(new ContactViewModel {
         User = new User {
             Email = "*****@*****.**", Name = "user2", Online = false
         }, IsOnline = false, Status = "Offline", Message = new Message {
             Id = -1, DateReceived = DateTime.Now.AddMinutes(-2), Value = "Test Message 2", From = "user", To = "user2", IsMine = true, Initiator = new User {
                 Email = "*****@*****.**", Name = "user", Online = true
             }, Contact = new User {
                 Email = "*****@*****.**", Name = "user2", Online = false
             }
         }
     });
     Conversations.Add(new ContactViewModel {
         User = new User {
             Email = "*****@*****.**", Name = "user3", Online = true
         }, IsOnline = true, Status = "Online", Message = new Message {
             Id = -1, DateReceived = DateTime.Now.AddMinutes(-2), Value = "Test Message 3", From = "user", To = "user3", IsMine = true, Initiator = new User {
                 Email = "*****@*****.**", Name = "user", Online = true
             }, Contact = new User {
                 Email = "*****@*****.**", Name = "user3", Online = true
             }
         }
     });
     Conversations.Add(new ContactViewModel {
         User = new User {
             Email = "*****@*****.**", Name = "user4", Online = false
         }, IsOnline = false, Status = "Offline", Message = new Message {
             Id = -1, DateReceived = DateTime.Now.AddMinutes(-2), Value = "Test Message 4", From = "user", To = "user4", IsMine = true, Initiator = new User {
                 Email = "*****@*****.**", Name = "user", Online = true
             }, Contact = new User {
                 Email = "*****@*****.**", Name = "user4", Online = false
             }
         }
     });
     Contacts = new ObservableCollection <ContactViewModel>();
     Contacts.Add(new ContactViewModel {
         User = new User {
             Email = "*****@*****.**", Name = "user1", Online = true
         }, IsOnline = true, Status = "Online"
     });
     Contacts.Add(new ContactViewModel {
         User = new User {
             Email = "*****@*****.**", Name = "user2", Online = false
         }, IsOnline = false, Status = "Offline"
     });
     Contacts.Add(new ContactViewModel {
         User = new User {
             Email = "*****@*****.**", Name = "user3", Online = true
         }, IsOnline = true, Status = "Online"
     });
     Contacts.Add(new ContactViewModel {
         User = new User {
             Email = "*****@*****.**", Name = "user4", Online = false
         }, IsOnline = false, Status = "Offline"
     });
 }
Beispiel #5
0
        private void InitializeConnection(string url, Cookie authCookie)
        {
            _connection = new HubConnection(url)
            {
                CookieContainer = new CookieContainer()
            };
            _connection.CookieContainer.Add(authCookie);

            // Get a reference to the chat proxy
            _chat = new Chat(_connection);

            // Start the connection
            _connection.Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    // Show a connection error here
                }
                else
                {
                    _chat.GetUser(Name).ContinueWith(getUserTask =>
                    {
                        if (getUserTask.IsFaulted)
                        {
                        }
                        else
                        {
                            if (getUserTask.Result != null)
                            {
                                Me = new ContactViewModel(getUserTask.Result);
                                Me.OpenChatEvent += OnOpenChat;

                                _chat.GetConversations(Me.User).ContinueWith(getConversationTask =>
                                {
                                    if (getConversationTask.IsFaulted)
                                    {
                                        Debug.WriteLine("GetConversations Failed: " + getConversationTask.Status);
                                    }
                                    else
                                    {
                                        var conversations = from Message message in getConversationTask.Result
                                                            select new ContactViewModel(message.Contact, message, Me);
                                        Conversations = new ObservableCollection <ContactViewModel>(conversations);
                                        Debug.WriteLine("Conversations Count: " + conversations.Count());
                                    }
                                });

                                // Get a list of users and add it to the view model
                                _chat.GetUsers().ContinueWith(getUsersTask =>
                                {
                                    if (getUsersTask.IsFaulted)
                                    {
                                        // Show a connection error here
                                    }
                                    else
                                    {
                                        // Exclude current user from Contact list
                                        var contacts = from User user in getUsersTask.Result
                                                       where !user.Name.Equals(Me.User.Name, StringComparison.OrdinalIgnoreCase)
                                                       select new ContactViewModel(user, Me);

                                        Contacts = new ObservableCollection <ContactViewModel>(contacts);
                                        Debug.WriteLine("Contacts Count: " + contacts.Count());
                                    }
                                });
                            }
                        }
                    });
                }
            });

            // Fire events on the ui thread
            _chat.UserOffline += user => _syncContext.Post(_ => OnUserStatusChange(user), null);
            _chat.UserOnline  += user => _syncContext.Post(_ => OnUserStatusChange(user), null);
            _chat.Message     += message => _syncContext.Post(_ => OnMessage(message), null);
        }