public Task <IObjectState> LogInAsync(string authType, IDictionary <string, object> data, CancellationToken cancellationToken) { var authData = new Dictionary <string, object>(); authData[authType] = data; var command = new ParseCommand("users", method: "POST", data: new Dictionary <string, object> { { "authData", authData } }); return(_commandRunner.RunCommandAsync(command, cancellationToken: cancellationToken).OnSuccess(t => { var serverState = ParseObjectCoder.Decode(t.Result.Item2, ParseDecoder.Instance); serverState = serverState.MutatedClone(mutableClone => { mutableClone.IsNew = t.Result.Item1 == System.Net.HttpStatusCode.Created; }); return serverState; })); }
public IEnumerable <Task <IObjectState> > SaveAllAsync(IEnumerable <IObjectState> states, IEnumerable <IDictionary <string, IParseFieldOperation> > operationsList, string sessionToken, CancellationToken cancellationToken) { var requests = states .Zip(operationsList, (item, ops) => new ParseCommand( item.ObjectId == null ? string.Format("classes/{0}", Uri.EscapeDataString(item.ClassName)) : string.Format("classes/{0}/{1}", Uri.EscapeDataString(item.ClassName), Uri.EscapeDataString(item.ObjectId)), method: item.ObjectId == null ? "POST" : "PUT", data: ParseObject.ToJsonObjectForSaving(ops))) .ToList(); var batchTasks = ExecuteBatchRequests(requests, sessionToken, cancellationToken); var stateTasks = new List <Task <IObjectState> >(); foreach (var task in batchTasks) { stateTasks.Add(task.OnSuccess(t => { return(ParseObjectCoder.Decode(t.Result, ParseDecoder.Instance)); })); } return(stateTasks); }
public Task <IObjectState> LogInAsync(string username, string password, CancellationToken cancellationToken) { var data = new Dictionary <string, object> { { "username", username }, { "password", password } }; var command = new ParseCommand(string.Format("login?{0}", ParseClient.BuildQueryString(data)), method: "GET", data: null); return(_commandRunner.RunCommandAsync(command, cancellationToken: cancellationToken) .ContinueWith(result => { var serverState = ParseObjectCoder.Decode(result.Result.Item2, ParseDecoder.Instance); serverState = serverState.MutatedClone(mutableClone => { mutableClone.IsNew = result.Result.Item1 == System.Net.HttpStatusCode.Created; }); return serverState; }, TaskContinuationOptions.OnlyOnRanToCompletion)); }
public Task <IObjectState> SaveAsync(IObjectState state, IDictionary <string, IParseFieldOperation> operations, string sessionToken, CancellationToken cancellationToken) { var objectJson = ParseObject.ToJsonObjectForSaving(operations); var command = new ParseCommand( (state.ObjectId == null ? string.Format("classes/{0}", Uri.EscapeDataString(state.ClassName)) : string.Format("classes/{0}/{1}", Uri.EscapeDataString(state.ClassName), state.ObjectId)), method: (state.ObjectId == null ? "POST" : "PUT"), sessionToken: sessionToken, data: objectJson); return(_commandRunner.RunCommandAsync(command, cancellationToken: cancellationToken).OnSuccess(t => { var serverState = ParseObjectCoder.Decode(t.Result.Item2, ParseDecoder.Instance); serverState = serverState.MutatedClone(mutableClone => { mutableClone.IsNew = t.Result.Item1 == System.Net.HttpStatusCode.Created; }); return serverState; })); }
public Task <IObjectState> GetUserAsync(string sessionToken, CancellationToken cancellationToken) { var command = new ParseCommand("users/me", method: "GET", sessionToken: sessionToken, data: null); return(_commandRunner.RunCommandAsync(command, cancellationToken: cancellationToken) .OnSuccess(t => ParseObjectCoder.Decode(t.Result.Item2, ParseDecoder.Instance))); }
public Task <IObjectState> UpgradeToRevocableSessionAsync(string sessionToken, CancellationToken cancellationToken) { var command = new ParseCommand("upgradeToRevocableSession", method: "POST", sessionToken: sessionToken, data: new Dictionary <string, object>()); return(_commandRunner.RunCommandAsync(command, cancellationToken: cancellationToken) .OnSuccess(t => ParseObjectCoder.Decode(t.Result.Item2, ParseDecoder.Instance))); }
public Task <IObjectState> FetchAsync(IObjectState state, string sessionToken, CancellationToken cancellationToken) { var command = new ParseCommand(string.Format("classes/{0}/{1}", Uri.EscapeDataString(state.ClassName), Uri.EscapeDataString(state.ObjectId)), method: "GET", sessionToken: sessionToken, data: null); return(_commandRunner.RunCommandAsync(command, cancellationToken: cancellationToken) .OnSuccess(t => ParseObjectCoder.Decode(t.Result.Item2, ParseDecoder.Instance))); }
public Task <IEnumerable <IObjectState> > FindAsync <T>(ParseQuery <T> query, ParseUser user, CancellationToken cancellationToken) where T : ParseObject { string sessionToken = user?.SessionToken; return(FindAsync(query.ClassName, query.BuildParameters(), sessionToken, cancellationToken).OnSuccess(t => { var items = t.Result["results"] as IList <object>; return (from item in items select ParseObjectCoder.Decode(item as IDictionary <string, object>, ParseDecoder.Instance) ); })); }
public Task <IObjectState> SignUpAsync(IObjectState state, IDictionary <string, IParseFieldOperation> operations, CancellationToken cancellationToken) { var objectJson = ParseObject.ToJsonObjectForSaving(operations); var command = new ParseCommand("classes/_User", method: "POST", data: objectJson); return(_commandRunner.RunCommandAsync(command, cancellationToken: cancellationToken).OnSuccess(t => { var serverState = ParseObjectCoder.Decode(t.Result.Item2, ParseDecoder.Instance); serverState = serverState.MutatedClone(mutableClone => { mutableClone.IsNew = true; }); return serverState; })); }
public Task <IObjectState> FirstAsync <T>(ParseQuery <T> query, ParseUser user, CancellationToken cancellationToken) where T : ParseObject { var sessionToken = user?.SessionToken; var parameters = query.BuildParameters(); parameters["limit"] = 1; return(FindAsync(query.ClassName, parameters, sessionToken, cancellationToken).OnSuccess(t => { var items = t.Result["results"] as IList <object>; // Not found. Return empty state. if (!(items.FirstOrDefault() is IDictionary <string, object> item)) { return (IObjectState)null; } return ParseObjectCoder.Decode(item, ParseDecoder.Instance); })); }
public Task <ParseUser> GetAsync(CancellationToken cancellationToken) { ParseUser cachedCurrent; lock (_mutex) { cachedCurrent = CurrentUser; } if (cachedCurrent != null) { return(Task.FromResult(cachedCurrent)); } return(_taskQueue.Enqueue(toAwait => { return toAwait.ContinueWith(_ => { return _storageController.LoadAsync().OnSuccess(t => { t.Result.TryGetValue("CurrentUser", out var temp); var userDataString = temp as string; ParseUser user = null; if (userDataString != null) { var userData = Json.Parse(userDataString) as IDictionary <string, object>; var state = ParseObjectCoder.Decode(userData, ParseDecoder.Instance); user = ParseObject.FromState <ParseUser>(state, "_User"); } CurrentUser = user; return user; }); }, cancellationToken).Unwrap(); }, cancellationToken)); }