Ejemplo n.º 1
0
        private void _update_response_headers(WebClient webClient = null, WebResponse webResponse = null, SearchAPIResponse response = null, SearchAPIError errResponse = null)
        {
            WebHeaderCollection headers = null;

            if (webClient != null)
            {
                headers = webClient.ResponseHeaders;
            }
            else if (webResponse != null)
            {
                headers = webResponse.Headers;
            }

            if (headers == null)
            {
                return;
            }


            string value = headers.Get("X-QPS-Allotted");
            int    intVal;

            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsAllotted = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QpsAllotted = intVal;
                    }
                }
            }

            value = headers.Get("X-QPS-Current");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsCurrent = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QpsCurrent = intVal;
                    }
                }
            }

            value = headers.Get("X-APIKey-Quota-Allotted");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QuotaAllotted = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QuotaAllotted = intVal;
                    }
                }
            }

            value = headers.Get("X-APIKey-Quota-Current");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QuotaCurrent = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QuotaCurrent = intVal;
                    }
                }
            }

            value = headers.Get("X-QPS-Live-Allotted");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsLiveAllotted = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QpsLiveAllotted = intVal;
                    }
                }
            }

            value = headers.Get("X-QPS-Live-Current");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsLiveCurrent = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QpsLiveCurrent = intVal;
                    }
                }
            }

            value = headers.Get("X-QPS-Demo-Allotted");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsDemoAllotted = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QpsDemoAllotted = intVal;
                    }
                }
            }

            value = headers.Get("X-QPS-Demo-Current");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsDemoCurrent = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QpsDemoCurrent = intVal;
                    }
                }
            }

            value = headers.Get("X-Quota-Reset");
            if (value != null)
            {
                try
                {
                    value = value.Replace(" UTC", " +0");
                    DateTime quotaReset = DateTime.ParseExact(value, "dddd, MMMM dd, yyyy hh:mm:ss tt z", CultureInfo.InvariantCulture);
                    if (response != null)
                    {
                        response.QuotaReset = quotaReset;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QuotaReset = quotaReset;
                    }
                }
                catch {}
            }

            value = headers.Get("X-Demo-Usage-Allotted");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.DemoUsageAlloted = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.DemoUsageAlloted = intVal;
                    }
                }
            }

            value = headers.Get("X-Demo-Usage-Current");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.DemoUsageCurrent = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.DemoUsageCurrent = intVal;
                    }
                }
            }

            value = headers.Get("X-Demo-Usage-Expiry");
            if (value != null)
            {
                try
                {
                    value = value.Replace(" UTC", " +0");
                    DateTime quotaReset = DateTime.ParseExact(value, "dddd, MMMM dd, yyyy hh:mm:ss tt z", CultureInfo.InvariantCulture);
                    if (response != null)
                    {
                        response.DemoUsageExpiry = quotaReset;
                    }
                    if (errResponse != null)
                    {
                        errResponse.DemoUsageExpiry = quotaReset;
                    }
                }
                catch { }
            }
        }
Ejemplo n.º 2
0
        private void _update_response_headers(WebClient webClient= null, WebResponse webResponse = null, SearchAPIResponse response = null, SearchAPIError errResponse = null)
        {
            WebHeaderCollection headers = null;

            if (webClient != null)
            {
                headers = webClient.ResponseHeaders;
            }
            else if (webResponse != null) {
                headers = webResponse.Headers;
            }

            if (headers == null)
            {
                return;
            }

            string value = headers.Get("X-QPS-Allotted");
            int intVal;
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsAllotted = intVal;
                    }
                    if (errResponse != null) {
                        errResponse.QpsAllotted = intVal;
                    }
                }
            }

            value = headers.Get("X-QPS-Current");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsCurrent = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QpsCurrent = intVal;
                    }
                }
            }

            value = headers.Get("X-APIKey-Quota-Allotted");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QuotaAllotted = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QuotaAllotted = intVal;
                    }
                }
            }

            value = headers.Get("X-APIKey-Quota-Current");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QuotaCurrent = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QuotaCurrent = intVal;
                    }
                }
            }

            value = headers.Get("X-QPS-Live-Allotted");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsLiveAllotted = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QpsLiveAllotted = intVal;
                    }
                }
            }

            value = headers.Get("X-QPS-Live-Current");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsLiveCurrent = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QpsLiveCurrent = intVal;
                    }
                }
            }

            value = headers.Get("X-QPS-Demo-Allotted");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsDemoAllotted = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QpsDemoAllotted = intVal;
                    }
                }
            }

            value = headers.Get("X-QPS-Demo-Current");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.QpsDemoCurrent = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QpsDemoCurrent = intVal;
                    }
                }
            }

            value = headers.Get("X-Quota-Reset");
            if (value != null)
            {
                try
                {
                    value = value.Replace(" UTC", " +0");
                    DateTime quotaReset = DateTime.ParseExact(value, "dddd, MMMM dd, yyyy hh:mm:ss tt z", CultureInfo.InvariantCulture);
                    if (response != null)
                    {
                        response.QuotaReset = quotaReset;
                    }
                    if (errResponse != null)
                    {
                        errResponse.QuotaReset = quotaReset;
                    }
                }
                catch {}
            }

            value = headers.Get("X-Demo-Usage-Allotted");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.DemoUsageAlloted = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.DemoUsageAlloted = intVal;
                    }
                }
            }

            value = headers.Get("X-Demo-Usage-Current");
            if (value != null)
            {
                if (Int32.TryParse(value, out intVal))
                {
                    if (response != null)
                    {
                        response.DemoUsageCurrent = intVal;
                    }
                    if (errResponse != null)
                    {
                        errResponse.DemoUsageCurrent = intVal;
                    }
                }
            }

            value = headers.Get("X-Demo-Usage-Expiry");
            if (value != null)
            {
                try
                {
                    value = value.Replace(" UTC", " +0");
                    DateTime quotaReset = DateTime.ParseExact(value, "dddd, MMMM dd, yyyy hh:mm:ss tt z", CultureInfo.InvariantCulture);
                    if (response != null)
                    {
                        response.DemoUsageExpiry = quotaReset;
                    }
                    if (errResponse != null)
                    {
                        errResponse.DemoUsageExpiry = quotaReset;
                    }
                }
                catch { }
            }
        }