Beispiel #1
0
        protected IEnumerable <RestItem> FindRelationAndFollow(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 = ConnectClient.Request <List <RestItem> >(theUri, Method.GET);
                        break;
                    }
                    catch (JsonSerializationException ex)
                    {
                        if (tryIterationCounter == 3)
                        {
                            Logger.LogWarning($"JsonSerializationException Method=FindRelationAndFollow {ex}");
                            return(null);
                        }
                        Thread.Sleep(1000);
                    }
                    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);
        }
Beispiel #2
0
        protected string FindRelationAndFollowAsString(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 = ConnectClient.Request(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);
        }
        public void 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 = ConnectClient.Request(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);
            }
        }