public void SendRequestToServer(MyRequestMethod requestMethod, RequestUser requestUser, OnRequestCompletedMethod method) { BackgroundWorker backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork); backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_Completed); Tuple<MyRequestMethod, RequestUser, OnRequestCompletedMethod> tuple = Tuple.Create<MyRequestMethod, RequestUser, OnRequestCompletedMethod>(requestMethod, requestUser, method); backgroundWorker.RunWorkerAsync(tuple); }
private void OnRefreshWallsCompleted(RequestUser userRequest, ResponseJson response) { if (response.value.Equals("success")) { //reset text error wallView.ErrorText = ""; //save new user data in model string selectedWallName = wallView.SelectedWall; Wall selectedWallChanges = dataModel.MergeAndReturnWallChanges(response.user, selectedWallName); //add new messages on the selected wall if any foreach (Message mess in selectedWallChanges.messages) { wallView.AddMessageToSelectedWall(mess.content, mess.author, mess.date); } //create new notifications ManageNewMessagesNotification(response.user); } else if (response.value.Equals("fail")) { wallView.ErrorText = response.details; } else { wallView.ErrorText = "Unexpected error"; } }
private void OnLoginUserCompleted(RequestUser userRequest, ResponseJson response) { if (response.value.Equals("success")) { //reset text error loginUserView.ErrorText = ""; //create login user - response request doesn't contain usernames or passwords User loginUser = response.user; loginUser.username = userRequest.username; loginUser.password = userRequest.password; //save new user data in model dataModel.User = loginUser; //set new user data to wallView PopulateWallView(); //load wallView parentView.CurrentChildView = wallView; wallView.AutoRefreshWorking = true; } else if (response.value.Equals("fail")) { loginUserView.ErrorText = response.details; } else { loginUserView.ErrorText = "Unexpected error"; } }
private void OnAddWallCompleted(RequestUser userRequest, ResponseJson response) { if (response.value.Equals("success")) { //reset text error wallView.ErrorText = ""; //save new user data in model dataModel.MergeUserModel(response.user); if (response.user.walls != null && response.user.walls.Count > 0) { wallView.AddNewWallName(response.user.walls[0].name); wallView.SelectedWall = response.user.walls[0].name; } //wallView.NewWallNameText = ""; } else if (response.value.Equals("fail")) { wallView.ErrorText = response.details; } else { wallView.ErrorText = "Unexpected error"; } }
private void OnAddMessageCompleted(RequestUser userRequest, ResponseJson response) { if (response.value.Equals("success")) { //reset text error wallView.ErrorText = ""; //save new user data in model dataModel.MergeUserModel(response.user); if (userRequest.name.Equals(wallView.SelectedWall)) { if (response.user.walls != null && response.user.walls.Count > 0 && response.user.walls[0].messages != null && response.user.walls[0].messages.Count > 0) { Message mess = response.user.walls[0].messages[0]; wallView.AddMessageToSelectedWall(mess.content, mess.author, mess.date); } } wallView.NewMessageText = ""; } else if (response.value.Equals("fail")) { wallView.ErrorText = response.details; } else { wallView.ErrorText = "Unexpected error"; } }
public void OnRefreshWallsClicked(object sender, System.EventArgs e) { RequestUser userRequest = new RequestUser(); userRequest.username = dataModel.User.username; userRequest.password = dataModel.User.password; userRequest.date = dataModel.User.date; serverRequest.SendRequestToServer(MyRequestMethod.GetUser, userRequest, OnRefreshWallsCompleted); }
//////////////////////////////////// //Methods from IWallPresenter// public void OnNewWallClicked(object sender, System.EventArgs e) { if (IsNewWallValid()) { RequestUser userRequest = new RequestUser(); userRequest.username = dataModel.User.username; userRequest.password = dataModel.User.password; userRequest.name = wallView.NewWallNameText; //send request to server serverRequest.SendRequestToServer(MyRequestMethod.AddWall, userRequest, OnAddWallCompleted); } wallView.SetNewMessageFocus(); }
//////////////////////////////////// //Methods from ILoginUserPresenter// public void OnLoginUserClicked(object sender, System.EventArgs e) { if (IsUserLoginValid()) { //make visible the loading bar while retrieving data from server loginUserView.LoginLoadingVisible = true; RequestUser userRequest = new RequestUser(); userRequest.username = loginUserView.Username; userRequest.password = loginUserView.Password; //send request to server serverRequest.SendRequestToServer(MyRequestMethod.GetUser, userRequest, OnLoginUserCompleted); } }
//////////////////////////////////// //Methods from ICreateUserPresenter// public void OnCreateUserClicked(object sender, System.EventArgs e) { if (IsUserCreateValid()) { createUserView.CreateLoadingVisible = true; RequestUser userRequest = new RequestUser(); userRequest.username = createUserView.Username; userRequest.password = createUserView.Password; userRequest.name = createUserView.DisplayName; //send request to server serverRequest.SendRequestToServer(MyRequestMethod.CreateUser, userRequest, OnCreateUserCompleted); } }