/// <summary>
        /// Initializes the HTTP Commands.
        /// </summary>
        private void InitializeHttpCommands()
        {
            // get and post types init
            getForm = new GetForm();
            postForm = new PostForm();

            getForm.EndHttp += new ResponseCallbackDelegate(http_EndGetHttp);
            postForm.EndHttp += new ResponseCallbackDelegate(postRequest_EndPostHttp);
        }
        /// <summary>
        /// Loads scripts with SRC attribute and adds it to the Script Collection in ResponseBuffer.
        /// </summary>
        /// <param name="requestUrl"> The top url.</param>
        /// <param name="response"> The ResponseBuffer.</param>
        /// <param name="clientSettings"> The http settings.</param>
        /// <returns> An updated ResponseBuffer.</returns>
        internal static ResponseBuffer LoadScriptsFromSrc(Uri requestUrl,ResponseBuffer response,HttpProperties clientSettings)
        {
            GetForm http = new GetForm();
            HtmlScriptCollection scripts = response.Scripts;

            for (int i=0;i<scripts.Count;i++)
            {
                if ( scripts[i].Source.Length!=0 )
                {
                    string src = scripts[i].Source;
                    string requestData = string.Empty;

                    requestData = UriResolver.ResolveUrl(requestUrl,src);

                    // add User Agent
                    clientSettings.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0)";

                    try
                    {
                        // load
                        ResponseBuffer result = http.StartSyncHttpGet(requestData,clientSettings,null,response.CookieCollection);

                        scripts[i].Text = result.HttpBody;
                    }
                    catch (Exception ex)
                    {
                        // TODO: Log this errors as SCRIPT loading failed error
                        System.Diagnostics.Debug.Write(ex.Message);
                    }
                }
            }

            return response;
        }
        /// <summary>
        /// Get Async get request.
        /// </summary>
        /// <param name="getUrl"> The url.</param>
        /// <param name="values"> The get values.</param>
        /// <param name="cookies"> The cookies.</param>
        /// <param name="state"> The http state.</param>
        private void StartGetRequest(GetForm httpCommand, string getUrl, ArrayList values, CookieCollection cookies, HttpProperties settings, HttpState state)
        {
            try
            {
                httpCommand.StartAsyncHttpGet(
                    getUrl,
                    settings,
                    values,
                    cookies,
                    state,
                    false);
            }
            catch (Exception ex)
            {
                // register and show
                ExceptionHandler.RegisterException(ex);

                AbortSessionRun(ex.Message);
            }
        }
        /// <summary>
        /// Executes the session.
        /// </summary>
        public void Run()
        {
            this._isRunning = true;

            reports = new ArrayList();

            unitTestPostRequest = new PostForm();
            unitTestGetRequest = new GetForm();

            safeSessionGetRequest = new GetForm();
            safeSessionPostRequest = new PostForm();

            loopPostRequest = new PostForm();
            loopGetRequest = new GetForm();

            // Add proxy settings
            loopPostRequest.ProxySettings = this.Proxy;
            loopGetRequest.ProxySettings = this.Proxy;
            unitTestPostRequest.ProxySettings = this.Proxy;
            unitTestGetRequest.ProxySettings = this.Proxy;
            safeSessionGetRequest.ProxySettings = this.Proxy;
            safeSessionPostRequest.ProxySettings = this.Proxy;

            // http settings
            loopPostRequest.ClientSettings  = this.ProtocolProperties;
            loopGetRequest.ClientSettings  = this.ProtocolProperties;
            unitTestPostRequest.ClientSettings = this.ProtocolProperties;
            unitTestGetRequest.ClientSettings = this.ProtocolProperties;
            safeSessionGetRequest.ClientSettings = this.ProtocolProperties;
            safeSessionPostRequest.ClientSettings = this.ProtocolProperties;

            // set events for looping requests
            loopPostRequest.EndHttp += new ResponseCallbackDelegate(LoopToNextSafeRequest_EndHttp);
            loopGetRequest.EndHttp += new ResponseCallbackDelegate(LoopToNextSafeRequest_EndHttp);

            // set events for unit test requests
            unitTestPostRequest.EndHttp += new ResponseCallbackDelegate(UnitTestResult_EndHttp);
            unitTestGetRequest.EndHttp += new ResponseCallbackDelegate(UnitTestResult_EndHttp);

            // set events for safe session requests
            safeSessionGetRequest.EndHttp += new ResponseCallbackDelegate(SafeSessionResult_EndHttp);
            safeSessionPostRequest.EndHttp += new ResponseCallbackDelegate(SafeSessionResult_EndHttp);

            HttpState state = new HttpState();

            // the test sessin request of the safe request.
            state.TestSessionRequest = this.TestSession.SessionRequests[0];
            state.SessionRequestId = 0;
            state.IsLastItem = true;

            ExecuteNextSafeRequest(state);
        }
        /// <summary>
        /// Runs the command.
        /// </summary>
        public void Run()
        {
            this._isRunning = true;

            postRequest = new PostForm();
            getRequest = new GetForm();

            postRequest.EndHttp += new ResponseCallbackDelegate(httpResponse_EndHttp);
            getRequest.EndHttp += new ResponseCallbackDelegate(httpResponse_EndHttp);

            reports = new ArrayList();

            TestCollection tests = GetTests();

            UnitTestItem testItem = new UnitTestItem(FormTag, tests);

            int availableTests = tests.Count;
            bool lastItem = false;

            #region Run each test in UnitTestItem

                // run each test in Form
                foreach (DictionaryEntry de in tests)
                {
                    Test test = (Test)de.Value;

                    // apply test to form
                    HtmlFormTag filledForm = ApplyTestToForm(test, FormTag.CloneTag());

                    // set current test index
                    testItem.SelectedTestIndex = testItem.Tests.IndexOfValue(test);

                    // resolve uri
                    string url = UriResolver.ResolveUrl(this.Url,filledForm.Action);

                    // convert to array list
                    // TODO: Send HTML Source for bypassing fields. Will be needed for ASP.NET testing.
                    ArrayList al = parser.GetArrayList(filledForm);

                    // set posted data
                    StringBuilder postDataBuffer = new StringBuilder();

                    postDataBuffer.Append("?");
                    for (int k=0;k<al.Count;k++)
                    {
                        postDataBuffer.Append(al[k]);
                        postDataBuffer.Append("&");
                    }

                    test.Arguments.PostData = postDataBuffer.ToString();

                    // set last item flag
                    if ( availableTests == 1)
                    {
                        lastItem = true;
                    }

                    CookieManager cookieManager = new CookieManager();
                    CookieCollection cookies = cookieManager.GetCookies(new Uri(url));

                    HttpState httpRequestState = new HttpState();
                    httpRequestState.TestItem = testItem.Clone();
                    httpRequestState.IsLastItem = lastItem;

                    if ( filledForm.Method.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "get" )
                    {

                        getRequest.StartAsyncHttpGet(
                            url,
                            this.ProtocolProperties,
                            al,
                            cookies,
                            httpRequestState,
                            false);

                    }
                    else
                    {
                        postRequest.StartAsyncHttpPost(
                            url,
                            this.ProtocolProperties,
                            al,
                            cookies,
                            httpRequestState);
                    }

                    availableTests--;
                }
                #endregion
        }