private static async Task InitializeAsync() { Console.WriteLine("Creating DocumentClient ..."); ConnectionPolicy connectionPolicy = new ConnectionPolicy { ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp }; connectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 100; connectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 60; Program.client = new DocumentClient( new Uri(ConfigurationManager.AppSettings["endpoint"]), ConfigurationManager.AppSettings["accountKey"], connectionPolicy); await client.OpenAsync(); Console.WriteLine("Creating MediaDatabase ..."); try { await client.CreateDatabaseAsync(new Database { Id = mediaDatabaseName }); } catch (DocumentClientException exception) { if (exception.StatusCode == HttpStatusCode.Conflict) { Console.WriteLine("Media Database already exists"); } } DocumentCollection collection = null; try { collection = await client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri( Program.mediaDatabaseName, Program.mediaCollectionName)); Console.WriteLine("Media collection exists"); } catch (DocumentClientException exception) { if (exception.StatusCode == HttpStatusCode.NotFound) { Console.WriteLine("Media collection doesnt exists"); } } if (collection == null) { Console.WriteLine("Creating MediaCollection ..."); await client.CreateDocumentCollectionAsync(UriFactory.CreateDatabaseUri(mediaDatabaseName), new DocumentCollection { Id = mediaCollectionName, PartitionKey = new PartitionKeyDefinition { Paths = { "/mediaId" } } }, new RequestOptions { OfferThroughput = 250000 }); } else { Console.WriteLine("Collection already exisits, cleaning contents ..."); await client.ClearAllMediaAsync(mediaDatabaseName, mediaCollectionName); } }