public IAsyncOperation <StorageResult> replace(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 is an array of documents to replace JArray documents = JArray.Parse(paramStrings[1]); // the third argument is a JSON object of options JSONStoreReplaceOptions options = JsonConvert.DeserializeObject <JSONStoreReplaceOptions>(paramStrings[2]); // get the collection JSONStoreCollection collection = JSONStore.getCollectionWithName(collectionName); if (collection == null) { return new StorageResult(Status.ERROR, JSONStoreConstants.JSON_STORE_DATABASE_NOT_OPEN); } else { int numReplaced = collection.replaceDocuments(documents, !options.isRefresh); return new StorageResult(Status.OK, numReplaced); } } catch (JSONStoreException jsonException) { if (jsonException.data != null) { // catch a JSONStore specific exception and return the failed update data return new StorageResult(Status.ERROR, jsonException.data); } else { // catch a JSONStore specific exception and return the error code return new StorageResult(Status.ERROR, jsonException.errorCode); } } catch (Exception) { // unexpected error return new StorageResult(Status.ERROR, JSONStoreConstants.JSON_STORE_PERSISTENT_STORE_FAILURE); } }, token))); }
public IAsyncOperation <StorageResult> change(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 data to be changed in the collection JArray dataArray = JArray.Parse(paramStrings[1]); // the third argument is a JSON object of options JSONStoreReplaceOptions options = JsonConvert.DeserializeObject <JSONStoreReplaceOptions>(paramStrings[2]); // get the JSONStoreCollection to add the new data to JSONStoreCollection collection = JSONStore.getCollectionWithName(collectionName); if (collection == null) { return new StorageResult(Status.ERROR, JSONStoreConstants.JSON_STORE_DATABASE_NOT_OPEN); } else { int updatedOrAdded = collection.changeData(dataArray, options); return new StorageResult(Status.OK, updatedOrAdded); } } 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))); }