Beispiel #1
0
        /* This function sends "RegisterTerminalRequest" to register the device */
        public bool RegisterTerminal(string device_id, string password, string telecommuter_number)
        {
            try
            {
                /* Get the XML string for "RegisterTerminalRequest" and
                 * send the request
                 */

                xmlHandler.sendRequest(XMLFormatter.FormatRegisterTerminalDeviceRequest(device_id, password, telecommuter_number));

                /*
                 * Now wait for a response, parse it, and interpert the response
                 */
                string      response = xmlHandler.readXMLMessage();
                XmlDocument doc      = new XmlDocument();
                doc.LoadXml(response);
                XmlElement  root     = doc.DocumentElement;
                XmlNodeList NodeList = root.GetElementsByTagName("code");

                if (NodeList == null || NodeList.Count <= 0)
                {
                    Console.WriteLine("Received error response for RegisterTerminalResponse");
                    Console.WriteLine(response);
                    return(false);
                }
                else
                {
                    /* Parsing the inner text message in the "code" element.
                     */
                    int ID = Int32.Parse(NodeList[0].InnerText);

                    if (ID == NORMAL_REGISTER)
                    {
                        /* The value of the data received in the "code" element is "1".
                         * This indicates normal and successful registration.
                         */
                        return(true);
                    }
                    else
                    {
                        /* The value of the data received in the "code" element
                         *  is an integer other than "1".
                         *  This indicates erroneous registration.
                         *  The positive integer gives the error code and the error
                         *  message is contained in the "reason" element.
                         */

                        XmlNodeList NodeList_reason = root.GetElementsByTagName("reason");
                        String      reason          = NodeList_reason[0].InnerText;
                        Console.WriteLine("Reason for RegisterTerminalResponse error= {0}", reason);
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception at RegisterTerminalDevice: {0}", ex.Message);
                return(false);
            }
        }
Beispiel #2
0
        /*
         * This function sends a "MonitorStart" request and starts a monitor for telephony events.
         * By starting a monitor, the application indicates the device that it is interested in observing.
         * By default, application starts receiving all the events. An application should state which events
         * it does not want to receive.
         * */
        public string MonitorStart(string deviceID)
        {
            try
            {
                // Get the XML string for the "MonitorStart" request and send the request
                xmlHandler.sendRequest(XMLFormatter.FormatMonitorStartRequest(deviceID));

                // Read response
                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;
                XmlNodeList NodeList = root.GetElementsByTagName("monitorCrossRefID");
                if (NodeList == null || NodeList.Count <= 0)
                {
                    Console.WriteLine("Received error response for MonitorStartResponse");
                    Console.WriteLine(response);
                    return(null);
                }
                else
                {
                    // Extract monitor reference ID from response XML
                    string ID = NodeList[0].InnerText;
                    return(ID);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception at MonitorStart: {0}", ex.Message);
                return(null);
            }
        }
Beispiel #3
0
        /* This function sets up a device identifier for the phone or extension supplied.
         * The response will contain device ID to uniquely identify a device.
         *
         * */
        public string GetDeviceID(string callserver, string ext)
        {
            try
            {
                // Get the XML string for the "GetDeviceID" request and send the request
                xmlHandler.sendRequest(XMLFormatter.FormatDeviceIDRequest(callserver, ext));

                // Read the response
                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;
                XmlNodeList NodeList = root.GetElementsByTagName("device");
                if (NodeList == null || NodeList.Count <= 0)
                {
                    Console.WriteLine("Received error response for GetDeviceIdResponse");
                    Console.WriteLine(response);
                    return(null);
                }
                else
                {
                    // Extract device ID
                    string ID = NodeList[0].InnerText;
                    return(ID);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception at GetDeviceID: {0}", ex.Message);
                return(null);
            }
        }
Beispiel #4
0
 /* This function stops monitor */
 public void MonitorStop(string monitor_id)
 {
     try
     {
         xmlHandler.sendRequest(XMLFormatter.FormatMonitorStopRequest(monitor_id));
         string response = xmlHandler.readXMLMessage();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Exception at MonitorStop: {0}", ex.Message);
         return;
     }
 }
Beispiel #5
0
 /* This function releases the device or station.
  * */
 public void ReleaseDeviceID(string device_id)
 {
     try
     {
         xmlHandler.sendRequest(XMLFormatter.FormatReleaseDeviceIDRequest(device_id));
         string response = xmlHandler.readXMLMessage();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Exception at GetDeviceID: {0}", ex.Message);
         return;
     }
 }
Beispiel #6
0
 /* This function unregisters the terminal */
 public void UnregisterTerminal(string device_id)
 {
     try
     {
         xmlHandler.sendRequest(XMLFormatter.FormatUnregisterTerminalRequest(device_id));
         string response = xmlHandler.readXMLMessage();
         return;
     }
     catch (Exception ex)
     {
         Console.WriteLine("Exception at RegisterTerminalDevice: {0}", ex.Message);
         return;
     }
 }
Beispiel #7
0
        /* This function will send the "StopApplicationRequest" and end the application session.
         * It also closes the TCP socket and the reader and writer streams attached to it.
         * */
        public void StopApplicationSession(string session_id)
        {
            try
            {
                // Get the XML string for "StopApplicationRequest" and send the request
                xmlHandler.sendRequest(XMLFormatter.FormatStopApplicationSessionRequest(session_id));
                string response = xmlHandler.readXMLMessage();

                // Close the TCP Socket connection.
                if (socket_handle.closeSocket())
                {
                    Console.WriteLine("Socket close operation performed successfully");
                }
                else
                {
                    Console.WriteLine("Error encountered during socket close operation");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception at StopApplicationSession: {0}", ex.Message);
                return;
            }
        }
Beispiel #8
0
        /* This function starts an application session with the AE Services server and returns a
         * session ID to uniquely identify the session.
         */
        public string StartApplicationSession(string server_ip, int server_port, bool isSecure, string username, string password, string protocol_version)
        {
            try
            {
                /*
                 * Create TCP socket and attach stream Reader and Writer. This reader and writer
                 * will be used to read response data and write request data respectively
                 * */
                socket_handle = new SocketHandler();

                Console.WriteLine("Connecting to AE Services Server..");
                if (socket_handle.openSocket(server_ip, server_port, isSecure))
                {
                    Console.WriteLine("Socket open operation performed successfully");
                    xmlHandler = new XMLHandler();
                    xmlHandler.setParameters(socket_handle);
                }
                else
                {
                    Console.WriteLine("Error encountered during socket open operation.\n" +
                                      "Please check IP address and port for the AE Services server");
                    if (isSecure)
                    {
                        Console.WriteLine("Ensure that the secure port is enabled");
                    }
                    else
                    {
                        Console.WriteLine("Ensure that the non-secure port is enabled");
                    }

                    Console.ReadKey();
                    Environment.Exit(1);
                }

                // Get the XML string for the "StartApplicationSession" request and send the request
                xmlHandler.sendRequest(XMLFormatter.FormatStartAppSessionRequest(username, password, protocol_version));

                // Read the response
                string response = xmlHandler.readXMLMessage();

                // parse the response and create a document node tree structure for accessing XML data
                XmlDocument doc = new XmlDocument();

                if (response.Contains("StartApplicationSessionPosResponse"))
                {
                    doc.LoadXml(response);
                    XmlElement  root      = doc.DocumentElement;
                    XmlNodeList NodeList  = root.GetElementsByTagName("sessionID");
                    string      sessionID = NodeList[0].InnerText;
                    return(sessionID);
                }
                else
                {
                    /* Parsing the reason for the reception of "StartApplicationSessionNegResponse" response
                     */
                    doc.LoadXml(response);
                    XmlElement  root     = doc.DocumentElement;
                    XmlNodeList NodeList = root.GetElementsByTagName("errorCode");
                    if (NodeList.Count > 0)
                    {
                        string errorResponse = NodeList[0].InnerText;
                        Console.WriteLine("Received error response for StartApplicationSession:\n {0}", errorResponse);
                        return(null);
                    }
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception at StartApplicationSession:\n {0}", ex.Message);
                return(null);
            }
        }
Beispiel #9
0
 /* This function sends the Keep Alive messages to keep the session active */
 private void SessionKeepAlive(Object stateInfo)
 {
     Console.WriteLine("\nSending session keep alive request at {0}", DateTime.Now.TimeOfDay);
     xmlHandler.sendRequest(XMLFormatter.FormatSessionKeepAlive((string)stateInfo));
     return;
 }