@@ -46,6 +46,7 @@ public ApiFixupApplier (XDocument theDoc, XDocument theFixups, string fixupsFile
46
46
47
47
public void Apply ( )
48
48
{
49
+ Logger . Debug ( $ "Applying fixups from: { fixupsPath } ") ;
49
50
foreach ( XElement fixup in fixups . XPathSelectElements ( "/metadata/*" ) )
50
51
Apply ( doc , fixup ) ;
51
52
}
@@ -56,34 +57,34 @@ protected virtual void Apply (XDocument doc, XElement fixup)
56
57
switch ( fixup . Name . LocalName ) {
57
58
case "remove-node" :
58
59
DoOp ( ( XElement node ) => node . Remove ( ) ,
59
- // BG8A00
60
- ( ) => Report . Warning ( 0 , Report . WarningApiFixup + 0 , null , fixup , $ "<remove-node path=\" { path } \" /> matched no nodes.") ,
61
- // BG4A01
62
- ( Exception e ) => Report . Error ( Report . ErrorApiFixup + 1 , e , fixup , $ "Invalid XPath specification: { path } ")
63
- ) ;
60
+ // BG8A00
61
+ ( ) => Report . Warning ( 0 , Report . WarningApiFixup + 0 , null , fixup , $ "<remove-node path=\" { path } \" /> matched no nodes.") ,
62
+ // BG4A01
63
+ ( Exception e ) => Report . Error ( Report . ErrorApiFixup + 1 , e , fixup , $ "Invalid XPath specification: { path } ")
64
+ ) ;
64
65
break ;
65
66
66
67
case "add-node" :
67
68
DoOp ( ( XElement node ) => node . Add ( fixup . Nodes ( ) ) ,
68
- // BG8A01
69
- ( ) => Report . Warning ( 0 , Report . WarningApiFixup + 1 , null , fixup , $ "<add-node path=\" { path } \" /> matched no nodes.") ,
70
- // BG4A02
71
- ( Exception e ) => Report . Error ( Report . ErrorApiFixup + 2 , e , fixup , $ "Invalid XPath specification: { path } ")
72
- ) ;
69
+ // BG8A01
70
+ ( ) => Report . Warning ( 0 , Report . WarningApiFixup + 1 , null , fixup , $ "<add-node path=\" { path } \" /> matched no nodes.") ,
71
+ // BG4A02
72
+ ( Exception e ) => Report . Error ( Report . ErrorApiFixup + 2 , e , fixup , $ "Invalid XPath specification: { path } ")
73
+ ) ;
73
74
break ;
74
75
75
76
case "change-node" :
76
77
DoOp ( ( XElement node ) => {
77
- var newChild = new XElement ( fixup . Value ) ;
78
- newChild . Add ( node . Attributes ( ) ) ;
79
- newChild . Add ( node . Nodes ( ) ) ;
80
- node . ReplaceWith ( newChild ) ;
81
- } ,
78
+ var newChild = new XElement ( fixup . Value ) ;
79
+ newChild . Add ( node . Attributes ( ) ) ;
80
+ newChild . Add ( node . Nodes ( ) ) ;
81
+ node . ReplaceWith ( newChild ) ;
82
+ } ,
82
83
// BG8A03
83
84
( ) => Report . Warning ( 0 , Report . WarningApiFixup + 3 , null , fixup , $ "<change-node-type path=\" { path } \" /> matched no nodes.") ,
84
85
// BG4A03
85
86
( Exception e ) => Report . Error ( Report . ErrorApiFixup + 3 , e , fixup , $ "Invalid XPath specification: { path } ")
86
- ) ;
87
+ ) ;
87
88
break ;
88
89
89
90
case "attr" :
@@ -93,11 +94,11 @@ protected virtual void Apply (XDocument doc, XElement fixup)
93
94
Report . Error ( Report . ErrorApiFixup + 7 , null , fixup , $ "Target attribute name is not specified for path: { path } ") ;
94
95
95
96
DoOp ( ( XElement node ) => node . SetAttributeValue ( attr_name , fixup . Value ) ,
96
- // BG8A04
97
- ( ) => Report . Warning ( 0 , Report . WarningApiFixup + 4 , null , fixup , $ "<attr path=\" { path } \" /> matched no nodes.") ,
98
- // BG4A04
99
- ( Exception e ) => Report . Error ( Report . ErrorApiFixup + 4 , e , fixup , $ "Invalid XPath specification: { path } ")
100
- ) ;
97
+ // BG8A04
98
+ ( ) => Report . Warning ( 0 , Report . WarningApiFixup + 4 , null , fixup , $ "<attr path=\" { path } \" /> matched no nodes.") ,
99
+ // BG4A04
100
+ ( Exception e ) => Report . Error ( Report . ErrorApiFixup + 4 , e , fixup , $ "Invalid XPath specification: { path } ")
101
+ ) ;
101
102
break ;
102
103
103
104
case "move-node" :
@@ -123,11 +124,11 @@ protected virtual void Apply (XDocument doc, XElement fixup)
123
124
124
125
case "remove-attr" :
125
126
DoOp ( ( XElement node ) => node . RemoveAttributes ( ) ,
126
- // BG8A06
127
- ( ) => Report . Warning ( 0 , Report . WarningApiFixup + 6 , null , fixup , $ "<remove-attr path=\" { path } \" /> matched no nodes.") ,
128
- // BG4A06
129
- ( Exception e ) => Report . Error ( Report . ErrorApiFixup + 6 , e , fixup , $ "Invalid XPath specification: { path } ")
130
- ) ;
127
+ // BG8A06
128
+ ( ) => Report . Warning ( 0 , Report . WarningApiFixup + 6 , null , fixup , $ "<remove-attr path=\" { path } \" /> matched no nodes.") ,
129
+ // BG4A06
130
+ ( Exception e ) => Report . Error ( Report . ErrorApiFixup + 6 , e , fixup , $ "Invalid XPath specification: { path } ")
131
+ ) ;
131
132
break ;
132
133
133
134
default :
@@ -137,12 +138,19 @@ protected virtual void Apply (XDocument doc, XElement fixup)
137
138
138
139
void DoOp ( Action < XElement > operation , Action warning = null , Action < Exception > exception = null )
139
140
{
141
+ // Serialization is expensive
142
+ if ( Logger . Level >= LogLevel . Excessive )
143
+ Logger . Excessive ( $ " Fixup source: { fixup . ToString ( ) } ") ;
144
+
140
145
try {
141
- IEnumerable < XElement > nodes = doc . XPathSelectElements ( path ) ;
146
+ IEnumerable < XElement > nodes = doc . XPathSelectElements ( path ) ;
142
147
if ( nodes . Any ( ) ) {
143
148
foreach ( XElement node in nodes ) {
144
149
if ( node == null ) // Unlikely, but won't hurt
145
- operation ( node ) ;
150
+ continue ;
151
+ if ( Logger . Level >= LogLevel . Excessive )
152
+ Logger . Excessive ( $ " Applying to: { node . ToString ( ) } ") ;
153
+ operation ( node ) ;
146
154
}
147
155
} else
148
156
warning ? . Invoke ( ) ;
0 commit comments