예제 #1
0
        internal Task UpgradeToRevocableSessionAsync(Task toAwait, CancellationToken cancellationToken)
        {
            string sessionToken = SessionToken;

            return(toAwait.OnSuccess(_ => {
                return ParseSession.UpgradeToRevocableSessionAsync(sessionToken, cancellationToken);
            }).Unwrap().OnSuccess(t => {
                return SetSessionTokenAsync(t.Result);
            }).Unwrap());
        }
예제 #2
0
        internal Task SignUpAsync(Task toAwait, CancellationToken cancellationToken)
        {
            if (AuthData == null)
            {
                // TODO (hallucinogen): make an Extension of Task to create Task with exception/canceled.
                if (string.IsNullOrEmpty(Username))
                {
                    TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();
                    tcs.TrySetException(new InvalidOperationException("Cannot sign up user with an empty name."));
                    return(tcs.Task);
                }
                if (string.IsNullOrEmpty(Password))
                {
                    TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();
                    tcs.TrySetException(new InvalidOperationException("Cannot sign up user with an empty password."));
                    return(tcs.Task);
                }
            }
            if (!string.IsNullOrEmpty(ObjectId))
            {
                TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();
                tcs.TrySetException(new InvalidOperationException("Cannot sign up a user that already exists."));
                return(tcs.Task);
            }

            IDictionary <string, IParseFieldOperation> currentOperations = StartSave();

            return(toAwait.OnSuccess(_ =>
            {
                return UserController.SignUpAsync(State, currentOperations, cancellationToken);
            }).Unwrap().ContinueWith(t =>
            {
                if (t.IsFaulted || t.IsCanceled)
                {
                    HandleFailedSave(currentOperations);
                }
                else
                {
                    var serverState = t.Result;
                    HandleSave(serverState);
                }
                return t;
            }).Unwrap().OnSuccess(_ => SaveCurrentUserAsync(this)).Unwrap());
        }