public void SendAlert(int level, AlertType type, Action <ISendAlertResult> callback) { try { IWebCall <TriggerAlertRequest, BaseResponse> webCall = mixWebCallFactory.IntegrationTestSupportUserAlertPost(new TriggerAlertRequest { Level = level.ToString(), Text = AlertTypeUtils.ToString(type) }); webCall.OnResponse += delegate { callback(new SendAlertResult(success: true)); }; webCall.OnError += delegate { callback(new SendAlertResult(success: false)); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); callback(new SendAlertResult(success: false)); } }
public void SetLanguagePreference(string languageCode, Action <ISetLangaugePreferenceResult> callback) { try { IWebCall <SetLanguageRequest, BaseResponse> webCall = mixWebCallFactory.LanguagePreferencePost(new SetLanguageRequest { LanguageCode = languageCode }); webCall.OnResponse += delegate { callback(new SetLangaugePreferenceResult(success: true)); }; webCall.OnError += delegate { logger.Critical("Error setting language preference"); callback(new SetLangaugePreferenceResult(success: false)); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); callback(new SetLangaugePreferenceResult(success: false)); } }
public static void GetRequirements(AbstractLogger logger, string countryCode, IMixWebCallFactory mixWebCallFactory, Action <bool, bool> successCallback, Action failureCallback) { try { PilCheckRequest pilCheckRequest = new PilCheckRequest(); pilCheckRequest.PersonalInformationUsage = "PUBLIC_DISCLOSURE"; pilCheckRequest.CountryCode = countryCode; PilCheckRequest request = pilCheckRequest; IWebCall <PilCheckRequest, PilCheckResponse> webCall = mixWebCallFactory.PilCheckPost(request); webCall.OnResponse += delegate(object sender, WebCallEventArgs <PilCheckResponse> e) { bool?adultVerificationRequired = e.Response.AdultVerificationRequired; bool?adultVerificationAvailable = e.Response.AdultVerificationAvailable; if (!adultVerificationRequired.HasValue || !adultVerificationAvailable.HasValue) { failureCallback(); } else { successCallback(adultVerificationRequired.Value, adultVerificationAvailable.Value); } }; webCall.OnError += delegate { failureCallback(); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); failureCallback(); } }
public static void Report(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string userId, ReportUserReason reason, Action successCallback, Action failureCallback) { try { ReportPlayerRequest reportPlayerRequest = new ReportPlayerRequest(); reportPlayerRequest.ReportedUserId = userId; reportPlayerRequest.Reason = reason.ToString(); ReportPlayerRequest request = reportPlayerRequest; IWebCall <ReportPlayerRequest, BaseResponse> webCall = mixWebCallFactory.ModerationReportPlayerPut(request); webCall.OnResponse += delegate { successCallback(); }; webCall.OnError += delegate { failureCallback(); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); failureCallback(); } }
public static void GetState(AbstractLogger logger, IEpochTime epochTime, string clientVersion, IDatabase database, IUserDatabase userDatabase, INotificationQueue notificationQueue, IMixWebCallFactory mixWebCallFactory, string localUserId, long lastNotificationTime, Action <GetStateResponse> successCallback, Action failureCallback) { try { GetStateRequest getStateRequest = new GetStateRequest(); getStateRequest.UserId = localUserId; getStateRequest.ClientVersion = clientVersion; GetStateRequest request = getStateRequest; IWebCall <GetStateRequest, GetStateResponse> webCall = mixWebCallFactory.StatePost(request); webCall.OnResponse += delegate(object sender, WebCallEventArgs <GetStateResponse> e) { HandleGetStateSuccess(logger, epochTime, database, userDatabase, notificationQueue, e.Response, mixWebCallFactory, successCallback, failureCallback); }; webCall.OnError += delegate { failureCallback(); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); failureCallback(); } }
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 arg) { logger.Critical("Unhandled exception: " + arg); failureCallback(); } }
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(); } }
public static void SetAway(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, Action <BaseResponse> successCallback, Action failureCallback) { try { SetPresenceRequest setPresenceRequest = new SetPresenceRequest(); setPresenceRequest.State = "away"; SetPresenceRequest request = setPresenceRequest; IWebCall <SetPresenceRequest, BaseResponse> webCall = mixWebCallFactory.PresencePut(request); webCall.OnResponse += delegate(object sender, WebCallEventArgs <BaseResponse> e) { BaseResponse response = e.Response; successCallback(response); }; webCall.OnError += delegate { failureCallback(); }; webCall.Execute(); } catch (Exception arg) { logger.Critical("Unhandled exception: " + arg); failureCallback(); } }
private static void HandleRefreshCallback <TRequest, TResponse>(IWebCall <TRequest, TResponse> webCall, bool needAuthToken, string authToken, bool needSession, IWebCallEncryptor webCallEncryptor) where TRequest : BaseUserRequest where TResponse : BaseResponse, new() { if (needAuthToken && authToken != null) { webCall.SetHeader("X-Mix-OneIdToken", authToken); } if (needSession && webCallEncryptor != null) { webCall.WebCallEncryptor = webCallEncryptor; webCall.SetHeader("X-Mix-UserSessionId", webCallEncryptor.SessionId); } if (webCall.RefreshStatus == WebCallRefreshStatus.WaitingForRefreshCallback) { webCall.RefreshStatus = WebCallRefreshStatus.NotRefreshing; bool flag = true; if (needAuthToken && authToken == null) { flag = false; webCall.DispatchError("GuestController token expired and couldn't get a new token"); } if (needSession && webCallEncryptor == null) { flag = false; webCall.DispatchError("Session expired and couldn't start a new session"); } if (flag) { webCall.Execute(); } } else { webCall.RefreshStatus = WebCallRefreshStatus.RefreshedWhileWaitingForCallback; } }
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)); } }
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 void Get(Action <IGetGeolocationResult> callback) { IWebCall <BaseUserRequest, GetGeolocationResponse> webCall = mixWebCallFactory.GeolocationPost(new BaseUserRequest()); webCall.OnResponse += delegate(object sender, WebCallEventArgs <GetGeolocationResponse> e) { callback(new GetGeolocationResult(success: true, e.Response.CountryCode)); }; webCall.OnError += delegate { logger.Critical("Failed to get geolocation info"); callback(new GetGeolocationResult(success: false, null)); }; webCall.Execute(); }
public static void UpdateDisplayName(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string displayName, Action <IUpdateDisplayNameResult> callback) { try { SetDisplayNameRequest setDisplayNameRequest = new SetDisplayNameRequest(); setDisplayNameRequest.DisplayName = displayName; SetDisplayNameRequest request = setDisplayNameRequest; IWebCall <SetDisplayNameRequest, SetDisplayNameResponse> webCall = mixWebCallFactory.DisplaynamePut(request); webCall.OnResponse += delegate(object sender, WebCallEventArgs <SetDisplayNameResponse> e) { SetDisplayNameResponse response = e.Response; if (ValidateSetDisplayNameResponse(response)) { callback(new UpdateDisplayNameResult(success: true)); } else { logger.Critical("Failed to validate update display name response!"); callback(new UpdateDisplayNameResult(success: false)); } }; webCall.OnError += delegate(object sender, WebCallErrorEventArgs e) { switch (e.Status) { case "DISPLAYNAME_MODERATION_FAILED": logger.Warning("Failed to update display name due to moderation failure: " + e.Message); callback(new UpdateDisplayNameFailedModerationResult(success: false)); break; case "DISPLAYNAME_ASSIGNMENT_FAILED": logger.Warning("Failed to update display name due to assignment failure: " + e.Message); callback(new UpdateDisplayNameExistsResult(success: false)); break; default: callback(new UpdateDisplayNameResult(success: false)); break; } }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); callback(new UpdateDisplayNameResult(success: false)); } }
private void Start(string swid, string guestControllerAccessToken, RSAParameters rsaParameters, Action<MixSessionStartResult> successCallback, Action failureCallback) { try { ISessionRefresher sessionRefresher = sessionRefresherFactory.Create(this); IMixWebCallFactory mixWebCallFactory = mixWebCallFactoryFactory.Create(sessionStartEncryptor, swid, guestControllerAccessToken, sessionRefresher); StartUserSessionRequest request = BuildRequest(swid, rsaParameters); IWebCall<StartUserSessionRequest, StartUserSessionResponse> webCall = mixWebCallFactory.SessionUserPut(request); webCall.OnResponse += delegate(object sender, WebCallEventArgs<StartUserSessionResponse> e) { StartUserSessionResponse response = e.Response; if (!ValidateResponse(response)) { logger.Critical("Error parsing the session start response: " + JsonParser.ToJson(response)); failureCallback(); } else { long sessionId = response.SessionId.Value; byte[] ciphertext = Convert.FromBase64String(response.EncryptedSymmetricKey); byte[] symmetricKey = rsaEncryptor.Decrypt(ciphertext, rsaParameters); keychain.PushNotificationKey = symmetricKey; database.UpdateSessionDocument(swid, delegate(SessionDocument doc) { doc.PreviousSymmetricEncryptionKey = doc.CurrentSymmetricEncryptionKey; doc.CurrentSymmetricEncryptionKey = symmetricKey; doc.SessionId = sessionId; doc.LatestNotificationSequenceNumber = 0L; }); IWebCallEncryptor webCallEncryptor = webCallEncryptorFactory.Create(symmetricKey, sessionId); MixSessionStartResult obj = new MixSessionStartResult(webCallEncryptor); successCallback(obj); } }; webCall.OnError += delegate { failureCallback(); }; webCall.Execute(force: true); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); failureCallback(); } }
public static void Get(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, IList <Profile> profiles, Action <LinkedUser[]> callback) { IWebCall <GetUsersByUserIdRequest, GetUsersResponse> webCall = mixWebCallFactory.UsersByUserIdPost(new GetUsersByUserIdRequest { UserIds = profiles.Select((Profile u) => u.swid).ToList() }); webCall.OnResponse += delegate(object sender, WebCallEventArgs <GetUsersResponse> e) { HandleGetUsersByIdSuccess(logger, e.Response, profiles, callback); }; webCall.OnError += delegate { callback(null); }; webCall.Execute(); }
private static void Enable(AbstractLogger logger, IDatabase database, IMixWebCallFactory mixWebCallFactory, string token, string tokenType, string provisionId, bool enableVisible, string swid, Action successCallback, Action failureCallback) { try { TogglePushNotificationRequest togglePushNotificationRequest = new TogglePushNotificationRequest(); togglePushNotificationRequest.PushToken = new PushToken { Token = token, TokenType = tokenType }; togglePushNotificationRequest.State = (enableVisible ? "ALL" : "ONLY_SILENT"); togglePushNotificationRequest.IosProvisioningId = provisionId; TogglePushNotificationRequest request = togglePushNotificationRequest; IWebCall <TogglePushNotificationRequest, BaseResponse> webCall = mixWebCallFactory.PushNotificationsSettingPost(request); webCall.OnResponse += delegate { try { database.UpdateSessionDocument(swid, delegate(SessionDocument sessionDoc) { sessionDoc.PushNotificationToken = token; sessionDoc.PushNotificationTokenType = tokenType; sessionDoc.VisiblePushNotificationsEnabled = enableVisible; sessionDoc.ProvisionId = provisionId; }); successCallback(); } catch (Exception ex2) { logger.Critical("Unhandled exception: " + ex2); failureCallback(); } }; webCall.OnError += delegate { failureCallback(); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); failureCallback(); } }
public static void DisableAllPushNotifications(AbstractLogger logger, IDatabase database, IMixWebCallFactory mixWebCallFactory, string swid, Action <IDisableAllPushNotificationsResult> callback) { try { SessionDocument sessionDocument = database.GetSessionDocument(swid); if (sessionDocument.PushNotificationToken == null) { callback(new DisableAllPushNotificationsResult(success: false)); } else { BaseUserRequest request = new BaseUserRequest(); IWebCall <BaseUserRequest, BaseResponse> webCall = mixWebCallFactory.PushNotificationsSettingDeletePost(request); webCall.OnResponse += delegate { try { database.UpdateSessionDocument(swid, delegate(SessionDocument d) { d.PushNotificationToken = null; d.PushNotificationTokenType = null; d.VisiblePushNotificationsEnabled = false; }); callback(new DisableAllPushNotificationsResult(success: true)); } catch (Exception arg2) { logger.Critical("Unhandled exception: " + arg2); callback(new DisableAllPushNotificationsResult(success: false)); } }; webCall.OnError += delegate { callback(new DisableAllPushNotificationsResult(success: false)); }; webCall.Execute(); } } catch (Exception arg) { logger.Critical("Unhandled exception: " + arg); callback(new DisableAllPushNotificationsResult(success: false)); } }
private void GetRegistrationText(SiteConfigurationData siteConfig, ConfigurationAgeBand configurationAgeBand, string configurationAgeBandKey, string languageCode, bool registration, Action <IGetAgeBandResult> callback) { List <string> documentIds = GetAllTextIds(siteConfig, configurationAgeBandKey, registration); if (documentIds.Count == 0) { HandleRequestSuccess(siteConfig, configurationAgeBand, configurationAgeBandKey, registration, new List <RegistrationText>(), callback); } else { try { GetRegistrationTextRequest getRegistrationTextRequest = new GetRegistrationTextRequest(); getRegistrationTextRequest.LanguageCode = languageCode; getRegistrationTextRequest.TextCodes = documentIds; getRegistrationTextRequest.CountryCode = configurationAgeBand.country; getRegistrationTextRequest.AgeBand = configurationAgeBandKey; GetRegistrationTextRequest request = getRegistrationTextRequest; IWebCall <GetRegistrationTextRequest, GetRegistrationTextResponse> webCall = webCallFactory.RegistrationTextPost(request); webCall.OnResponse += delegate(object sender, WebCallEventArgs <GetRegistrationTextResponse> e) { GetRegistrationTextResponse response = e.Response; if (ValidateResponse(response, documentIds)) { HandleRequestSuccess(siteConfig, configurationAgeBand, configurationAgeBandKey, registration, response.RegistrationText, callback); } else { callback(new GetAgeBandResult(success: false, null)); } }; webCall.OnError += delegate { callback(new GetAgeBandResult(success: false, null)); }; webCall.Execute(); } catch (Exception arg) { logger.Critical("Unhandled exception: " + arg); callback(new GetAgeBandResult(success: false, null)); } } }
public static void Search(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string displayName, IUserDatabase userDatabase, Action <IInternalUnidentifiedUser> successCallback, Action failureCallback) { try { DisplayNameSearchRequest displayNameSearchRequest = new DisplayNameSearchRequest(); displayNameSearchRequest.DisplayName = displayName; DisplayNameSearchRequest request = displayNameSearchRequest; IWebCall <DisplayNameSearchRequest, DisplayNameSearchResponse> webCall = mixWebCallFactory.SearchDisplaynamePost(request); webCall.OnResponse += delegate(object sender, WebCallEventArgs <DisplayNameSearchResponse> e) { DisplayNameSearchResponse response = e.Response; if (ValidateResponse(response)) { userDatabase.InsertUserDocument(new UserDocument { DisplayName = response.DisplayName, FirstName = response.FirstName, Swid = null, HashedSwid = null }); IInternalUnidentifiedUser obj = RemoteUserFactory.CreateUnidentifiedUser(response.DisplayName, response.FirstName, userDatabase); successCallback(obj); } else { logger.Critical("Failed to validate display name search response: " + JsonParser.ToJson(response)); failureCallback(); } }; webCall.OnError += delegate(object sender, WebCallErrorEventArgs e) { logger.Debug("Failed to find user: "******"Unhandled exception: " + arg); failureCallback(); } }
public static void Recommend(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, IUserDatabase userDatabase, Action <IEnumerable <IInternalUnidentifiedUser> > successCallback, Action failureCallback) { try { BaseUserRequest request = new BaseUserRequest(); IWebCall <BaseUserRequest, GetFriendshipRecommendationResponse> webCall = mixWebCallFactory.FriendshipRecommendPost(request); webCall.OnResponse += delegate(object sender, WebCallEventArgs <GetFriendshipRecommendationResponse> e) { List <FriendRecommendation> friendRecommendations = e.Response.FriendRecommendations; if (friendRecommendations == null) { failureCallback(); } else { foreach (FriendRecommendation item in friendRecommendations) { userDatabase.InsertUserDocument(new UserDocument { DisplayName = item.DisplayName, FirstName = item.FirstName, Swid = null, HashedSwid = null }); } IInternalUnidentifiedUser[] obj = (from item in friendRecommendations select RemoteUserFactory.CreateUnidentifiedUser(item.DisplayName, item.FirstName, userDatabase)).ToArray(); successCallback(obj); } }; webCall.OnError += delegate { failureCallback(); }; webCall.Execute(); } catch (Exception arg) { logger.Critical("Unhandled exception: " + arg); failureCallback(); } }
public static void ValidateDisplayName(AbstractLogger logger, IGuestControllerClient guestControllerClient, IMixWebCallFactory mixWebCallFactory, string displayName, Action <IValidateDisplayNameResult> callback) { try { ModerateTextRequest moderateTextRequest = new ModerateTextRequest(); moderateTextRequest.ModerationPolicy = "DisplayName"; moderateTextRequest.Text = displayName; 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)) { if (response.Moderated.Value) { callback(new ValidateDisplayNameFailedModerationResult(success: false)); } else { CheckForValidation(guestControllerClient, displayName, callback); } } else { logger.Critical("Failed to validate moderate display name response!"); callback(new ValidateDisplayNameResult(success: false)); } }; webCall.OnError += delegate { callback(new ValidateDisplayNameResult(success: false)); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); callback(new ValidateDisplayNameExistsResult(success: false)); } }
public static void Expire(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, Action <bool> callback) { try { BaseUserRequest request = new BaseUserRequest(); IWebCall <BaseUserRequest, BaseResponse> webCall = mixWebCallFactory.IntegrationTestSupportUserSessionExpirePost(request); webCall.OnResponse += delegate { callback(obj: true); }; webCall.OnError += delegate { callback(obj: false); }; webCall.Execute(); } catch (Exception arg) { logger.Critical("Unhandled exception: " + arg); callback(obj: false); } }
private void Poll() { isPolling = true; pollCountdownStopwatch.Reset(); pollCountdownStopwatch.Start(); long value = queue.LatestSequenceNumber + 1; List <long> source = queue.SequenceNumbers.ToList(); List <long?> excludeNotificationSequenceNumbers = source.Cast <long?>().ToList(); GetNotificationsSinceSequenceRequest getNotificationsSinceSequenceRequest = new GetNotificationsSinceSequenceRequest(); getNotificationsSinceSequenceRequest.SequenceNumber = value; getNotificationsSinceSequenceRequest.ExcludeNotificationSequenceNumbers = excludeNotificationSequenceNumbers; GetNotificationsSinceSequenceRequest request = getNotificationsSinceSequenceRequest; IWebCall <GetNotificationsSinceSequenceRequest, GetNotificationsResponse> webCall = webCallFactory.NotificationsSinceSequencePost(request); webCall.OnResponse += delegate(object sender, WebCallEventArgs <GetNotificationsResponse> e) { HandleGetNotificationsResponse(e.Response); }; webCall.OnError += HandleGetNotificationsError; webCall.Execute(); }
public static void TemporarilyBan(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, Action <bool> callback) { try { BaseUserRequest request = new BaseUserRequest(); IWebCall <BaseUserRequest, BaseResponse> webCall = mixWebCallFactory.IntegrationTestSupportModerationTempBanPut(request); webCall.OnResponse += delegate { callback(obj: true); }; webCall.OnError += delegate { callback(obj: false); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); callback(obj: false); } }
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(); } }
public static void ValidateDisplayNames(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, IEnumerable <string> displayNames, Action <IValidateDisplayNamesResult> callback) { try { List <string> list = new List <string>(); list.AddRange(displayNames); ValidateDisplayNamesRequest validateRequest = new ValidateDisplayNamesRequest { DisplayNames = list }; IWebCall <ValidateDisplayNamesRequest, ValidateDisplayNamesResponse> webCall = mixWebCallFactory.DisplaynameValidatePost(validateRequest); webCall.OnResponse += delegate(object sender, WebCallEventArgs <ValidateDisplayNamesResponse> e) { ValidateDisplayNamesResponse response = e.Response; if (response.DisplayNames != null) { callback(new ValidateDisplayNamesResult(success: true, response.DisplayNames)); } else { string text = string.Join(",", validateRequest.DisplayNames.ToArray()); logger.Critical("Failed to validate display names " + text); callback(new ValidateDisplayNamesResult(success: false, Enumerable.Empty <string>())); } }; webCall.OnError += delegate { callback(new ValidateDisplayNamesResult(success: false, Enumerable.Empty <string>())); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); callback(new ValidateDisplayNamesResult(success: false, Enumerable.Empty <string>())); } }
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(); } }
public static void ValidateDisplayNameV2(AbstractLogger logger, IMixWebCallFactory mixWebCallFactory, string displayName, Action <IValidateDisplayNameResult> callback) { try { ValidateDisplayNameRequest validateDisplayNameRequest = new ValidateDisplayNameRequest(); validateDisplayNameRequest.DisplayName = displayName; ValidateDisplayNameRequest request = validateDisplayNameRequest; IWebCall <ValidateDisplayNameRequest, ValidateDisplayNameResponse> webCall = mixWebCallFactory.DisplaynameValidateV2Post(request); webCall.OnResponse += delegate(object sender, WebCallEventArgs <ValidateDisplayNameResponse> e) { ValidateDisplayNameResponse response = e.Response; if (response.DisplayNameStatus == "VALID") { callback(new ValidateDisplayNameResult(success: true)); } else if (response.DisplayNameStatus == "IN_USE") { callback(new ValidateDisplayNameExistsResult(success: false, response.DisplayNames)); } else { callback(new ValidateDisplayNameFailedModerationResult(success: false)); } }; webCall.OnError += delegate { callback(new ValidateDisplayNameFailedModerationResult(success: false)); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); callback(new ValidateDisplayNameFailedModerationResult(success: false)); } }
public static void End(AbstractLogger logger, IDatabase database, IKeychain keychain, IMixWebCallFactory mixWebCallFactory, string swid, Action successCallback, Action failureCallback) { try { keychain.PushNotificationKey = null; BaseUserRequest request = new BaseUserRequest(); IWebCall <BaseUserRequest, BaseResponse> webCall = mixWebCallFactory.SessionUserDeletePost(request); webCall.OnResponse += delegate { database.LogOutSession(swid); successCallback(); }; webCall.OnError += delegate { failureCallback(); }; webCall.Execute(); } catch (Exception ex) { logger.Critical("Unhandled exception: " + ex); failureCallback(); } }
private void HandleOnUnauthorized <TRequest, TResponse>(IWebCall <TRequest, TResponse> webCall, WebCallUnauthorizedEventArgs e) where TRequest : BaseUserRequest where TResponse : BaseResponse, new() { if (webCallEncryptor.SessionId == null) { webCall.DispatchError("Unauthorized access to start a new session!"); } else if (!isSessionRefreshing) { if (webCall.RefreshStatus == WebCallRefreshStatus.RefreshedWhileWaitingForCallback) { webCall.RefreshStatus = WebCallRefreshStatus.NotRefreshing; webCall.Execute(); return; } webCall.RefreshStatus = WebCallRefreshStatus.WaitingForRefreshCallback; isSessionRefreshing = true; switch (e.Status) { case "UNAUTHORIZED_ONEID_TOKEN": sessionRefresher.RefreshGuestControllerToken(swid, delegate { isSessionRefreshing = false; }, delegate { isSessionRefreshing = false; }); break; case "UNAUTHORIZED_MIX_SESSION": sessionRefresher.RefreshSession(guestControllerAccessToken, swid, delegate(IWebCallEncryptor encryptor) { isSessionRefreshing = false; webCallEncryptor = encryptor; }, delegate { isSessionRefreshing = false; this.OnAuthenticationLost(this, new AuthenticationUnavailableEventArgs()); }); break; case "UNAUTHORIZED_BANNED": webCall.DispatchError("Account is banned!"); isSessionRefreshing = false; this.OnAuthenticationLost(this, new AccountBannedEventArgs(logger, e.ResponseText)); break; default: sessionRefresher.RefreshAll(swid, delegate(IWebCallEncryptor encryptor) { isSessionRefreshing = false; webCallEncryptor = encryptor; }, delegate { isSessionRefreshing = false; this.OnAuthenticationLost(this, new AuthenticationUnavailableEventArgs()); }); break; } } else { webCall.RefreshStatus = WebCallRefreshStatus.WaitingForRefreshCallback; } }