/// <summary> /// Remove all contents (normally by use of a truncate operation) from the data store and persist the change. /// </summary> public void RemoveAll() { Logger.LogDebug("Removing all from the Azure database", "AzureDocumentDbDataStore\\RemoveAll"); try { ResourceResponse <DocumentCollection> result = AzureDocumentDbHelper.ExecuteFaultTollerantFunction(() => AzureDocumentDbClient.DeleteDocumentCollectionAsync(AzureDocumentDbCollection.SelfLink, new RequestOptions()).Result); } finally { Logger.LogDebug("Removing all from the Azure database... Done", "AzureDocumentDbDataStore\\RemoveAll"); } }
/// <summary> /// Add the provided <paramref name="data"/> to the data store and persist the change. /// </summary> public void Add(TData data) { Logger.LogDebug("Adding data to the Azure database", "AzureDocumentDbDataStore\\Add"); try { DateTime start = DateTime.Now; ResourceResponse <Document> result = AzureDocumentDbHelper.ExecuteFaultTollerantFunction(() => AzureDocumentDbClient.CreateDocumentAsync((AzureDocumentDbCollection).SelfLink, data).Result); DateTime end = DateTime.Now; Logger.LogDebug(string.Format("Adding data in the Azure database took {0} and cost:r\n{1}", end - start, result), "AzureDocumentDbDataStore\\Add"); } finally { Logger.LogDebug("Adding data to the Azure database... Done", "AzureDocumentDbDataStore\\Add"); } }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection. /// </returns> /// <filterpriority>1</filterpriority> public IEnumerator <TData> GetEnumerator() { Logger.LogDebug("Getting the enumerator for an Azure database query", "AzureDocumentDbDataStore\\GetEnumerator"); try { DateTime start = DateTime.Now; IEnumerator <TData> result = AzureDocumentDbHelper.ExecuteFaultTollerantFunction(() => AzureDocumentDbQuery.GetEnumerator()); DateTime end = DateTime.Now; Logger.LogDebug(string.Format("Getting the enumerator for an Azure database query took {0}", end - start), "AzureDocumentDbDataStore\\GetEnumerator"); return(result); } finally { Logger.LogDebug("Getting the enumerator for an Azure database query... Done", "AzureDocumentDbDataStore\\GetEnumerator"); } }
/// <summary> /// Update the provided <paramref name="data"/> in the data store and persist the change. /// </summary> public void Update(TData data) { Logger.LogDebug("Updating data in the Azure database", "AzureDocumentDbDataStore\\Update"); try { Logger.LogDebug("Getting existing document from the Azure database", "AzureDocumentDbDataStore\\Update"); DateTime start = DateTime.Now; Document documentToUpdate = AzureDocumentDbClient.CreateDocumentQuery(AzureDocumentDbCollection.DocumentsLink) .Where(d => d.Id == data.id) .AsEnumerable() .Single(); DateTime mid = DateTime.Now; Logger.LogDebug(string.Format("Getting existing document from the Azure database took {0}", mid - start), "AzureDocumentDbDataStore\\Update"); Logger.LogDebug("Replacing existing document in the Azure database", "AzureDocumentDbDataStore\\Update"); ResourceResponse <Document> result = AzureDocumentDbHelper.ExecuteFaultTollerantFunction(() => AzureDocumentDbClient.ReplaceDocumentAsync(documentToUpdate.SelfLink, data).Result); DateTime end = DateTime.Now; Logger.LogDebug(string.Format("Replacing existing document in the Azure database took {0} and cost:r\n{1}", end - mid, result), "AzureDocumentDbDataStore\\Update"); } finally { Logger.LogDebug("Updating data in the Azure database... Done", "AzureDocumentDbDataStore\\Update"); } }