/// <summary> /// Submit the document to the government gateway. /// Returns the Xml from the GatewayServer, or an empty /// string if nothing to submit. /// </summary> public string Submit(string Class, bool UsesTestGateway, string DocumentXml) { if (DocumentXml != null && DocumentXml != "") { GatewayDocument submission = new GatewayDocument(); // The Posting settings must be applied first. // Assign posting settings. submission.Url = _submissionUrl; //... and fill in the fields ... submission.DocumentType = Class; submission.UsesTestGateway = UsesTestGateway; // Stuff the XML into the document submission.GatewayDoc = DocumentXml; // Submit the document XmlDocument returnDoc = GatewayServer.Submit(submission); // return the generated Xml return(returnDoc.OuterXml); } else { // Nothing to do return(""); } }
public XmlDocument RequestList(string CorrelationID, string Class, bool UsesTestGateway, string GovTalkUrl) { GatewayDocument gwDoc = new GatewayDocument(); gwDoc.CorrelationID = CorrelationID; gwDoc.UsesTestGateway = UsesTestGateway; gwDoc.DocumentType = Class; gwDoc.Url = GovTalkUrl; return(GatewayServer.RequestList(gwDoc)); }
public string Delete(string CorrelationID, string Class, bool UsesTestGateway, string GovTalkUrl) { XmlDocument DeleteResponse; GatewayDocument gwDoc = new GatewayDocument(); gwDoc.CorrelationID = CorrelationID; gwDoc.UsesTestGateway = UsesTestGateway; gwDoc.DocumentType = Class; gwDoc.Url = GovTalkUrl; DeleteResponse = GatewayServer.Delete(gwDoc); return(DeleteResponse.OuterXml); }
private void PostThread() { Trace.WriteLine("Got into Processing Thread " + Thread.CurrentThread.ManagedThreadId); List <GatewayDocument> gatewayDocList = gatewayDB.GetDocumentsWithStatus(DocumentStatus.NOSTATUS); while (gatewayDocList.Count > 0) { Trace.WriteLine("Documents in Posting Queue"); foreach (GatewayDocument gDoc in gatewayDocList) { Trace.WriteLine("About to send Document " + gDoc.SubmissionID); gatewayDB.SetStatus(gDoc.SubmissionID, DocumentStatus.SUBMITTING); XmlDocument gtwResponse = GatewayServer.Submit(gDoc); if (gtwResponse != null) { if (gDoc.InsertXmlUpdate(gtwResponse)) { Trace.WriteLine("XML Response from Gateway for document " + gDoc.SubmissionID + " was imported sucessfully into GatewayDocument. Writing to Database"); gatewayDB.UpdateDocument(gDoc); gatewayDB.SetStatus(gDoc.SubmissionID, DocumentStatus.POLLING); } else { Trace.WriteLine("GatewayDocument " + gDoc.SubmissionID + " could not be saved to the database"); } } else { gatewayDB.SetStatus(gDoc.SubmissionID, DocumentStatus.UNKNOWN); break; } } gatewayDocList = gatewayDB.GetDocumentsWithStatus(DocumentStatus.NOSTATUS); } Trace.WriteLine("Posting Queue is empty. Exiting Posting Thread"); }
/// <summary> /// Provides the meat of the polling mechanism. /// </summary> internal static void RunPollingThread(object Parameters) { try { // Prepare the thread for execution ICallback callback = ((ThreadParam)Parameters).callback; GatewayDocument gwDoc = ((ThreadParam)Parameters).document; if (callback == null) { // MAG Removing Event Log Stuff _eventLog.WriteEntry(string.Format("Callback is null")); return; } int interval = ((ThreadParam)Parameters).IntervalSeconds; // Make sure the thread is always running, occasionally sleeping XmlDocument returnDoc; bool threadRunning = true; do { // Check for redirection information foreach (PollingParameters param in _messages) { if (param.Guid == ((ThreadParam)Parameters).Guid) { // rather than using the Parameters paramerter, should we be using the param for the test, // so the thread actually stops? if (param.Url == "" && param.IntervalSeconds < 0) { threadRunning = false; _messages.Remove(param); return; } // Will redirect to the first message in the queue, then delete it ((ThreadParam)Parameters).document.Url = param.Url; interval = ((ThreadParam)Parameters).IntervalSeconds; _messages.Remove(param); break; } } // Poll... returnDoc = GatewayServer.Poll(gwDoc); if (returnDoc == null) { } else { // A response has been received, so check the message for any redirection or poll interval changes, and // implement those changes XmlNodeList ResponseParams = returnDoc.GetElementsByTagName("ResponseEndPoint"); try { // Get the polling interval and set out internal timer, and the interval in the thread parameters interval = Convert.ToInt32(ResponseParams[0].Attributes["PollInterval"].InnerText); } catch (Exception) { interval = 60; // the default } try { // Now redirect as well ((ThreadParam)Parameters).document.Url = ResponseParams[0].InnerText; } catch (Exception) { // Nothing to do leave it as it is } // Invoke the callback callback.Response(returnDoc.InnerXml); } // Pause until the next polling period Thread.Sleep(interval * 1000); } while (threadRunning); } catch (Exception ex) { throw (ex); } }