public CosmosDBService(CosmosDBConfig config, bool allowBulkInsert = false) { if (config==null) { throw new ArgumentException("Argument can not be null", "config"); } if (string.IsNullOrWhiteSpace(config.EndpointUri)) { throw new ArgumentException("Argument can not be null", "config.EndpointUri"); } if (string.IsNullOrWhiteSpace(config.PrimaryKey)) { throw new ArgumentException("Argument can not be null", "config.PrimaryKey"); } if (string.IsNullOrWhiteSpace(config.DatabaseName)) { throw new ArgumentException("Argument can not be null", "config.DatabaseName"); } configuration = config; client = new CosmosClient(config.EndpointUri, config.PrimaryKey, new CosmosClientOptions { AllowBulkExecution = allowBulkInsert, MaxRetryWaitTimeOnRateLimitedRequests = TimeSpan.FromSeconds(5), MaxRetryAttemptsOnRateLimitedRequests = 5 }); }
public CollectionController(IOptions <CosmosDBConfig> configSettings) { dbConfig = configSettings.Value; cosmosClient = new CosmosClient( dbConfig.CoreSQLEndpointUrl, dbConfig.PrimaryKey); }
private async Task Run() { SetupActions(); _connections = AppSettings.Instance.GetSection <CosmosDBConfig[]>("CosmosDBConfig")?.ToDictionary(d => d.Name); if (_connections == null || !_connections.Any()) { _logger.Warning("No Connections defined. Please define a connection in appsettings.json."); return; } _selectedConnection = _connections.First().Value; while (true) { ConsoleEx.WriteLine("Submit Gremlin:", ConsoleColor.DarkYellow); var queryString = Console.ReadLine(); if (queryString == "q") { break; } var queryCommand = queryString.Split(' ').FirstOrDefault(); if (_actions.ContainsKey(queryCommand)) { await _actions[queryCommand](queryString); } else { Query(queryString); } } }
static void Main(string[] args) { //Add build Configuration var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", false) .Build(); //Load the gremlin config CosmosDBConfig config = new CosmosDBConfig(); configuration.GetSection("CosmosDBConfig").Bind(config); new GremlinClientFactory(config); StorageAccountConfig saConfig = new StorageAccountConfig(); configuration.GetSection("StorageAccountConfig").Bind(saConfig); //RunGremlinTestingRepository(); //TestUserRepository(); //RunStorageAccountUploadTest(saConfig); //RunTestOfContainerCreation(saConfig); //DownloadFileFromContainer(saConfig); TestPropertiesSerialization(); }
private async Task Initialize(CosmosClient cosmosClient, CosmosDBConfig configuration) { DatabaseResponse databaseResponse = await cosmosClient .CreateDatabaseIfNotExistsAsync(configuration.DatabaseName) .ConfigureAwait(false); _container = await databaseResponse.Database.CreateContainerIfNotExistsAsync(configuration.Containers[typeof(TEntity).Name], "/id") .ConfigureAwait(false); }
private async Task SelectConnection(string text) { var name = text.Split(' ').Skip(1).FirstOrDefault(); if (int.TryParse(name, out var index)) { name = _connections.Keys.ElementAt(index); } if (name == null || !_connections.ContainsKey(name)) { Console.WriteLine("Can't find connection with the given name."); } else { _selectedConnection = _connections[name]; Console.WriteLine($"Selected {_selectedConnection.Name}"); } }
public GremlinController(IOptions <CosmosDBConfig> configSettings) { dbConfig = configSettings.Value; }