@@ -141,19 +141,17 @@ private static Item RunAndLogArasMethod(Func<Item, Item> method, Item item,
141
141
public static string LogException ( string msg , Exception exception )
142
142
{
143
143
var errMsg = msg ;
144
-
145
- var exceptions = new Queue < Exception > ( ) ;
146
- exceptions . Enqueue ( exception ) ;
144
+ var exceptions = new Queue < Exception > ( new [ ] { exception } ) ;
147
145
148
146
while ( exceptions . Any ( ) )
149
147
{
150
148
var e = exceptions . Dequeue ( ) ;
151
149
errMsg += "\n <MethodException>\n " +
152
150
$ " { e . GetType ( ) } : { e . Message } \n " +
153
151
$ " { e . Source } \n " +
154
- $ " <![CDATA[\n " +
152
+ " <![CDATA[\n " +
155
153
$ "{ e . StackTrace } \n " +
156
- $ " ]]>\n " +
154
+ " ]]>\n " +
157
155
"</MethodException>\n " ;
158
156
159
157
if ( e is AggregateException ae )
@@ -187,30 +185,24 @@ public static string LogException(string msg, Exception exception)
187
185
internal static Item WithLogger ( string methodLogFile , Innovator innovator ,
188
186
Func < Item > action )
189
187
{
190
- if ( ThreadLogger . Value == null || ThreadInnovator . Value == null )
188
+ // This happens when one of our Aras methods directly or indirectly calls another of our Aras methods.
189
+ if ( ThreadLogger . Value != null && ThreadInnovator . Value != null )
190
+ return action ( ) ;
191
+
192
+ using ( var logger = new Logger ( methodLogFile ) )
191
193
{
192
- using ( var logger = new Logger ( methodLogFile ) )
194
+ ThreadLogger . Value = logger ;
195
+ ThreadInnovator . Value = innovator ;
196
+
197
+ try
193
198
{
194
- ThreadLogger . Value = logger ;
195
- ThreadInnovator . Value = innovator ;
196
-
197
- try
198
- {
199
- return action ( ) ;
200
- }
201
- finally
202
- {
203
- // BUG: Should not clear on recursive method calls
204
-
205
- ThreadLogger . Value = null ;
206
- ThreadInnovator . Value = null ;
207
- }
199
+ return action ( ) ;
200
+ }
201
+ finally
202
+ {
203
+ ThreadLogger . Value = null ;
204
+ ThreadInnovator . Value = null ;
208
205
}
209
- }
210
- else
211
- {
212
- // This happens when one of our Aras methods directly or indirectly calls another of our Aras methods.
213
- return action ( ) ;
214
206
}
215
207
}
216
208
@@ -269,17 +261,18 @@ public static Item ApplySQL(this Innovator innovator, [NotNull] string sqlQuery)
269
261
/// <summary>
270
262
/// Run and log Item query
271
263
/// </summary>
272
- /// <param name="innovator "></param>
264
+ /// <param name="_ "></param>
273
265
/// <param name="item"></param>
274
266
/// <param name="logResult"></param>
275
267
/// <returns></returns>
276
268
/// <exception cref="ArasException"></exception>
277
269
[ NotNull ]
278
- public static Item ApplyItem ( this Innovator innovator , [ NotNull ] Item item , bool logResult = true )
270
+ // ReSharper disable once UnusedParameter.Global
271
+ public static Item ApplyItem ( this Innovator _ , [ NotNull ] Item item , bool logResult = true )
279
272
{
280
273
Log ( $ "<ApplyItem logresult='{ logResult } '>\n <input>\n { FormatXml ( item . node ) } \n </input>\n ") ;
281
274
282
- var result = LogTime ( ( ) => item . apply ( ) , "QueryTime" ) ;
275
+ var result = LogTime ( item . apply , "QueryTime" ) ;
283
276
284
277
if ( logResult )
285
278
{
@@ -318,8 +311,7 @@ public static Item GetItemByKeyedName(this Innovator innovator, [NotNull] string
318
311
{
319
312
Log ( $ "<GetItemByKeyedName>\n <input>\n type = '{ itemType } ', keyedName = '{ keyedName } '\n </input>\n ") ;
320
313
321
- var mock = innovator as MockInnovator ;
322
- var result = mock != null
314
+ var result = innovator is MockInnovator mock
323
315
? mock . getItemByKeyedName ( itemType , keyedName )
324
316
: LogTime ( ( ) => innovator . getItemByKeyedName ( itemType , keyedName ) , "QueryTime" ) ;
325
317
@@ -348,8 +340,7 @@ public static Item GetItemById(this Innovator innovator, [NotNull] string itemTy
348
340
{
349
341
Log ( $ "<GetItemByID>\n <input>\n type = '{ itemType } ', id = '{ id } '\n </input>\n ") ;
350
342
351
- var mock = innovator as MockInnovator ;
352
- var result = mock != null
343
+ var result = innovator is MockInnovator mock
353
344
? mock . getItemById ( itemType , id )
354
345
: LogTime ( ( ) => innovator . getItemById ( itemType , id ) , "QueryTime" ) ;
355
346
@@ -396,14 +387,15 @@ public static Item ApplyMethod(this Innovator innovator, [NotNull] string method
396
387
/// <summary>
397
388
/// Run and log fetchRelationships query
398
389
/// </summary>
399
- /// <param name="innovator "></param>
390
+ /// <param name="_ "></param>
400
391
/// <param name="item"></param>
401
392
/// <param name="relationShipTypeName"></param>
402
393
/// <param name="selectList"></param>
403
394
/// <returns></returns>
404
395
/// <exception cref="ArasException"></exception>
405
396
[ NotNull ]
406
- public static Item FetchRelationships ( this Innovator innovator , [ NotNull ] Item item , string relationShipTypeName , string selectList = "related_id(*)" )
397
+ // ReSharper disable once UnusedParameter.Global
398
+ public static Item FetchRelationships ( this Innovator _ , [ NotNull ] Item item , string relationShipTypeName , string selectList = "related_id(*)" )
407
399
{
408
400
Log ( $ "<FetchRelationships type='{ relationShipTypeName } ' " +
409
401
$ "selectList='{ selectList } '>\n " +
@@ -530,7 +522,7 @@ internal static void Log(string message)
530
522
/// <param name="node">node to print</param>
531
523
/// <param name="indent">default indent</param>
532
524
/// <returns></returns>
533
- static public string FormatXml ( this XmlNode node , int indent = 4 )
525
+ public static string FormatXml ( this XmlNode node , int indent = 4 )
534
526
{
535
527
if ( node == null )
536
528
return "(null)" ;
0 commit comments