Example #1
0
        Exception IDiffPatchTask.PatchTarget(XmlDocument target)
        {
            string  searchPath = "/root/data[@name='{0}']";
            XmlNode rootNode   = target.DocumentElement;

            foreach (XmlNode sn in s.SelectNodes("/root/data"))
            {
                if (!this.NodeRequired(sn))
                {
                    continue;
                }

                XmlNode val = sn.SelectSingleNode("value");
                if (val == null || val.InnerText == null || val.InnerText.Length == 0)
                {
                    continue;
                }

                XmlNode name       = sn.Attributes.GetNamedItem("name");
                string  idName     = name.InnerText;
                XmlNode targetNode = target.SelectSingleNode(String.Format(searchPath, name.InnerText));
                if (targetNode == null)
                {
                    rootNode.AppendChild(DiffPatchResource.CopyOfNode(sn, target));
                    rootNode.AppendChild(target.CreateWhitespace("\n\t"));
                    if (verbose)
                    {
                        Console.WriteLine("NEW " + idName);
                    }
                    else
                    {
                        Console.Write(".");
                    }
                    nodesAppended++;
                }
                else
                {
                    XmlNode comment = sn.SelectSingleNode("comment");
                    if (comment != null && comment.InnerText.IndexOf("CHANGED") == 0)
                    {
                        rootNode.ReplaceChild(DiffPatchResource.CopyOfNode(sn, target), targetNode);
                        if (verbose)
                        {
                            Console.WriteLine("CHANGED " + idName);
                        }
                        else
                        {
                            Console.Write(".");
                        }
                        nodesChanged++;
                    }
                }
            }

            return(null);
        }
Example #2
0
        Exception IDiffPatchTask.PatchTarget(XmlDocument target)
        {
            string  searchPath = "/root/data[@name='{0}']";
            XmlNode rootNode   = target.DocumentElement;

            foreach (XmlNode sn in s.SelectNodes("/root/data"))
            {
                XmlNode name          = sn.Attributes.GetNamedItem("name");
                string  idName        = name.InnerText;
                XmlNode srcValue      = sn.SelectSingleNode("value");
                int     srcParamCount = 0;
                if (findSimpleParamPlaceHolders.IsMatch(srcValue.InnerText))
                {
                    srcParamCount = findSimpleParamPlaceHolders.Matches(srcValue.InnerText).Count;
                }

                XmlNode targetNode = target.SelectSingleNode(String.Format(searchPath, name.InnerText));
                if (targetNode == null)
                {
                    rootNode.AppendChild(DiffPatchResource.CopyOfNode(sn, target));
                    rootNode.AppendChild(target.CreateWhitespace("\n\t"));
                    if (verbose)
                    {
                        Console.WriteLine("NEW " + idName);
                    }
                    else
                    {
                        Console.Write(".");
                    }
                    nodesAppended++;
                }
                else
                {
                    XmlNode comment = sn.SelectSingleNode("comment");
                    if (comment != null && comment.InnerText.IndexOf("CHANGED") == 0)
                    {
                        rootNode.ReplaceChild(DiffPatchResource.CopyOfNode(sn, target), targetNode);
                        if (verbose)
                        {
                            Console.WriteLine("CHANGED " + idName);
                        }
                        else
                        {
                            Console.Write(".");
                        }
                        nodesChanged++;
                    }
                    else
                    {
                        XmlNode targetValue = targetNode.SelectSingleNode("value");
                        if (findSimpleParamPlaceHolders.IsMatch(targetValue.InnerText))
                        {
                            if (srcParamCount != findSimpleParamPlaceHolders.Matches(targetValue.InnerText).Count)
                            {
                                rootNode.ReplaceChild(DiffPatchResource.CopyOfNode(sn, target), targetNode);
                                if (verbose)
                                {
                                    Console.WriteLine("PARAM mismatch " + idName);
                                }
                                else
                                {
                                    Console.Write(".");
                                }
                                nodesChanged++;
                            }
                        }
                    }
                }
            }
            return(null);
        }