コード例 #1
0
        /**
         * Creates the datababase table based on the json schema passed in
         */
        public IAsyncOperation <StorageResult> provision(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 parameter is the collection name
                    string collectionName = paramStrings[0];

                    // the second parameter is a JSON object of serach fields, needs further parsing into a Dictionary
                    IDictionary <string, string> searchFields = JsonConvert.DeserializeObject <Dictionary <string, string> >(paramStrings[1]);

                    // the third paramter is a JSON object of options, needs further parsing into JSONStoreProvisionOptions object
                    JSONStoreProvisionOptions storeOptions = JsonConvert.DeserializeObject <JSONStoreProvisionOptions>(paramStrings[2]);

                    // create a new JSONStoreCollection object
                    JSONStoreCollection[] collections = { new JSONStoreCollection(collectionName, searchFields, storeOptions.additionalSearchFields, storeOptions.dropCollection) };

                    // create/open the collection
                    JSONStore.openCollections(collections, storeOptions);

                    // determine the return code
                    int rc = collections[0].wasReopened ? JSONStoreConstants.JSON_STORE_PROVISION_TABLE_EXISTS : JSONStoreConstants.JSON_STORE_RC_OK;

                    // pass the return code back to the JavaScript layer
                    return new StorageResult(Status.OK, rc);
                }
                catch (JSONStoreException jsonException)
                {
                    // catch a JSONStore specific exception and return the error code
                    return new StorageResult(Status.ERROR, jsonException.errorCode);
                }
                catch (Exception)
                {
                    // something unknown went wrong
                    //JSONStoreLoggerException(exception);
                    return new StorageResult(Status.ERROR, JSONStoreConstants.JSON_STORE_PERSISTENT_STORE_FAILURE);
                }
            }, token)));
        }