private void SendLoginRequest() { LoginResponse response = UserServiceProxy.Login(new LoginRequest { UserName = this.UserName, Password = this.Password }); ConsoleLog.Document += $" { response.IsSuccess } {response.Message} \n "; if (response.IsSuccess == true) { //save loged user authentication AuthenticatedUser.Authentication = response.Authentication; AuthenticatedUser.UserName = this.UserName; //update contactList ContactStateManager.AssignAllCurrentOnlineContacts(response.AllOtherUsers); //joining the chat service: JoinChatServiceResponse responseFromChatService = ChatServiceProxy.JoinService(new JoinChatServiceRequest()); ConsoleLog.Document += responseFromChatService.Message; //joining the Game Service: JoinGameServiceResponse responseFromGameService = GameServiceProxy.JoinService(new JoinGameServiceRequest()); ConsoleLog.Document += responseFromGameService.Message; UserServiceProxy.OnLoginEvent += UserServiceProxy_OnLoginEvent; ViewChanging("ContactListView"); //set online users to something : new class that will save online users } }
private void UserServiceProxy_OnLoginEvent(object sender, OnLoginEventArgs e) { OnlineUsers = new ObservableCollection <UserDTO>(ContactStateManager.GetOnlineContacts()); OfflineUsers = new ObservableCollection <UserDTO>(ContactStateManager.GetOfflineContacts()); ConsoleLog.Document = e.UserName + "has loged in"; //OnlineUsers.Add(new UserDTO {UserName= e.UserName }); }
public void OnSignedUp(OnSignedUpRequest userSignedUp) { ContactStateManager.AddNewSignedContact(new UserDTO { UserName = userSignedUp.UserName }); OnSignedUpEvent?.Invoke(this, new OnSignedUpEventArgs { UserName = userSignedUp.UserName }); }
public void OnLogout(OnlogoutRequest userLogedout) { ContactStateManager.UpdateContactToOffline(new UserDTO { UserName = userLogedout.UserName }); OnLogoutEvent?.Invoke(this, new OnLogoutEventArgs { UserName = userLogedout.UserName }); }
public void OnLogin(OnLoginRequest userLogedin) // call back from server about new user that logged in { //adding the new logedin to the OnlineUsers: ContactStateManager.UpdateContactToOnline(new UserDTO { UserName = userLogedin.UserName }); //raising the event: OnLoginEvent?.Invoke(this, new OnLoginEventArgs { UserName = userLogedin.UserName }); //TODO: implement a info to the wpf about the user. // return new OnLoginResponse { IsSuccess = true, Message = "here the user info", userAlreadyLoged = new UserDTO { UserName = "******" } }; }
private void SendSignUpRequest() { SignUpResponse response = UserServiceProxy.SignUp(new SignUpRequest { UserName = UserName, Password = Password, PasswordConfirm = PasswordConfirm }); ConsoleLog.Document += $" {response.IsSuccess} {response.Message}"; //update ContactsManager: if (response.IsSuccess == true) { response.AllOtherSignedUpUsers.ForEach(u => ConsoleLog.Document += $"other users: \n{u.UserName}"); ContactStateManager.AssignAllCurrentContacts(response.AllOtherSignedUpUsers); } }
public LoginViewModel() { ConsoleLog = new ConsoleLog { Document = "check binding \n" }; //test AuthenticatedUser = AuthenticatedUser.Instance; //load all contacts: ContactStateManager.LoadAllContacts(); //init Proxies: UserServiceProxy = UserServiceProxy.Instance; ChatServiceProxy = ChatServiceProxy.Instance; GameServiceProxy = GameServiceProxy.Instance; //Init Commands: SendLoginRequestCommand = new MyCommand(SendLoginRequest); ChangeViewToSignUpCommand = new MyCommand(ChangeViewToSignUp); }
//ctor: public ContactListViewModel() { onlineUsers = new ObservableCollection <UserDTO>(ContactStateManager.GetOnlineContacts()); offlineUsers = new ObservableCollection <UserDTO>(ContactStateManager.GetOfflineContacts()); ConsoleLog = new ConsoleLog(); //init proxies: UserServiceProxy = UserServiceProxy.Instance; //TODO: is needed? UserServiceProxy.OnLoginEvent += UserServiceProxy_OnLoginEvent; UserServiceProxy.OnSignedUpEvent += UserServiceProxy_OnSignedUp; UserServiceProxy.OnLogoutEvent += UserServiceProxy_OnLogout; ChatServiceProxy = ChatServiceProxy.Instance; ChatServiceProxy.OnMessageSentEvent += ChatServiceProxy_OnMessageSent; GameServiceProxy = GameServiceProxy.Instance; GameServiceProxy.OnGameEvent += GameServiceProxy_OnGameEvent; //init ICommands: SendGameRequestCommand = new MyCommand(SendGameRequest); OpenChatWindowCommand = new MyCommand(OpenChatWindow); //subscribe to Closing Window event: Application.Current.MainWindow.Closing += MainWindow_OnWindowClosing; }
private void UserServiceProxy_OnLogout(object sender, OnLogoutEventArgs e) { OnlineUsers = new ObservableCollection <UserDTO>(ContactStateManager.GetOnlineContacts()); OfflineUsers = new ObservableCollection <UserDTO>(ContactStateManager.GetOfflineContacts()); ConsoleLog.Document += $"{e.UserName} has loged out"; }
private void UserServiceProxy_OnSignedUp(object sender, OnSignedUpEventArgs e) { //Getting the updated Offline contacts list: OfflineUsers = new ObservableCollection <UserDTO>(ContactStateManager.GetOfflineContacts()); ConsoleLog.Document = e.UserName + "has singed up"; }