public async Task<IActionResult> Get() { Uri serviceName = OrderEntryWeb.GetVotingDataServiceName(this.serviceContext); Uri proxyAddress = this.GetProxyAddress(serviceName); ServicePartitionList partitions = await this.fabricClient.QueryManager.GetPartitionListAsync(serviceName); List<KeyValuePair<string, int>> result = new List<KeyValuePair<string, int>>(); foreach (Partition partition in partitions) { string proxyUrl = $"{proxyAddress}/api/VoteData?PartitionKey={((Int64RangePartitionInformation) partition.PartitionInformation).LowKey}&PartitionKind=Int64Range"; using (HttpResponseMessage response = await this.httpClient.GetAsync(proxyUrl)) { if (response.StatusCode != System.Net.HttpStatusCode.OK) { continue; } result.AddRange(JsonConvert.DeserializeObject<List<KeyValuePair<string, int>>>(await response.Content.ReadAsStringAsync())); } } return this.Json(result); }
public async Task<IActionResult> Delete(string name) { Uri serviceName = OrderEntryWeb.GetVotingDataServiceName(this.serviceContext); Uri proxyAddress = this.GetProxyAddress(serviceName); long partitionKey = this.GetPartitionKey(name); string proxyUrl = $"{proxyAddress}/api/VoteData/{name}?PartitionKey={partitionKey}&PartitionKind=Int64Range"; using (HttpResponseMessage response = await this.httpClient.DeleteAsync(proxyUrl)) { if (response.StatusCode != System.Net.HttpStatusCode.OK) { return this.StatusCode((int) response.StatusCode); } } return new OkResult(); }
public async Task<IActionResult> Put(string name) { Uri serviceName = OrderEntryWeb.GetVotingDataServiceName(this.serviceContext); Uri proxyAddress = this.GetProxyAddress(serviceName); long partitionKey = this.GetPartitionKey(name); string proxyUrl = $"{proxyAddress}/api/VoteData/{name}?PartitionKey={partitionKey}&PartitionKind=Int64Range"; StringContent putContent = new StringContent($"{{ 'name' : '{name}' }}", Encoding.UTF8, "application/json"); putContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); using (HttpResponseMessage response = await this.httpClient.PutAsync(proxyUrl, putContent)) { return new ContentResult() { StatusCode = (int) response.StatusCode, Content = await response.Content.ReadAsStringAsync() }; } }