public JObject GetDocument(string collectionId, string procedureId, params dynamic[] procedureParameters) { Uri collectionUri = UriFactory.CreateDocumentCollectionUri(_databaseId, collectionId); Uri procedureUri = UriFactory.CreateStoredProcedureUri(_databaseId, collectionId, procedureId); Task <StoredProcedureResponse <JValue> > procedureTask = _database.ExecuteStoredProcedureAsync <JValue>(procedureUri, procedureParameters); procedureTask.Wait(); StoredProcedureResponse <JValue> procedureResponse = procedureTask.Result; JValue procedureValue = procedureResponse.Response; return(ParseDocument(procedureValue.ToString())); }
private static async Task InvokeBulkImportSproc() { int numDocs = 1000; ExampleDoc[] docs = new ExampleDoc[numDocs]; for (int i = 0; i < numDocs; i++) { ExampleDoc doc = new ExampleDoc { Id = Guid.NewGuid().ToString() }; docs[i] = doc; } var client = new DocumentClient(new Uri(Endpoint), AuthKey); Uri collectionLink = UriFactory.CreateDocumentCollectionUri(DbName, CollectionName); string scriptFileName = @"bulkImport.js"; string scriptId = Path.GetFileNameWithoutExtension(scriptFileName); string scriptName = "bulkImport"; await CreateSprocIfNotExists(scriptFileName, scriptId, scriptName); Uri sprocUri = UriFactory.CreateStoredProcedureUri(DbName, CollectionName, scriptName); try { await client.ExecuteStoredProcedureAsync<int>(sprocUri, transactionId.ToString(), docs); } catch (DocumentClientException ex) { throw; } catch (AggregateException ex) { // If bulk import failed, delete all documents in the collection with TransactionId = id of the failed transaction. InvokeBulkDeleteSproc().Wait(); } }
private static async Task InvokeBulkDeleteSproc() { var client = new DocumentClient(new Uri(Endpoint), AuthKey); Uri collectionLink = UriFactory.CreateDocumentCollectionUri(DbName, CollectionName); string scriptFileName = @"bulkDelete.js"; string scriptId = Path.GetFileNameWithoutExtension(scriptFileName); string scriptName = "bulkDelete"; await CreateSprocIfNotExists(scriptFileName, scriptId, scriptName); Uri sprocUri = UriFactory.CreateStoredProcedureUri(DbName, CollectionName, scriptName); try { await client.ExecuteStoredProcedureAsync<Document>(sprocUri, transactionId.ToString()); } catch (DocumentClientException ex) { throw; } }