wasStitchNET

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 7  →  ?path2? @ 8
/Patchers/XML.cs
@@ -13,11 +13,34 @@
{
public static class XML
{
public static XDocument PatchConfiguration(XDocument cfg, XDocument nfg, HashSet<string> configuredTags)
public static HashSet<string> GetFileDelta(string cfg, string nfg)
{
/*foreach (var e in nfg.Descendants()
.Where(e => !configuredTags.Contains(e.Name.LocalName) &&
!e.Ancestors().Any(o => configuredTags.Contains(o.Name.LocalName))))*/
var configuredTags = new HashSet<string>();
 
var configuration = XDocument.Load(cfg);
foreach (var e in XDocument.Load(nfg).Descendants())
{
var cfgElement = configuration.XPathSelectElement(e.GetAbsoluteXPath());
if (cfgElement == null)
{
configuredTags.Add(e.Name.LocalName);
continue;
}
 
if (e.Descendants().Any())
continue;
 
if (!cfgElement.Value.Equals(e.Value))
continue;
 
configuredTags.Add(e.Name.LocalName);
}
 
return configuredTags;
}
 
public static XDocument PatchXDocument(XDocument cfg, XDocument nfg, HashSet<string> configuredTags)
{
foreach (var e in nfg.Descendants()
.Where(e => configuredTags.Contains(e.Name.LocalName)))
{
@@ -34,16 +57,19 @@
// Element not found in the current configuration.
default:
// Find the first existing parent of the default configuration in the current configuration.
var parent = e.Parent;
XElement cfgParentElement = null;
var parent = e;
do
{
cfgParentElement = cfg.XPathSelectElement(parent.GetAbsoluteXPath());
parent = e.Parent;
} while (cfgParentElement == null);
 
// Add the default configuration parent to the current configuration.
cfgParentElement = nfg.XPathSelectElement(cfgParentElement.GetAbsoluteXPath());
var cfgParentElement = cfg.XPathSelectElement(parent.GetAbsoluteXPath());
if (cfgParentElement != null)
{
// Add the default configuration parent to the current configuration.
cfgParentElement.ReplaceWith(
nfg.XPathSelectElement(cfgParentElement.GetAbsoluteXPath()));
break;
}
parent = parent.Parent;
} while (parent != null);
break;
}
}
@@ -50,9 +76,4 @@
return cfg;
}
}
}
 
 
 
 
 
}