/// <summary> /// Creates a scanner on the server side. /// The resulting ScannerInformation can be used to read query the CellSets returned by this scanner in the #ScannerGetNext/Async method. /// </summary> /// <param name="tableName">the table to scan</param> /// <param name="scannerSettings">the settings to e.g. set the batch size of this scan</param> /// <param name="options">the request options, scan requests must set endpoint(Gateway mode) or host(VNET mode) to receive the scan request</param> /// <returns>A ScannerInformation which contains the continuation url/token and the table name</returns> public async Task <ScannerInformation> CreateScannerAsync(string tableName, Scanner scannerSettings, RequestOptions options) { tableName.ArgumentNotNullNorEmpty("tableName"); scannerSettings.ArgumentNotNull("scannerSettings"); options.ArgumentNotNull("options"); return(await options.RetryPolicy.ExecuteAsync(() => CreateScannerAsyncInternal(tableName, scannerSettings, options))); }
private async Task <ScannerInformation> CreateScannerAsyncInternal(string tableName, Scanner scannerSettings, string alternativeEndpointBase = null) { tableName.ArgumentNotNullNorEmpty("tableName"); scannerSettings.ArgumentNotNull("scannerSettings"); while (true) { IRetryPolicy retryPolicy = _retryPolicyFactory.Create(); try { using (HttpWebResponse response = await PostRequestAsync(tableName + "/scanner", scannerSettings, alternativeEndpointBase ?? Constants.RestEndpointBaseZero)) { if (response.StatusCode != HttpStatusCode.Created) { using (var output = new StreamReader(response.GetResponseStream())) { string message = output.ReadToEnd(); throw new WebException( string.Format( "Couldn't create a scanner for table {0}! Response code was: {1}, expected 201! Response body was: {2}", tableName, response.StatusCode, message)); } } string location = response.Headers.Get("Location"); if (location == null) { throw new ArgumentException("Couldn't find header 'Location' in the response!"); } return(new ScannerInformation(new Uri(location), tableName)); } } catch (Exception e) { if (!retryPolicy.ShouldRetryAttempt(e)) { throw; } } } }
/// <summary> /// Creates a scanner on the server side. /// The resulting ScannerInformation can be used to read query the CellSets returned by this scanner in the #ScannerGetNext/Async method. /// </summary> /// <param name="tableName">the table to scan</param> /// <param name="scannerSettings">the settings to e.g. set the batch size of this scan</param> /// <returns>A ScannerInformation which contains the continuation url/token and the table name</returns> public async Task <ScannerInformation> CreateScannerAsync(string tableName, Scanner scannerSettings) { tableName.ArgumentNotNullNorEmpty(nameof(tableName)); scannerSettings.ArgumentNotNull(nameof(scannerSettings)); using (var response = await PostRequestAsync(tableName + "/scanner", scannerSettings).ConfigureAwait(false)) { if (response.WebResponse.StatusCode != HttpStatusCode.Created) { throw new HttpRequestException($"Couldn't create a scanner for table {tableName}! Response code was: {response.WebResponse.StatusCode}, expected 201! Response body was: {await response.WebResponse.Content.ReadAsStringAsync().ConfigureAwait(false)}"); } var location = response.WebResponse.Headers.Location; if (location == null) { throw new ArgumentException("Couldn't find header 'Location' in the response!"); } return(new ScannerInformation(location, tableName, response.WebResponse.Headers)); } }