public IAsyncOperation <StorageResult> findById(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 second are the ids to search on JArray ids = JArray.Parse(paramStrings[1]); // 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 { JArray fullResults = new JArray(); foreach (JValue i in ids) { // the individual query parts that we will pull out of the inputQuery List <JSONStoreQuery> queryParts = new List <JSONStoreQuery>(); JSONStoreQuery query = new JSONStoreQuery(); JArray idArray = new JArray(); idArray.Add(i); query.ids = idArray; queryParts.Add(query); // execute the query JArray results = collection.findWithAdvancedQuery(queryParts, null); foreach (JToken jtoken in results) { fullResults.Add(jtoken); } } return new StorageResult(Status.OK, fullResults); } } 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))); }
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))); }