Beispiel #1
0
        private bool InsertNode(XmlNode childRootNode, XmlNode actionNode, NodeInsertType mode)
        {
            XmlNode rootNode = childRootNode.ParentNode;

            Debug.Assert(rootNode != null);

            var changedNode = false;

            foreach (XmlNode child in actionNode.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element || child.NodeType == XmlNodeType.Comment)
                {
                    DnnInstallLogger.InstallLogInfo(Localization.GetString("LogStart", Localization.GlobalResourceFile) + "InsertNode:" + child.InnerXml.ToString());
                    switch (mode)
                    {
                    case NodeInsertType.Before:
                        rootNode.InsertBefore(this.TargetConfig.ImportNode(child, true), childRootNode);
                        changedNode = true;
                        break;

                    case NodeInsertType.After:
                        rootNode.InsertAfter(this.TargetConfig.ImportNode(child, true), childRootNode);
                        changedNode = true;
                        break;
                    }
                }
            }

            return(changedNode);
        }
Beispiel #2
0
        private bool UpdateAttribute(XmlNode rootNode, XmlNode actionNode)
        {
            Debug.Assert(actionNode.Attributes != null, "actionNode.Attributes != null");
            Debug.Assert(rootNode.Attributes != null, "rootNode.Attributes != null");

            var changedNode = false;

            if (actionNode.Attributes["name"] != null && actionNode.Attributes["value"] != null)
            {
                string attributeName  = actionNode.Attributes["name"].Value;
                string attributeValue = actionNode.Attributes["value"].Value;
                if (!string.IsNullOrEmpty(attributeName))
                {
                    DnnInstallLogger.InstallLogInfo(Localization.GetString("LogStart", Localization.GlobalResourceFile) + "UpdateAttribute:attributeName=" + attributeName.ToString());
                    if (rootNode.Attributes[attributeName] == null)
                    {
                        rootNode.Attributes.Append(this.TargetConfig.CreateAttribute(attributeName));
                        changedNode = true;
                    }

                    var oldAttributeValue = rootNode.Attributes[attributeName].Value;
                    rootNode.Attributes[attributeName].Value = attributeValue;
                    if (!string.Equals(oldAttributeValue, attributeValue, StringComparison.Ordinal))
                    {
                        changedNode = true;
                    }
                }
            }

            return(changedNode);
        }
Beispiel #3
0
 private void AddNode(XmlNode rootNode, XmlNode actionNode)
 {
     foreach (XmlNode child in actionNode.ChildNodes)
     {
         if (child.NodeType == XmlNodeType.Element || child.NodeType == XmlNodeType.Comment)
         {
             rootNode.AppendChild(TargetConfig.ImportNode(child, true));
             DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "AddNode:" + child.InnerXml.ToString());
         }
     }
 }
Beispiel #4
0
        public void UpdateConfigs(bool autoSave)
        {
            var changedAnyNodes = false;
            var nodes           = this.SourceConfig.SelectNodes("/configuration/nodes");

            if (nodes != null)
            {
                foreach (XmlNode configNode in nodes)
                {
                    Debug.Assert(configNode.Attributes != null, "configNode.Attributes != null");

                    // Attempt to load TargetFile property from configFile Atribute
                    this.TargetFileName = configNode.Attributes["configfile"].Value;
                    string targetProductName = string.Empty;
                    if (configNode.Attributes["productName"] != null)
                    {
                        targetProductName = configNode.Attributes["productName"].Value;
                    }

                    bool isAppliedToProduct;

                    if (!File.Exists(Globals.ApplicationMapPath + "\\" + this.TargetFileName))
                    {
                        DnnInstallLogger.InstallLogInfo($"Target File {this.TargetFileName} doesn't exist, ignore the merge process");
                        return;
                    }

                    this.TargetConfig = Config.Load(this.TargetFileName);
                    if (string.IsNullOrEmpty(targetProductName) || targetProductName == "All")
                    {
                        isAppliedToProduct = true;
                    }
                    else
                    {
                        isAppliedToProduct = DotNetNukeContext.Current.Application.ApplyToProduct(targetProductName);
                    }

                    // The nodes definition is not correct so skip changes
                    if (this.TargetConfig != null && isAppliedToProduct)
                    {
                        var changedNodes = this.ProcessNodes(configNode.SelectNodes("node"), autoSave);
                        changedAnyNodes = changedAnyNodes || changedNodes;
                        if (!autoSave && changedNodes)
                        {
                            this.PendingDocuments.Add(this.TargetFileName, this.TargetConfig);
                        }
                    }
                }
            }

            this.ConfigUpdateChangedNodes = changedAnyNodes;
        }
Beispiel #5
0
        private void RemoveNode(XmlNode node)
        {
            if (node != null)
            {
                //Get Parent
                XmlNode parentNode = node.ParentNode;

                //Remove current Node
                if (parentNode != null)
                {
                    parentNode.RemoveChild(node);
                    DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "RemoveNode:" + node.InnerXml.ToString());
                }
            }
        }
Beispiel #6
0
        private bool PrependNode(XmlNode rootNode, XmlNode actionNode)
        {
            var changedNode = false;

            foreach (XmlNode child in actionNode.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element || child.NodeType == XmlNodeType.Comment)
                {
                    rootNode.PrependChild(this.TargetConfig.ImportNode(child, true));
                    DnnInstallLogger.InstallLogInfo(Localization.GetString("LogStart", Localization.GlobalResourceFile) + "PrependNode:" + child.InnerXml.ToString());
                    changedNode = true;
                }
            }

            return(changedNode);
        }
Beispiel #7
0
        private void RemoveAttribute(XmlNode rootNode, XmlNode actionNode)
        {
            Debug.Assert(actionNode.Attributes != null, "actionNode.Attributes != null");
            Debug.Assert(rootNode.Attributes != null, "rootNode.Attributes != null");

            if (actionNode.Attributes["name"] != null)
            {
                string attributeName = actionNode.Attributes["name"].Value;
                if (!string.IsNullOrEmpty(attributeName))
                {
                    if (rootNode.Attributes[attributeName] != null)
                    {
                        rootNode.Attributes.Remove(rootNode.Attributes[attributeName]);
                        DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "RemoveAttribute:attributeName=" + attributeName.ToString());
                    }
                }
            }
        }
Beispiel #8
0
        private bool RemoveNode(XmlNode node)
        {
            var changedNode = false;

            if (node != null)
            {
                // Get Parent
                XmlNode parentNode = node.ParentNode;

                // Remove current Node
                if (parentNode != null)
                {
                    parentNode.RemoveChild(node);
                    DnnInstallLogger.InstallLogInfo(Localization.GetString("LogStart", Localization.GlobalResourceFile) + "RemoveNode:" + node.InnerXml.ToString());
                    changedNode = true;
                }
            }

            return(changedNode);
        }
Beispiel #9
0
        private void UpdateAttribute(XmlNode rootNode, XmlNode actionNode)
        {
            Debug.Assert(actionNode.Attributes != null, "actionNode.Attributes != null");
            Debug.Assert(rootNode.Attributes != null, "rootNode.Attributes != null");

            if (actionNode.Attributes["name"] != null && actionNode.Attributes["value"] != null)
            {
                string attributeName  = actionNode.Attributes["name"].Value;
                string attributeValue = actionNode.Attributes["value"].Value;
                if (!string.IsNullOrEmpty(attributeName))
                {
                    DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "UpdateAttribute:attributeName=" + attributeName.ToString());
                    if (rootNode.Attributes[attributeName] == null)
                    {
                        rootNode.Attributes.Append(TargetConfig.CreateAttribute(attributeName));
                    }
                    rootNode.Attributes[attributeName].Value = attributeValue;
                }
            }
        }
Beispiel #10
0
        private bool UpdateNode(XmlNode rootNode, XmlNode actionNode)
        {
            Debug.Assert(actionNode.Attributes != null, "actionNode.Attributes != null");

            var    changedNode  = false;
            string keyAttribute = string.Empty;

            if (actionNode.Attributes["key"] != null)
            {
                keyAttribute = actionNode.Attributes["key"].Value;
                DnnInstallLogger.InstallLogInfo(Localization.GetString("LogStart", Localization.GlobalResourceFile) + "UpdateNode: keyAttribute=" + keyAttribute.ToString());
            }

            foreach (XmlNode child in actionNode.ChildNodes)
            {
                Debug.Assert(child.Attributes != null, "child.Attributes != null");

                if (child.NodeType == XmlNodeType.Element)
                {
                    XmlNode targetNode = null;
                    if (!string.IsNullOrEmpty(keyAttribute))
                    {
                        if (child.Attributes[keyAttribute] != null)
                        {
                            string path = string.Format("{0}[@{1}='{2}']", child.LocalName, keyAttribute, child.Attributes[keyAttribute].Value);
                            targetNode = rootNode.SelectSingleNode(path);
                        }
                    }
                    else
                    {
                        targetNode = this.FindMatchingNode(rootNode, actionNode, "targetpath");
                    }

                    if (targetNode == null)
                    {
                        // Since there is no collision we can just add the node
                        rootNode.AppendChild(this.TargetConfig.ImportNode(child, true));
                        changedNode = true;
                        continue;
                    }

                    // There is a collision so we need to determine what to do.
                    string collisionAction = actionNode.Attributes["collision"].Value;
                    switch (collisionAction.ToLowerInvariant())
                    {
                    case "overwrite":
                        var oldContent = rootNode.InnerXml;
                        rootNode.ReplaceChild(this.TargetConfig.ImportNode(child, true), targetNode);
                        var newContent = rootNode.InnerXml;
                        changedNode = !string.Equals(oldContent, newContent, StringComparison.Ordinal);
                        break;

                    case "save":
                        string commentHeaderText = string.Format(
                            Localization.GetString("XMLMERGE_Upgrade", Localization.SharedResourceFile),
                            Environment.NewLine,
                            this.Sender,
                            this.Version,
                            DateTime.Now);
                        XmlComment commentHeader = this.TargetConfig.CreateComment(commentHeaderText);

                        var        targetNodeContent = this.GetNodeContentWithoutComment(targetNode);
                        XmlComment commentNode       = this.TargetConfig.CreateComment(targetNodeContent);
                        var        newChild          = this.TargetConfig.ImportNode(child, true);
                        rootNode.ReplaceChild(newChild, targetNode);
                        rootNode.InsertBefore(commentHeader, newChild);
                        rootNode.InsertBefore(commentNode, newChild);
                        changedNode = true;
                        break;

                    case "ignore":
                        break;
                    }
                }
            }

            return(changedNode);
        }
Beispiel #11
0
        private void UpdateNode(XmlNode rootNode, XmlNode actionNode)
        {
            Debug.Assert(actionNode.Attributes != null, "actionNode.Attributes != null");

            string keyAttribute = "";

            if (actionNode.Attributes["key"] != null)
            {
                keyAttribute = actionNode.Attributes["key"].Value;
                DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "UpdateNode: keyAttribute=" + keyAttribute.ToString());
            }
            foreach (XmlNode child in actionNode.ChildNodes)
            {
                Debug.Assert(child.Attributes != null, "child.Attributes != null");

                if (child.NodeType == XmlNodeType.Element)
                {
                    XmlNode targetNode = null;
                    if (!string.IsNullOrEmpty(keyAttribute))
                    {
                        if (child.Attributes[keyAttribute] != null)
                        {
                            string path = string.Format("{0}[@{1}='{2}']", child.LocalName, keyAttribute, child.Attributes[keyAttribute].Value);
                            targetNode = rootNode.SelectSingleNode(path);
                        }
                    }
                    else
                    {
                        targetNode = FindMatchingNode(rootNode, actionNode, "targetpath");
                    }
                    if (targetNode == null)
                    {
                        //Since there is no collision we can just add the node
                        rootNode.AppendChild(TargetConfig.ImportNode(child, true));
                        continue;
                    }

                    //There is a collision so we need to determine what to do.
                    string collisionAction = actionNode.Attributes["collision"].Value;
                    switch (collisionAction.ToLowerInvariant())
                    {
                    case "overwrite":
                        rootNode.RemoveChild(targetNode);
                        rootNode.InnerXml = rootNode.InnerXml + child.OuterXml;
                        break;

                    case "save":
                        string commentHeaderText = string.Format(Localization.Localization.GetString("XMLMERGE_Upgrade", Localization.Localization.SharedResourceFile),
                                                                 Environment.NewLine,
                                                                 Sender,
                                                                 Version,
                                                                 DateTime.Now);
                        XmlComment commentHeader = TargetConfig.CreateComment(commentHeaderText);
                        XmlComment commentNode   = TargetConfig.CreateComment(targetNode.OuterXml);
                        rootNode.RemoveChild(targetNode);
                        rootNode.InnerXml = rootNode.InnerXml + commentHeader.OuterXml + commentNode.OuterXml + child.OuterXml;
                        break;

                    case "ignore":
                        break;
                    }
                }
            }
        }