/// <summary>
        /// Disconnect server
        /// </summary>
        public void Disconnect()
        {
            lock (s_SyncVar)
            {
                s_Connected = false;

                if (TelephonyServer != null)
                {
                    try
                    {
                        // stop campaign polling
                        if (tmrGetCampaigns != null)
                        {
                            tmrGetCampaigns.Stop();
                            tmrGetCampaigns = null;
                        }

                        // stop agents pooling
                        if (tmrGetAgents != null)
                        {
                            tmrGetAgents.Stop();
                            tmrGetAgents = null;
                        }

                        // stop running campaigns
                        StopAllCampaigns();

                        // dispose all channels
                        ManagedChannel.Dispose();
                        ManagedAgent.Dispose();

                        CampaignProcess.Dispose();
                    }
                    catch { }

                    try
                    {
                        CampaignAPI.DialerStoped(this.ActivityId);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteException(ex, "Updating Dialer start error");
                    }

                    TelephonyServer.NewCall -= new NewCall(m_TelephonyServer_NewCall);
                    TelephonyServer.Dispose();
                    TelephonyServer = null;

                    // wait for a while, Child threads release the resources
                    Thread.Sleep(10);
                    Log.Write("|DE|Disconnected from VE server.");
                }
            }
        }
 /// <summary>
 /// Get all loggedin agents and add it to pool
 /// </summary>
 private void GetLoggodInAgents()
 {
     try
     {
         //lock (s_SyncVar)
         //{
         // Update agents pool
         List <Agent> agentList = AgentAPI.GetLoggedInAgents();
         if (agentList != null)
         {
             ManagedAgent.InitializeAgents(agentList);
         }
         // }
     }
     catch (Exception ex)
     {
         Log.WriteException(ex, "Error Getting Campaigns");
     }
 }
Example #3
0
        /// <summary>
        /// New call event for channel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ChannelResource_NewCall(object sender, NewCallEventArgs e)
        {
            if (e.ChannelResource is MsiChannel)
            {
                Log.Write("|MC|Msi {0} went off hook", e.ChannelResource.DeviceName);

                // Start something here to managed an off hook agent...

                //Check if the agent is logged in or not and play message
                //to agent to Login else add to off hook list
                ManagedAgent   ma = ManagedAgent.CheckAgentLoggedIn(e.ChannelResource.DeviceName);
                ManagedChannel mc = null;

                if (ma != null)
                {
                    if (!ma.AgentDetails.AllwaysOffHook)
                    {
                        foreach (ManagedChannel mc2 in ManagedChannel.MsiChannelList)
                        {
                            if (mc2.ChannelResource.Equals(e.ChannelResource))
                            {
                                mc = mc2;
                                break;
                            }
                        }

                        if (mc == null)
                        {
                            Log.Write("|MC|ChannelResource_NewCall unable to locate channel.");
                        }
                        else
                        {
                            ma.InboundAgent(mc);
                        }
                    }
                    else
                    {
                        Log.Write("|MC|ChannelResource_NewCall AllwaysOffHook agent with station-{0}", e.ChannelResource.DeviceName);
                    }
                }
                else
                {
                    try
                    {
                        // VoiceResource on MSIChannel,
                        // e.ChannelResource.VoiceResource.PlayTTS("Please Login");
                    }
                    finally
                    {
                        e.ChannelResource.Disconnect();
                    }
                }
            }
            else
            {
                // Handle new call event
                try
                {
                    Log.Write("|MC|{0} NewCall. Answering.", e.ChannelResource.DeviceName);   // MONROE
                    e.ChannelResource.Answer();
                    Log.Write("|MC|{0} Playing Good Bye Message.", e.ChannelResource.DeviceName);
                    e.ChannelResource.VoiceResource.Play(@"AudioFiles\Goodbye.wav");
                }
                finally
                {
                    Log.Write("|MC|{0} Disconnecting.", e.ChannelResource.DeviceName);
                    e.ChannelResource.Disconnect();
                }
            }
        }