Пример #1
0
 /**
  * This callback method is invoked in response to the 'TerminalUnregisteredEvent'. The application may
  * receive this event if the terminal if forcefully unregistered by the AE Service Server
  * This application sets the isTerminalRegistered flag to false and displays reason for unregistration.
  * This handler can be modified to provide more involved display information handling.
  **/
 public void OnTerminalUnregisteredEventHandler(object sender, TerminalUnregisteredEventArgs args)
 {
     Console.WriteLine("Application exiting as TerminalUnregisterd event received ");
     if (args.Reason != null)
     {
         Console.WriteLine("Reason = {0}: ", args.Reason);
     }
     isTerminalRegistered = false;
     CleanUp();
 }
Пример #2
0
        /* This function is the thread procedure for reader thread.
         * This reads the responses and appropriately converts them into events.
         * */
        private void HandleReponseThreadProc()
        {
            try
            {
                while (!StopReadResponse)
                {
                    /* Ensure there is some data on the stream */
                    if (socket_handle.NWStream.DataAvailable == false)
                    {
                        System.Threading.Thread.Sleep(1000);
                        continue;
                    }

                    string response = xmlHandler.readXMLMessage();

                    // parse the response and create a document node tree structure for accessing XML data
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(response);
                    XmlElement root = doc.DocumentElement;
                    Console.WriteLine("Received event : {0}", root.Name);

                    switch (root.Name)
                    {
                    case "LampModeEvent":
                    {
                        LampModeEventArgs lampModeEventArgs = new LampModeEventArgs(root);
                        OnLampModeEvent(this, lampModeEventArgs);
                        break;
                    }

                    case "DisplayUpdatedEvent":
                    {
                        DisplayUpdatedEventArgs displayUpdatedArgs = new DisplayUpdatedEventArgs(root);
                        OnDisplayUpdatedEvent(this, displayUpdatedArgs);
                        break;
                    }

                    case "RingerStatusEvent":
                    {
                        RingerStatusEventArgs ringerStatusEventArgs = new RingerStatusEventArgs(root);
                        OnRingerStatusEvent(this, ringerStatusEventArgs);
                        break;
                    }

                    case "ResetApplicationSessionTimerPosResponse":
                    {
                        Console.WriteLine("ResetApplicationSessionTimerPosResponse received from AE Services server");
                        break;
                    }

                    case "CSTAException":
                    {
                        XmlNodeList NodeList = root.GetElementsByTagName("message");
                        Console.WriteLine(NodeList[0].InnerText);
                    }
                    break;

                    case "TerminalUnregisteredEvent":
                    {
                        TerminalUnregisteredEventArgs terminalUnregisteredEventArgs = new TerminalUnregisteredEventArgs(root);
                        OnTerminalUnregisteredEvent(this, terminalUnregisteredEventArgs);
                        break;
                    }

                    default:
                    {
                        Console.WriteLine("Unknown event received from AE Services server: {0}", root.Name);
                        // This application ignores unrecognized events.
                        break;
                    }
                    }   // End of switch
                }// End of while
            }

            catch (ThreadAbortException ex)
            {
                /* When user presses 'any key' to stop the application, reader thread is aborted to immediately
                 * stop the processing. This results in receiveing ThreadAbortException here.
                 * Do nothing in this exception handler. */
            }
            catch (Exception ex)
            {
                ExceptionArgs args = new ExceptionArgs(ex.Message);
                OnException(this, args);
            }

            finally
            {
            }
        }