コード例 #1
0
        public void SetProperties(HttpResponseHeaders headers)
        {
            var properties = this.GetType().GetTypeInfo().DeclaredProperties;

            foreach (var prop in properties.Where(prop => headers.Any(h => h.Key == prop.Name)))
            {
                var value = headers.First(h => NetNamingMapper.GetPropertyName(h.Key) == prop.Name).Value;
                if (value == null)
                {
                    continue;
                }

                if (value.Count() == 1)
                {
                    prop.SetValue(this, value.FirstOrDefault());
                }
                else
                {
                    try
                    {
                        prop.SetValue(this, value.FirstOrDefault());
                    }
                    catch (Exception)
                    {
                        // do nothing
                    }
                }
            }
        }
コード例 #2
0
ファイル: WebApi.cs プロジェクト: teamviewer/Xrm.Crm.WebApi
        private Guid GetEntityIdFromResponse(string fullUrl, HttpResponseMessage response)
        {
            HttpResponseHeaders headers = response.Headers;
            string headerValue          = headers.First(h => h.Key.Contains("OData-EntityId")).Value.First();

            return(new Guid(headerValue.Split('(').Last().Split(')')[0]));
        }
コード例 #3
0
ファイル: CodApiClient.cs プロジェクト: cst95/Warzone.NET
        private static string ParseXsrfTokenFromHeaders(HttpResponseHeaders headers)
        {
            var xsrfHeader    = headers.First(h => h.Key.Equals("Set-Cookie")).Value.First(v => v.Contains("XSRF-TOKEN"));
            var regex         = new Regex("(XSRF-TOKEN=|;)");
            var cookieStrings = regex.Split(xsrfHeader.Trim());

            return(cookieStrings[2]);
        }
コード例 #4
0
        public void SetProperties(HttpResponseHeaders headers)
        {
            var properties = this.GetType().GetProperties().Where(p => p.GetValue(this) != null);

            foreach (var prop in properties.Where(prop => headers.Any(h => h.Key == prop.Name)))
            {
                prop.SetValue(this, headers.First(h => NetNamingMapper.GetPropertyName(h.Key) == prop.Name));
            }
        }
コード例 #5
0
 public static string GetSingleHeaderValue(HttpResponseHeaders responseHeaders,
                                           string keyName)
 {
     if (responseHeaders.Contains(keyName))
     {
         return(responseHeaders.First(ph => ph.Key == keyName).Value.First());
     }
     return(null);
 }
コード例 #6
0
ファイル: HeaderParser.cs プロジェクト: TharinduK/MovieInfo
 public static PagingInfo FindAndParsePagingInfo(HttpResponseHeaders respHeader)
 {
     //find x-pagination info form http header
     if (respHeader.Contains("x-pagination"))
     {
         var xPageInfo = respHeader.First(ph => ph.Key == "x-pagination").Value;
         return(JsonConvert.DeserializeObject <PagingInfo>(xPageInfo.First()));
     }
     return(null);
 }
コード例 #7
0
ファイル: HeaderParser.cs プロジェクト: frankdersjant/PWET
 public static PagingInfo FindAndParsePagingInfo(HttpResponseHeaders responseHeaders)
 {
     //added in controller
     if (responseHeaders.Contains("X-Pagination"))
     {
         var xPag = responseHeaders.First(ph => ph.Key == "X-Pagination").Value;
         return(JsonConvert.DeserializeObject <PagingInfo>(xPag.First()));
     }
     return(null);
 }
コード例 #8
0
        private string ReadETagHeader(HttpResponseHeaders responseHeaders)
        {
            if (responseHeaders.Contains("ETag"))
            {
                var etagHeaderValue = responseHeaders.First(h => h.Key == "ETag").Value;

                return(etagHeaderValue.First());
            }

            return(null);
        }
コード例 #9
0
        private PageInfo ReadPageInfroFromHeader(HttpResponseHeaders responseHeaders)
        {
            if (responseHeaders.Contains("X-PageInfo"))
            {
                var pageHeaderValue = responseHeaders.First(h => h.Key == "X-PageInfo").Value;

                return(JsonConvert.DeserializeObject <PageInfo>(pageHeaderValue.First()));
            }

            return(null);
        }
コード例 #10
0
 public static PagingInfo FindAndParsePagingInfo(HttpResponseHeaders responseHeaders)
 {
     // find the "X-Pagination" info in header
     if (responseHeaders.Contains("X-Pagination"))
     {
         var xPag = responseHeaders.First(ph => ph.Key == "X-Pagination").Value;
         // parse the value - this is a JSON-string.
         return(JsonConvert.DeserializeObject <PagingInfo>(xPag.First()));
     }
     return(null);
 }
コード例 #11
0
        public static PagingInfoDto FindAndParsePagingInfo(this HttpResponseHeaders responseHeaders)
        {
            // find the "X-Pagination" info in header
            if (responseHeaders.Contains("X-Pagination"))
            {
                var xPag = responseHeaders.First(ph => ph.Key == "X-Pagination").Value;

                // parse the value - this is a JSON-string.
                return(JsonSerializer.Deserialize <PagingInfoDto>(xPag.First(), new JsonSerializerOptions()
                {
                    WriteIndented = true,
                    PropertyNameCaseInsensitive = true,
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                    DictionaryKeyPolicy = JsonNamingPolicy.CamelCase
                }));
            }
            return(null);
        }
コード例 #12
0
        /// <summary>
        /// Tries the get session token.
        /// </summary>
        /// <param name="headers">The headers from the server response.</param>
        /// <param name="value">The value of the session token.</param>
        /// <returns><see langword="true" /> if a token was found, <see langword="false" /> otherwise.</returns>
        private bool TryGetSessionToken(HttpResponseHeaders headers, out string value)
        {
            value = null;

            if (headers.Any(x => x.Key == "Set-Cookie"))
            {
                var sessionId = headers
                                .First(x => x.Key == "Set-Cookie").Value
                                .ToList()
                                .FirstOrDefault(x => x.Contains("JSESSION"));

                if (sessionId != null)
                {
                    value = sessionId.Split(';')[0];

                    return(true);
                }
            }

            return(false);
        }
コード例 #13
0
 public static string GetFirstValue(this HttpResponseHeaders headers, string key)
 {
     return(headers.First(x => x.Key.ToLower() == key.ToLower()).Value.First());
 }