public async Task <IQueryExecutor> SwitchConnectionType(CancellationToken ct = default)
        {
            IQueryExecutor newExec = null;
            ConnectionType newType;

            try
            {
                switch (CurrentType)
                {
                case ConnectionType.AzureGraphs:
                    newExec = new GremlinExecutor(_settings.CosmosDbConnections[CurrentName], _console);
                    newType = ConnectionType.GremlinNet;
                    break;

                case ConnectionType.GremlinNet:     //fall through here intentional
                default:
                    newExec = new AzureGraphsExecutor(_settings.CosmosDbConnections[CurrentName], _console);
                    newType = ConnectionType.AzureGraphs;
                    break;
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Failed to switch executors.", ex);
            }
            if (await newExec?.TestConnection(ct))
            {
                CurrentQueryExecutor?.Dispose();
                CurrentQueryExecutor = newExec;
                CurrentType          = newType;
                return(CurrentQueryExecutor);
            }
            throw new ApplicationException("Failed to switch executors.");
        }
 public GremlinExecutor(CosmosDbConnection config, IConsole console)
 {
     _console      = console;
     _server       = GremlinExecutor.GetGremlinServer(config);
     _partitionKey = config.PartitionKey;
     _client       = new GremlinClient(_server, new GraphSON2Reader(), new GraphSON2Writer(), GremlinClient.GraphSON2MimeType);
 }
        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);
        }