//Other general information /// <summary> /// Read the first error description from the document, or the "error_srcText" in case of a "runtime_error" document /// </summary> public string GetFirstErrorDescr() { if (hasError) { return(doc.GetStringValue("//ERROR/DESCRIPTION/text()")); } else if (hasRuntimeError) { return(doc.GetStringValue("/runtime_error/error_srcText/text()")); } else { return(null); } }
/// <summary> /// Checks for unpleasant HTTP status codes as well as other problems with the response. /// All errors found here are fatal: they break the chain of async processes. /// </summary> /// <param name="content">HttpContent for Posting to TNT</param> /// <param name="expectXml">Do we expect the response to be XML?</param> private async Task <PostResults> PostAsync(HttpContent content, bool expectXml) { HttpResponseMessage resp = null; try { resp = await client.PostAsync(new Uri(TARGET_URL), content); } catch (Exception e) { FirePostError(0, "PostAsync Exception: " + e.Message); throw e; //just to stop the flow } if (!resp.IsSuccessStatusCode) { FirePostError(0, "HTTP error status " + resp.StatusCode + ": " + resp.ReasonPhrase); throw new InvalidOperationException("HTTP error status " + resp.StatusCode + ": " + resp.ReasonPhrase); } //xml checks if (expectXml) { MyXMLDocument xdoc = null; Stream st = await resp.Content.ReadAsStreamAsync(); try { TextReader rd = new StreamReader(st, new UTF8Encoding(false, true)); XmlReader XReader = XmlReader.Create(rd); xdoc = new MyXMLDocument(XReader, readOnly: true); if ( xdoc.NodeExists("/runtime_error") || xdoc.NodeExists("/parse_error") ) { string errormsg = xdoc.GetStringValue("//error_reason/text()"); FirePostError(0, "Errormessage sent by TNT: " + errormsg); throw new InvalidOperationException("Errormessage sent by TNT: " + errormsg); } } catch (Exception e) { FirePostError(0, "Problem parsing xml " + e.Message); throw e; } return(new PostResults(null, xdoc)); } else { string c = await resp.Content.ReadAsStringAsync(); return(new PostResults(c, null)); } }
//Methods to read the current Consigment from the doc /// <summary> /// Get a Consignment property from either CREATE or SHIP /// Note: We could even require that they are equal in both, or we could require SHIP and disregard CREATE /// </summary> /// <param name="prop">the property to get</param> private string GetConProp(ConsignmentProps prop) { if (hasShip) { return(curShip.GetStringValue("./" + prop.ToString() + "/text()")); } else if (hasCreate) { return(curCreate.GetStringValue("./" + prop.ToString() + "/text()")); } else { return(null); } }