protected async ValueTask <IEnumerable <RestItem> > FindRelationAndFollowAsync(string relation, string errorHeading, StringBuilder loggingStringBuilder) { var stopwatch = new Stopwatch(); IEnumerable <RestItem> result = new List <RestItem>(); if (State != null) { var theUri = FindRelationUri(relation); loggingStringBuilder.AppendFormat("Call to url={0} ", theUri); stopwatch.Start(); IRestResponse <List <RestItem> > response = new RestResponse <List <RestItem> >(); int tryIterationCounter = 1; while (tryIterationCounter <= 3) { try { response = await ConnectClient.RequestAsync <List <RestItem> >(theUri, Method.GET); break; } catch (JsonSerializationException ex) { if (tryIterationCounter == 3) { Logger.LogWarning($"JsonSerializationException Method=FindRelationAndFollow {ex}"); return(null); } await Task.Delay(500); } catch (Exception ex) { throw ex; } tryIterationCounter++; } loggingStringBuilder.AppendFormat("took duration={0}ms - ", stopwatch.ElapsedMilliseconds); if (response.ErrorException != null) { RestErrorHelper.LogRestError(Logger, response, errorHeading); throw new Exception($"Error calling {theUri} - ", response.ErrorException); } result = response.Data; } stopwatch.Stop(); return(result); }
public async Task SendEcho() { if (string.IsNullOrEmpty(_virtualHost)) { throw new Exception("virtualHost is not defined"); } var link = State.Links.First(restLink => restLink.Relation == "http://api.sportingsolutions.com/rels/stream/batchecho"); var echouri = new Uri(link.Href); var streamEcho = new StreamEcho { Host = _virtualHost, Message = Guid.NewGuid() + ";" + DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ") }; var response = await ConnectClient.RequestAsync(echouri, RestSharp.Method.POST, streamEcho, UDAPI.Configuration.ContentType, 3000); if (response.ErrorException != null || response.Content == null) { RestErrorHelper.LogRestError(Logger, response, "Error sending echo request"); throw new Exception(string.Format("Error calling {0}", echouri), response.ErrorException); } }
protected async ValueTask <string> FindRelationAndFollowAsStringAsync(string relation, string errorHeading, StringBuilder loggingStringBuilder) { var stopwatch = new Stopwatch(); var result = string.Empty; if (State != null) { var theUri = FindRelationUri(relation); loggingStringBuilder.AppendFormat("Beginning call to url={0} ", theUri); stopwatch.Start(); var response = await ConnectClient.RequestAsync(theUri, Method.GET); loggingStringBuilder.AppendFormat("took duration={0}ms", stopwatch.ElapsedMilliseconds); if (response.ErrorException != null || response.Content == null) { RestErrorHelper.LogRestError(Logger, response, errorHeading); throw new Exception(string.Format("Error calling {0}", theUri), response.ErrorException); } result = response.Content; } stopwatch.Stop(); return(result); }