public override void ApplyTransform(WebRequest request, WebResponse response)
        {
            //base.ApplyTransform(request, response);
            string httpBody = response.HttpBody;

            QueryCommandAction[] queryActions = this.QueryCommandActions;

            bool sumMatches = true;

            for (int i = 0; i < queryActions.Length; i++)
            {
                QueryCommandAction action = queryActions[i];

                if ( (action.Value is RegExQueryCommand) )
                {
                    string regex = ((RegExQueryCommand)action.Value).Expression;

                    // Apply regular expression
                    sumMatches &= CheckMatches(httpBody, regex);
                }
            }

            // if matches, send message
            if ( sumMatches == _matchType )
            {
                if (this.Transport != null)
                {
                    this.Transport.Send(new string[] {httpBody});
                }
            }
        }
        public override void ApplyTransform(WebRequest request, WebResponse response)
        {
            base.ApplyTransform (request, response);

            if ( request.XmlEnvelope != null )
            {
                XmlDocument document = new XmlDocument();
                XmlNode n = document.ImportNode(request.XmlEnvelope,true);
                document.AppendChild(n);

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable);
                nsmgr = HtmlParser.ResolveNamespaces(new StringReader(request.XmlEnvelope.OuterXml),nsmgr);

                foreach ( XmlElementField field in XmlElementFields )
                {
                    // Get Xml Element Location
                    XmlNode selectedNode = document.SelectSingleNode(field.Location, nsmgr);

                    // Generate TransformValue
                    string result = Convert.ToString(field.TransformValue.GetValue(response));

                    // Set value
                    if ( selectedNode.NodeType == XmlNodeType.Element )
                    {
                        selectedNode.InnerText = result;
                    }
                    if ( selectedNode.NodeType == XmlNodeType.Attribute )
                    {
                        selectedNode.Value = result;
                    }
                }

                if ( request.RequestType == HttpRequestType.PUT )
                {
                    ((PutWebRequest)request).PostData = document.DocumentElement.OuterXml;
                }
                if ( request.RequestType == HttpRequestType.POST )
                {
                    ((PostWebRequest)request).PostData = document.DocumentElement.OuterXml;
                }
                if ( request.RequestType == HttpRequestType.SOAPHTTP )
                {
                    request.XmlEnvelope = document.DocumentElement;
                }
            }
        }
 public void ApplySecurityTransformAction(WebRequest request, WebResponse response)
 {
     switch ( this.RequestStateDataType )
     {
         case  RequestStateDataType.Form:
             ApplyFormTest(request);
             break;
         case  RequestStateDataType.Cookies:
             //ApplyCookiesTest();
             break;
         case  RequestStateDataType.PostData:
             //ApplyPostDataTest();
             break;
         case  RequestStateDataType.Url:
             //ApplyUrlTest();
             break;
     }
 }
        /// <summary>
        /// Applies the transform to the request.
        /// </summary>		
        /// <param name="request"> The web request.</param>
        /// <param name="response"> The web response.</param>
        public override void ApplyTransform(WebRequest request, WebResponse response)
        {
            base.ApplyTransform (request, response);

            // Apply TransformAction
            object value = _updateTransformAction.ApplyTransformAction(response);

            switch ( this.RequestFieldName )
            {
                case "ChangeUrlHostname":
                    string hostname =  Convert.ToString(value);
                    Uri ur = new Uri(request.Url);
                    Uri temp = new Uri(ur.Scheme + "://" + hostname + "/");
                    Uri temp1 = new Uri(temp, ur.AbsolutePath);
                    request.Url = temp1.ToString();
                    break;
                case "ChangeUrlPath":
                    string path =  Convert.ToString(value).TrimStart('/');
                    Uri _ur = new Uri(request.Url);
                    Uri _temp = new Uri(_ur.Scheme + "://" + _ur.Host + "/" + path);
                    request.Url = _temp.ToString();
                    break;
                case "Username":
                    request.RequestHttpSettings.UseBasicAuthentication = true;
                    request.RequestHttpSettings.Username = Convert.ToString(value);
                    break;
                case "Password":
                    request.RequestHttpSettings.UseBasicAuthentication = true;
                    request.RequestHttpSettings.Password = Convert.ToString(value);
                    break;
                default:
                    Type requestType = request.GetType();
                    PropertyInfo pi = requestType.GetProperty(RequestFieldName);

                    if ( pi != null )
                    {
                        pi.SetValue(request,value,null);
                    }

                    break;
            }
        }
        /// <summary>
        /// Applies the transform to the request.
        /// </summary>
        /// <param name="request"> The web request.</param>
        /// <param name="response"> The web response.</param>
        public override void ApplyTransform(WebRequest request, WebResponse response)
        {
            base.ApplyTransform (request, response);

            Hashtable cookieTable = new Hashtable();
            foreach ( Ecyware.GreenBlue.Engine.Scripting.Cookie cookie in request.Cookies )
            {
                cookieTable.Add(cookie.Name, cookie);
            }

            try
            {
                int i = 0;
                foreach ( TransformAction transformAction in _actions )
                {
                    // Add Cookie
                    if ( transformAction is AddTransformAction )
                    {
                        AddTransformAction add = (AddTransformAction)transformAction;

                        object result = add.Value.GetValue(response);

                        if ( result != null )
                        {
                            // add cookie
                            Cookie ck = GetCookie(add.Name);
                            ck.Value = result.ToString();

                            if ( !cookieTable.ContainsKey(add.Name) )
                            {
                                cookieTable.Add(add.Name, ck);
                            }
                        }
                    }

                    // Update Cookie
                    if ( transformAction is UpdateTransformAction )
                    {
                        UpdateTransformAction update = (UpdateTransformAction)transformAction;

                        object result = update.Value.GetValue(response);

                        if ( cookieTable[update.Name] != null )
                        {
                            // Update cookie
                            Cookie ck = (Cookie)cookieTable[update.Name];
                            ck.Value = result.ToString();
                            cookieTable[update.Name] = ck;
                        }
                    }

                    // Remove Cookie
                    if ( transformAction is RemoveTransformAction )
                    {
                        RemoveTransformAction remove = (RemoveTransformAction)transformAction;

                        if ( cookieTable.ContainsKey(remove.Name) )
                        {
                            cookieTable.Remove(remove.Name);
                        }
                    }

                    i++;
                }

                ArrayList cks = new ArrayList();
                foreach ( DictionaryEntry de in cookieTable )
                {
                    cks.Add(de.Value);
                }

                // update request
                request.Cookies = (Ecyware.GreenBlue.Engine.Scripting.Cookie[])cks.ToArray(typeof(Ecyware.GreenBlue.Engine.Scripting.Cookie));
            }
            catch ( Exception ex )
            {
                ExceptionManager.Publish(ex);
            }
        }
        /// <summary>
        /// Load the form values.
        /// </summary>
        /// <param name="request"> The current web request.</param>
        public virtual void LoadFormValues(WebRequest request)
        {
            ArrayList list = new ArrayList();

            foreach ( HtmlTagListXml tagList in request.Form.Elements )
            {
                list.Add(tagList.Name);
            }

            htmlValueDialog.LoadForm(list);
        }
 protected virtual void ApplyCustomTest(WebRequest request, SecurityTransformAction action)
 {
 }
        /// <summary>
        /// Applies the transform to the request.
        /// </summary>
        /// <param name="request"> The web request.</param>
        /// <param name="response"> The web response.</param>
        public override void ApplyTransform(WebRequest request, WebResponse response)
        {
            base.ApplyTransform (request, response);

            try
            {
                System.Net.WebHeaderCollection headers = new System.Net.WebHeaderCollection();
                WebHeader.FillWebHeaderCollection(headers,request.RequestHttpSettings.AdditionalHeaders);

                foreach ( TransformAction transformAction in _actions )
                {
                    // Add Header
                    if ( transformAction is AddTransformAction )
                    {
                        AddTransformAction add = (AddTransformAction)transformAction;

                        object result = add.Value.GetValue(response);

                        if ( headers[add.Name] == null )
                        {
                            headers.Add(add.Name, Convert.ToString(result));
                        }
                    }

                    // Update Header
                    if ( transformAction is UpdateTransformAction )
                    {
                        UpdateTransformAction update = (UpdateTransformAction)transformAction;

                        object result = update.Value.GetValue(response);
                        SetHeaderValue(request, update.Name, Convert.ToString(result), headers);
                    }

                    // Remove Header
                    if ( transformAction is RemoveTransformAction )
                    {
                        RemoveTransformAction remove = (RemoveTransformAction)transformAction;

                        if ( headers[remove.Name] != null )
                        {
                            headers.Remove(remove.Name);
                        }
                    }
                }

                // update request
                request.RequestHttpSettings.AdditionalHeaders = WebHeader.ToArray(headers);
            }
            catch ( Exception ex )
            {
                ExceptionManager.Publish(ex);
            }
        }
 /// <summary>
 /// Updates the xml element.
 /// </summary>
 /// <param name="request"> The current web request.</param>
 private void UpdateXmlElement(WebRequest request)
 {
     if ( request.RequestType == HttpRequestType.POST )
     {
         request.UpdateXmlEnvelope(((PostWebRequest)request).PostData);
     }
     if ( request.RequestType == HttpRequestType.PUT )
     {
         request.UpdateXmlEnvelope(((PutWebRequest)request).PostData);
     }
 }
 /// <summary>
 /// Applies the current transform to a web request.
 /// </summary>
 public virtual void ApplyTransform(WebRequest request, WebResponse response)
 {
     ValidateLicense();
 }
 /// <summary>
 /// Inserts a WebRequest.
 /// </summary>
 /// <param name="index"> The index to insert at.</param>
 /// <param name="request"> The request to add.</param>
 public void InsertWebRequest(int index, WebRequest request)
 {
     _list.Insert(index, request);
 }
        public override void ApplyTransform(WebRequest request, WebResponse response)
        {
            // base.ApplyTransform (request, response);
            string result = response.HttpBody;

            try
            {
                // Apply transform value and append each value.
                foreach ( QueryCommandAction action in this.QueryCommandActions )
                {
                    if (( action.Value is XPathQueryCommand ) || ( action.Value is RegExQueryCommand ))
                    {
                        result = action.ApplyQueryCommandAction(result);
                    }
                }

                if ( Transport != null )
                {
                    // Send message to transport.
                    Transport.Send(new string[] {result});
                }

            }
            catch ( Exception ex )
            {
                throw ex;
            }
        }
 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>
        /// Applies the form test.
        /// </summary>
        /// <param name="request"> The WebRequest type.</param>
        protected virtual void ApplyFormTest(WebRequest request)
        {
            if ( request.Form != null )
            {
                // Create HtmlFormTag
                HtmlFormTag formTag = request.Form.WriteHtmlFormTag();

                // Generate value.
                string testValue = this.TestValue.Value;

                FillFormField(request, formTag, testValue);

                // Update request
                request.Form.ReadHtmlFormTag(formTag);
            }
        }
 /// <summary>
 /// Appens the request headers.
 /// </summary>
 /// <param name="text"> The StringBuilder.</param>
 /// <param name="request"> The web request.</param>
 public static void AppendRequestHeaders(StringBuilder text, WebRequest request)
 {
     text.AppendFormat("{0}: {1}\r\n",
         "Accept",
         request.RequestHttpSettings.Accept);
     text.AppendFormat("{0}: {1}\r\n",
         "Content Length",
         request.RequestHttpSettings.ContentLength);
     text.AppendFormat("{0}: {1}\r\n",
         "Content Type",
         request.RequestHttpSettings.ContentType);
     text.AppendFormat("{0}: {1}\r\n",
         "If Modified Since",
         request.RequestHttpSettings.IfModifiedSince);
     text.AppendFormat("{0}: {1}\r\n",
         "Keep Alive",
         request.RequestHttpSettings.KeepAlive);
     text.AppendFormat("{0}: {1}\r\n",
         "Referer",
         request.RequestHttpSettings.Referer);
     text.AppendFormat("{0}: {1}\r\n",
         "Send Chunked",
         request.RequestHttpSettings.SendChunked);
     text.AppendFormat("{0}: {1}\r\n",
         "Transfer Encoding",
         request.RequestHttpSettings.TransferEncoding);
     text.AppendFormat("{0}: {1}\r\n",
         "User Agent",
         request.RequestHttpSettings.UserAgent);
     foreach ( WebHeader header in request.RequestHttpSettings.AdditionalHeaders )
     {
         text.AppendFormat("{0}: {1}\r\n", header.Name, header.Value);
     }
 }
 /// <summary>
 /// Adds a WebRequest.
 /// </summary>
 /// <param name="request"> The request to add.</param>
 public void AddWebRequest(WebRequest request)
 {
     _list.Add(request);
 }
 /// <summary>
 /// Creates a HttpRequestContext.
 /// </summary>
 /// <param name="request"></param>
 /// <param name="requestIndex"></param>
 /// <param name="decodeUrl"></param>
 public HttpRequestResponseContext(WebRequest request, int requestIndex, bool decodeUrl)
 {
     _request = request;
     _decodeUrl = decodeUrl;
     _index = requestIndex;
 }
 /// <summary>
 /// Updates the web request.
 /// </summary>
 /// <param name="index"> The request index.</param>
 /// <param name="request"> The web request type.</param>
 public void UpdateWebRequest(int index, WebRequest request)
 {
     if ( index > -1 )
     {
         if ( request != null )
         {
             // Update request index.
             _list[index] = request;
         }
     }
 }
        /// <summary>
        /// Add request progress.
        /// </summary>
        /// <param name="request"> The web request.</param>
        private void AddRequestProgress(WebRequest request)
        {
            ListViewItem item = new ListViewItem();

            item.UseItemStyleForSubItems = true;

            // Main Request
            item.ImageIndex = 9;
            item.Text = request.ID;
            item.SubItems.Add(request.RequestType.ToString());
            item.SubItems.Add(request.Url);
            item.ForeColor = Color.Green;
            lvRequests.Items.Add(item);

            // Add Transform Info
            foreach ( WebTransform transform in request.InputTransforms )
            {
                ListViewItem subitem = new ListViewItem();
                subitem.ImageIndex = 8;
                subitem.Text = "";
                subitem.SubItems.Add("");
                subitem.SubItems.Add("Input Transform " + transform.Name + " applied.");
                subitem.ForeColor = Color.LightSeaGreen;

                lvRequests.Items.Add(subitem);
            }

            lvRequests.Refresh();
        }
 /// <summary>
 /// Updates the current postdata.
 /// </summary>
 /// <param name="request"></param>
 private void UpdatePostData(WebRequest request)
 {
     if ( request.RequestType == HttpRequestType.POST )
     {
         ((PostWebRequest)request).PostData = this.EditorText;
     }
     if ( request.RequestType == HttpRequestType.PUT )
     {
         ((PutWebRequest)request).PostData = this.EditorText;
     }
     request.UpdateXmlEnvelope(this.EditorText);
 }
        /// <summary>
        /// Adds a response node to the tree.
        /// </summary>
        /// <param name="request"> The web request.</param>
        private void AddResponseNode(WebRequest request)
        {
            TreeNode parent = tvResponses.Nodes[0];

            TreeNode responseNode = new TreeNode(request.WebResponse.ResponseUri);
            responseNode.ImageIndex = 9;
            responseNode.SelectedImageIndex = 9;
            responseNode.Tag = request;

            responseNode.Nodes.Add("Request Information");
            responseNode.Nodes[0].ImageIndex = 1;
            responseNode.Nodes[0].SelectedImageIndex = 1;
            responseNode.Nodes.Add("Response Headers");
            responseNode.Nodes[1].ImageIndex = 1;
            responseNode.Nodes[1].SelectedImageIndex = 1;
            responseNode.Nodes.Add("Response Cookies");
            responseNode.Nodes[2].ImageIndex = 1;
            responseNode.Nodes[2].SelectedImageIndex = 1;
            responseNode.Nodes.Add("HTML Body");
            responseNode.Nodes[3].ImageIndex = 1;
            responseNode.Nodes[3].SelectedImageIndex = 1;
            parent.Nodes.Add(responseNode);
        }
        public override void ApplyTransform(WebRequest request, WebResponse response)
        {
            base.ApplyTransform (request, response);

            if ( request.Form != null )
            {
                HtmlFormTag formTag = request.Form.WriteHtmlFormTag();

                #region Fill Form
                foreach ( FormField formField in FormFields )
                {
                    string result = Convert.ToString(formField.TransformValue.GetValue(response));

                    HtmlTagBaseList tagList = formTag[formField.FieldName];
                    HtmlTagBase tagBase = tagList[formField.Index];

                    if ( tagBase is HtmlInputTag )
                    {
                        ((HtmlInputTag)tagBase).Value = result;
                    }
                    if ( tagBase is HtmlButtonTag)
                    {
                        HtmlButtonTag button = (HtmlButtonTag)tagBase;
                        button.Value = result;
                    }
                    if ( tagBase is HtmlSelectTag )
                    {
                        HtmlSelectTag select = (HtmlSelectTag)tagBase;
                        if  ( select.Multiple )
                        {
                            foreach ( HtmlOptionTag opt in select.Options )
                            {
                                //HtmlOptionTag opt = tag;
                                if ( opt.Selected )
                                {
                                    opt.Value = result;
                                }
                            }
                        }
                        else
                        {
                            select.Value = result;
                        }
                    }
                    if  ( tagBase is HtmlTextAreaTag )
                    {
                        ((HtmlTextAreaTag)tagBase).Value = result;
                    }
                }
                #endregion

                // Update request
                request.Form.ReadHtmlFormTag(formTag);
            }
        }
 /// <summary>
 /// Loads a WebRequest.
 /// </summary>
 /// <param name="request"> Loads a WebRequest.</param>
 public virtual void LoadRequest(int requestIndex, ScriptingApplication sessionScripting, WebRequest request)
 {
     _requestIndex = requestIndex;
     _scripting = sessionScripting;
     _request = request;
 }
        /// <summary>
        /// Gets the value from the web response.
        /// </summary>
        /// <param name="request"> The request name</param>
        /// <param name="name"> The header name.</param>
        /// <param name="value"> The header value.</param>
        /// <param name="headers"> The headers.</param>
        /// <returns> An object.</returns>
        public void SetHeaderValue(WebRequest request, string name, string value, System.Net.WebHeaderCollection headers)
        {
            object result = string.Empty;

            switch ( name )
            {
                case "Accept":
                    request.RequestHttpSettings.Accept = value;
                    break;
                case "Content Length":
                    request.RequestHttpSettings.ContentLength = Convert.ToInt32(value);
                    break;
                case "Content Type":
                    request.RequestHttpSettings.ContentType = value;
                    break;
                case "If Modified Since":
                    request.RequestHttpSettings.IfModifiedSince = DateTime.Parse(value);
                    break;
                case "Keep Alive":
                    if ( value.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "true" )
                    {
                        request.RequestHttpSettings.KeepAlive = true;
                    }
                    else
                    {
                        request.RequestHttpSettings.KeepAlive = false;
                    }
                    break;
                case "Media Type":
                    request.RequestHttpSettings.MediaType = value;
                    break;
                case "Referer":
                    request.RequestHttpSettings.Referer = value;
                    break;
                case "Send Chunked":
                    if ( value.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "true" )
                    {
                        request.RequestHttpSettings.SendChunked = true;
                    }
                    else
                    {
                        request.RequestHttpSettings.SendChunked = false;
                    }
                    break;
                case "Transfer Encoding":
                    request.RequestHttpSettings.TransferEncoding = value;
                    break;
                case "User Agent":
                    request.RequestHttpSettings.UserAgent = value;
                    break;
                default:
                    headers[name] = value;
                    break;
            }
        }
        /// <summary>
        /// Load the cookie names.
        /// </summary>
        /// <param name="request">  The current web request.</param>
        public virtual void LoadCookieNames(WebRequest request)
        {
            ArrayList list = new ArrayList();

            foreach ( Cookie cookie in request.Cookies )
            {
                list.Add(cookie.Name);
            }

            cookiesTransformDialog.LoadCookies(list);
        }