Esempio n. 1
0
        public async Task <IQueryExecutor> Open(string connectionName, ConnectionType connectionType, CancellationToken ct = default)
        {
            if (!_settings.CosmosDbConnections.ContainsKey(connectionName))
            {
                throw new ArgumentException($"ConnectionName {connectionName} does not exist", "connectionName");
            }

            if (CurrentName == connectionName && CurrentType == connectionType && CurrentQueryExecutor != null)
            {
                //just reuse the existing connection, it's still good
                return(CurrentQueryExecutor);
            }

            //ResetConnection();

            IQueryExecutor newExec = null;

            switch (connectionType)
            {
            case ConnectionType.AzureGraphs:
                newExec = new AzureGraphsExecutor(_settings.CosmosDbConnections[connectionName], _console);
                break;

            case ConnectionType.GremlinNet:
                newExec = new GremlinExecutor(_settings.CosmosDbConnections[connectionName], _console);
                break;
            }

            if (await newExec?.TestConnection(ct))
            {
                CurrentQueryExecutor?.Dispose();
                CurrentName          = connectionName;
                CurrentType          = connectionType;
                CurrentQueryExecutor = newExec;
            }
            else
            {
                throw new ApplicationException("Failed to switch executors.");
            }

            return(CurrentQueryExecutor);
        }