示例#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();
     }
 }
示例#2
0
 public static void ModerateText(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string text, bool isTrusted, Action <ModerateTextResponse> successCallback, Action failureCallback)
 {
     try
     {
         ModerateTextRequest moderateTextRequest = new ModerateTextRequest();
         moderateTextRequest.Text             = text;
         moderateTextRequest.ModerationPolicy = (isTrusted ? "Trusted" : "UnTrusted");
         ModerateTextRequest request = moderateTextRequest;
         IWebCall <ModerateTextRequest, ModerateTextResponse> webCall = mixWebCallFactory.ModerationTextPut(request);
         webCall.OnResponse += delegate(object sender, WebCallEventArgs <ModerateTextResponse> e)
         {
             ModerateTextResponse response = e.Response;
             if (ValidateModerateTextResponse(response))
             {
                 successCallback(response);
             }
             else
             {
                 logger.Critical("Failed to validate moderate text response: " + JsonParser.ToJson(response));
                 failureCallback();
             }
         };
         webCall.OnError += delegate
         {
             failureCallback();
         };
         webCall.Execute();
     }
     catch (Exception ex)
     {
         logger.Critical("Unhandled exception: " + ex);
         failureCallback();
     }
 }
示例#3
0
        private void HandleLoginSuccess(GuestControllerResult <LogInResponse> result, Action <ILoginResult> callback)
        {
            try
            {
                LogInResponse           response          = result.Response;
                LogInData               data              = response.data;
                GuestApiErrorCollection gcErrorCollection = response.error;
                ILoginResult            loginResult       = GuestControllerErrorParser.GetLoginResult(gcErrorCollection);
                bool   flag          = false;
                string hallPassToken = string.Empty;
                string swid          = string.Empty;
                if (data != null || loginResult == null)
                {
                    goto IL_015d;
                }
                if (loginResult is ILoginFailedParentalConsentResult)
                {
                    foreach (GuestApiError error in gcErrorCollection.errors)
                    {
                        TemporaryToken data2 = error.data;
                        if (data2 != null)
                        {
                            flag          = true;
                            hallPassToken = data2.accessToken;
                            swid          = data2.swid;
                            break;
                        }
                    }
                    if (flag)
                    {
                        goto IL_015d;
                    }
                    callback(loginResult);
                }
                else
                {
                    callback(loginResult);
                }
                goto end_IL_0018;
IL_015d:
                if (data == null && !flag)
                {
                    if (gcErrorCollection != null)
                    {
                        logger.Critical("Received unhandled error exception: " + JsonParser.ToJson(gcErrorCollection));
                    }
                    callback(new LoginResult(success: false, null));
                }
                else if (flag)
                {
                    database.StoreSession(swid, hallPassToken, null, null, null, null, null, null, null, null, updateLastProfileRefreshTime: false, null);
                    IGuestControllerClient guestControllerClient = guestControllerClientFactory.Create(swid);
                    ProfileGetter.GetProfile(logger, guestControllerClient, delegate(ProfileData profileData)
                    {
                        if (profileData == null)
                        {
                            database.DeleteSession(swid);
                            callback(new LoginFailedParentalConsentResult());
                        }
                        else
                        {
                            StoreSession(swid, hallPassToken, null, profileData.etag, profileData.displayName, profileData.profile);
                            HandleRefreshProfileSuccess(callback, loginResult, gcErrorCollection, profileData.profile, profileData.displayName, profileData.marketing, swid, hallPassToken);
                        }
                    });
                }
                else if (!ValidateLogInData(data))
                {
                    logger.Critical("Error parsing the login data:" + JsonParser.ToJson(data));
                    callback(new LoginResult(success: false, null));
                }
                else
                {
                    Token token = data.token;
                    StoreSession(token.swid, token.access_token, token.refresh_token, data.etag, data.displayName, data.profile);
                    HandleRefreshProfileSuccess(callback, loginResult, gcErrorCollection, data.profile, data.displayName, data.marketing, token.swid, token.access_token);
                }
                end_IL_0018 :;
            }
            catch (CorruptionException ex)
            {
                logger.Fatal("Corruption detected during login: "******"Unhandled exception: " + ex2);
                callback(new LoginResult(success: false, null));
            }
        }