private void SubscribeRequestResponseHandler(SubscribeRq request, SubscribeRs response, Exception e) { if (e != null) { Logger.Error("Failed to send subscribe answer to " + request.username + " : " + e.Message, e); } }
private void SubscribePersonResponseHandler(SubscribeRq request, SubscribeRs response, Exception e, Person person) { if (e == null) { person.SubscriptionStatus = "subscribe"; Logger.Debug("Succeeded in sending subscribe request for " + person.Username); } else { Logger.Error("Failed to subscribe to " + person.Username + " : " + e.Message, e); } }
private void SendSubscribe(bool subscribe) { UiHelper.Disabler.DisableInputs(true, "Updating"); ThreadPool.QueueUserWorkItem(state => { try { SubscribeRq request = new SubscribeRq { subscribe = subscribe, username = Team.Username }; GwupeClientAppContext.CurrentAppContext.ConnectionManager.Connection .Request <SubscribeRq, SubscribeRs>(request); // Hack the answer (actual notify comes through a little later) Dispatcher.Invoke(new Action(() => { Team.Player = subscribe ? PlayerMembership.player : PlayerMembership.none; })); // look through notifications to make sure that none related to this are there foreach ( var notification in GwupeClientAppContext.CurrentAppContext.NotificationManager.Notifications) { if (notification is JoinTeamNotification) { var teamNotification = notification as JoinTeamNotification; if (!String.IsNullOrEmpty(teamNotification.TeamUsername) && teamNotification.TeamUsername.Equals(Team.Username)) { // this is the one, delete and break GwupeClientAppContext.CurrentAppContext.NotificationManager.DeleteNotification( notification); break; } } } } catch (Exception ex) { Logger.Error( "Failed to " + (subscribe ? "accept" : "decline") + " subscription to " + Team.Username, ex); UiHelper.Validator.SetError("Failed to send subscription status to server."); } finally { UiHelper.Disabler.DisableInputs(false); } }); }
private void ProcessAnswer(bool answer, String username) { if (answer) { SubscribeRq request = new SubscribeRq { subscribe = true, username = username }; _appContext.ConnectionManager.Connection.RequestAsync <SubscribeRq, SubscribeRs>(request, SubscribeRequestResponseHandler); } else { SubscribeRq request = new SubscribeRq { subscribe = false, username = username }; _appContext.ConnectionManager.Connection.RequestAsync <SubscribeRq, SubscribeRs>(request, SubscribeRequestResponseHandler); } }
public Response process(Request req) { SubscribeRq request = (SubscribeRq)req; SubscribeRs response = new SubscribeRs(); if (request.subscribe) { TrueFalseNotification notification; if (request.team) { notification = new JoinTeamNotification() { Manager = _appContext.NotificationManager, Avatar = request.teamElement.hasAvatar ? Convert.FromBase64String(request.teamElement.avatarData) : null, Name = request.teamElement.name, Location = request.teamElement.location, Message = "Join Team?", TeamUsername = request.teamElement.user, }; } else { notification = new AddBuddyNotification() { Manager = _appContext.NotificationManager, Avatar = request.userElement.hasAvatar ? Convert.FromBase64String(request.userElement.avatarData) : null, Name = request.userElement.name, Location = request.userElement.location, Message = "Add Contact?", }; } notification.AnswerHandler.Answered += delegate { ProcessAnswer(notification.AnswerHandler.Answer, request.username); }; _appContext.NotificationManager.AddNotification(notification); _appContext.UIManager.Show(); } return(response); }