protected async Task Initialize(string collectionName) { try { if (client == null) { client = new DocumentClient(new Uri(DocumentDBSettings.Current().DocDBUrl), DocumentDBSettings.Current().DocDBPrimaryKey); database = await client.RetrieveOrCreateDatabaseAsync(DocumentDBSettings.Current().DatabaseName); collection = await client.RetrieveOrCreateCollectionAsync(database.SelfLink, collectionName); } } catch (DocumentClientException de) { Exception baseException = de.GetBaseException(); Console.WriteLine("Status code {0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message); throw baseException; } catch (Exception ex) { Exception baseException = ex.GetBaseException(); Console.WriteLine("Error: {0}, Message: {1}", ex.Message, baseException.Message); throw baseException; } }
public static Database RetrieveDatabase(this DocumentClient client) { var database = client.CreateDatabaseQuery().Where(db => db.Id == DocumentDBSettings.Current().DatabaseName).AsEnumerable().FirstOrDefault(); if (database == null) { throw new InvalidProgramException("No mataching DocumentDB database was found"); } return(database); }
public static DocumentClient RetrieveClient() { return(new DocumentClient(new Uri(DocumentDBSettings.Current().DocDBUrl), DocumentDBSettings.Current().DocDBPrimaryKey)); }