public async Task <TimeSeriesKey[]> GetKeys(string type, CancellationToken token = default(CancellationToken)) { parent.AssertInitialized(); await parent.ReplicationInformer.UpdateReplicationInformationIfNeededAsync().ConfigureAwait(false); return(await parent.ReplicationInformer.ExecuteWithReplicationAsync(parent.Url, HttpMethods.Get, async (url, timeSeriesName) => { var requestUriString = string.Format(CultureInfo.InvariantCulture, "{0}ts/{1}/keys/{2}", url, timeSeriesName, type); using (var request = parent.CreateHttpJsonRequest(requestUriString, HttpMethods.Get)) { var result = await request.ReadResponseJsonAsync().WithCancellation(token).ConfigureAwait(false); return result.JsonDeserialization <TimeSeriesKey[]>(); } }, token).ConfigureAwait(false)); }
/// <summary> /// Create new time series on the server. /// </summary> /// <param name="timeSeriesDocument">Settings for the time series. If null, default settings will be used, and the name specified in the client ctor will be used</param> /// <param name="shouldUpdateIfExists">Indicates if time series should be updated if they exist.</param> /// <param name="credentials">Credentials used for this operation.</param> /// <param name="token">Cancellation token used for this operation.</param> public async Task <TimeSeriesStore> CreateTimeSeriesAsync(TimeSeriesDocument timeSeriesDocument, bool shouldUpdateIfExists = false, OperationCredentials credentials = null, CancellationToken token = default(CancellationToken)) { if (timeSeriesDocument == null) { throw new ArgumentNullException("timeSeriesDocument"); } parent.AssertInitialized(); var timeSeriesName = timeSeriesDocument.Id.Replace(Constants.TimeSeries.Prefix, ""); var requestUri = parent.Url + "admin/ts/" + timeSeriesName; if (shouldUpdateIfExists) { requestUri += "?update=true"; } using (var request = parent.CreateHttpJsonRequest(requestUri, HttpMethods.Put)) { try { await request.WriteAsync(RavenJObject.FromObject(timeSeriesDocument)).WithCancellation(token).ConfigureAwait(false); } catch (ErrorResponseException e) { if (e.StatusCode == HttpStatusCode.Conflict) { throw new InvalidOperationException("Cannot create time series with the name '" + timeSeriesName + "' because it already exists. Use CreateOrUpdateTimeSeriesAsync in case you want to update an existing time series", e); } throw; } } return(new TimeSeriesStore { Name = timeSeriesName, Url = parent.Url, Credentials = credentials ?? parent.Credentials }); }