public static IEnumerable <T> ToParseObjects <T>(this string jsonInput, string className)
            where T : ParseObject
        {
            var parseEncodeList = Json.Parse(jsonInput) as IList <object>;
            var states          = parseEncodeList.Select(item =>
            {
                try
                {
                    return(ParseObjectCoder.Instance.Decode(item as IDictionary <string, object>, ParseDecoder.Instance));
                }
                catch (Exception decodeException)
                {
                    throw decodeException;
                }
            });

            var result = states.Select(state =>
            {
                try
                {
                    return(ParseObject.FromState <T>(state, className));
                }
                catch (Exception conventionException)
                {
                    throw conventionException;
                }
            });

            return(result);
        }
示例#2
0
 /// <summary>
 /// Logs in a user with a username and password. On success, this saves the session to disk so you
 /// can retrieve the currently logged in user using <see cref="CurrentUser"/>.
 /// </summary>
 /// <param name="sessionToken">The session token to authorize with</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The user if authorization was successful</returns>
 public static Task <ParseUser> BecomeAsync(string sessionToken, CancellationToken cancellationToken)
 {
     return(UserController.GetUserAsync(sessionToken, cancellationToken).OnSuccess(t => {
         ParseUser user = ParseObject.FromState <ParseUser>(t.Result, "_User");
         return SaveCurrentUserAsync(user).OnSuccess(_ => user);
     }).Unwrap());
 }
示例#3
0
 /// <summary>
 /// Logs in a user with a username and password. On success, this saves the session to disk so you
 /// can retrieve the currently logged in user using <see cref="CurrentUser"/>.
 /// </summary>
 /// <param name="username">The username to log in with.</param>
 /// <param name="password">The password to log in with.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The newly logged-in user.</returns>
 public static Task <ParseUser> LogInAsync(string username,
                                           string password,
                                           CancellationToken cancellationToken)
 {
     return(UserController.LogInAsync(username, password, cancellationToken).OnSuccess(t => {
         ParseUser user = ParseObject.FromState <ParseUser>(t.Result, "_User");
         return SaveCurrentUserAsync(user).OnSuccess(_ => user);
     }).Unwrap());
 }
示例#4
0
        /// <summary>
        /// Retrieves at most one ParseObject that satisfies this query.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A single ParseObject that satisfies this query, or else null.</returns>
        public Task <T> FirstOrDefaultAsync(CancellationToken cancellationToken)
        {
            EnsureNotInstallationQuery();
            return(QueryController.FirstAsync <T>(this, ParseUser.CurrentUser, cancellationToken).OnSuccess(t => {
                IObjectState state = t.Result;

                return state == null ? default(T) : ParseObject.FromState <T>(state, ClassName);
            }));
        }
示例#5
0
        /// <summary>
        /// Retrieves a list of ParseObjects that satisfy this query from Parse.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The list of ParseObjects that match this query.</returns>
        public Task <IEnumerable <T> > FindAsync(CancellationToken cancellationToken)
        {
            EnsureNotInstallationQuery();
            return(QueryController.FindAsync <T>(this, ParseUser.CurrentUser, cancellationToken).OnSuccess(t => {
                IEnumerable <IObjectState> states = t.Result;

                return (from state in states
                        select ParseObject.FromState <T>(state, ClassName));
            }));
        }
示例#6
0
        internal static Task <string> UpgradeToRevocableSessionAsync(string sessionToken, CancellationToken cancellationToken)
        {
            if (sessionToken == null || SessionController.IsRevocableSessionToken(sessionToken))
            {
                return(Task <string> .FromResult(sessionToken));
            }

            return(SessionController.UpgradeToRevocableSessionAsync(sessionToken, cancellationToken).OnSuccess(t => {
                ParseSession session = ParseObject.FromState <ParseSession>(t.Result, "_Session");
                return session.SessionToken;
            }));
        }
示例#7
0
        internal static Task <ParseUser> LogInWithAsync(string authType,
                                                        IDictionary <string, object> data,
                                                        CancellationToken cancellationToken)
        {
            ParseUser user = null;

            return(UserController.LogInAsync(authType, data, cancellationToken).OnSuccess(t => {
                user = ParseObject.FromState <ParseUser>(t.Result, "_User");

                lock (user.mutex) {
                    if (user.AuthData == null)
                    {
                        user.AuthData = new Dictionary <string, IDictionary <string, object> >();
                    }
                    user.AuthData[authType] = data;
                    user.SynchronizeAllAuthData();
                }

                return SaveCurrentUserAsync(user);
            }).Unwrap().OnSuccess(t => user));
        }
示例#8
0
        /// <summary>
        /// Gets the current <see cref="ParseSession"/> object related to the current user.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token</param>
        public static Task <ParseSession> GetCurrentSessionAsync(CancellationToken cancellationToken)
        {
            return(ParseUser.GetCurrentUserAsync().OnSuccess(t1 => {
                ParseUser user = t1.Result;
                if (user == null)
                {
                    return Task <ParseSession> .FromResult((ParseSession)null);
                }

                string sessionToken = user.SessionToken;
                if (sessionToken == null)
                {
                    return Task <ParseSession> .FromResult((ParseSession)null);
                }

                return SessionController.GetSessionAsync(sessionToken, cancellationToken).OnSuccess(t => {
                    ParseSession session = ParseObject.FromState <ParseSession>(t.Result, "_Session");
                    return session;
                });
            }).Unwrap());
        }