예제 #1
0
        public async Task <ExecuteResult> ExecuteBulkAsync(List <string> querys, string overwriteUrl = null)
        {
            if (_httpClient != null)
            {
                string[] jsonArray = querys.ToArray();

                var content = new StringContent(JsonConvert.SerializeObject(jsonArray), Encoding.UTF8, "application/json");
                var result  = await _httpClient.PostAsync(string.IsNullOrWhiteSpace(overwriteUrl)? "db/execute?transaction" : overwriteUrl, content);

                if (result.StatusCode == System.Net.HttpStatusCode.MovedPermanently)
                {
                    return(await ExecuteBulkAsync(querys, result.Headers.Location.ToString()));
                }
                else
                {
                    result.EnsureSuccessStatusCode();
                    var response = await result.Content.ReadAsStringAsync();

                    _logger.LogDebug($"Rqlite Response:{response}");
                    return(ExecuteResult.FromJson(response));
                }
            }
            else
            {
                throw new Exception("HttpClient not initialized!");
            }
        }