private static async Task DeleteStoredProcedure(IDocumentClient client, string sprocId) { Uri sprocUri = UriFactory.CreateStoredProcedureUri("mydb", "mystore", sprocId); await client.DeleteStoredProcedureAsync(sprocUri); Console.WriteLine($"Deleted stored procedure: {sprocId}"); }
private static async Task DeleteStoredProcedures(IDocumentClient client, Uri collectionUri) { Console.WriteLine("Deleting stored procedures"); IEnumerable <StoredProcedure> storedProcedures = client.CreateStoredProcedureQuery(collectionUri).AsEnumerable(); foreach (StoredProcedure storedProcedure in storedProcedures) { await client.DeleteStoredProcedureAsync(storedProcedure.SelfLink); } }
private async Task CreateBulkImportStoredProcedure(IDocumentClient client, bool dropExistingProc = false) { var currentAssembly = typeof(AzureDocumentDBSink).GetTypeInfo().Assembly; SelfLog.WriteLine("Getting required resource."); var resourceName = currentAssembly.GetManifestResourceNames().Where(w => w.EndsWith("bulkImport.js")).FirstOrDefault(); if (string.IsNullOrEmpty(resourceName)) { SelfLog.WriteLine("Unable to find required resource."); return; } SelfLog.WriteLine($"Found resource: {resourceName}"); using (var resourceStream = currentAssembly.GetManifestResourceStream(resourceName)) { if (resourceStream != null) { var reader = new StreamReader(resourceStream); var bulkImportSrc = reader.ReadToEnd(); try { var sp = new StoredProcedure { Id = BulkStoredProcedureId, Body = bulkImportSrc }; var sproc = GetStoredProcedure(_collectionLink, sp.Id); if ((sproc != null) && dropExistingProc) { await client.DeleteStoredProcedureAsync(sproc.SelfLink); sproc = null; } if (sproc == null) { sproc = await client.CreateStoredProcedureAsync(_collectionLink, sp); } _bulkStoredProcedureLink = sproc.SelfLink; } catch (Exception ex) { SelfLog.WriteLine(ex.Message); } } } }
/// <summary> /// Deletes the stored procedure. /// </summary> /// <param name="dbId">The id of the Database to search for, or create.</param> /// <param name="collectionId">The id of the document db collection.</param> /// <param name="storedProcedureId">The stored procedure to get or create.</param> /// <returns>True if operation is successful, false otherwise</returns> public Task DeleteStoredProcedureAsync(string dbId, string collectionId, string storedProcedureId) { Code.ExpectsNotNullOrWhiteSpaceArgument(dbId, nameof(dbId), TaggingUtilities.ReserveTag(0x2381b152 /* tag_961fs */)); Code.ExpectsNotNullOrWhiteSpaceArgument(collectionId, nameof(collectionId), TaggingUtilities.ReserveTag(0x2381b153 /* tag_961ft */)); Code.ExpectsNotNullOrWhiteSpaceArgument(storedProcedureId, nameof(storedProcedureId), TaggingUtilities.ReserveTag(0x2381b154 /* tag_961fu */)); return(DocumentDbAdapter.ExecuteAndLogAsync(TaggingUtilities.ReserveTag(0x2381b155 /* tag_961fv */), async() => { try { IDocumentClient client = await GetDocumentClientAsync().ConfigureAwait(false); await client.DeleteStoredProcedureAsync( UriFactory.CreateStoredProcedureUri(dbId, collectionId, storedProcedureId)) .ConfigureAwait(false); } catch (DocumentClientException clientEx) when(clientEx.StatusCode == HttpStatusCode.NotFound) { } })); }