private SFDCHttpServer()
 {
     this.logger           = Log.GenInstance();
     this.makeOutboundCall = VoiceMakeOutbound.GetInstance();
     this.generalOptions   = Settings.SFDCOptions;
     voiceEvents           = VoiceEvents.GetInstance();
     if (Settings.SFDCOptions.EnableTimerForSFDCPingCheck)
     {
         pingTimer          = new System.Timers.Timer(Settings.SFDCOptions.PingCheckElapsedTime);
         pingTimer.Elapsed += pingTimer_Elapsed;
     }
 }
Exemple #2
0
 private CallRejected()
 {
     this.logger      = Log.GenInstance();
     this.voiceEvents = VoiceEvents.GetInstance();
 }
 private CallEventError()
 {
     this.logger      = Log.GenInstance();
     this.voiceEvents = VoiceEvents.GetInstance();
 }
 /// <summary>
 /// This method Notifies the subscriber.
 /// </summary>
 /// <param name="callData">The call data.</param>
 public void NotifySubscriber(VoiceEvents voiceEvents, object callData)
 {
     //throw new NotImplementedException();
 }
 private CallAttachedDataChanged()
 {
     this.logger      = Log.GenInstance();
     this.voiceEvents = VoiceEvents.GetInstance();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 private CallEventAbandoned()
 {
     this.logger      = Log.GenInstance();
     this.voiceEvents = VoiceEvents.GetInstance();
 }
 private CallEventDestinationBusy()
 {
     this.logger      = Log.GenInstance();
     this.voiceEvents = VoiceEvents.GetInstance();
 }
        private void Process(IAsyncResult result)
        {
            try
            {
                lastPingTime = DateTime.Now;
                HttpListener listener = (HttpListener)result.AsyncState;
                listener.IgnoreWriteExceptions = true;
                if (listener.IsListening && !AdapeterStopped)
                {
                    HttpListenerContext context = listener.EndGetContext(result);
                    HttpListenerRequest request = context.Request;
                    // Obtain a response object.
                    HttpListenerResponse response = context.Response;
                    string filename = context.Request.Url.AbsolutePath;
                    string ack      = context.Request.QueryString["ack"];
                    filename = filename.Substring(1);

                    if (string.IsNullOrEmpty(filename))
                    {
                        if (File.Exists(Path.Combine(_rootDirectory, startPage)))
                        {
                            filename = startPage;
                        }
                    }

                    #region Dial Region

                    if (filename.Equals("dial"))
                    {
                        try
                        {
                            string phoneno = context.Request.QueryString["phoneno"];
                            logger.Info("Phone number received from salesforce : " + phoneno);
                            if (!String.IsNullOrEmpty(phoneno))
                            {
                                //phoneno = TruncateNumbers(phoneno, 10);
                                logger.Info("Invoking Call dialing procedure");
                                this.makeOutboundCall.MakeVoiceCall(phoneno, context.Request.QueryString["Type"], context.Request.QueryString["Id"]);
                                context.Response.OutputStream.Flush();
                                context.Response.StatusCode = (int)HttpStatusCode.OK;
                                context.Response.OutputStream.Close();
                                return;
                            }
                        }
                        catch (Exception generalException)
                        {
                            logger.Error("Process : Error occurred while processing dial request : " + generalException.ToString());
                        }
                    }

                    #endregion Dial Region

                    #region SessionId Region

                    if (filename.Equals("sessionid"))
                    {
                        try
                        {
                            string sessionId = context.Request.QueryString["sessionid"];
                            context.Response.ContentType = "text/html";
                            context.Response.AddHeader("Date", DateTime.Now.ToString("r"));
                            logger.Info("SessionId Received from Salesforce : " + (string.IsNullOrEmpty(sessionId) ? "0 Length" :
                                                                                   Convert.ToString(sessionId.Length)));
                            if (Settings.SFDCOptions.CanEnableSessionIDInLog)
                            {
                                logger.Info("Received session id is:" + sessionId);
                            }
                            if (!string.IsNullOrEmpty(sessionId))
                            {
                                //if (!string.IsNullOrEmpty(SFDCUtility.SForce.SessionHeaderValue.sessionId) &&
                                //    (SFDCUtility.SForce.SessionHeaderValue.sessionId == sessionId))
                                //{
                                //    logger.Info("Same SessionId Received from Salesforce, TestRequest not invoked");
                                //}
                                //else
                                {
                                    SFDCUtility.SForce.SessionHeaderValue.sessionId = sessionId;
                                    SessionKeepAliveInit();
                                    if (!NewSessionIDFlag)
                                    {
                                        logger.Info("New SessionId Received from Salesforce, Invoking Salesforce TestRequest");

                                        new System.Threading.Tasks.Task(() =>
                                                                        Pointel.Salesforce.Adapter.SFDCModels.SFDCUtility.GetInstance().SendTestRequest()).Start();
                                    }
                                    else
                                    {
                                        logger.Info("sessionId received retrying search operation");
                                        SFDCUtility sFDCUtility = SFDCUtility.GetInstance();
                                        if (sFDCUtility != null)
                                        {
                                            Settings.SFDCListener.SendSessionStatus(SFDCSessionStatus.Connected);
                                            logger.Info("sFDCUtility.SessionSearchCollection count :" + sFDCUtility.SessionSearchCollection.Count);
                                            logger.Info("sFDCUtility.SessionCreateActivityCollection count :" + sFDCUtility.SessionCreateActivityCollection.Count);
                                            logger.Info("sFDCUtility.SessionUpdateActivityCollection count :" + sFDCUtility.SessionUpdateActivityCollection.Count);
                                            if (sFDCUtility.SessionSearchCollection.Count > 0)
                                            {
                                                foreach (var tuple in sFDCUtility.SessionSearchCollection.ToArray())
                                                {
                                                    logger.Info("search method invoked for interaction id :" + tuple.Item1);
                                                    VoiceEvents.GetInstance().ProcessSearchData(tuple.Item1, tuple.Item3, tuple.Item2);
                                                }
                                                NewSessionIDFlag = false;
                                            }
                                            if (sFDCUtility.SessionCreateActivityCollection.Count > 0)
                                            {
                                                foreach (var tuple in sFDCUtility.SessionCreateActivityCollection.ToArray())
                                                {
                                                    logger.Info("Create activity log method invoked for interaction id :" + tuple.Item1);
                                                    sFDCUtility.CreateActivityLog(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4, tuple.Item5);
                                                }
                                                NewSessionIDFlag = false;
                                            }
                                            if (sFDCUtility.SessionUpdateActivityCollection.Count > 0)
                                            {
                                                foreach (var tuple in sFDCUtility.SessionUpdateActivityCollection.ToArray())
                                                {
                                                    logger.Info("update activity log method invoked for interaction id :" + tuple.Item1);
                                                    sFDCUtility.UpdateActivityLog(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4, tuple.Item5);
                                                }
                                                NewSessionIDFlag = false;
                                            }
                                        }
                                        else
                                        {
                                            logger.Error("SFDCHttpServer: Session id: SFDC utility object is null cannot perform retry");
                                        }
                                    }
                                }
                            }
                            context.Response.OutputStream.Flush();
                            context.Response.StatusCode = (int)HttpStatusCode.OK;
                            context.Response.OutputStream.Close();
                            return;
                        }
                        catch (Exception generalException)
                        {
                            logger.Error("Process : Error occurred while receiving sesssionId : " + generalException.ToString());
                        }
                    }

                    #endregion SessionId Region

                    #region TimeZone Region

                    if (filename.Equals("timezone"))
                    {
                        try
                        {
                            string timeZone = context.Request.QueryString["timezone"];
                            logger.Info("TimeZone received from Salesforce :" + timeZone);
                            if (!string.IsNullOrEmpty(timeZone))
                            {
                                timeZone = timeZone.Substring(1, timeZone.IndexOf(')') - 1);
                                if (CanGetTimeZoneFromSFDC)
                                {
                                    Settings.SFDCOptions.SFDCTimeZone = timeZone;
                                    logger.Info("TimeZone value taken as :" + timeZone);
                                }
                            }
                            context.Response.OutputStream.Flush();
                            context.Response.StatusCode = (int)HttpStatusCode.OK;
                            context.Response.OutputStream.Close();
                            return;
                        }
                        catch (Exception generalException)
                        {
                            logger.Error("Process : Error occurred while receiving TimeZone from SFDC : " + generalException.ToString());
                        }
                    }

                    #endregion TimeZone Region

                    #region ScriptError Region

                    if (filename.Equals("scripterror"))
                    {
                        try
                        {
                            logger.Error("Script Error Received from SFDC Script : " + context.Request.QueryString["log"]);
                            context.Response.OutputStream.Flush();
                            context.Response.StatusCode = (int)HttpStatusCode.OK;
                            context.Response.OutputStream.Close();
                            return;
                        }
                        catch (Exception generalException)
                        {
                            logger.Error("Process : Error occurred receiving script error : " + generalException.ToString());
                        }
                    }

                    #endregion ScriptError Region

                    #region SFDCConnection Opened

                    if (filename.Equals("opened"))
                    {
                        flagPrompt = true;
                        if (IsFirstRequestMade && Settings.SFDCOptions.NotifyAllConnectionStateChange)
                        {
                            Settings.SFDCListener.SendSessionStatus(SFDCSessionStatus.Connected);
                        }
                        connectionStatus = true;

                        if (IsFirstRequestMade)
                        {
                            this.logger.Info("Salesforce Connected with SFDC Adapter.....");
                        }
                        else
                        {
                            this.logger.Info("Adapter page loaded in Salesforce,SessionId is not verfied yet..");
                        }

                        if (IsFirstRequestMade && Settings.SFDCOptions.AlertSFDCConnectionStatus)
                        {
                            Settings.SFDCListener.SFDCConnectionStatus(LogMode.Info, Settings.SFDCOptions.SFDCConnectionSuccessMessage);
                        }

                        context.Response.OutputStream.Flush();
                        context.Response.StatusCode = (int)HttpStatusCode.OK;
                        context.Response.OutputStream.Close();
                    }

                    #endregion SFDCConnection Opened

                    #region SFDCConnection Closed

                    if (filename.Equals("closed"))
                    {
                        if (Settings.SFDCOptions.NotifyAllConnectionStateChange)
                        {
                            Settings.SFDCListener.SendSessionStatus(SFDCSessionStatus.NotConnected);
                        }
                        connectionStatus = false;
                        this.logger.Warn("Salesforce DisConnected from SFDC Adapter.....");
                        if (Settings.SFDCOptions.AlertSFDCConnectionStatus)
                        {
                            Settings.SFDCListener.SFDCConnectionStatus(LogMode.Error, Settings.SFDCOptions.SFDCConnectionFailureMessage);
                        }
                        context.Response.OutputStream.Flush();
                        context.Response.StatusCode = (int)HttpStatusCode.OK;
                        context.Response.OutputStream.Close();
                    }

                    #endregion SFDCConnection Closed

                    #region Push Region

                    if (filename.Equals("push"))
                    {
                        try
                        {
                            if (!Settings.SFDCListener.IsSFDCConnected)
                            {
                                if (IsFirstRequestMade && Settings.SFDCOptions.NotifyAllConnectionStateChange)
                                {
                                    Settings.SFDCListener.SendSessionStatus(SFDCSessionStatus.Connected);
                                }
                                if (IsFirstRequestMade && Settings.SFDCOptions.AlertSFDCConnectionStatus)
                                {
                                    Settings.SFDCListener.SFDCConnectionStatus(LogMode.Info, Settings.SFDCOptions.SFDCConnectionSuccessMessage);
                                }
                            }

                            int    i            = 0;
                            string noEvent      = " { \"Event\":  " + "\"" + "Ping" + "\"" + ", \"ANI\": " + "\"" + "test" + "\"" + " }";
                            byte[] pingResponse = ASCIIEncoding.ASCII.GetBytes(noEvent);
                            while (i <= 20)
                            {
                                if (ack == "true")
                                {
                                    context.Response.OutputStream.Write(pingResponse, 0, pingResponse.Length);

                                    context.Response.OutputStream.Flush();
                                    context.Response.StatusCode = (int)HttpStatusCode.OK;
                                    context.Response.OutputStream.Close();
                                    return;
                                }
                                if (sessionFlag)
                                {
                                    sessionFlag = false;

                                    string session         = " { \"Event\":  " + "\"" + "sessionid" + "\"" + ", \"ANI\": " + "\"" + "test" + "\"" + " }";
                                    byte[] sessionResponse = ASCIIEncoding.ASCII.GetBytes(session);
                                    context.Response.OutputStream.Write(sessionResponse, 0, sessionResponse.Length);
                                    context.Response.OutputStream.Flush();
                                    context.Response.StatusCode = (int)HttpStatusCode.OK;
                                    context.Response.OutputStream.Close();
                                    return;
                                }
                                if (flagPrompt && Settings.SFDCOptions.CanEditDialNo)
                                {
                                    flagPrompt = false;
                                    string promptEvent    = " { \"Event\":  " + "\"" + "init" + "\"" + ", \"EnablePrompt\": " + "\"" + "true" + "\"" + " }";
                                    byte[] promptResponse = ASCIIEncoding.ASCII.GetBytes(promptEvent);

                                    context.Response.OutputStream.Write(promptResponse, 0, promptResponse.Length);
                                    context.Response.OutputStream.Flush();
                                    context.Response.StatusCode = (int)HttpStatusCode.OK;
                                    context.Response.OutputStream.Close();
                                }
                                if (Settings.SFDCPopupData.Count > 0)
                                {
                                    foreach (string key in Settings.SFDCPopupData.Keys)
                                    {
                                        sfdcData = Settings.SFDCPopupData[key];
                                        Settings.SFDCPopupData.Remove(key);
                                        break;
                                    }
                                    try
                                    {
                                        jsonEvent = JsonConvert.SerializeObject(sfdcData);
                                        byte[] respons = ASCIIEncoding.ASCII.GetBytes(jsonEvent);
                                        context.Response.OutputStream.Write(respons, 0, respons.Length);
                                        context.Response.OutputStream.Flush();
                                        context.Response.StatusCode = (int)HttpStatusCode.OK;
                                        context.Response.OutputStream.Close();
                                        try
                                        {
                                            logger.Info("\n******Sending popup data to SalesForce ******" + sfdcData.ToString()
                                                        + "\n***************************************");
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    }
                                    catch (Exception generalException)
                                    {
                                        logger.Error("Error occurred while sending search and Activity Log data to salesforce : " + generalException.ToString());
                                    }
                                    return;
                                }
                                Thread.Sleep(200);
                                i++;
                            }
                            context.Response.OutputStream.Write(pingResponse, 0, pingResponse.Length);
                            context.Response.OutputStream.Flush();
                            context.Response.StatusCode = (int)HttpStatusCode.OK;
                            context.Response.OutputStream.Close();
                            return;
                        }
                        catch (HttpListenerException listenerException)
                        {
                            logger.Warn("Process : Listener write operation can't be performed : " + listenerException.ToString());
                        }
                        catch (Exception generalException)
                        {
                            logger.Error("Process : Error occurred while sending json data to Salesforce  : " + generalException.ToString());
                        }
                    }

                    #endregion Push Region

                    #region Basic Function

                    filename = Path.Combine(_rootDirectory, filename);
                    if (File.Exists(filename))
                    {
                        try
                        {
                            Stream input = new FileStream(filename, FileMode.Open, FileAccess.Read);
                            //Adding permanent http response headers
                            string mime;
                            context.Response.ContentType     = _mimeTypeMappings.TryGetValue(Path.GetExtension(filename), out mime) ? mime : "application/octet-stream";
                            context.Response.ContentLength64 = input.Length;
                            context.Response.AddHeader("Date", DateTime.Now.ToString("r"));
                            context.Response.AddHeader("Last-Modified", System.IO.File.GetLastWriteTime(filename).ToString("r"));

                            byte[] buffer = new byte[1024 * 16];
                            int    nbytes;
                            while ((nbytes = input.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                context.Response.OutputStream.Write(buffer, 0, nbytes);
                            }
                            input.Close();
                            context.Response.OutputStream.Flush();
                            context.Response.StatusCode = (int)HttpStatusCode.OK;
                        }
                        catch (Exception generalException)
                        {
                            logger.Error("process() : Error occurred while executing start page file from process method  " + generalException.ToString());
                            context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        }
                    }
                    else
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    }

                    #endregion Basic Function

                    context.Response.OutputStream.Close();
                }
            }
            catch (Exception generalException)
            {
                logger.Error("Process : Error occurred while processing request from Salesforce or AID : " + generalException.ToString());
            }
        }
 /// <summary>
 /// Constructor
 /// </summary>
 private CallDialing()
 {
     this.logger      = Log.GenInstance();
     this.voiceEvents = VoiceEvents.GetInstance();
 }
 private CallUserEvent()
 {
     this.logger      = Log.GenInstance();
     this.voiceEvents = VoiceEvents.GetInstance();
 }
Exemple #11
0
 public VoiceSDKListenerBinding(VoiceEvents voiceEvents) : base(
         "com.oculus.assistant.api.unity.dictation.UnityDictationListener")
 {
     this.voiceEvents = voiceEvents;
 }
 private CallPartyChanged()
 {
     this.logger      = Log.GenInstance();
     this.voiceEvents = VoiceEvents.GetInstance();
 }