first commit
This commit is contained in:
43
Yapper/MVVM/ViewModel/MainViewModel.cs
Normal file
43
Yapper/MVVM/ViewModel/MainViewModel.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using YapperClient.MVVM.Core;
|
||||
using YapperClient.MVVM.Model;
|
||||
using YapperClient.Net;
|
||||
|
||||
namespace YapperClient.MVVM.ViewModel
|
||||
{
|
||||
class MainViewModel
|
||||
{
|
||||
public ObservableCollection<UserModel> Users { get; set; }
|
||||
public RelayCommand ConnectToServerCommand { get; set; }
|
||||
|
||||
public string UserName { get; set; }
|
||||
|
||||
private Server _server;
|
||||
public MainViewModel() {
|
||||
Users = new ObservableCollection<UserModel>();
|
||||
_server = new Server();
|
||||
_server.connectedEvent += UserConnected;
|
||||
ConnectToServerCommand = new RelayCommand(o => _server.ConnectToServer(UserName), o => !string.IsNullOrEmpty(UserName));
|
||||
}
|
||||
|
||||
private void UserConnected()
|
||||
{
|
||||
var user = new UserModel
|
||||
{
|
||||
UserName = _server.PacketReader.ReadMessage(),
|
||||
UID = _server.PacketReader.ReadMessage(),
|
||||
};
|
||||
|
||||
if (!Users.Any(x => x.UID == user.UID))
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() => Users.Add(user));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user