/// <summary>
        /// Remove campaign from list
        /// </summary>
        /// <param name="id"></param>
        /// <param name="stopCampaign"></param>
        public static void RemoveCampaignFromList(string name, bool stopCampaign)
        {
            DialerEngine.Log.Write("Remove campaign start " + name);
            Log.Write("|DE|Remove {0} thread begin.", name);
            try
            {
                lock (lstCampaignThreads)
                {
                    for (int i = 0; i < lstCampaignThreads.Count; i++)
                    {
                        if (lstCampaignThreads[i].Name == name)
                        {
                            if (stopCampaign)
                            {
                                try
                                {
                                    // stop campaigning.  This method will trigger on idle or completed.
                                    Log.Write("|DE|Abort {0} thread begin.", name);
                                    if (lstCampaignThreads[i].IsAlive)
                                    {
                                        lstCampaignThreads[i].Abort();
                                    }
                                }
                                catch (Exception ee)
                                {
                                    Log.WriteException(ee, "Error aborting thread.");
                                    //throw ee;
                                }
                            }
                            try
                            {
                                lstCampaignThreads[i] = null;
                                lstCampaignThreads.RemoveAt(i);

                                // Remove silent call counts
                                CampaignProcess.RemoveSilentCallCount(name);
                            }
                            catch (Exception ee)
                            {
                                Log.WriteException(ee, "Error in RemoveCampaignFromList RemoveAt");
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteException(ex, "Error in RemoveCampaignFromList");
                throw ex;
            }
            finally
            {
                //DialerEngine.Log.Write("Remove end");
            }
        }
        /// <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>
        /// Stop and remove all campaigns
        /// </summary>
        private static void StopAllCampaigns()
        {
            Log.Write("|DE|Stop all campaigns invoked.");
            lock (lstCampaignThreads)
            {
                try
                {
                    if (lstCampaignThreads.Count > 0)
                    {
                        for (int i = 0; i < lstCampaignThreads.Count; i++)
                        {
                            try
                            {
                                // stop campaigning
                                Log.Write("|DE|Campaign thread abort {0}.", lstCampaignThreads[i].Name);
                                if (lstCampaignThreads[i].IsAlive)
                                {
                                    lstCampaignThreads[i].Abort();
                                }
                                //break;
                            }
                            catch (Exception ex)
                            {
                                Log.WriteException(ex, "Error in StopAllCampaigns");
                            }
                        }
                    }
                    lstCampaignThreads.Clear();

                    CampaignProcess.RemoveSilentCallCount("-ALL-");

                    // Added GW 10.01.10 to reset any campaigns that somehow locked into run or paused states.
                    CampaignAPI.ResetCampaignsToIdle();
                }
                catch (Exception ex1)
                {
                    Log.WriteException(ex1, "Error in StopAllCampaigns Main");
                }
            }
            Log.Write("|DE|Stop all campaigns complete.");
        }
        /// <summary>
        /// Start campaigns for dialing
        /// </summary>
        /// <param name="campaign"></param>
        /// <returns></returns>
        private void StartCampaignProcess()
        {
            Log.Write("|DE|Checking for start times for {0} new campaigns.", qCampaignQueue.Count);
            if (qCampaignQueue.Count == 0)
            {
                // no campaigns
                DialerEngine.Log.Write("No active campaigns found");
                return;
            }

            // clear
            GC.Collect();
            try
            {
                ThreadStart ts = null;

                while (qCampaignQueue.Count != 0)
                {
                    Campaign objCampaign = null;
                    lock (qCampaignQueue)
                    {
                        objCampaign = qCampaignQueue.Dequeue();
                    }
                    // add to running list
                    // m_RunningCampaignIdList.Add(campaign.CampaignID.ToString());

                    DialingParameter objDialParam   = CampaignAPI.GetDialParam(objCampaign);
                    OtherParameter   objOtherParam  = null;
                    bool             bStartCampaign = false;

                    CallType callType = CallType.AMCall;
                    DateTime dtStartTime;
                    if (DateTime.Now.Hour >= 12)
                    {
                        callType    = CallType.PMCall;
                        dtStartTime = objDialParam.PMDialingStart;
                    }
                    else
                    {
                        dtStartTime = objDialParam.AMDialingStart;
                    }

                    int iCurrHour    = DateTime.Now.Hour;
                    int iCurrMinutes = DateTime.Now.Minute;
                    int iDPhour      = dtStartTime.Hour;
                    int iDPMinutes   = dtStartTime.Minute;

                    //-------------------------------------------------
                    // We ignore time issue for anything
                    // other than unmanned campaigns.
                    //-------------------------------------------------
                    Log.Write("|DE|Campaign - Dialing Mode: {0})", objDialParam.DialingMode.ToString());
                    if (objDialParam.DialingMode != 6)
                    {
                        bStartCampaign = true;
                    }
                    else if (iCurrHour > iDPhour || ((iCurrHour == iDPhour) && (iCurrMinutes >= iDPMinutes)))
                    {
                        bStartCampaign = true;
                    }

                    try
                    {
                        if (bStartCampaign)
                        {
                            DigitalizedRecording digRecording = CampaignAPI.GetDigitizedRecordings(objCampaign);

                            objOtherParam = CampaignAPI.GetOtherParam(objCampaign);

                            CampaignProcess campProcess = new CampaignProcess(objCampaign, objDialParam, objOtherParam);
                            if (digRecording != null)
                            {
                                campProcess.RecordingsPath = digRecording.RecordingFilePath;
                                campProcess.RecordCalls    = digRecording.EnableRecording;
                                campProcess.RecordBeep     = digRecording.StartWithABeep;
                            }

                            // weekend call checking
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday ||
                                DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                            {
                                callType = CallType.WkendCall;
                            }

                            campProcess.CallType = callType;

                            Log.Write("|DE|Starting campaign '{0}'.", objCampaign.ShortDescription);

                            // Start campaignprocess thread.  Different startup method for normal / unmanned mode
                            if (objDialParam.DialingMode == Convert.ToInt32(DialingMode.Unmanned))
                            {
                                ts = new ThreadStart(campProcess.RunCampaignUnmannedMode);
                            }
                            else
                            {
                                ts = new ThreadStart(campProcess.RunCampaign);
                            }
                            Thread t = new Thread(ts);
                            t.Priority     = ThreadPriority.Normal;
                            t.IsBackground = true;
                            t.Name         = objCampaign.ShortDescription.ToString();

                            lock (lstCampaignThreads)
                            {
                                lstCampaignThreads.Add(t);
                            }
                            if (objDialParam.DialingMode != Convert.ToInt32(DialingMode.ManualDial))
                            {
                                t.Start();
                            }
                        }
                        else
                        {
                            Log.Write("|DE|Campaign '{0}' not started, outside of schedule range. (Start time = {1}:{2})",
                                      objCampaign.ShortDescription, iDPhour.ToString(), iDPMinutes.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteException(ex, "Error in Starting Campaign " + objCampaign.ShortDescription);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteException(ex, "Error in StartCampaignProcess");
            }
            finally
            {
                //
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult GetAll()
        {
            var response = new CampaignProcess().GetAllCampaigns();

            return(Ok(response));
        }