Example #1
0
        // Display data
        public void Display(string jsonData, HttpResponseHeaders headers, DataGridView dataGridView, Label label)
        {
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add();
            dataTable.Columns.Add();

            // Parsing the Json data and adding data to the DataTable two columns at a time.
            JToken json = JToken.Parse(jsonData);
            IEnumerable <KeyValuePair <string, JValue> > fields = new JsonFieldsCollector(json).GetAllFields();

            if (fields.Count() > 0)
            {
                foreach (var field in fields)
                {
                    dataTable.Rows.Add(field.Key, field.Value);
                }
            }
            else
            {
                dataTable.Rows.Add("No data");
            }

            // Complete the number of rows in DataGridView
            dataGridView.RowCount = dataTable.Rows.Count;

            // Index of first visible row.
            // If there is no data, the return value will be -1.
            int firstVisibleIndex = dataGridView.FirstDisplayedScrollingRowIndex;

            if (firstVisibleIndex >= 0)
            {
                // Calculate the index of last visible row.
                int maxIndex = (dataGridView.Height / dataGridView.Rows[0].Height + firstVisibleIndex) - 1;
                maxIndex = (maxIndex > dataGridView.RowCount) ? dataGridView.RowCount : maxIndex;
                // Update values only in the visible range of DataGridView.
                for (int i = firstVisibleIndex; i < maxIndex; i++)
                {
                    dataGridView[0, i].Value = dataTable.Rows[i].ItemArray[0];
                    dataGridView[1, i].Value = dataTable.Rows[i].ItemArray[1];
                }
            }

            // Output Timestamp from Http headers.
            if (headers != null)
            {
                var headerTimeStamp =
                    headers.FirstOrDefault(pair => string.Compare(pair.Key, "Engine-Timestamp") == 0).Value;
                if (headerTimeStamp != null)
                {
                    var timeStamp = double.Parse(headerTimeStamp.ElementAt(0) /*,System.Globalization.NumberStyles.Float*/);
                    var span      = TimeSpan.FromSeconds(timeStamp);
                    label.Text = $"TS: {timeStamp.ToString("F3")} ({span.ToString(@"h\:mm\:ss")})";
                }
            }
        }
        public static long ParseLong(this HttpResponseHeaders header, string key, long defaultValue = 0)
        {
            var hit = header.FirstOrDefault(h => h.Key == key);

            if (hit.Value != null && hit.Value.Count() > 0)
            {
                return(long.Parse(hit.Value.First()));
            }
            return(defaultValue);
        }
Example #3
0
 /// <summary>
 /// 从http headers中查询cookie
 /// </summary>
 /// <param name="headers"></param>
 /// <param name="key"></param>
 /// <returns></returns>
 public static string GetCookie(this HttpResponseHeaders headers, string key)
 {
     if (string.IsNullOrWhiteSpace(key))
     {
         return(null);
     }
     return(headers.FirstOrDefault(x => x.Key == "Set-Cookie").Value?
            .FirstOrDefault(x => x.StartsWith(key))?
            .Split(";")
            .FirstOrDefault());
 }
        public static IEnumerable <string> HeaderValue(this HttpResponseHeaders headers, string name)
        {
            if (headers == null ||
                string.IsNullOrEmpty(name))
            {
                return(null);
            }

            var match = headers.FirstOrDefault(z => string.Equals(z.Key, name, StringComparison.InvariantCultureIgnoreCase));

            return(match.Value ?? new List <string>());
        }
Example #5
0
        public static CacheCowHeader GetCacheCowHeader(this HttpResponseHeaders headers)
        {
            CacheCowHeader header = null;

            if (headers == null)
            {
                return(null);
            }

            var cacheCowHeader = headers.FirstOrDefault(x => x.Key == CacheCowHeader.Name);

            if (cacheCowHeader.Value != null && cacheCowHeader.Value.Count() > 0)
            {
                var last = cacheCowHeader.Value.Last();
                CacheCowHeader.TryParse(last, out header);
            }

            return(header);
        }
        public static string GetFirstValueOrNull(this HttpResponseHeaders headers, string key)
        {
            var header = headers.FirstOrDefault(x => x.Key == key);

            return(header.Key == null ? null : header.Value.FirstOrDefault());
        }
Example #7
0
        public string GetHeaderResponse(string key)
        {
            var header = _responseHeader.FirstOrDefault(f => f.Key == key);

            return(header.Value.First());
        }