Skip to content

Commit

Permalink
Improve logging for GetArchetypeData
Browse files Browse the repository at this point in the history
  • Loading branch information
JonSaffron committed Jun 22, 2023
1 parent fb75372 commit b3ec9e8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion FacadeFor3e/ExecuteProcessExceptionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static ExecuteProcessException BuildForProcessError(ExecuteProcessResul
if (isReadDataError)
{
errorMessages.Insert(0,
"An error occurred while the transaction service populated the data object(s). Among other things this can mean:\r\n"
"An error occurred while the transaction service populated the data object(s). Amongst other things this can mean:\r\n"
+ "- An invalid attribute was specified that doesn't exist on the object\r\n"
+ "- An invalid child object was specified that doesn't exist on the object\r\n"
+ "- If multiple child objects were used then the order they were specified in was wrong\r\n"
Expand Down
22 changes: 12 additions & 10 deletions FacadeFor3e/ExecuteProcessResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Guid ProcessId
/// <remarks>Can be one of
/// <c>Success</c> (the process completed),
/// <c>Failure</c> (an error occurred), or
/// <c>Interface</c> (the process is still running)</remarks>
/// <c>Interface</c> (the process has not finished running and is stopped at a UI step)</remarks>
public string ExecutionResult
{
get
Expand Down Expand Up @@ -251,22 +251,24 @@ internal AttributeError(XmlElement attributeElement)
/// <summary>
/// Generates a string description from a list of <see cref="DataErrors">DataError</see>
/// </summary>
/// <param name="dataErrors"></param>
/// <returns></returns>
public static string RenderDataErrors(IEnumerable<DataError> dataErrors)
/// <param name="dataErrors">A collection of data errors returned from running a process</param>
/// <returns>A string containing a description of each of the data errors specified, or null if the data errors collection is empty</returns>
public static string? RenderDataErrors(IEnumerable<DataError> dataErrors)
{
if (dataErrors == null)
throw new ArgumentNullException(nameof(dataErrors));
var sb = new StringBuilder();
bool isSubsequentRecord = false;
foreach (var item in dataErrors)
using (var enumerator = dataErrors.GetEnumerator())
{
if (isSubsequentRecord)
if (!enumerator.MoveNext())
return null;
AppendDataErrorInfo(enumerator.Current!, sb, 0);
while (enumerator.MoveNext())
{
sb.AppendLine();
AppendDataErrorInfo(enumerator.Current!, sb, 0);
}
AppendDataErrorInfo(item, sb, 0);
isSubsequentRecord = true;
}

return sb.ToString();
}

Expand Down
2 changes: 1 addition & 1 deletion FacadeFor3e/FacadeFor3e.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageId>FacadeFor3E</PackageId>
<Authors>J Saffron Consulting</Authors>
<Product>FacadeFor3E</Product>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
<Description>A library that makes using the 3E transaction service a little easier.</Description>
<Copyright>Copyright © J Saffron Consulting Ltd 2014 - 2023</Copyright>
<RepositoryUrl>https://github.com/JonSaffron/FacadeFor3e</RepositoryUrl>
Expand Down
15 changes: 10 additions & 5 deletions FacadeFor3e/GetArchetypeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,36 @@ public XmlDocument GetData(XmlDocument xoql)

if (response == null)
{
// if no rows returned, then return something useful
// when no rows are returned, then return something useful
var result = new XmlDocument();
result.AppendChild(result.CreateElement("Data"));
this._transactionServices.LogForDebug("no results returned from xoql query");
return result;
}

if (response.StartsWith("<Data>") && response.EndsWith("</Data>"))
{
var result = new XmlDocument();
result.LoadXml(response);
string responseFormatted = result.PrettyPrintXml();
this._transactionServices.LogForDebug(responseFormatted);
return result;
}

this._transactionServices.LogForError(response);
throw new InvalidOperationException("An invalid response was received from the web server:\r\n" + response);
}

private string? CallTransactionService(XmlDocument xoql)
{
var ts = this._transactionServices.GetSoapClient();
OutputToConsoleDetailsOfTheJob(xoql);
this._transactionServices.LogForDebug(xoql.PrettyPrintXml());

// deliberately only passing through the document element, not the xml declaration on any leading or following comments
// this is because the 3E transaction service is intolerant of anything but the simplest xml
// ReSharper disable once PossibleNullReferenceException
var request = xoql.DocumentElement!.OuterXml;
OutputToConsoleDetailsOfTheJob(xoql);

var ts = this._transactionServices.GetSoapClient();
var result = ts.GetArchetypeData(request); // if no rows are returned, then result will be null
return result;
}
Expand All @@ -121,7 +126,7 @@ private void OutputToConsoleDetailsOfTheJob(XmlDocument xoql)
xnm.AddNamespace("ns", "http://elite.com/schemas/query");
XmlElement? arch = (XmlElement?) xoql.SelectSingleNode("ns:SELECT/ns:OQL_CONTEXT/ns:NODEMAP[@ID='Node#1']", xnm);
var archetype = arch?.GetAttribute("QueryID");
var jobSpecifics = $"Getting data for {archetype ?? "unknown"}";
var jobSpecifics = $"Getting data from {archetype ?? "unknown"}";
this._transactionServices.LogDetailsOfTheJob(jobSpecifics);
}
}
Expand Down
7 changes: 6 additions & 1 deletion FacadeFor3e/ReleaseHistory.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
2.1.0
2.1.1
-----
Improve logging for GetArchetypeData calls
Fix potential null reference error in RenderDataErrors

2.1.0
-----
Improve functionality for attaching files (this is a change to the interface)

Expand Down

0 comments on commit b3ec9e8

Please sign in to comment.