コード例 #1
0
        public IAsyncOperation <StorageResult> find(string parameters)
        {
            return(AsyncInfo.Run((token) =>
                                 Task.Run <StorageResult>(() =>
            {
                try {
                    // deserialize the parameters passed in as an array of strings
                    string[] paramStrings = JsonConvert.DeserializeObject <string[]>(parameters);

                    // the parameter first is the collection name
                    string collectionName = paramStrings[0];

                    // the second paramter is the queries to execute
                    JArray queries = JArray.Parse(paramStrings[1]);

                    // the third parameter is a JSON object of options, needs furthe prarsing into JSONStoreQueryOptions object
                    JSONStoreQueryOptions queryOptions = JsonConvert.DeserializeObject <JSONStoreQueryOptions>(paramStrings[2]);

                    // get the JSONStoreCollection to query
                    JSONStoreCollection collection = JSONStore.getCollectionWithName(collectionName);

                    if (collection == null)
                    {
                        return new StorageResult(Status.ERROR, JSONStoreConstants.JSON_STORE_DATABASE_NOT_OPEN);
                    }
                    else
                    {
                        // execute the queries
                        JArray results = collection.findWithQueries(queries, queryOptions);
                        return new StorageResult(Status.OK, results);
                    }
                }
                catch (JSONStoreException jsonException)
                {
                    // catch a JSONStore specific exception and return the error code
                    return new StorageResult(Status.ERROR, jsonException.errorCode);
                }
                catch (Exception) {
                    return new StorageResult(Status.ERROR, JSONStoreConstants.JSON_STORE_PERSISTENT_STORE_FAILURE);
                }
            }, token)));
        }
コード例 #2
0
        public IAsyncOperation <StorageResult> count(string parameters)
        {
            return(AsyncInfo.Run((token) =>
                                 Task.Run <StorageResult>(() =>
            {
                try
                {
                    // deserialize the parameters passed in as an array of strings
                    string[] paramStrings = JsonConvert.DeserializeObject <string[]>(parameters);

                    // the first is the collection name
                    string collectionName = paramStrings[0];

                    // the query
                    JObject query = JObject.Parse(paramStrings[1]);

                    // the third argument is a JSON object of options
                    JSONStoreQueryOptions queryOptions = JsonConvert.DeserializeObject <JSONStoreQueryOptions>(paramStrings[2]);

                    // get the JSONStoreCollection to query
                    JSONStoreCollection collection = JSONStore.getCollectionWithName(collectionName);
                    if (collection == null)
                    {
                        return new StorageResult(Status.ERROR, JSONStoreConstants.JSON_STORE_DATABASE_NOT_OPEN);
                    }
                    else
                    {
                        int countResult = collection.countDocuments(query, queryOptions.exact);
                        return new StorageResult(Status.OK, countResult);
                    }
                }
                catch (JSONStoreException jsonException)
                {
                    // catch a JSONStore specific exception and return the error code
                    return new StorageResult(Status.ERROR, jsonException.errorCode);
                }
                catch (Exception)
                {
                    return new StorageResult(Status.ERROR, JSONStoreConstants.JSON_STORE_PERSISTENT_STORE_FAILURE);
                }
            }, token)));
        }
コード例 #3
0
        public IAsyncOperation <StorageResult> advancedFind(string parameters)
        {
            return(AsyncInfo.Run((token) =>
                                 Task.Run <StorageResult>(() =>
            {
                try
                {
                    // deserialize the parameters passed in as an array of strings
                    string[] paramStrings = JsonConvert.DeserializeObject <string[]>(parameters);

                    // the parameter first is the collection name
                    string collectionName = paramStrings[0];

                    // the second paramter is the queries to execute
                    JArray inputQuery = JArray.Parse(paramStrings[1]);

                    // the third parameter is a JSON object of options, needs furthe prarsing into JSONStoreQueryOptions object
                    JSONStoreQueryOptions queryOptions = JsonConvert.DeserializeObject <JSONStoreQueryOptions>(paramStrings[2]);

                    // get the JSONStoreCollection to query
                    JSONStoreCollection collection = JSONStore.getCollectionWithName(collectionName);

                    if (collection == null)
                    {
                        return new StorageResult(Status.ERROR, JSONStoreConstants.JSON_STORE_DATABASE_NOT_OPEN);
                    }
                    else
                    {
                        // the individual query parts that we will pull out of the inputQuery
                        List <JSONStoreQuery> queryParts = new List <JSONStoreQuery>();

                        // loop through the query parts and store the values into a JSONStoreQuery object
                        foreach (JObject queryPart in inputQuery)
                        {
                            JSONStoreQuery query = new JSONStoreQuery();
                            foreach (JProperty part in queryPart.Children())
                            {
                                if (part.Value.Type == JTokenType.Array)
                                {
                                    if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_LIKE) >= 0)
                                    {
                                        query.like = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_NOT_LIKE) >= 0)
                                    {
                                        query.notLike = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_RIGHT_LIKE) >= 0)
                                    {
                                        query.rightLike = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_NOT_RIGHT_LIKE) >= 0)
                                    {
                                        query.notRightLike = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_LEFT_LIKE) >= 0)
                                    {
                                        query.leftLike = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_NOT_LEFT_LIKE) >= 0)
                                    {
                                        query.notLeftLike = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_LESSTHAN) >= 0)
                                    {
                                        query.lessThan = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_LESSTHANEQUALS) >= 0)
                                    {
                                        query.lessOrEqualThan = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_GREATERTHAN) >= 0)
                                    {
                                        query.greaterThan = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_GREATERTHANEQUALS) >= 0)
                                    {
                                        query.greaterOrEqualThan = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_EQUALS) >= 0)
                                    {
                                        query.equal = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_NOT_EQUALS) >= 0)
                                    {
                                        query.notEqual = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_INSIDE) >= 0)
                                    {
                                        query.inside = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_NOT_INSIDE) >= 0)
                                    {
                                        query.notInside = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_BETWEEN) >= 0)
                                    {
                                        query.between = (JArray)part.Value;
                                    }
                                    else if (part.Name.IndexOf(JSONStoreConstants.JSON_STORE_QUERY_NOT_BETWEEN) >= 0)
                                    {
                                        query.notBetween = (JArray)part.Value;
                                    }

                                    queryParts.Add(query);
                                }
                            }
                        }

                        // execute the queries
                        JArray results = collection.findWithAdvancedQuery(queryParts, queryOptions);
                        return new StorageResult(Status.OK, results);
                    }
                }
                catch (JSONStoreException jsonException)
                {
                    // catch a JSONStore specific exception and return the error code
                    return new StorageResult(Status.ERROR, jsonException.errorCode);
                }
                catch (Exception)
                {
                    return new StorageResult(Status.ERROR, JSONStoreConstants.JSON_STORE_PERSISTENT_STORE_FAILURE);
                }
            }, token)));
        }