Exemple #1
0
        public IDictionary <string, object> EncodeParseObject(AVObject value, bool isPointer)
        {
            if (isPointer)
            {
                return(EncodeParseObject(value));
            }

            var operations    = value.GetCurrentOperations();
            var operationJSON = AVObject.ToJSONObjectForSaving(operations);
            var objectJSON    = value.ToDictionary(kvp => kvp.Key, kvp => EncodeProperty(kvp.Value));

            foreach (var kvp in operationJSON)
            {
                objectJSON[kvp.Key] = kvp.Value;
            }
            if (value.CreatedAt.HasValue)
            {
                objectJSON["createdAt"] = value.CreatedAt.Value.ToString(DateFormatStrings.First(),
                                                                         CultureInfo.InvariantCulture);
            }
            if (value.UpdatedAt.HasValue)
            {
                objectJSON["updatedAt"] = value.UpdatedAt.Value.ToString(DateFormatStrings.First(),
                                                                         CultureInfo.InvariantCulture);
            }
            if (!string.IsNullOrEmpty(value.ObjectId))
            {
                objectJSON["objectId"] = value.ObjectId;
            }
            objectJSON["className"] = value.ClassName;
            objectJSON["__type"]    = "Object";
            return(objectJSON);
        }
Exemple #2
0
        internal IDictionary <string, object> EncodeAttributes()
        {
            var currentOperations = convState.StartSave();
            var jsonToSave        = AVObject.ToJSONObjectForSaving(currentOperations);

            return(jsonToSave);
        }
        public IList <Task <IObjectState> > SaveAllAsync(IList <IObjectState> states,
                                                         IList <IDictionary <string, IAVFieldOperation> > operationsList,
                                                         string sessionToken,
                                                         CancellationToken cancellationToken)
        {
            var requests = states.Zip(operationsList, (item, ops) => new Dictionary <string, object> {
                { "method", (item.ObjectId == null ? "POST" : "PUT") },
                { "path", (item.ObjectId == null ?
                           string.Format("/classes/{0}", Uri.EscapeDataString(item.ClassName)) :
                           string.Format("/classes/{0}/{1}", Uri.EscapeDataString(item.ClassName),
                                         Uri.EscapeDataString(item.ObjectId))) },
                { "body", AVObject.ToJSONObjectForSaving(ops) }
            }).Cast <object>().ToList();

            var batchTasks = ExecuteBatchRequests(requests, sessionToken, cancellationToken);
            var stateTasks = new List <Task <IObjectState> >();

            foreach (var task in batchTasks)
            {
                stateTasks.Add(task.OnSuccess(t => {
                    return(AVObjectCoder.Instance.Decode(t.Result, AVDecoder.Instance));
                }));
            }

            return(stateTasks);
        }
Exemple #4
0
        public Task <IObjectState> SignUpAsync(IObjectState state,
                                               IDictionary <string, IAVFieldOperation> operations,
                                               CancellationToken cancellationToken)
        {
            var objectJSON = AVObject.ToJSONObjectForSaving(operations);

            var command = new AVCommand("/classes/_User",
                                        method: "POST",
                                        data: objectJSON);

            return(commandRunner.RunCommandAsync(command, cancellationToken: cancellationToken).OnSuccess(t => {
                var serverState = AVObjectCoder.Instance.Decode(t.Result.Item2, AVDecoder.Instance);
                serverState = serverState.MutatedClone(mutableClone => {
                    mutableClone.IsNew = true;
                });
                return serverState;
            }));
        }
        public Task <IObjectState> SaveAsync(IObjectState state,
                                             IDictionary <string, IAVFieldOperation> operations,
                                             string sessionToken,
                                             CancellationToken cancellationToken)
        {
            var objectJSON = AVObject.ToJSONObjectForSaving(operations);

            var command = new AVCommand((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 = AVObjectCoder.Instance.Decode(t.Result.Item2, AVDecoder.Instance);
                serverState = serverState.MutatedClone(mutableClone => {
                    mutableClone.IsNew = t.Result.Item1 == System.Net.HttpStatusCode.Created;
                });
                return serverState;
            }));
        }