public Request(ConnectionData connectionData, DataProvider dataProvider)
        {
            ID = dataProvider.Register(connectionData);

            ConnectionData = connectionData;
            DataProvider = dataProvider;
        }
        private Response RetrieveResponse(ConnectionData connectionData, Uri url)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.KeepAlive = false;
            webRequest.Method = "GET";
            webRequest.AutomaticDecompression = DecompressionMethods.GZip;
            webRequest.Headers.Add(connectionData.HttpHeaderFields);
          
            var config = ConnectionSection.GetSection();

            if (config.Language != "")
            {
                webRequest.Headers.Add(HttpRequestHeader.AcceptLanguage, config.Language);
            }

            log.InfoFormat("Sending request to URL: {0}", url);
            HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

            var statusCode = webResponse.StatusCode;

            StreamReader responseStream = new StreamReader(webResponse.GetResponseStream(), true);

            string responseText = responseStream.ReadToEnd();

            responseStream.Close();
            webResponse.Close();

            return new Response(
                responseText,
                statusCode
            );
        }
        /**
         * Make a connection data object known to the data provider and obtain an ID
         * for it (basically, a handle).
         */
        public int Register(ConnectionData connectionData)
        {
            int id = NextID++;
            ConnectionData[id] = connectionData;

            log.DebugFormat("Registered connection data for ID {0}.", id);

            return id;
        }
        public void TestLoadResponse()
        {
            var connectionData = new ConnectionData();
            int id = DataProvider.Register(connectionData);

            var parameters = connectionData.Parameters;

            parameters["format"] = "json";
            parameters["do"] = "getTagCloud";
            parameters["test"] = "test";

            connectionData.Action = RequestType.TagCloud;

            DataProvider.LoadResponse(id);

            var response = connectionData.Response;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual("test response", response.Content);
        }
        public Request GetRequest()
        {
            var connectionData = new ConnectionData(new NameValueCollection(RequestParameters));

            return new Request(connectionData, DataProvider);
        }
        private NameValueCollection PrepareParameters(ConnectionData connectionData)
        {
            var parameters = connectionData.Parameters;

            // TODO: Should we introduce a debug flag into the app.config?
            // If so, we'd set the parameters['verbose'] = true; here

            return parameters;
        }