Ejemplo n.º 1
0
        public void runThread()
        {
            logwrite.write("Finesse FinesseKeepAlive", "Finesse FinesseKeepAlive Thread Start!!");

            try
            {
                while (true)
                {
                    Thread.Sleep(10000);
                    string agentID  = agent.getAgentID();
                    string serverIP = finesseClient.getCurrentServerIP();

                    FinesseDomain domainVO = FinesseDomain.getInstance();
                    string        domain   = domainVO.getFinesseDomain();

                    string strMsg = @"<iq id='" + agentID + "@" + serverIP + "/pidgin' to='" + domain + "' type='get' from='" + agentID + "@" + serverIP + "/pidgin'><ping xmlns='urn:xmpp:ping'/></iq>";

                    logwrite.write("Finesse FinesseKeepAlive", "SEND -> " + strMsg);
                    writer.WriteLine(strMsg);
                    writer.Flush();
                }
            }
            catch (Exception e)
            {
                if (writer != null)
                {
                    writer.Close();
                }
                if (sock != null)
                {
                    sock.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public void runThread()
        {
            try
            {
                logwrite.write("ISPSClient runThread", "\t ISPS Thread Start!!");

                String readLine = "";

                while (true)
                {
                    readLine = reader.ReadLine();
                    logwrite.write("ISPSReceiver runThread", readLine);
                }
            }
            catch (Exception e)
            {
                if (reader != null)
                {
                    reader.Close();
                    reader = null;
                }
                if (writeStream != null)
                {
                    writeStream.Close();
                    writeStream = null;
                }

                logwrite.write("ISPSReceiver runThread", e.ToString());
            }
            finally
            {
                ispsClient.sessionClose();



                // 사용자가 Disconnect 를 요청하지 않고 세션이 끊어진 경우 재접속 시도
                if (!ispsClient.getDisconnectReq())
                {
                    logwrite.write("ISPSReceiver runThread", "########## ISPS Session Closed !! ##########");

                    Event evt = new Event();
                    evt.setEvtCode(EVENT_TYPE.ON_DISCONNECTION);
                    evt.setEvtMsg("ISPS Session Disconnected");
                    evt.setCurIspsIP(ispsClient.getCurrentServerIP());
                    finesseObj.raiseEvent(evt);


                    if (ispsClient.reConnect() != ERRORCODE.SUCCESS)
                    {
                        // 서버 세션이 끊어지고, 재접속이 안될시 서버 프로세스가 올라올때까지 감지하는 스레드 시작한다.
                        ISocketSender ispsSender = new ISPSSender(logwrite, ispsClient);
                        ThreadStart   ts         = new ThreadStart(ispsSender.runThread);
                        Thread        thread     = new Thread(ts);
                        thread.Start();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected int connect(String ip, int port)
        {
            try
            {
                sock = new TcpClient();

                IAsyncResult result = sock.BeginConnect(ip, port, null, null);

                var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(CONNECTION.CONNECTION_TIMEOUT), true);

                if (success)
                {
                    writeStream = sock.GetStream();

                    //writeStream.ReadTimeout = 3000;

                    writer = new StreamWriter(writeStream);

                    Encoding encode = System.Text.Encoding.GetEncoding("UTF-8");

                    //Encoding encode = System.Text.Encoding.Default;

                    reader = new StreamReader(writeStream, encode);

                    if (currentServer.ContainsKey("IP"))
                    {
                        currentServer.Remove("IP");
                    }
                    if (currentServer.ContainsKey("PORT"))
                    {
                        currentServer.Remove("PORT");
                    }

                    currentServer.Add("IP", ip);
                    currentServer.Add("PORT", port);
                }
                else
                {
                    return(ERRORCODE.SOCKET_CONNECTION_FAIL);
                }
            }
            catch (Exception e)
            {
                logwrite.write("connect", e.ToString());

                if (sock != null)
                {
                    sock = null;
                }

                return(ERRORCODE.SOCKET_CONNECTION_FAIL);
            }

            return(ERRORCODE.SUCCESS);
        }
Ejemplo n.º 4
0
        public Event parseXML(string xml)
        {
            try
            {
                if (xml == null)
                {
                    return(null);
                }

                logwrite.write("### CHECK ###", xml);

                // xml 로드
                xmlDoucment.LoadXml(xml);

                evt = null;

                // Agent State Event
                nodeList = xmlDoucment.GetElementsByTagName("user");
                if (nodeList.Count > 0)
                {
                    evt = getUserEvent(nodeList);
                    evt.setEvtMsg(xml);
                    return(evt);
                }
                // Call Event
                nodeList = xmlDoucment.GetElementsByTagName("Dialog");
                if (nodeList.Count > 0)
                {
                    evt = getdialogEvent(nodeList);
                    evt.setEvtMsg(xml);
                    return(evt);
                }

                // Call Event
                nodeList = xmlDoucment.GetElementsByTagName("dialog");
                if (nodeList.Count > 0)
                {
                    evt = getdialogEvent(nodeList);
                    evt.setEvtMsg(xml);
                    return(evt);
                }

                // Error Event
                nodeList = xmlDoucment.GetElementsByTagName("apiErrors");
                if (nodeList.Count > 0)
                {
                    evt = getErrorEvent(nodeList);
                    evt.setEvtMsg(xml);
                    return(evt);
                }
            }
            catch (Exception e)
            {
                logwrite.write("parseXML", e.ToString());
            }

            return(evt);
        }
Ejemplo n.º 5
0
        public void runThread()
        {
            ArrayList ipList = new ArrayList();

            ServerInfo serverInfo = finesseClient.getServerInfo();

            ipList = serverInfo.getIPList();
            int port = serverInfo.getPort();

            bool connectSuccess = false;

            while (!connectSuccess)
            {
                for (int i = 0; i < ipList.Count; i++)
                {
                    string ip = (string)ipList[i];

                    sock = new TcpClient();

                    var result = sock.BeginConnect(ip, port, null, null);

                    var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(CONNECTION.CONNECTION_TIMEOUT));

                    if (sock != null && sock.Connected)
                    {
                        connectSuccess = true;
                        logwrite.write("Finesse Sender", "Connection SUCCESS IP [" + ip + "] PORT [" + port + "]");
                        break;
                    }
                    else
                    {
                        logwrite.write("Finesse Sender", "Connection Fail IP [" + ip + "] PORT [" + port + "]");
                    }
                }
            }

            if (sock != null)
            {
                sock.Close();
            }

            finesseClient.finesseReConnect();
        }
Ejemplo n.º 6
0
 private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
 {
     setConsultCallSetting();
     logwrite.write("", "RETURN DATA : " + useDll.fnDisconnect());
 }
Ejemplo n.º 7
0
        public void runThread()
        {
            try
            {
                logwrite.write("FinesseReceiver runThread", " Finesse Recv Thread Start !!");

                writeStream.ReadTimeout = Timeout.Infinite;

                Event evt = null;

                if (writeStream == null)
                {
                    logwrite.write("FinesseReceiver runThread", "writeStream null");
                }

                int    BUFFERSIZE = sock.ReceiveBufferSize;
                byte[] buffer     = new byte[BUFFERSIZE];
                int    bytelen    = 0;

                StringBuilder sb = new StringBuilder();



                while ((bytelen = writeStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    string message = Encoding.UTF8.GetString(buffer, 0, bytelen);
                    message = message.Replace("&lt;", "<");
                    message = message.Replace("&gt;", ">");
                    message = message.Replace("\n", "");
                    message = message.Trim();

                    //Console.WriteLine(message);
                    logwrite.write("FinesseReceiver runThread", message.Replace("\n", ""));

                    int endIndex  = 0;
                    int subLength = 0;

                    while (message.Length > 0)
                    {
                        //Console.WriteLine("message Len : " + message.Length);
                        if (message.StartsWith("<message"))
                        {
                            endIndex = message.IndexOf("</message>");
                            if (endIndex > -1)
                            {
                                subLength = endIndex + "</message>".Length;
                                string resultStr = message.Substring(0, subLength);

                                evt = xmlParser.parseXML(resultStr);
                                finesseObj.raiseEvent(evt);
                                //Console.WriteLine("\n\n1. result -> " + resultStr);
                                message = message.Substring(subLength, message.Length - subLength);
                            }
                            else
                            {
                                sb.Append(message);
                                break;
                            }
                        }
                        else
                        {
                            endIndex = message.IndexOf("</message>");
                            if (endIndex > -1)
                            {
                                subLength = endIndex + "</message>".Length;
                                string resultStr = message.Substring(0, subLength);

                                if (sb.ToString().Length > 0)
                                {
                                    sb.Append(resultStr);
                                    resultStr = sb.ToString().Replace("&gt;", ">").Replace("&lt;", "<");
                                    evt       = xmlParser.parseXML(resultStr);
                                    finesseObj.raiseEvent(evt);
                                    //Console.WriteLine("\n\n2. result -> " + sb.ToString());
                                    sb = new StringBuilder();
                                }
                                message = message.Substring(subLength, message.Length - subLength);
                            }
                            else
                            {
                                if (sb.ToString().Length > 0)
                                {
                                    sb.Append(message);
                                    break;
                                }
                                else
                                {
                                    sb = new StringBuilder();
                                    break;
                                }
                            }
                        }
                    }
                }



                /*
                 * while ((bytelen = writeStream.Read(buffer, 0, buffer.Length)) > 0)
                 * {
                 *
                 *  string message = Encoding.UTF8.GetString(buffer, 0, bytelen);
                 *  message = message.Replace("&lt;", "<");
                 *  message = message.Replace("&gt;", ">");
                 *
                 *  message = message.Replace("\n", "");
                 *
                 *  logwrite.write("FinesseReceiver runThread", message.Replace("\n", ""));
                 *
                 *  int startIndex = message.IndexOf("<message");
                 *  int endIndex = message.IndexOf("</message>");
                 *
                 *  int endTaglen = "</message>".Length;
                 *  int messagelen = message.Length;
                 *
                 *  string tempStr = "";
                 *
                 *  if (startIndex > -1)
                 *  {
                 *      if (endIndex > -1)
                 *      {
                 *          sb.Append(message.Substring(startIndex, endIndex + endTaglen - startIndex));
                 *          evt = xmlParser.parseXML(sb.ToString());
                 *          finesseObj.raiseEvent(evt);
                 *          //Console.WriteLine("result -> " + sb.ToString());
                 *          sb = new StringBuilder();
                 *          if (message.Length > endIndex + endTaglen)
                 *          {
                 *              // 완료 XML 뒤에 데이터가 있는경우
                 *              int start = endIndex + endTaglen;
                 *              tempStr = message.Substring(start, messagelen - start);
                 *
                 *              startIndex = tempStr.IndexOf("<message");
                 *              endIndex = tempStr.IndexOf("</message>");
                 *
                 *              if (startIndex > -1)
                 *              {
                 *                  if (endIndex > -1)
                 *                  {
                 *                      // 완료 XML 이 뒤에 또 붙은 경우
                 *                      start = endIndex + endTaglen;
                 *                      tempStr = tempStr.Substring(startIndex, start - startIndex);
                 *                      sb.Append(tempStr);
                 *                      evt = xmlParser.parseXML(sb.ToString());
                 *                      finesseObj.raiseEvent(evt);
                 *                      //Console.WriteLine("result -> " + sb.ToString());
                 *                      sb = new StringBuilder();
                 *                  }
                 *                  else
                 *                  {
                 *                      // 완료 XML 이 아닌경우
                 *                      tempStr = tempStr.Substring(startIndex, tempStr.Length);
                 *                      sb.Append(tempStr);
                 *                  }
                 *              }
                 *
                 *          }
                 *
                 *      }
                 *      else
                 *      {
                 *          // 마지막 <message>이 또 붙어서 XML 이 끝이 나지 않은 경우
                 *          tempStr = message.Substring(startIndex, messagelen - startIndex);
                 *          sb = new StringBuilder();
                 *          sb.Append(tempStr);
                 *      }
                 *  }
                 *  else if (endIndex > -1)
                 *  {
                 *      tempStr = message.Substring(0, endIndex + endTaglen);
                 *      sb.Append(tempStr);
                 *      evt = xmlParser.parseXML(sb.ToString());
                 *      finesseObj.raiseEvent(evt);
                 *      //Console.WriteLine("result -> " + sb.ToString());
                 *      sb = new StringBuilder();
                 *  }
                 *
                 * }
                 */
            }
            catch (Exception e)
            {
                if (reader != null)
                {
                    reader.Close();
                    reader = null;
                }

                if (writeStream != null)
                {
                    writeStream.Close();
                    writeStream = null;
                }
                logwrite.write("FinesseReceiver runThread", e.ToString());
            }
            finally
            {
                finesseClient.sessionClose();
                finesseClient.setXMPPAuth(false);   // Finesse 세션이 끊어지면 다른 서버로 재접속 할떄 XMPP 인증이 필요하기 때문에 Flag 세팅

                // 사용자가 Disconnect 를 요청하지 않고 세션이 끊어진 경우 재접속 시도
                if (!finesseClient.getDisconnectReq())
                {
                    logwrite.write("FinesseReceiver runThread", "########## Finesse Session Closed !! ##########");

                    Event evt = new ErrorEvent();
                    evt.setEvtCode(EVENT_TYPE.ON_DISCONNECTION);
                    evt.setEvtMsg("Finesse Session Disconnected");
                    evt.setCurFinesseIP(finesseClient.getCurrentServerIP());
                    finesseObj.raiseEvent(evt);

                    if (finesseClient.finesseReConnect() == ERRORCODE.SUCCESS)
                    {
                        logwrite.write("FinesseReceiver runThread", " TRY TO CHECK AGENT PREVIOUS STATE");
                        // XMPP 인증 성공하면 이전 상담원 상태를 가져온다.
                        finesseClient.checkAgentState();
                    }
                    else
                    {
                        // 서버 세션이 끊어지고, 재접속이 안될시 서버 프로세스가 올라올때까지 감지하는 스레드 시작한다.
                        ISocketSender finesseSender = new FinesseSender(logwrite, finesseClient);
                        ThreadStart   ts            = new ThreadStart(finesseSender.runThread);
                        Thread        thread        = new Thread(ts);
                        thread.Start();
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public override void GetEventOnCallAlerting(string dialogID, string callType, string fromAddress, string toAddress, string callState, string actionList)
        {
            if (actionList != null && actionList.Length != 0)
            {
                char[]   delimiterChars = { '^' };
                string[] arr            = actionList.Split(delimiterChars);
                form.setButtonMask(arr);
            }
            else
            {
                string[] arr = { BTNMASK.ANSWER };
                form.setButtonMask(arr);
            }

            logwrite.write("USEDLL", "callState : " + callState);
            logwrite.write("USEDLL", "actionList : " + actionList);
        }
Ejemplo n.º 9
0
        public string requestGETAPI(string url, Agent agent, string methodType)
        {
            this.URL = url;

            try
            {
                request        = (HttpWebRequest)WebRequest.Create(URL);
                request.Method = methodType;

                string basicEncode = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(agent.getAgentID() + ":" + agent.getAgentPwd()));

                request.Headers.Add("Authorization", "Basic " + basicEncode);

                logwrite.write("requestRESTAPI", "============================= REQUEST REST API =================================");
                logwrite.write("requestRESTAPI", "  URL \t : " + URL);
                logwrite.write("requestRESTAPI", "  METHOD \t : " + methodType);
                logwrite.write("requestRESTAPI", "  basicEncode \t : " + basicEncode);

                response = (HttpWebResponse)request.GetResponse();
                int code = Convert.ToInt32(response.StatusCode);


                Stream webStream = response.GetResponseStream();
                reader = new StreamReader(webStream);

                string responseStr = reader.ReadToEnd();

                logwrite.write("requestRESTAPI", "============================= RESPONSE REST API =================================");
                logwrite.write("requestRESTAPI", "  code \t : " + code);
                logwrite.write("requestRESTAPI", "  DATA \t : " + responseStr);
                logwrite.write("requestRESTAPI", "=================================================================================");

                reader.Close();

                return(responseStr);
            }
            catch (Exception e)
            {
                logwrite.write("requestRESTAPI", e.ToString());
                return(null);
            }
        }
Ejemplo n.º 10
0
        public void runThread()
        {
            try
            {
                /*
                 * String readLine = "";
                 *
                 * while (true)
                 * {
                 *  readLine = reader.ReadLine();
                 *  logwrite.write("AEMSReceiver runThread", readLine);
                 * }
                 * */

                logwrite.write("AEMSReceiver runThread", "\t AEMS Receiver Thread Start!!");

                int    BUFFERSIZE = sock.ReceiveBufferSize;
                byte[] buffer     = new byte[BUFFERSIZE];
                int    bytelen    = 0;
                while ((bytelen = writeStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    string message = Encoding.UTF8.GetString(buffer, 0, bytelen);
                    logwrite.write("recv", message);
                }
            }
            catch (Exception e)
            {
                if (reader != null)
                {
                    reader.Close();
                    reader = null;
                }
                if (writeStream != null)
                {
                    writeStream.Close();
                    writeStream = null;
                }
                logwrite.write("AEMSReceiver runThread", e.ToString());
            }
            finally
            {
                aemsClient.sessionClose();

                if (!aemsClient.getDisconnectReq())
                {
                    logwrite.write("AEMSReceiver runThread", "########## AEMS Session Closed !! ##########");

                    Event evt = new Event();
                    evt.setEvtCode(EVENT_TYPE.ON_DISCONNECTION);
                    evt.setEvtMsg("AEMS Session Disconnected");
                    evt.setCurAemsIP(aemsClient.getCurrentServerIP());
                    finesseObj.raiseEvent(evt);

                    if (aemsClient.reConnect() != ERRORCODE.SUCCESS)
                    {
                        // 서버 세션이 끊어지고, 재접속이 안될시 서버 프로세스가 올라올때까지 감지하는 스레드 시작한다.

                        ISocketSender aemsSender = new AEMSSender(logwrite, aemsClient);
                        ThreadStart   ts         = new ThreadStart(aemsSender.runThread);
                        Thread        thread     = new Thread(ts);
                        thread.Start();
                    }
                }
            }
        }