/// <summary>
        /// Normalizes the form tag. For use with the multipart/form-data.
        /// </summary>
        public static HtmlFormTag NormalizeFormTag(HtmlFormTag formTag, string data)
        {
            FormConverter converter = new FormConverter();
            PostDataCollection postDataItems = converter.GetPostDataCollection(data);
            // removes extra tags.

            foreach ( string name in postDataItems.Keys )
            {
                if ( formTag.ContainsKey(name) )
                {
                    HtmlTagBaseList list = formTag[name];

                    if ( list.Count > 1 )
                    {
                        for ( int i=1;i<(list.Count+1);i++ )
                        {
                            list.Remove(list[i]);
                        }
                    }
                }
                else
                {
                    formTag.Remove(name);
                }
            }

            return formTag;
        }
        /// <summary>
        /// Creates a new SoftTestCommand.
        /// </summary>
        /// <param name="url"> The url to apply the test.</param>
        /// <param name="form"> The form to apply the tests.</param>
        /// <param name="proxySettings"> The http proxy settings.</param>
        /// <param name="httpProperties"> The http settings.</param>
        /// <param name="sqlTest"> The sql test to use.</param>
        /// <param name="xssTest"> The xss test to use.</param>
        /// <param name="bufferLength"> The buffer overflow length to use.</param>
        public SoftTestCommand(Uri url,
			HtmlFormTag form,
			HttpProxy proxySettings,
			HttpProperties httpProperties,
			string sqlTest,
			string xssTest,
			int bufferLength)
            : this()
        {
            this._xssSignature = xssTest;
            this._sqlSignature = sqlTest;
            this._bufferLen = bufferLength;

            this.Url = url;
            this.FormTag = form;
            this.Proxy = proxySettings;
            this.ProtocolProperties = httpProperties;

            //			updateElementNames.Add("__VIEWSTATE");
            //			updateElementNames.Add("__EVENTTARGET");
        }
 /// <summary>
 /// Fills the form tag with tests.
 /// </summary>
 /// <param name="formTag"> The HtmlFormTag.</param>
 /// <returns> The updated HtmlFormTag.</returns>
 public HtmlFormTag FillForm(HtmlFormTag formTag)
 {
     // ignore pattern and send HtmlFormTag from FormData
     return arguments.FormData;
 }
        //        /// <summary>
        //        /// Converts the hashtable to a post data ArrayList.
        //        /// </summary>
        //        /// <param name="data"> The post data hashtable.</param>
        //        /// <returns> An ArrayList representation of the post data.</returns>
        //        public ArrayList ConvertPostDataArrayList(Hashtable data)
        //        {
        //
        //            ArrayList list = new ArrayList();
        //            foreach ( DictionaryEntry de in data)
        //            {
        //                string key = (string)de.Key;
        //
        //                foreach ( string s in ((ArrayList)de.Value) )
        //                {
        //                    list.Add(key + "=" + s);
        //                }
        //            }
        //
        //            return list;
        //        }
        /// <summary>
        /// Adds post data values for a form tag.
        /// </summary>
        /// <param name="formTag"> The HtmlFormTag.</param>
        /// <param name="postDataString"> The post data as a string.</param>
        /// <returns> An updated HtmlFormTag with the post data values.</returns>
        public HtmlFormTag AddPostDataValues(HtmlFormTag formTag, string postDataString)
        {
            PostDataCollection postDataItems = GetPostDataCollection(postDataString);

            for (int j=0;j<formTag.Count;j++)
            {
                HtmlTagBaseList elementList =(HtmlTagBaseList)((DictionaryEntry)formTag[j]).Value;

                // foreach tag in elementList
                for (int i=0;i<elementList.Count;i++)
                {
                    HtmlTagBase tagBase = elementList[i];

                    SetTagValue(postDataItems,tagBase,i);
                }
            }

            return formTag;
        }
 public bool ContainsValue(HtmlFormTag value)
 {
     return innerHash.ContainsValue(value);
 }
        /// <summary>
        /// Fills the form tag with tests.
        /// </summary>
        /// <param name="form"> The HtmlFormTag.</param>
        /// <returns> The updated HtmlFormTag.</returns>
        public HtmlFormTag FillForm(HtmlFormTag form)
        {
            string buffer = this.SqlValue;

            for (int i=0;i<form.Count;i++)
            {
                HtmlTagBaseList controlArray = (HtmlTagBaseList)((DictionaryEntry)form[i]).Value;

                #region inner foreach loop
                foreach (HtmlTagBase tag in controlArray)
                {
                    if (tag is HtmlInputTag)
                    {
                        HtmlInputTag input=(HtmlInputTag)tag;
                        input.Value = buffer;
                    }
                    if (tag is HtmlButtonTag)
                    {
                        HtmlButtonTag button = (HtmlButtonTag)tag;
                        button.Value=buffer;
                    }
                    if (tag is HtmlSelectTag)
                    {
                        HtmlSelectTag select = (HtmlSelectTag)tag;
                        if  ( select.Multiple )
                        {
                            foreach ( HtmlOptionTag opt in select.Options )
                            {
                                //HtmlOptionTag opt = tag;
                                if ( opt.Selected )
                                {
                                    opt.Value=buffer;
                                }
                            }
                        }
                        else
                        {
                            select.Value = buffer;
                        }
                    }

                    if (tag is HtmlTextAreaTag)
                    {
                        HtmlTextAreaTag textarea=(HtmlTextAreaTag)tag;
                        textarea.Value=buffer;
                    }
                }
                #endregion
            }

            return form;
        }
        /// <summary>
        /// Adds a GetSessionRequest to a recording session.
        /// </summary>
        /// <param name="url"> The requested url.</param>
        /// <param name="queryString"> The url query string.</param>
        /// <param name="form"> The get form.</param>
        /// <param name="cookies"> The current cookies.</param>
        private void AddSessionGet(string url, string queryString, HtmlFormTag form, CookieCollection cookies)
        {
            if ( IsRecording )
            {
                GetSessionRequest getSessionRequest = new GetSessionRequest();
                if ( form != null )
                {
                    getSessionRequest.Form = form.CloneTag();
                }
                getSessionRequest.QueryString = queryString;
                getSessionRequest.RequestCookies = cookies;
                getSessionRequest.Url = new Uri(url);
                getSessionRequest.RequestHttpSettings = this.ClientProperties.Clone();

                this.CurrentSessionRecording.SessionRequests.Add(getSessionRequest);
            }
        }
        /// <summary>
        /// Builds a unit test for a form.
        /// </summary>
        /// <param name="testType"> The test type to create.</param>
        /// <param name="form"> The form to edit.</param>
        /// <returns> An edited form tag with applied test.</returns>
        public HtmlFormTag BuildUnitTestForm(UnitTestType testType, HtmlFormTag form)
        {
            HtmlFormTag ret=null;
            IHtmlFormUnitTest tester;
            // Call FillForm
            switch (testType)
            {
                case UnitTestType.BufferOverflow:
                    tester = new BufferOverflowTester((BufferOverflowTesterArgs)this.Arguments);
                    ret = tester.FillForm(form);
                    break;
                case UnitTestType.DataTypes:
                    tester = new DataTypesTester((DataTypesTesterArgs)this.Arguments);
                    ret = tester.FillForm(form);
                    break;
                case UnitTestType.Predefined:
                    tester = new PredefinedTester(((PredefinedTesterArgs)this.Arguments));
                    ret = tester.FillForm(form);
                    break;
                case UnitTestType.SqlInjection:
                    tester = new SqlInjectionTester((SqlInjectionTesterArgs)this.Arguments);
                    ret = tester.FillForm(form);
                    break;
                case UnitTestType.XSS:
                    tester = new XssInjectionTester((XssInjectionTesterArgs)this.Arguments);
                    ret = tester.FillForm(form);
                    break;
            }

            return ret;
        }
 /// <summary>
 /// Adds a Form Node.
 /// </summary>
 /// <param name="node"> A FormEditorNode to add.</param>
 /// <param name="text"> The node text.</param>
 /// <param name="formtag"> The HtmFormTag.</param>
 public void AddFormNode(FormEditorNode node,string text, HtmlFormTag formtag)
 {
     node.Text=text;
     node.BaseHtmlTag=formtag;
     this.Nodes.Add(node);
 }
        // BeforeNavigate event used for post data mapping to forms editor.
        private void web_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
        {
            if ( e.postData != null )
            {
                this.postData = (byte[])e.postData;

                Invoke(new OnPostDataMatchEventHandler(OnPostDataSubmitMatch),
                            new Object[] {(byte[])e.postData});
            }
            else
            {
                string url = (string)e.uRL;
                if ( isLinkNavigation )
                {
                    Uri uri = new Uri(url);
                    string queryString = uri.Query;

                    if ( queryString.Length > 0 )
                    {
                        Invoke(new OnQueryStringMatchEventHandler(OnQueryStringSubmitMatch),
                            new Object[] {queryString});
                    }

                    if ( (url.StartsWith("http:"))
                        ||
                        (url.StartsWith("https:")) )
                    {
                        RequestGetEventArgs args = new RequestGetEventArgs();
                        if ( _getformTag != null )
                        {
                            args.Form = _getformTag.CloneTag();
                            _getformTag = null;
                        }
                        args.Url = (string)url;
                        args.InspectorRequestAction = InspectorAction.WebBrowserGet;
                        this.StartEvent(this, args);

                        isLinkNavigation = false;
                    }
                }
            }
        }
        /// <summary>
        /// Occurs when post data is to match.
        /// </summary>
        /// <param name="data"></param>
        private void OnQueryStringSubmitMatch(string data)
        {
            try
            {
                // Check for any form
                HtmlFormTag formTag = formHeuristicEngine.MatchPostDataToForm(formCollection, data.TrimStart('?'));

                // if null, we know this is not a form get post.
                if ( formTag != null )
                {
                    _getformTag = formTag;
                }
            }
            catch ( Exception ex )
            {
                MessageBox.Show(ex.ToString());
            }
        }
 private HtmlFormTag FillFormField(WebRequest request, HtmlFormTag form, string test)
 {
     foreach ( HtmlTagListXml list in request.Form.Elements )
     {
         HtmlTagBaseList tagList = form[list.Name];
         #region Fill Form
         foreach ( HtmlTagBase tagBase in tagList )
         {
             if ( tagBase is HtmlInputTag )
             {
                 ((HtmlInputTag)tagBase).Value = test;
             }
             if ( tagBase is HtmlButtonTag)
             {
                 HtmlButtonTag button = (HtmlButtonTag)tagBase;
                 button.Value = test;
             }
             if ( tagBase is HtmlSelectTag )
             {
                 HtmlSelectTag select = (HtmlSelectTag)tagBase;
                 if  ( select.Multiple )
                 {
                     foreach ( HtmlOptionTag opt in select.Options )
                     {
                         if ( opt.Selected )
                         {
                             opt.Value = test;
                         }
                     }
                 }
                 else
                 {
                     select.Value = test;
                 }
             }
             if  ( tagBase is HtmlTextAreaTag )
             {
                 ((HtmlTextAreaTag)tagBase).Value = test;
             }
         }
         #endregion
     }
     return form;
 }
        /// <summary>
        /// Writes the HtmlFormTagXml to a HtmlFormTag.
        /// </summary>
        /// <returns>A new cloned HtmlFormTag.</returns>
        public HtmlFormTag WriteHtmlFormTag()
        {
            HtmlFormTag form = new HtmlFormTag();
            form.Action = this.Action;
            form.Enctype = this.Enctype;
            form.FormIndex = this.FormIndex;
            form.Method = this.Method;
            form.Name = this.Name;
            form.OnSubmit = this.OnSubmit;

            foreach ( HtmlTagListXml listXml in Elements )
            {
                HtmlTagBaseList list = new HtmlTagBaseList();

                list.AddRange(listXml.Tags);
                form.Add(listXml.Name, list);
            }

            return form;
        }
        /// <summary>
        /// Fills the form tag with tests.
        /// </summary>
        /// <param name="formTag"> The HtmlFormTag.</param>
        /// <returns> The updated HtmlFormTag.</returns>
        public HtmlFormTag FillForm(HtmlFormTag formTag)
        {
            string buffer = String.Empty;

            switch ( this.SelectedDataType )
            {
                case DataType.Character:
                    buffer = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                    break;
                case DataType.Numeric:
                    buffer = "0123456789";
                    break;
                case DataType.Null:
                    buffer = "";
                    break;
            }

            for (int i=0;i<formTag.Count;i++)
            {
                HtmlTagBaseList controlArray = (HtmlTagBaseList)((DictionaryEntry)formTag[i]).Value;

                #region inner foreach loop
                foreach (HtmlTagBase tag in controlArray)
                {
                    if (tag is HtmlInputTag)
                    {
                        HtmlInputTag input=(HtmlInputTag)tag;
                        input.Value = buffer;
                    }
                    if (tag is HtmlButtonTag)
                    {
                        HtmlButtonTag button = (HtmlButtonTag)tag;
                        button.Value=buffer;
                    }
                    if (tag is HtmlSelectTag)
                    {
                        HtmlSelectTag select = (HtmlSelectTag)tag;
                        if  ( select.Multiple )
                        {
                            foreach (HtmlOptionTag opt in select.Options )
                            {
                                //HtmlOptionTag opt = tag;
                                if ( opt.Selected )
                                {
                                    opt.Value=buffer;
                                }
                            }
                        }
                        else
                        {
                            select.Value = buffer;
                        }
                    }

                    if (tag is HtmlTextAreaTag)
                    {
                        HtmlTextAreaTag textarea=(HtmlTextAreaTag)tag;
                        textarea.Value=buffer;
                    }
                }
                #endregion
            }

            return formTag;
        }
        /// <summary>
        /// Displays a message indicating that no data could be showed.
        /// </summary>
        public void DisplayNoDataMessage()
        {
            _form = null;
            formEditor.Clear();

            FormEditorNode node = new FormEditorNode();
            node.Text = "No data available for display.";
            formEditor.Nodes.Add(node);
        }
        /// <summary>
        /// Adds a FormNode and returns the added node.
        /// </summary>
        /// <param name="text"> The node text.</param>
        /// <param name="formtag"> The HtmlFormTag.</param>
        /// <returns> Returns a FormEditorNode.</returns>
        public FormEditorNode AddFormNode(string text, HtmlFormTag formtag)
        {
            FormEditorNode node = new FormEditorNode();
            node.Text=text;
            node.BaseHtmlTag=formtag;
            this.Nodes.Add(node);

            return node;
        }
        /// <summary>
        /// Begins a new asynchronous HTTP Post request. This function is not thread safe.
        /// </summary>
        /// <param name="uriString"> The URL string.</param>
        /// <param name="clientSettings"> The client settings.</param>
        /// <param name="form"> The HTML Form tag.</param>
        /// <param name="cookies"> The cookies collection.</param>
        /// <param name="decodeUrl"> Decodes the url in Url and Html decoding.</param>
        public void StartAsyncHttpPost(string uriString, HttpProperties clientSettings, HtmlFormTag form, CookieCollection cookies, bool decodeUrl)
        {
            HtmlParser parser = new HtmlParser();
            ArrayList values = parser.GetArrayList(form);

            httpRequestState = new HttpState();

            if ( decodeUrl )
            {
                uriString = EncodeDecode.UrlDecode(uriString);
                uriString = EncodeDecode.HtmlDecode(uriString);
            }

            // create webrequest
            try
            {
                //this.ValidateIPAddress(new Uri(uriString));

                httpRequestState.HttpRequest = (HttpWebRequest)WebRequest.Create(uriString);

                // Set HttpWebRequestProperties
                SetHttpWebRequestProperties(httpRequestState.HttpRequest, clientSettings);

                // Apply proxy settings
                if ( this.ProxySettings != null )
                {
                    SetProxy(httpRequestState.HttpRequest,this.ProxySettings);
                }

                //httpRequestState.httpRequest.Referer = postUri;

                // Continue headers
                //hwr.ContinueDelegate = getRedirectHeaders;

                // save cookies
                httpRequestState.HttpRequest.CookieContainer=new CookieContainer();

                if ( cookies!=null )
                {
                    httpRequestState.HttpRequest.CookieContainer.Add(cookies);
                }

                byte[] data=null;
                if (values!=null)
                {
                    // transform to postdata and encode in bytes
                    string postData = GetPostData(values);
                    data = Encoding.UTF8.GetBytes(postData);

                    // set properties
                    httpRequestState.HttpRequest.Method="POST";
                    httpRequestState.HttpRequest.ContentType="application/x-www-form-urlencoded";
                    httpRequestState.HttpRequest.ContentLength=data.Length;

                    // get request stream
                    Stream stm = httpRequestState.HttpRequest.GetRequestStream();
                    stm.Write(data,0,data.Length);
                    stm.Flush();
                    stm.Close();
                }

                // Get Response
                IAsyncResult ar = httpRequestState.HttpRequest.BeginGetResponse(new AsyncCallback(FastResponseCallback),httpRequestState);

                // register a timeout
                ThreadPool.RegisterWaitForSingleObject(ar.AsyncWaitHandle, new WaitOrTimerCallback(BaseHttpForm.RequestTimeoutCallback), httpRequestState, this.GetTimeout(), true);

            }
            catch
            {
                throw;
            }
            finally
            {
                if ( httpRequestState.HttpResponse != null )
                {
                    httpRequestState.HttpResponse.Close();
                }
            }
        }
        /// <summary>
        /// Fills the form tag with tests.
        /// </summary>
        /// <param name="form"> The HtmlFormTag.</param>
        /// <returns> The updated HtmlFormTag.</returns>
        public HtmlFormTag FillForm(HtmlFormTag form)
        {
            BufferOverflowGenerator gen = new BufferOverflowGenerator();
            string buffer = gen.GenerateStringBuffer(this.BufferLength);

            // chop extra chars
            buffer = buffer.Substring(0,this.BufferLength);
            buffer = EncodeDecode.UrlEncode(buffer);

            for (int i=0;i<form.Count;i++)
            {
                HtmlTagBaseList controlArray = (HtmlTagBaseList)((DictionaryEntry)form[i]).Value;

                #region inner foreach loop
                foreach (HtmlTagBase tag in controlArray)
                {
                    if (tag is HtmlInputTag)
                    {
                        HtmlInputTag input=(HtmlInputTag)tag;
                        input.Value = buffer;
                    }
                    if (tag is HtmlButtonTag)
                    {
                        HtmlButtonTag button = (HtmlButtonTag)tag;
                        button.Value=buffer;
                    }
                    if (tag is HtmlSelectTag)
                    {
                        HtmlSelectTag select = (HtmlSelectTag)tag;
                        if  ( select.Multiple )
                        {
                            foreach ( HtmlOptionTag opt in select.Options )
                            {
                                //HtmlOptionTag opt = tag;
                                if ( opt.Selected )
                                {
                                    opt.Value=buffer;
                                }
                            }
                        }
                        else
                        {
                            select.Value = buffer;
                        }
                    }

                    if (tag is HtmlTextAreaTag)
                    {
                        HtmlTextAreaTag textarea=(HtmlTextAreaTag)tag;
                        textarea.Value=buffer;
                    }
                }
                #endregion
            }

            return form;
        }
        /// <summary>
        /// Sends POST Requests.
        /// </summary>
        /// <param name="postUri"> Post uri.</param>
        /// <param name="values"> Values to post.</param>
        /// <param name="stateData"> ResponseBuffer from site.</param>
        /// <param name="cookies"> Cookies from site.</param>
        /// <param name="formTag"> The HtmlFormTag value.</param>
        private void GetPostRequest(string postUri,ArrayList values,ResponseBuffer stateData, CookieCollection cookies, HtmlFormTag formTag)
        {
            // disable
            DisableFormView();

            // add Messaging
            ShowPostRequestMessage(postUri);

            if ( values != null )
                ShowPostedData(values);

            try
            {
                InitializeHttpCommands();
                postForm.ProxySettings = this.ProxySettings;

                if ( formTag.Enctype.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "multipart/form-data" )
                {
                    HttpRequestResponseContext context = new HttpRequestResponseContext();
                    PostWebRequest postReq = new PostWebRequest();
                    postReq.Form.ReadHtmlFormTag(formTag);
                    Ecyware.GreenBlue.Engine.Scripting.Cookies c = new Cookies(cookies);
                    postReq.Cookies =  c.GetCookies();
                    postReq.RequestType = HttpRequestType.POST;
                    postReq.Url = postUri;
                    postReq.RequestHttpSettings = this.GetHttpPropertiesFromPanel();
                    context.Request = postReq;

                    postForm.StartAsyncHttpPostFileUpload(context);
                }
                else
                {
                    postForm.StartAsyncHttpPost(postUri,this.GetHttpPropertiesFromPanel(),values,cookies);
                }
            }
            catch ( Exception ex )
            {
                this.txtMessaging.SelectionColor = Color.Red;
                this.txtMessaging.SelectedText = "Html Browser Error: " + ex.Message + "\r\n";

                textViewerForm.EditorText = ex.Message;
                // enable
                EnableFormView();
                this.navForm.StopNavigation();
                this.StopProgressBarEvent(this,new ProgressBarControlEventArgs("Ready"));
            }
        }
        private void SetInputTextareaValue(HtmlFormTag form, string tagName, string name, string value)
        {
            for (int i=0;i<form.Count;i++)
            {
                FormEditorNode child = new FormEditorNode();
                HtmlTagBaseList controlArray = (HtmlTagBaseList)((DictionaryEntry)form[i]).Value;
                int controlIndex = 0;

                #region inner loop
                foreach (HtmlTagBase tag in controlArray)
                {
                    // Input tags
                    if ( (tag is HtmlInputTag) && (tagName.ToLower() == "input") )
                    {
                        HtmlInputTag input=(HtmlInputTag)tag;
                        if ( input.Name == name )
                        {
                            input.Value = value;
                            return;
                        }
                    }

                    // Textarea tags
                    if ( (tag is HtmlTextAreaTag) && (tagName.ToLower()=="textarea") )
                    {
                        HtmlTextAreaTag textarea=(HtmlTextAreaTag)tag;

                        if ( textarea.Name == name )
                        {
                            textarea.Value = value;
                            return;
                        }
                    }

                    controlIndex++;
                }
                #endregion
            }
        }
        /// <summary>
        /// Adds a PostSesionRequest to a recording session.
        /// </summary>
        /// <param name="url"> The requested url.</param>
        /// <param name="postData"> The post data in bytes.</param>
        /// <param name="form"> The post form.</param>
        /// <param name="cookies"> The current cookies.</param>
        private void AddSessionPost(string url, string postData, HtmlFormTag form, CookieCollection cookies)
        {
            if ( IsRecording )
            {
                PostSessionRequest postSessionRequest = new PostSessionRequest();
                postSessionRequest.PostData = postData;
                if ( form != null )
                {
                    postSessionRequest.Form = form.CloneTag();
                }
                postSessionRequest.RequestCookies = cookies;
                postSessionRequest.Url = new Uri(url);
                postSessionRequest.RequestHttpSettings = this.ClientProperties.Clone();

                this.CurrentSessionRecording.SessionRequests.Add(postSessionRequest);
            }
        }
 /// <summary>
 /// Applies the test to a form.
 /// </summary>
 /// <param name="test"> The test to apply.</param>
 /// <param name="formTag"> The form.</param>
 /// <returns> A form with the new values.</returns>
 protected HtmlFormTag ApplyTestToForm(Test test, HtmlFormTag formTag)
 {
     UnitTester tester = new UnitTester(test.Arguments);
     return tester.BuildUnitTestForm(test.TestType, formTag);
 }
 public void Add(string key, HtmlFormTag value)
 {
     innerHash.Add (key, value);
 }
        /// <summary>
        /// Upload the file infos.
        /// </summary>
        /// <param name="formTag"> The form tag to get the UploadFileInfo items.</param>
        /// <returns> An UploadFileInfo array.</returns>
        public static UploadFileInfo[] GetUploadFiles(HtmlFormTag formTag)
        {
            ArrayList list = new ArrayList();
            foreach ( HtmlTagBaseList tagBaseList in formTag.AllValues )
            {
                foreach ( HtmlTagBase tag in tagBaseList )
                {
                    if ( tag is HtmlInputTag )
                    {
                        HtmlInputTag input = (HtmlInputTag)tag;

                        if ( input.Type == HtmlInputType.File )
                        {
                            UploadFileInfo fileInfo = new UploadFileInfo();

                            // get file name
                            fileInfo.FormFieldName = input.Name;
                            if ( input.Value == null )
                            {
                                input.Value = string.Empty;
                            }

                            fileInfo.FileName = input.Value.Trim('"').Trim('\0').Trim();

                            if ( fileInfo.FileName.Length > 0 )
                            {
                                fileInfo.ContentType = AppLocation.GetMIMEType(fileInfo.FileName);
                                list.Add(fileInfo);
                            }
                        }
                    }
                }
            }

            return (UploadFileInfo[])list.ToArray(typeof(UploadFileInfo));
        }
        /// <summary>
        /// Converts a HTMLFormElementClass to a GB HtmlFormTag.
        /// </summary>
        /// <param name="formElement"> The HTMLFormElementClass to convert.</param>
        /// <param name="currentUri"> The current uri.</param>
        /// <returns> A HtmlFormTag.</returns>
        public HtmlFormTag ConvertToHtmlFormTag(HTMLFormElementClass formElement, Uri currentUri)
        {
            IHTMLElement el = (IHTMLElement)formElement.elements;
            ArrayList elements = new ArrayList();
            // Converts the element tag to an array list
            elements = ParseTags(elements,(IHTMLElementCollection)el.children);

            HtmlFormTag formTag = new HtmlFormTag();

            #region Set Form Properties
            if ( formElement.action == null )
            {
                formTag.Action = currentUri.Scheme + "://" + currentUri.Authority + currentUri.AbsolutePath;
            }
            else
            {
                formTag.Action = formElement.action;
            }

            formTag.Class = formElement.className;

            if ( formElement.method == null )
            {
                formTag.Method = "GET";
            } else {
                formTag.Method = formElement.method;
            }
            if ( formElement.encoding == null )
            {
                formTag.Enctype = "";
            }
            else
            {
                formTag.Enctype = formElement.encoding;
            }

            // formTag.FormIndex = formElement.
            formTag.Id = formElement.id;

            if ( formElement.name != null )
            {
                formTag.Name = formElement.name;
            }
            else
            {
                if ( formElement.id != null )
                {
                    formTag.Name = formElement.id;
                }
                else
                {
                    formTag.Name = formElement.uniqueID;
                    formTag.Id = formElement.uniqueID;
                }
            }
            formTag.OnSubmit = string.Empty;
            formTag.Style = string.Empty;
            formTag.Title = formElement.title;
            #endregion
            #region Add Tags
            foreach (object obj in elements)
            {
                // The last check is the most significant type

                #region Button Element
                if (obj is mshtml.HTMLInputButtonElementClass)
                {
                    HtmlButtonTag button = CreateHtmlButtonTag((HTMLInputButtonElementClass)obj);

                    if ( formTag.ContainsKey(button.Name) )
                    {
                        // just add the value
                        HtmlTagBaseList array = ((HtmlTagBaseList)formTag[button.Name]);
                        array.Add(button);
                    }
                    else
                    {
                        HtmlTagBaseList list = new HtmlTagBaseList();
                        list.Add(button);
                        formTag.Add(button.Name,list);
                    }
                    continue;
                }
                #endregion

                #region Select Element
                if (obj is mshtml.HTMLSelectElementClass)
                {
                    HtmlSelectTag select = CreateHtmlSelectTag((HTMLSelectElementClass)obj);

                    if ( formTag.ContainsKey(select.Name) )
                    {
                        // just add the value
                        HtmlTagBaseList array = ((HtmlTagBaseList)formTag[select.Name]);
                        array.Add(select);
                    }
                    else
                    {
                        HtmlTagBaseList list = new HtmlTagBaseList();
                        list.Add(select);
                        formTag.Add(select.Name,list);
                    }
                    continue;
                }
                #endregion

                #region Textarea Element
                if (obj is mshtml.HTMLTextAreaElementClass)
                {
                    HtmlTextAreaTag textarea=CreateHtmlTextAreaTag((HTMLTextAreaElementClass)obj);
                    if ( formTag.ContainsKey(textarea.Name) )
                    {
                        // just add the value
                        HtmlTagBaseList array = ((HtmlTagBaseList)formTag[textarea.Name]);
                        array.Add(textarea);
                    }
                    else
                    {
                        HtmlTagBaseList list = new HtmlTagBaseList();
                        list.Add(textarea);
                        formTag.Add(textarea.Name,list);
                    }
                    continue;
                }
                #endregion

                #region Input Element
                if (obj is mshtml.HTMLInputElementClass)
                {
                    HtmlInputTag input = CreateHtmlInputTag((HTMLInputElementClass)obj);
                    if ( formTag.ContainsKey(input.Name) )
                    {
                        // just add the value
                        HtmlTagBaseList array = ((HtmlTagBaseList)formTag[input.Name]);
                        array.Add(input);
                    }
                    else
                    {
                        HtmlTagBaseList list = new HtmlTagBaseList();
                        list.Add(input);
                        formTag.Add(input.Name,list);
                    }
                    continue;
                }
                #endregion

            }
            #endregion

            return formTag;
        }
        /// <summary>
        /// Loads the request.
        /// </summary>
        /// <param name="index"> The current request index.</param>
        /// <param name="scripting"> The scripting application.</param>
        /// <param name="request"> The current web request.</param>
        public override void LoadRequest(int index, ScriptingApplication scripting ,Ecyware.GreenBlue.Engine.Scripting.WebRequest request)
        {
            base.LoadRequest (index, scripting, request);

            try
            {
                //_httpRequestType = request.RequestType;
                _currentRequestUri = new Uri(request.Url);

                if ( request.Form.Elements.Length > 0 )
                {
                    HtmlFormTagCollection forms = new HtmlFormTagCollection(1);
                    _form = request.Form.WriteHtmlFormTag();
                    forms.Add(request.Form.Name, _form);

                    // Load tree
                    LoadFormTree(forms);
                }
                else
                {
                    DisplayNoDataMessage();
                }
            }
            catch ( Exception ex )
            {
                MessageBox.Show(ex.ToString(), AppLocation.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Updates the url to navigate for a GET request.
        /// </summary>
        /// <param name="formTag"> The HtmlFormTag type.</param>
        /// <param name="url"> The Url as a string.</param>
        /// <param name="multipartPost"> Is a multipart/form-data post. This flags skips the input=file.</param>
        /// <returns> The current or updated url.</returns>
        private string UpdateUrl(HtmlFormTag formTag, string url, bool multipartPost)
        {
            if ( multipartPost )
            {
                foreach ( HtmlTagBaseList tagBaseList in formTag )
                {
                    for (int i=0;i<tagBaseList.Count;i++)
                    {
                        if ( tagBaseList[i] is HtmlInputTag )
                        {
                            HtmlInputTag input = (HtmlInputTag)tagBaseList[i];
                            if ( input.Type == HtmlInputType.File )
                            {
                                tagBaseList.RemoveAt(i);
                            }
                        }
                    }
                }
            }

            string urlToNavigate = url;
            if ( formTag != null )
            {
                ArrayList values = parser.GetArrayList(formTag);
                if ( (new Uri(url)).Query.Length == 0 )
                {
                    urlToNavigate = GetForm.AppendToUri(url, values);
                }
            }

            return urlToNavigate.TrimEnd('?');
        }
        /// <summary>
        /// Creates a form from a query string.
        /// </summary>
        /// <param name="url"> The complete url.</param>
        /// <returns> A HtmlFormTag.</returns>
        private HtmlFormTag CreateFormFromQueryString(Uri url)
        {
            string action = url.Scheme + "://" + url.Host + url.AbsolutePath;
            FormConverter converter = new FormConverter();
            PostDataCollection postData = converter.GetPostDataCollection(url.Query.TrimStart('?'));

            HtmlFormTag formTag = new HtmlFormTag();
            formTag.Action = action;
            formTag.Name = "docform";
            formTag.Method = base.WebRequest.RequestType.ToString();

            foreach ( string key in postData.Keys )
            {
                ArrayList items = postData[key];

                HtmlTagBaseList list = new HtmlTagBaseList();
                formTag.Add(key, list);
                foreach ( string value in items )
                {
                    HtmlInputTag hiddenField = new HtmlInputTag();
                    hiddenField.Type = HtmlInputType.Hidden;
                    hiddenField.Name = key;
                    hiddenField.Value = value.Trim().TrimEnd('\0');
                    list.Add(hiddenField);
                }
            }

            return formTag;
        }
 /// <summary>
 /// Creates a new UnitTestItem.
 /// </summary>
 /// <param name="form"> The form that the tests will be applied.</param>
 /// <param name="tests"> The test collection.</param>
 public UnitTestItem(HtmlFormTag form, TestCollection tests)
 {
     this.Form = form;
     this.Tests = tests;
 }
        /// <summary>
        /// Loads the forms into a HtmlFormTagCollection.
        /// </summary>
        /// <param name="html"> The parsed HTML content.</param>
        /// <returns> Returns a HtmlFormTagCollection with the forms contained in the HTML.</returns>
        public HtmlFormTagCollection LoadForm(string html)
        {
            HtmlFormTagCollection forms;
            try
            {
                forms = new HtmlFormTagCollection();
                XPathDocument doc;

                if ( HasForms(html) )
                {
                    doc = this.DocumentCache;

                    XPathNavigator nav = doc.CreateNavigator();
                    #region "Set namespaces"
                    if ( this.NamespaceCache == null)
                    {
                        //create prefix<->namespace mappings (if any)
                        XmlNamespaceManager nsMgr = new XmlNamespaceManager(nav.NameTable);

                        // resolve namespaces before loading document
                        Hashtable values = ResolveNamespaces(new XmlTextReader(new StringReader(html)));

                        foreach (DictionaryEntry de in values)
                        {
                            nsMgr.AddNamespace((string)de.Key,(string)de.Value);
                        }

                        this.NamespaceCache = nsMgr;
                    }
                    #endregion
                    int i=0;
                    XPathExpression expr = nav.Compile("//form");
                    expr.SetContext(this.NamespaceCache);
                    // select all form elements
                    XPathNodeIterator nodes = nav.Select(expr);

                    #region Build Form Tag
                    while (nodes.MoveNext())
                    {
                        HtmlFormTag f = new HtmlFormTag();

                        f.FormIndex = i;
                        f.Id=nodes.Current.GetAttribute("id",nodes.Current.NamespaceURI);
                        f.Style=nodes.Current.GetAttribute("style",nodes.Current.NamespaceURI);
                        f.Enctype=nodes.Current.GetAttribute("enctype",nodes.Current.NamespaceURI);
                        f.Class=nodes.Current.GetAttribute("class",nodes.Current.NamespaceURI);
                        f.Name=nodes.Current.GetAttribute("name",nodes.Current.NamespaceURI);
                        f.Action=nodes.Current.GetAttribute("action",nodes.Current.NamespaceURI);
                        f.Method=nodes.Current.GetAttribute("method",nodes.Current.NamespaceURI);
                        f.Id=nodes.Current.GetAttribute("id",nodes.Current.NamespaceURI);
                        f.OnSubmit=nodes.Current.GetAttribute("onsubmit",nodes.Current.NamespaceURI);

                        if (f.Action.Length == 0 )
                        {
                            // add dummy action
                            f.Action = "dummyAction";
                        }

                        if ( f.Method.Length==0 )
                        {
                            f.Method="get";
                        }

                        if ( f.Id!=String.Empty )
                        {
                            f.Name = f.Id;
                        }
                        if ( forms.ContainsKey(f.Name) )
                        {
                            forms.Add("_" + f.Name,f);
                        }
                        else
                        {
                            if ( f.Name!=String.Empty )
                            {
                                forms.Add(f.Name,f);
                            }
                            if (f.Id==String.Empty && f.Name == String.Empty )
                            {
                                f.Id = "Form " + i;
                                f.Name = "Form " + i;
                                forms.Add(f.Name,f);
                            }
                        }

                        #region " Loop thru descendants from Form"
                        // Select descendants, childs
                        XPathNodeIterator items = nodes.Current.SelectDescendants(XPathNodeType.Element,true);

                        int autoId = 0;

                        while ( items.MoveNext() )
                        {

                            // if exists, add to same HtmlTagBaseList type
                            // else create new
                            string name = items.Current.GetAttribute("name",items.Current.NamespaceURI);
                            string id = items.Current.GetAttribute("id",items.Current.NamespaceURI);
                            string onclick = items.Current.GetAttribute("onclick",items.Current.NamespaceURI);

                            if ( onclick == String.Empty )
                            {
                                onclick = items.Current.GetAttribute("onClick",items.Current.NamespaceURI);
                            }

                            // prioritize name use
                            // else use id
                            if ( name == String.Empty )
                            {
                                name = id;
                                // if no id, generate one
                                if ( name == String.Empty )
                                {
                                    id = autoId.ToString();
                                    name = id;
                                }
                            }

                            switch ( items.Current.Name )
                            {
                                case "div":
                                    if ( onclick != String.Empty )
                                    {
                                        AddCommonTag(f,onclick,id,name);
                                    }
                                    break;
                                case "span":
                                    if ( onclick != String.Empty )
                                    {
                                        AddCommonTag(f,onclick,id,name);
                                    }
                                    break;
                                case "a":
                                    HtmlALinkTag a = CreateLinkTag(items.Current);
                                    if ( f.ContainsKey(name) )
                                    {
                                        // just add the value
                                        HtmlTagBaseList array = ((HtmlTagBaseList)f[name]);
                                        array.Add(a);
                                    }
                                    else
                                    {
                                        HtmlTagBaseList list = new HtmlTagBaseList();
                                        list.Add(a);
                                        f.Add("a" + autoId.ToString(),list);
                                    }
                                    break;
                                case "input":
                                    // if exists, add to same HtmlTagBaseList type
                                    // else create new
                                    // verify by name and type
                                    HtmlInputTag input = FillInputTag(items.Current);
                                    input.Name = name;

                                    if ( f.ContainsKey(name) )
                                    {
                                        // just add the value
                                        HtmlTagBaseList array = ((HtmlTagBaseList)f[name]);
                                        array.Add(input);
                                    }
                                    else
                                    {
                                        HtmlTagBaseList list = new HtmlTagBaseList();
                                        //HtmlInputTag input = FillInputTag(items.Current);
                                        list.Add(input);
                                        f.Add(input.Name,list);
                                    }
                                    break;
                                case "button":
                                    // if exists, add to same HtmlTagBaseList type
                                    // else create new
                                    // verify by name
                                    HtmlButtonTag button = FillButtonTag(items.Current);
                                    button.Name = name;

                                    if ( f.ContainsKey(name) )
                                    {
                                        // just add the value
                                        HtmlTagBaseList array = ((HtmlTagBaseList)f[name]);
                                        //HtmlButtonTag button = FillButtonTag(items.Current);
                                        array.Add(button);
                                    }
                                    else
                                    {
                                        HtmlTagBaseList buttonList = new HtmlTagBaseList();
                                        buttonList.Add(button);
                                        f.Add(button.Name,buttonList);
                                    }

                                    break;
                                case "select":
                                    // if exists, add to same HtmlTagBaseList type
                                    // else create new
                                    // verify by name
                                    HtmlSelectTag select = CreateSelectTag(items.Current);
                                    select.Name = name;

                                    if ( f.ContainsKey(name) )
                                    {
                                        HtmlTagBaseList array = ((HtmlTagBaseList)f[name]);
                                        array.Add(select);
                                    }
                                    else
                                    {
                                        HtmlTagBaseList selectList = new HtmlTagBaseList();
                                        //HtmlSelectTag select = FillSelectTag(items.Current);
                                        selectList.Add(select);
                                        f.Add(select.Name,selectList);
                                    }
                                    break;
                                case "textarea":
                                    // if exists, add to same HtmlTagBaseList type
                                    // else create new
                                    // verify by name
                                    HtmlTextAreaTag textarea = FillTextAreaTag(items.Current);
                                    textarea.Name = name;

                                    if ( f.ContainsKey(name) )
                                    {
                                        HtmlTagBaseList array = ((HtmlTagBaseList)f[name]);
                                        //HtmlTextAreaTag textarea = FillTextAreaTag(items.Current);
                                        array.Add(textarea);
                                    }
                                    else
                                    {
                                        HtmlTagBaseList textAreaList = new HtmlTagBaseList();
                                        textAreaList.Add(textarea);
                                        f.Add(textarea.Name,textAreaList);
                                    }
                                    break;
                            }

                            // increase
                            autoId++;
                        }
                        i++;
                        #endregion
                    }
                    #endregion
                }
            }
            catch
            {
                throw;
            }

            return forms;
        }