Exemplo n.º 1
0
        public int Submit(GatewayDocument gatewayDoc)
        {
            Trace.WriteLine("Got Submission. GatewayDocument object");

            if (gatewayDoc.GatewayDoc == null)
            {
                Trace.WriteLine("Xml Message not present. Returning 0");
                return(0);
            }

            int response = 0;

            response = gatewayDB.InsertDocument(gatewayDoc);

            Trace.WriteLine("Thread is in state: " + postThread.ThreadState.ToString());

            if (postThread.ThreadState == System.Threading.ThreadState.Stopped)
            {
                Trace.WriteLine("Starting posting thread");
                postThread = new Thread(PostThread);
                postThread.Start();
            }

            return(response);
        }
Exemplo n.º 2
0
        public GatewayDocument GetDocument(int submissionID)
        {
            SqlCommand cmd = cnn.CreateCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "GetDocument";

            cmd.Parameters.Add(new SqlParameter("@SubmissionID", SqlDbType.Int));
            cmd.Parameters["@SubmissionID"].Value = submissionID;

            SqlDataAdapter da = new SqlDataAdapter();

            da.SelectCommand = cmd;
            DataSet ds = new DataSet();

            da.Fill(ds, "GatewayDocuments");

            if (ds.Tables["GatewayDocuments"].Rows.Count == 1)
            {
                GatewayDocument gtwDoc = new GatewayDocument(ds.Tables["GatewayDocuments"].Rows[0]);
                return(gtwDoc);
            }
            else
            {
                Trace.WriteLine("Query did not return a result");
                return(null);
            }
        }
Exemplo n.º 3
0
        /// <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("");
            }
        }
Exemplo n.º 4
0
        internal string CreatePollingThread(ICallback callback, // Was CallbackContainer
                                            string CorrelationID,
                                            string Class,
                                            bool UsesTestGateway,
                                            string GovTalkUrl,
                                            string Guid,
                                            int IntervalSeconds)
        {
            // Begin constructing the gateway document to poll for
            GatewayDocument submission = new GatewayDocument();

            //... and fill in the fields ...
            submission.DocumentID       = "";
            submission.ApplicationID    = 0;
            submission.CorrelationID    = CorrelationID;
            submission.DocumentType     = Class;
            submission.IsTestMessage    = false;
            submission.UsesTestGateway  = UsesTestGateway;
            submission.RequiresAuditing = false;
            submission.RequiresLogging  = false;

            // Only replace the default if the supplied parameter is
            // not an empty string
            if (GovTalkUrl != "")
            {
                submission.Url = GovTalkUrl;
            }

            /*
             * Kick off a new thread; we have to be a little type un-safe here
             * because of the limitations of the parameterised ThreadStart
             * But that's OK because we've unforced the type in the call.
             */
            ThreadParam parameters = new ThreadParam();

            parameters.callback        = callback;
            parameters.document        = submission;
            parameters.Guid            = Guid;
            parameters.IntervalSeconds = IntervalSeconds;

            Thread pollingThread = new Thread(new ParameterizedThreadStart(RunPollingThread));

            pollingThread.Start(parameters);

            if (_parameters.ContainsKey(Guid))
            {
                _parameters.Remove(Guid);
            }

            _parameters.Add(Guid, parameters);

            // Register and reeeeee-eeeeeee-eeeeee-turn
            _threadDump.Add(Guid, pollingThread);
            return(Guid);
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public int UpdateDocument(GatewayDocument gatewayDoc)
        {
            SqlCommand cmd = cnn.CreateCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "procUpdateGatewayDocument";

            cmd.Parameters.Add(new SqlParameter("@SubmissionID", SqlDbType.Int));
            cmd.Parameters["@SubmissionID"].Value = gatewayDoc.SubmissionID;

            cmd.Parameters.Add(new SqlParameter("@ResponseDocument", SqlDbType.Xml));
            cmd.Parameters["@ResponseDocument"].Value = gatewayDoc.GatewayResponse;

            cmd.Parameters.Add(new SqlParameter("@RequiresAuditing", SqlDbType.Bit));
            cmd.Parameters["@RequiresAuditing"].Value = gatewayDoc.RequiresAuditing;

            cmd.Parameters.Add(new SqlParameter("@NextPoll", SqlDbType.DateTime));
            cmd.Parameters["@NextPoll"].Value = gatewayDoc.NextPoll;

            cmd.Parameters.Add(new SqlParameter("@LastPoll", SqlDbType.DateTime));
            cmd.Parameters["@LastPoll"].Value = gatewayDoc.LastPoll;

            cmd.Parameters.Add(new SqlParameter("@Url", SqlDbType.NChar, 256));
            cmd.Parameters["@Url"].Value = gatewayDoc.Url;

            cmd.Parameters.Add(new SqlParameter("@CorrelationID", SqlDbType.NChar, 32));
            cmd.Parameters["@CorrelationID"].Value = gatewayDoc.CorrelationID;

            try
            {
                cnn.Open();
                cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                Trace.WriteLine("There was an exception while adding a record to the database");
                Trace.WriteLine("The exception was:");
                Trace.WriteLine(ex.Message);
                cnn.Close();
                return(0);
            }

            cnn.Close();

            return(1);
        }
Exemplo n.º 8
0
 public int Submit(GatewayDocument fbiParams)
 {
     return(IRISGlobalVariables.CurrentServer.Submit(fbiParams));
 }
Exemplo n.º 9
0
 static public XmlDocument RequestList(GatewayDocument gtwDoc)
 {
     return(PollingMessage("request", "list", gtwDoc));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Allows an additional poll to be madce by the application, however if the polling
 /// </summary>
 /// <param name="gtwDoc"></param>
 /// <returns></returns>
 static public XmlDocument Poll(GatewayDocument gtwDoc)
 {
     return(PollingMessage("poll", "submit", gtwDoc));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Sends a delete request to the gateway specified in gtwDoc.Url, the gtwDoc must have a valid
 /// correlation identifier (i.e. it must be in the gateway somwhere.
 /// </summary>
 /// <param name="gtwDoc">The full assembled gateway document object</param>
 /// <returns>The reposnse receoived from the gateway, this will usually be the
 /// deleteion ackowledgement</returns>
 static public XmlDocument Delete(GatewayDocument gtwDoc)
 {
     return(PollingMessage("request", "delete", gtwDoc));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Subit the prepared document to the gateway specified in gtwDoc.Url
 /// </summary>
 /// <param name="gtwDoc">The full assembled gateway document object</param>
 /// <returns>Tne response message provided by the gateway, this will usually be
 /// the initial submission ackowledgement</returns>
 static public XmlDocument Submit(GatewayDocument gtwDoc)
 {
     return(PostToGateway(gtwDoc.GatewayDoc, gtwDoc.Url));
 }
Exemplo n.º 13
0
        static private XmlDocument PollingMessage(string strQualifier, string strFunction, GatewayDocument gtwDoc)
        {
            // Polling messages like Poll or Delete are pretty basic, so we build them on the fly
            // and use the same template for both

            XmlDocument    messageDoc = new XmlDocument();
            XmlDeclaration xmldecl    = messageDoc.CreateXmlDeclaration("1.0", null, null);

            XmlNode root = messageDoc.CreateElement("GovTalkMessage");

            messageDoc.AppendChild(root);
            messageDoc.InsertBefore(xmldecl, root);

            XmlNode currentNode = root;

            ((XmlElement)currentNode).SetAttribute("xmlns", "http://www.govtalk.gov.uk/CM/envelope");

            currentNode           = messageDoc.CreateElement("EnvelopeVersion");
            currentNode.InnerText = "2.0";
            root.AppendChild(currentNode);

            XmlNode headerNode;
            XmlNode parentNode;

            headerNode = messageDoc.CreateElement("Header");
            parentNode = root.AppendChild(headerNode);

            currentNode = messageDoc.CreateElement("MessageDetails");
            parentNode  = parentNode.AppendChild(currentNode);

            currentNode           = messageDoc.CreateElement("Class");
            currentNode.InnerText = gtwDoc.DocumentType;
            parentNode.AppendChild(currentNode);

            currentNode           = messageDoc.CreateElement("Qualifier");
            currentNode.InnerText = strQualifier;
            parentNode.AppendChild(currentNode);

            currentNode           = messageDoc.CreateElement("Function");
            currentNode.InnerText = strFunction;
            parentNode.AppendChild(currentNode);

            currentNode           = messageDoc.CreateElement("CorrelationID");
            currentNode.InnerText = gtwDoc.CorrelationID;
            parentNode.AppendChild(currentNode);

            currentNode           = messageDoc.CreateElement("Transformation");
            currentNode.InnerText = "XML";
            parentNode.AppendChild(currentNode);

            if (gtwDoc.UsesTestGateway)
            {
                currentNode           = messageDoc.CreateElement("GatewayTest");
                currentNode.InnerText = "1";
                parentNode.AppendChild(currentNode);
            }

            currentNode = messageDoc.CreateElement("SenderDetails");
            parentNode  = headerNode.AppendChild(currentNode);


            currentNode = messageDoc.CreateElement("GovTalkDetails");
            root        = root.AppendChild(currentNode);

            currentNode = messageDoc.CreateElement("Keys");
            root.AppendChild(currentNode);

            root = root.ParentNode;

            currentNode = messageDoc.CreateElement("Body");
            root.AppendChild(currentNode);

            // JAY - Debug method for testing generated polling message
            //StreamWriter writer = new StreamWriter(
            //   string.Format("{0}\\{1}",
            //                  Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
            //                  "out.xml"));
            //writer.Write(messageDoc.OuterXml);
            //writer.Close();

            return(PostToGateway(messageDoc.OuterXml, gtwDoc.Url));
        }
Exemplo n.º 14
0
        public int InsertDocument(GatewayDocument gatewayDoc)
        {
            SqlCommand cmd = cnn.CreateCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "procInsertGatewayDocument";

            cmd.Parameters.Add(new SqlParameter("@DocumentID", SqlDbType.NChar, 20));
            cmd.Parameters["@DocumentID"].Value = gatewayDoc.DocumentID;

            cmd.Parameters.Add(new SqlParameter("@ApplicationID", SqlDbType.Int));
            cmd.Parameters["@ApplicationID"].Value = gatewayDoc.ApplicationID;

            cmd.Parameters.Add(new SqlParameter("@SubmittedDocument", SqlDbType.Xml));
            cmd.Parameters["@SubmittedDocument"].Value = gatewayDoc.GatewayDoc;

            cmd.Parameters.Add(new SqlParameter("@DocumentType", SqlDbType.NChar, 20));
            cmd.Parameters["@DocumentType"].Value = gatewayDoc.DocumentType;

            cmd.Parameters.Add(new SqlParameter("@IsTestMessage", SqlDbType.Bit));
            cmd.Parameters["@IsTestMessage"].Value = gatewayDoc.IsTestMessage;

            cmd.Parameters.Add(new SqlParameter("@UsesTestGateway", SqlDbType.Bit));
            cmd.Parameters["@UsesTestGateway"].Value = gatewayDoc.UsesTestGateway;

            cmd.Parameters.Add(new SqlParameter("@RequiresAuditing", SqlDbType.Bit));
            cmd.Parameters["@RequiresAuditing"].Value = gatewayDoc.RequiresAuditing;

            cmd.Parameters.Add(new SqlParameter("@RequiresLogging", SqlDbType.Bit));
            cmd.Parameters["@RequiresLogging"].Value = gatewayDoc.RequiresLogging;

            cmd.Parameters.Add(new SqlParameter("@NextPoll", SqlDbType.DateTime));
            cmd.Parameters["@NextPoll"].Value = gatewayDoc.NextPoll;

            cmd.Parameters.Add(new SqlParameter("@Url", SqlDbType.NChar, 256));
            cmd.Parameters["@Url"].Value = gatewayDoc.Url;

            cmd.Parameters.Add(new SqlParameter("@SubmissionID", SqlDbType.Int));
            cmd.Parameters["@SubmissionID"].Direction = ParameterDirection.Output;


            try
            {
                cnn.Open();
                cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                Trace.WriteLine("There was an exception while adding a record to the database");
                Trace.WriteLine("The exception was:");
                Trace.WriteLine(ex.Message);
                cnn.Close();
                return(0);
            }

            cnn.Close();

            string submissionID = cmd.Parameters["@SubmissionID"].Value.ToString();

            Trace.WriteLine("Added GatewayDocument to Database with ID " + submissionID);

            return(int.Parse(submissionID));
        }
Exemplo n.º 15
0
        /// <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);
            }
        }