Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String adName   = Request.QueryString["ad"];
            String redirect = Request.QueryString["target"];

            if (adName == null | redirect == null)
            {
                redirect = "TestAds.aspx";
            }

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            String docPath             = @"~/App_Data/AdResponses.xml";

            doc.Load(Server.MapPath(docPath));
            System.Xml.XmlNode root   = doc.DocumentElement;
            System.Xml.XmlNode adNode =
                root.SelectSingleNode(
                    @"descendant::ad[@adname=""+adName + ""]");
            if (adNode != null)
            {
                int ctr =
                    int.Parse(adNode.Attributes["hitCount"].Value);
                ctr += 1;
                System.Xml.XmlNode newAdNode = adNode.CloneNode(false);
                newAdNode.Attributes["hitCount"].Value = ctr.ToString();
                root.ReplaceChild(newAdNode, adNode);
            }
            Response.Redirect(redirect);
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String adversitmentName = Request.QueryString["ad"];
            String redirectAspx     = Request.QueryString["target"];

            if (adversitmentName == null | redirectAspx == null)
            {
                redirectAspx = "ShoppingPage_WebForm.aspx";
            }
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            String path = @"~/App_Data/AdResponses1.xml";

            doc.Load(Server.MapPath(path));
            System.Xml.XmlNode root   = doc.DocumentElement;
            System.Xml.XmlNode adNode = root.SelectSingleNode(@"descendant::ad[@adname='" + adversitmentName + "']");
            if (adNode != null)
            {
                int count = int.Parse(adNode.Attributes["hitCount"].Value);
                count += 1;
                System.Xml.XmlNode newAdNode = adNode.CloneNode(false);
                newAdNode.Attributes["hitCount"].Value = count.ToString();
                root.ReplaceChild(newAdNode, adNode);
                doc.Save(Server.MapPath(path));
            }
            Response.Redirect(redirectAspx);
        }
Example #3
0
        private Configuration LoadWebConfig(string projectDir)
        {
            string webConfigFilePath = Path.Combine(projectDir, Constants.WebConfig);

            if (File.Exists(webConfigFilePath))
            {
                try
                {
                    XElement webConfigXml = XElement.Load(webConfigFilePath);
                    System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
                    xmlDocument.Load(webConfigFilePath);

                    // Comment out connection strings if type has a configProtectionProvider
                    // This can comment out connection strings that do not have "EncryptedData"
                    IEnumerable <XElement> encryptedConnectionStringElement =
                        from element in webConfigXml.Elements("connectionStrings")
                        where (string)element.Attribute("configProtectionProvider") != null
                        select element;

                    if (encryptedConnectionStringElement.HasAny())
                    {
                        System.Xml.XmlNode elementToComment = xmlDocument.SelectSingleNode("/configuration/connectionStrings");
                        string             commentContents  = elementToComment.OuterXml;

                        // Its contents are the XML content of target node
                        System.Xml.XmlComment commentNode = xmlDocument.CreateComment(commentContents);

                        // Get a reference to the parent of the target node
                        System.Xml.XmlNode parentNode = elementToComment.ParentNode;

                        // Replace the target node with the comment
                        parentNode.ReplaceChild(commentNode, elementToComment);
                        xmlDocument.Save(webConfigFilePath);
                    }

                    var fileMap = new ExeConfigurationFileMap()
                    {
                        ExeConfigFilename = webConfigFilePath
                    };
                    var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
                    return(configuration);
                }
                catch (Exception ex)
                {
                    LogHelper.LogError(ex, string.Format("Error processing web.config file {0}", webConfigFilePath));
                }
            }
            return(null);
        }
        /// <summary>
        /// Inserts the specified XML node at the specified position
        /// </summary>
        internal static bool InsertXmlNode(XmlCursorPos cursorPos, System.Xml.XmlNode node, XmlRules xmlRules, bool setNewCursorPosBehindNewInsertedNode)
        {
            System.Xml.XmlNode parentNode = cursorPos.ActualNode.ParentNode;

            switch (cursorPos.PosOnNode)
            {
            case XmlCursorPositions.CursorOnNodeStartTag:     // replace the acual node
            case XmlCursorPositions.CursorOnNodeEndTag:
                parentNode.ReplaceChild(node, cursorPos.ActualNode);
                break;

            case XmlCursorPositions.CursorInFrontOfNode:     // insert before actual node
                parentNode.InsertBefore(node, cursorPos.ActualNode);
                break;

            case XmlCursorPositions.CursorBehindTheNode:     // insert after actual node
                parentNode.InsertAfter(node, cursorPos.ActualNode);
                break;

            case XmlCursorPositions.CursorInsideTheEmptyNode:     // insert into empty node
                cursorPos.ActualNode.AppendChild(node);
                break;

            case XmlCursorPositions.CursorInsideTextNode:     // insert into textnode

                // Make the text available as a node before the insertion position
                string             textDavor     = cursorPos.ActualNode.InnerText.Substring(0, cursorPos.PosInTextNode);
                System.Xml.XmlNode textDavorNode = parentNode.OwnerDocument.CreateTextNode(textDavor);

                // Provide the text behind the insert position as a node
                string             textAfter     = cursorPos.ActualNode.InnerText.Substring(cursorPos.PosInTextNode, cursorPos.ActualNode.InnerText.Length - cursorPos.PosInTextNode);
                System.Xml.XmlNode textAfterNode = parentNode.OwnerDocument.CreateTextNode(textAfter);

                // Insert the node to be inserted between the new before and after text node
                // -> so replace the old text node with
                // textbefore - newNode - textafter
                parentNode.ReplaceChild(textDavorNode, cursorPos.ActualNode);
                parentNode.InsertAfter(node, textDavorNode);
                parentNode.InsertAfter(textAfterNode, node);
                break;

            default:
                throw new ApplicationException(String.Format("InsertXmlNode: unknown PosOnNode {0}", cursorPos.PosOnNode));
            }

            // set cursor
            if (setNewCursorPosBehindNewInsertedNode)
            {
                // Place cursor behind the new node
                cursorPos.SetPos(node, XmlCursorPositions.CursorBehindTheNode);
            }
            else
            {
                if (xmlRules.HasEndTag(node))
                {
                    // Place cursor in the new node
                    cursorPos.SetPos(node, XmlCursorPositions.CursorInsideTheEmptyNode);
                }
                else
                {
                    // Place cursor behind the new node
                    cursorPos.SetPos(node, XmlCursorPositions.CursorBehindTheNode);
                }
            }
            return(true);
        }