예제 #1
0
        public string BeginPolling(ICallback callback,
                                   string CorrelationID,
                                   string Class,
                                   bool UsesTestGateway,
                                   string GovTalkUrl,
                                   int PollingIntervalWholeSeconds)
        {
            string RetVal;

            // HACK: Temp just call back the response if the correlation ID is "-999"
            if (CorrelationID == "-999")
            {
                callback.Response("This is a test call back from the FBI COM Object 8.8.1.2");
                return("Test call back was performed");
            }
            else
            {
                try
                {
                    RetVal = _broker.BeginPolling(callback,
                                                  CorrelationID,
                                                  Class,
                                                  UsesTestGateway,
                                                  GovTalkUrl, PollingIntervalWholeSeconds);
                }
                catch (Exception ex)
                {
                    throw (ex);
                }

                return(RetVal);
            }
        }
예제 #2
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);
            }
        }