예제 #1
0
        public void WhenTheUserGetsThePost(int id)
        {
            _settings.Request.AddUrlSegment("id", id.ToString());

            _response = _restClientHelper.GetAsync <Posts>(_settings.Request)
                        .GetAwaiter().GetResult();
        }
예제 #2
0
        public async Task <ServiceResponse <LoginData> > GetUserAsync()
        {
            var client = new RestClientHelper(Constants.LoginServerUrl);
            var result = await client.GetAsync <LoginData>("/user/" + Constants.UserId);

            return(result);
        }
예제 #3
0
        public async Task <int> GetHeightAsync(string element, int?heightOfLadderInRungs = null, TimeSpan?timeout = null, CancellationToken cancellationToken = new CancellationToken())
        {
            DateTime whenAddedUtc;
            int      topOfLadder = heightOfLadderInRungs ?? MaxLadderHeight;

            bool cacheIndicatesTopOfLadder = CacheOfElementsAtTopOfLadder.TryGetValue(element, out whenAddedUtc);

            if (cacheIndicatesTopOfLadder && DateTime.UtcNow - whenAddedUtc < MinimumCacheFreshnessRequired)
            {
                return(topOfLadder);
            }

            int        shard  = GetShardIndex(element);
            RemoteHost host   = ShardToHostMapping.FindMemberResponsible(shard.ToString());
            int        height = await RestClientHelper.GetAsync <int>(host.Uri, ElementsPath + Uri.EscapeUriString(element), cancellationToken : cancellationToken,
                                                                      uriParameters : (!heightOfLadderInRungs.HasValue)?null : new[]
            {
                new KeyValuePair <string, string>("heightOfLadderInRungs", heightOfLadderInRungs.Value.ToString())
            });

            if (height < topOfLadder && cacheIndicatesTopOfLadder)
            {
                CacheOfElementsAtTopOfLadder.Remove(element);
            }
            else if (height == topOfLadder)
            {
                CacheOfElementsAtTopOfLadder[element] = DateTime.UtcNow;
            }

            return(height);
        }