/// <summary> /// Delete the existing Media server records from MediaServerCollection. /// </summary> /// <param name="documentDBName"></param> /// <returns></returns> public async Task DeleteMediaServer(string documentDBName) { LogUtility.LogInfoFunction("Entered DeleteMediaServer."); List <string> list = GetEndpointUrlAndAuthorizationKey(documentDBName); EndpointUrl = list[0]; AuthorizationKey = list[1]; using (client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey)) { try { Database db = client.CreateDatabaseQuery(). Where(o => o.Id == databaseId).AsEnumerable().FirstOrDefault(); var coll = client.CreateDocumentCollectionQuery(db.CollectionsLink).Where(c => c.Id == mediaServerCollectionId).ToList().First(); var collectionLink = UriFactory.CreateDocumentCollectionUri(databaseId, mediaServerCollectionId); var docs = client.CreateDocumentQuery( collectionLink, new SqlQuerySpec() { QueryText = "SELECT * FROM MediaServerCollection c WHERE c.Name = @MediaServerName", Parameters = new SqlParameterCollection() { new SqlParameter("@MediaServerName", MediaServerController.GetMediaSever()) } }); LogUtility.LogInfoFunction("Deleting Existing Media Server."); foreach (Document doc in docs) { await client.DeleteDocumentAsync(doc.SelfLink); } LogUtility.LogInfoFunctionFinished(); } catch (Exception e) { Console.WriteLine(e); LogUtility.LogExceptionFunction(e); } } LogUtility.LogInfoFunctionFinished(); }