wasStitchNET – Diff between revs 7 and 8

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 7 Rev 8
Line 11... Line 11...
11   11  
12 namespace wasStitchNET.Patchers 12 namespace wasStitchNET.Patchers
13 { 13 {
14 public static class XML 14 public static class XML
-   15 {
-   16 public static HashSet<string> GetFileDelta(string cfg, string nfg)
-   17 {
-   18 var configuredTags = new HashSet<string>();
-   19  
-   20 var configuration = XDocument.Load(cfg);
-   21 foreach (var e in XDocument.Load(nfg).Descendants())
-   22 {
-   23 var cfgElement = configuration.XPathSelectElement(e.GetAbsoluteXPath());
-   24 if (cfgElement == null)
-   25 {
-   26 configuredTags.Add(e.Name.LocalName);
-   27 continue;
-   28 }
-   29  
-   30 if (e.Descendants().Any())
-   31 continue;
-   32  
-   33 if (!cfgElement.Value.Equals(e.Value))
-   34 continue;
-   35  
-   36 configuredTags.Add(e.Name.LocalName);
-   37 }
-   38  
-   39 return configuredTags;
-   40 }
15 { 41  
16 public static XDocument PatchConfiguration(XDocument cfg, XDocument nfg, HashSet<string> configuredTags) 42 public static XDocument PatchXDocument(XDocument cfg, XDocument nfg, HashSet<string> configuredTags)
17 { -  
18 /*foreach (var e in nfg.Descendants() -  
19 .Where(e => !configuredTags.Contains(e.Name.LocalName) && -  
20 !e.Ancestors().Any(o => configuredTags.Contains(o.Name.LocalName))))*/ 43 {
21 foreach (var e in nfg.Descendants() 44 foreach (var e in nfg.Descendants()
22 .Where(e => configuredTags.Contains(e.Name.LocalName))) 45 .Where(e => configuredTags.Contains(e.Name.LocalName)))
23 { 46 {
24 // Select the element in the current configuration that is found in the default configuration. 47 // Select the element in the current configuration that is found in the default configuration.
Line 32... Line 55...
32 cfgElement.Value = e.Value; 55 cfgElement.Value = e.Value;
33 break; 56 break;
34 // Element not found in the current configuration. 57 // Element not found in the current configuration.
35 default: 58 default:
36 // Find the first existing parent of the default configuration in the current configuration. 59 // Find the first existing parent of the default configuration in the current configuration.
37 var parent = e.Parent; 60 var parent = e;
38 XElement cfgParentElement = null; -  
39 do 61 do
40 { 62 {
41 cfgParentElement = cfg.XPathSelectElement(parent.GetAbsoluteXPath()); 63 var cfgParentElement = cfg.XPathSelectElement(parent.GetAbsoluteXPath());
42 parent = e.Parent; 64 if (cfgParentElement != null)
43 } while (cfgParentElement == null); 65 {
44   -  
45 // Add the default configuration parent to the current configuration. 66 // Add the default configuration parent to the current configuration.
-   67 cfgParentElement.ReplaceWith(
46 cfgParentElement = nfg.XPathSelectElement(cfgParentElement.GetAbsoluteXPath()); 68 nfg.XPathSelectElement(cfgParentElement.GetAbsoluteXPath()));
-   69 break;
-   70 }
-   71 parent = parent.Parent;
-   72 } while (parent != null);
47 break; 73 break;
48 } 74 }
49 } 75 }
50 return cfg; 76 return cfg;
51 } 77 }
52 } 78 }
53 } 79 }
54   -  
55   -  
56   -  
57   -  
58   -  
59   80