示例#1
0
        /// <summary>
        /// Retrieves the list of all existing databases.
        /// (Only possible from within the _system database)
        /// </summary>
        /// <remarks>
        /// You should use <see cref="GetUserDatabasesAsync"/> to fetch the list of the databases
        /// available for the current user.
        /// </remarks>
        /// <returns></returns>
        public async Task <GetDatabasesResponse> GetDatabasesAsync()
        {
            using (var response = await _client.GetAsync(_databaseApiPath))
            {
                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStreamAsync();

                    return(DeserializeJsonFromStream <GetDatabasesResponse>(stream));
                }
                throw await GetApiErrorException(response);
            }
        }
示例#2
0
        /// <summary>
        /// Gets count of documents in a collection.
        /// GET/_api/collection/{collection-name}/count
        /// </summary>
        /// <param name="collectionName"></param>
        /// <returns></returns>
        public async Task <GetCollectionCountResponse> GetCollectionCountAsync(string collectionName)
        {
            using (var response = await _transport.GetAsync(_collectionApiPath + "/" + WebUtility.UrlEncode(collectionName) + "/count"))
            {
                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStreamAsync();

                    return(DeserializeJsonFromStream <GetCollectionCountResponse>(stream));
                }
                throw await GetApiErrorException(response);
            };
        }
示例#3
0
        /// <summary>
        /// Get currently running transactions.
        /// </summary>
        /// <remarks>
        /// https://www.arangodb.com/docs/stable/http/transaction-stream-transaction.html#get-currently-running-transactions
        /// </remarks>
        /// <returns>Response from ArangoDB with all running transactions.</returns>
        public virtual async Task <StreamTransactions> GetAllRunningTransactions()
        {
            using (var response = await _client.GetAsync(_transactionApiPath).ConfigureAwait(false))
            {
                var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    return(DeserializeJsonFromStream <StreamTransactions>(stream));
                }

                var error = DeserializeJsonFromStream <ApiErrorResponse>(stream);
                throw new ApiErrorException(error);
            }
        }
        /// <summary>
        /// Fetches data about the specified user.
        /// You can fetch information about yourself or you need the Administrate
        /// server access level in order to execute this REST call.
        /// </summary>
        /// <param name="username">The name of the user.</param>
        /// <returns></returns>
        public virtual async Task <GetUserResponse> GetUserAsync(string username)
        {
            string uri = _userApiPath + '/' + username;

            using (var response = await _client.GetAsync(uri))
            {
                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStreamAsync();

                    return(DeserializeJsonFromStream <GetUserResponse>(stream));
                }
                throw await GetApiErrorException(response);
            }
        }
示例#5
0
        /// <summary>
        /// Get an existing document based on its Document ID.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="documentId"></param>
        /// <returns></returns>
        public virtual async Task <T> GetDocumentAsync <T>(string documentId)
        {
            ValidateDocumentId(documentId);
            var response = await _client.GetAsync(_docApiPath + "/" + documentId);

            if (response.IsSuccessStatusCode)
            {
                var stream = await response.Content.ReadAsStreamAsync();

                var document = DeserializeJsonFromStream <T>(stream);
                return(document);
            }
            throw await GetApiErrorException(response);
        }
示例#6
0
        /// <summary>
        /// Get an existing document based on its Document ID.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="documentId"></param>
        /// <param name="headers">The <see cref="DocumentHeaderProperties"/> values.</param>
        /// <returns></returns>
        public virtual async Task <T> GetDocumentAsync <T>(string documentId, DocumentHeaderProperties headers = null)
        {
            ValidateDocumentId(documentId);
            var headerCollection = GetHeaderCollection(headers);
            var response         = await _client.GetAsync(_docApiPath + "/" + documentId, headerCollection).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

                var document = DeserializeJsonFromStream <T>(stream);
                return(document);
            }

            throw await GetApiErrorException(response).ConfigureAwait(false);
        }
        /// <summary>
        /// Lists all graphs stored in this database.
        /// GET /_api/gharial
        /// </summary>
        /// <remarks>
        /// Note: The <see cref="GraphResult.Name"/> property is null for <see cref="GraphApiClient.GetGraphsAsync"/>
        /// in ArangoDB 4.5.2 and below, in which case you can use <see cref="GraphResult._key"/> instead.
        /// </remarks>
        /// <returns></returns>
        public virtual async Task <GetGraphsResponse> GetGraphsAsync()
        {
            using (var response = await _transport.GetAsync(_graphApiPath))
            {
                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStreamAsync();

                    return(DeserializeJsonFromStream <GetGraphsResponse>(stream));
                }
                throw await GetApiErrorException(response);
            }
        }
        /// <summary>
        /// Get all registered AQL user functions.
        /// </summary>
        /// <returns></returns>
        public virtual async Task <GetAqlFunctionsResponse> GetAqlFunctionsAsync(GetAqlFunctionsQuery query = null)
        {
            string uri = _apiPath;

            if (query != null)
            {
                uri += "?" + query.ToQueryString();
            }

            using (var response = await _transport.GetAsync(uri))
            {
                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStreamAsync();

                    return(DeserializeJsonFromStream <GetAqlFunctionsResponse>(stream));
                }
                throw await GetApiErrorException(response);
            }
        }