From b3ec9e80b7e39abf47ebc859c99c4c46802e1bf2 Mon Sep 17 00:00:00 2001 From: Jon Saffron Date: Thu, 22 Jun 2023 22:57:27 +0100 Subject: [PATCH] Improve logging for GetArchetypeData --- FacadeFor3e/ExecuteProcessExceptionBuilder.cs | 2 +- FacadeFor3e/ExecuteProcessResult.cs | 22 ++++++++++--------- FacadeFor3e/FacadeFor3e.csproj | 2 +- FacadeFor3e/GetArchetypeData.cs | 15 ++++++++----- FacadeFor3e/ReleaseHistory.md | 7 +++++- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/FacadeFor3e/ExecuteProcessExceptionBuilder.cs b/FacadeFor3e/ExecuteProcessExceptionBuilder.cs index cd57ccf..185ebff 100644 --- a/FacadeFor3e/ExecuteProcessExceptionBuilder.cs +++ b/FacadeFor3e/ExecuteProcessExceptionBuilder.cs @@ -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" diff --git a/FacadeFor3e/ExecuteProcessResult.cs b/FacadeFor3e/ExecuteProcessResult.cs index f9fb26f..bc77877 100644 --- a/FacadeFor3e/ExecuteProcessResult.cs +++ b/FacadeFor3e/ExecuteProcessResult.cs @@ -58,7 +58,7 @@ public Guid ProcessId /// Can be one of /// Success (the process completed), /// Failure (an error occurred), or - /// Interface (the process is still running) + /// Interface (the process has not finished running and is stopped at a UI step) public string ExecutionResult { get @@ -251,22 +251,24 @@ internal AttributeError(XmlElement attributeElement) /// /// Generates a string description from a list of DataError /// - /// - /// - public static string RenderDataErrors(IEnumerable dataErrors) + /// A collection of data errors returned from running a process + /// A string containing a description of each of the data errors specified, or null if the data errors collection is empty + public static string? RenderDataErrors(IEnumerable 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(); } diff --git a/FacadeFor3e/FacadeFor3e.csproj b/FacadeFor3e/FacadeFor3e.csproj index 4438bbe..afd80d3 100644 --- a/FacadeFor3e/FacadeFor3e.csproj +++ b/FacadeFor3e/FacadeFor3e.csproj @@ -5,7 +5,7 @@ FacadeFor3E J Saffron Consulting FacadeFor3E - 2.1.0 + 2.1.1 A library that makes using the 3E transaction service a little easier. Copyright © J Saffron Consulting Ltd 2014 - 2023 https://github.com/JonSaffron/FacadeFor3e diff --git a/FacadeFor3e/GetArchetypeData.cs b/FacadeFor3e/GetArchetypeData.cs index 8283b18..812ad82 100644 --- a/FacadeFor3e/GetArchetypeData.cs +++ b/FacadeFor3e/GetArchetypeData.cs @@ -85,9 +85,10 @@ 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; } @@ -95,21 +96,25 @@ public XmlDocument GetData(XmlDocument xoql) { 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; } @@ -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); } } diff --git a/FacadeFor3e/ReleaseHistory.md b/FacadeFor3e/ReleaseHistory.md index 9f95f3d..5c342f5 100644 --- a/FacadeFor3e/ReleaseHistory.md +++ b/FacadeFor3e/ReleaseHistory.md @@ -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)