Skip to content

Commit 5eb33a2

Browse files
author
Marcus Sonestedt
committedMay 6, 2019
BitAddict.Aras: Code cleanup
(cherry picked from commit 119261b621b122a2f3b3394c9821075e9579ae45)
1 parent f65b9fe commit 5eb33a2

File tree

2 files changed

+30
-36
lines changed

2 files changed

+30
-36
lines changed
 

‎BitAddict.Aras.OpenSource.sln.DotSettings

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AML/@EntryIndexedValue">AML</s:String>
3+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SQL/@EntryIndexedValue">SQL</s:String>
24
<s:Boolean x:Key="/Default/UserDictionary/Words/=amlsync/@EntryIndexedValue">True</s:Boolean>
35
<s:Boolean x:Key="/Default/UserDictionary/Words/=Aras/@EntryIndexedValue">True</s:Boolean>
46
<s:Boolean x:Key="/Default/UserDictionary/Words/=arasdb/@EntryIndexedValue">True</s:Boolean>

‎BitAddict.Aras/ArasExtensions.cs

+28-36
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,17 @@ private static Item RunAndLogArasMethod(Func<Item, Item> method, Item item,
141141
public static string LogException(string msg, Exception exception)
142142
{
143143
var errMsg = msg;
144-
145-
var exceptions = new Queue<Exception>();
146-
exceptions.Enqueue(exception);
144+
var exceptions = new Queue<Exception>(new[] {exception});
147145

148146
while (exceptions.Any())
149147
{
150148
var e = exceptions.Dequeue();
151149
errMsg += "\n<MethodException>\n" +
152150
$" {e.GetType()}: {e.Message}\n" +
153151
$" {e.Source}\n" +
154-
$" <![CDATA[\n" +
152+
" <![CDATA[\n" +
155153
$"{e.StackTrace}\n" +
156-
$" ]]>\n" +
154+
" ]]>\n" +
157155
"</MethodException>\n";
158156

159157
if (e is AggregateException ae)
@@ -187,30 +185,24 @@ public static string LogException(string msg, Exception exception)
187185
internal static Item WithLogger(string methodLogFile, Innovator innovator,
188186
Func<Item> action)
189187
{
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))
191193
{
192-
using (var logger = new Logger(methodLogFile))
194+
ThreadLogger.Value = logger;
195+
ThreadInnovator.Value = innovator;
196+
197+
try
193198
{
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;
208205
}
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();
214206
}
215207
}
216208

@@ -269,17 +261,18 @@ public static Item ApplySQL(this Innovator innovator, [NotNull] string sqlQuery)
269261
/// <summary>
270262
/// Run and log Item query
271263
/// </summary>
272-
/// <param name="innovator"></param>
264+
/// <param name="_"></param>
273265
/// <param name="item"></param>
274266
/// <param name="logResult"></param>
275267
/// <returns></returns>
276268
/// <exception cref="ArasException"></exception>
277269
[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)
279272
{
280273
Log($"<ApplyItem logresult='{logResult}'>\n <input>\n{FormatXml(item.node)}\n </input>\n");
281274

282-
var result = LogTime(() => item.apply(), "QueryTime");
275+
var result = LogTime(item.apply, "QueryTime");
283276

284277
if (logResult)
285278
{
@@ -318,8 +311,7 @@ public static Item GetItemByKeyedName(this Innovator innovator, [NotNull] string
318311
{
319312
Log($"<GetItemByKeyedName>\n <input>\n type = '{itemType}', keyedName = '{keyedName}'\n </input>\n");
320313

321-
var mock = innovator as MockInnovator;
322-
var result = mock != null
314+
var result = innovator is MockInnovator mock
323315
? mock.getItemByKeyedName(itemType, keyedName)
324316
: LogTime(() => innovator.getItemByKeyedName(itemType, keyedName), "QueryTime");
325317

@@ -348,8 +340,7 @@ public static Item GetItemById(this Innovator innovator, [NotNull] string itemTy
348340
{
349341
Log($"<GetItemByID>\n <input>\n type = '{itemType}', id = '{id}'\n </input>\n");
350342

351-
var mock = innovator as MockInnovator;
352-
var result = mock != null
343+
var result = innovator is MockInnovator mock
353344
? mock.getItemById(itemType, id)
354345
: LogTime(() => innovator.getItemById(itemType, id), "QueryTime");
355346

@@ -396,14 +387,15 @@ public static Item ApplyMethod(this Innovator innovator, [NotNull] string method
396387
/// <summary>
397388
/// Run and log fetchRelationships query
398389
/// </summary>
399-
/// <param name="innovator"></param>
390+
/// <param name="_"></param>
400391
/// <param name="item"></param>
401392
/// <param name="relationShipTypeName"></param>
402393
/// <param name="selectList"></param>
403394
/// <returns></returns>
404395
/// <exception cref="ArasException"></exception>
405396
[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(*)")
407399
{
408400
Log($"<FetchRelationships type='{relationShipTypeName}' " +
409401
$"selectList='{selectList}'>\n" +
@@ -530,7 +522,7 @@ internal static void Log(string message)
530522
/// <param name="node">node to print</param>
531523
/// <param name="indent">default indent</param>
532524
/// <returns></returns>
533-
static public string FormatXml(this XmlNode node, int indent = 4)
525+
public static string FormatXml(this XmlNode node, int indent = 4)
534526
{
535527
if (node == null)
536528
return "(null)";

0 commit comments

Comments
 (0)
Please sign in to comment.