Exemplo n.º 1
0
 public static void Unfriend(AbstractLogger logger, INotificationQueue notificationQueue, IMixWebCallFactory mixWebCallFactory, string friendSwid, Action successCallback, Action failureCallback)
 {
     try
     {
         RemoveFriendshipRequest removeFriendshipRequest = new RemoveFriendshipRequest();
         removeFriendshipRequest.FriendUserId = friendSwid;
         RemoveFriendshipRequest request = removeFriendshipRequest;
         IWebCall <RemoveFriendshipRequest, RemoveFriendshipResponse> webCall = mixWebCallFactory.FriendshipDeletePost(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <RemoveFriendshipResponse> e)
         {
             RemoveFriendshipResponse     response     = e.Response;
             RemoveFriendshipNotification notification = response.Notification;
             if (NotificationValidator.Validate(notification))
             {
                 notificationQueue.Dispatch(notification, successCallback, failureCallback);
             }
             else
             {
                 logger.Critical("Failed to validate remove friendship response: " + JsonParser.ToJson(response));
                 failureCallback();
             }
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         failureCallback();
     }
 }
 public static void Send(AbstractLogger logger, INotificationQueue notificationQueue, IMixWebCallFactory mixWebCallFactory, string inviteeDisplayName, bool requestTrust, Action <long> successCallback, Action <ISendFriendInvitationResult> failureCallback)
 {
     try
     {
         AddFriendshipInvitationRequest addFriendshipInvitationRequest = new AddFriendshipInvitationRequest();
         addFriendshipInvitationRequest.InviteeDisplayName = inviteeDisplayName;
         addFriendshipInvitationRequest.IsTrusted          = requestTrust;
         AddFriendshipInvitationRequest request = addFriendshipInvitationRequest;
         IWebCall <AddFriendshipInvitationRequest, AddFriendshipInvitationResponse> webCall = mixWebCallFactory.FriendshipInvitationPut(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <AddFriendshipInvitationResponse> e)
         {
             AddFriendshipInvitationResponse response = e.Response;
             if (NotificationValidator.Validate(response.Notification))
             {
                 notificationQueue.Dispatch(response.Notification, delegate
                 {
                     successCallback(response.Notification.Invitation.FriendshipInvitationId.Value);
                 }, delegate
                 {
                     failureCallback(new SendFriendInvitationResult(success: false, null));
                 });
             }
             else
             {
                 logger.Critical("Failed to validate invitation: " + JsonParser.ToJson(response));
                 failureCallback(new SendFriendInvitationResult(success: false, null));
             }
         };
         webCall.OnError += delegate(object sender, WebCallErrorEventArgs e)
         {
             string status  = e.Status;
             string message = e.Message;
             string text    = status;
             if (text != null && text == "INVITATION_ALREADY_EXISTS")
             {
                 logger.Error("Failed to send invitation because it already exists: " + message);
                 failureCallback(new SendFriendInvitationAlreadyExistsResult(success: false, null));
             }
             else
             {
                 failureCallback(new SendFriendInvitationResult(success: false, null));
             }
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         failureCallback(new SendFriendInvitationResult(success: false, null));
     }
 }
Exemplo n.º 3
0
 public void ClearAlerts(IEnumerable <IAlert> alerts, Action <IClearAlertsResult> callback)
 {
     try
     {
         List <IInternalAlert> list = new List <IInternalAlert>();
         foreach (IAlert alert in alerts)
         {
             IInternalAlert internalAlert = alert as IInternalAlert;
             if (internalAlert == null)
             {
                 logger.Critical("Can't clear unknown alert");
                 callback(new ClearAlertsResult(success: false));
                 return;
             }
             list.Add(internalAlert);
         }
         IWebCall <ClearAlertsRequest, ClearAlertsResponse> webCall = mixWebCallFactory.AlertsClearPut(new ClearAlertsRequest
         {
             AlertIds = list.Select((IInternalAlert a) => a.AlertId).Cast <long?>().ToList()
         });
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <ClearAlertsResponse> e)
         {
             ClearAlertsResponse response = e.Response;
             if (NotificationValidator.Validate(response.Notification))
             {
                 notificationQueue.Dispatch(response.Notification, delegate
                 {
                     callback(new ClearAlertsResult(success: true));
                 }, delegate
                 {
                     callback(new ClearAlertsResult(success: false));
                 });
             }
             else
             {
                 logger.Critical("Failed to validate clear alerts response: " + JsonParser.ToJson(response));
                 callback(new ClearAlertsResult(success: false));
             }
         };
         webCall.OnError += delegate
         {
             callback(new ClearAlertsResult(success: false));
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         callback(new ClearAlertsResult(success: false));
     }
 }
 public static void Accept(AbstractLogger logger, INotificationQueue notificationQueue, IMixWebCallFactory mixWebCallFactory, long invitationId, bool isTrusted, Action <AddFriendshipNotification> successCallback, Action failureCallback)
 {
     try
     {
         AddFriendshipRequest addFriendshipRequest = new AddFriendshipRequest();
         addFriendshipRequest.InvitationId = invitationId;
         addFriendshipRequest.IsTrusted    = isTrusted;
         AddFriendshipRequest request = addFriendshipRequest;
         IWebCall <AddFriendshipRequest, AddFriendshipResponse> webCall = mixWebCallFactory.FriendshipPut(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <AddFriendshipResponse> e)
         {
             AddFriendshipResponse response = e.Response;
             if (NotificationValidator.Validate(response.Notification))
             {
                 notificationQueue.Dispatch(response.Notification, delegate
                 {
                     successCallback(response.Notification);
                 }, failureCallback);
             }
             else
             {
                 logger.Critical("Failed to validate invitation response: " + JsonParser.ToJson(response));
                 failureCallback();
             }
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         failureCallback();
     }
 }
Exemplo n.º 5
0
 public static void Reject(AbstractLogger logger, INotificationQueue notificationQueue, IMixWebCallFactory mixWebCallFactory, long invitationId, Action <RemoveFriendshipInvitationNotification> successCallback, Action failureCallback)
 {
     try
     {
         RemoveFriendshipInvitationRequest removeFriendshipInvitationRequest = new RemoveFriendshipInvitationRequest();
         removeFriendshipInvitationRequest.InvitationId = invitationId;
         RemoveFriendshipInvitationRequest request = removeFriendshipInvitationRequest;
         IWebCall <RemoveFriendshipInvitationRequest, RemoveFriendshipInvitationResponse> webCall = mixWebCallFactory.FriendshipInvitationDeletePost(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <RemoveFriendshipInvitationResponse> e)
         {
             RemoveFriendshipInvitationResponse response = e.Response;
             if (NotificationValidator.Validate(response.Notification))
             {
                 RemoveFriendshipInvitationNotification notification = response.Notification;
                 notificationQueue.Dispatch(notification, delegate
                 {
                     successCallback(notification);
                 }, failureCallback);
             }
             else
             {
                 logger.Critical("Failed to validate invitation response: " + JsonParser.ToJson(response));
                 failureCallback();
             }
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         failureCallback();
     }
 }