Пример #1
0
        // TODO: add support for fields
        // https://github.com/ParsePlatform/parse-server/issues/3671
        protected override IDictionary <string, object> ToJsonObject()
        {
            var poo = _query.BuildParameters();
            Dictionary <string, object> d = new Dictionary <string, object>
            {
                ["op"]        = "subscribe",
                ["requestId"] = _requestId,
                ["query"]     = new Dictionary <string, object>
                {
                    ["className"] = _query.GetClassName(),
                    ["where"]     = _query.BuildParameters().GetOrDefault("where", EmptyJsonObject)
                }
            };

            return(d);
        }
        public Task <int> CountAsync <T>(ParseQuery <T> query, ParseUser user, CancellationToken cancellationToken) where T : ParseObject
        {
            var parameters = query.BuildParameters();

            parameters["limit"] = 0;
            parameters["count"] = 1;

            return(FindAsync(query.ClassName, parameters, user?.SessionToken, cancellationToken).OnSuccess(t => Convert.ToInt32(t.Result["count"])));
        }
Пример #3
0
        public Task <IEnumerable <IObjectState> > FindAsync <T>(ParseQuery <T> query,
                                                                ParseUser user,
                                                                CancellationToken cancellationToken) where T : ParseObject
        {
            string sessionToken = user != null ? user.SessionToken : null;

            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.Instance.Decode(item as IDictionary <string, object>, ParseDecoder.Instance));
            }));
        }
        public void TestRelationQuery()
        {
            ParseObject parent = ParseObject.CreateWithoutData("Foo", "abcxyz");

            ParseRelation <ParseObject> relation = parent.GetRelation <ParseObject>("child");
            ParseQuery <ParseObject>    query    = relation.Query;

            // Client side, the query will appear to be for the wrong class.
            // When the server recieves it, the class name will be redirected using the 'redirectClassNameForKey' option.
            Assert.AreEqual("Foo", query.GetClassName());

            IDictionary <string, object> encoded = query.BuildParameters();

            Assert.AreEqual("child", encoded["redirectClassNameForKey"]);
        }
Пример #5
0
        public IDictionary <string, object> Encode(IPushState state)
        {
            if (state.Alert is null && state.Data is null)
            {
                throw new InvalidOperationException("A push must have either an Alert or Data");
            }
            if (state.Channels is null && state.Query is null)
            {
                throw new InvalidOperationException("A push must have either Channels or a Query");
            }

            ParseQuery <ParseInstallation> query = state.Query ?? ParseInstallation.Query;

            if (state.Channels != null)
            {
                query = query.WhereContainedIn("channels", state.Channels);
            }

            Dictionary <string, object> payload = new Dictionary <string, object>
            {
                ["data"] = state.Data ?? new Dictionary <string, object> {
                    ["alert"] = state.Alert
                },
                ["where"] = query.BuildParameters().GetOrDefault("where", new Dictionary <string, object> {
                }),
            };

            if (state.Expiration.HasValue)
            {
                payload["expiration_time"] = state.Expiration.Value.ToString("yyyy-MM-ddTHH:mm:ssZ");
            }
            else if (state.ExpirationInterval.HasValue)
            {
                payload["expiration_interval"] = state.ExpirationInterval.Value.TotalSeconds;
            }
            if (state.PushTime.HasValue)
            {
                payload["push_time"] = state.PushTime.Value.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");
            }

            return(payload);
        }
        public Task <IObjectState> FirstAsync <T>(ParseQuery <T> query, ParseUser user, CancellationToken cancellationToken) where T : ParseObject
        {
            var parameters = query.BuildParameters();

            parameters["limit"] = 1;

            return(FindAsync(query.ClassName, parameters, user?.SessionToken, cancellationToken).OnSuccess(t =>
            {
                var list = t.Result["results"] as IList <object>;
                if (list != null)
                {
                    var item = list.FirstOrDefault() as IDictionary <string, object>;
                    if (item != null)
                    {
                        return ParseObjectCoder.Instance.Decode(item, ParseDecoder.Instance);
                    }
                }

                return null;
            }));
        }
Пример #7
0
        public Task <IObjectState> FirstAsync <T>(ParseQuery <T> query,
                                                  ParseUser user,
                                                  CancellationToken cancellationToken) where T : ParseObject
        {
            string sessionToken = user != null ? user.SessionToken : null;
            var    parameters   = query.BuildParameters();

            parameters["limit"] = 1;

            return(FindAsync(query.ClassName, parameters, sessionToken, cancellationToken).OnSuccess(t => {
                var items = t.Result["results"] as IList <object>;
                var item = items.FirstOrDefault() as IDictionary <string, object>;

                // Not found. Return empty state.
                if (item == null)
                {
                    return (IObjectState)null;
                }

                return ParseObjectCoder.Instance.Decode(item, ParseDecoder.Instance);
            }));
        }
 public Task <IEnumerable <IObjectState> > FindAsync <T>(ParseQuery <T> query, ParseUser user, CancellationToken cancellationToken) where T : ParseObject => FindAsync(query.ClassName, query.BuildParameters(), user?.SessionToken, cancellationToken).OnSuccess(t => (from item in t.Result["results"] as IList <object> select ParseObjectCoder.Instance.Decode(item as IDictionary <string, object>, ParseDecoder.Instance)));
Пример #9
0
 public static IDictionary <String, object> BuildParameters <T>(this ParseQuery <T> query) where T : ParseObject
 {
     return(query.BuildParameters(false));
 }