/// <summary>
        ///
        /// </summary>
        /// <param name="i"></param>
        private void ResetRecording(FuentesGlp fuente)
        {
            if (!this._LocalRecordingEnabled)
            {
                return;
            }

            _Logger.Info("ResetRecording source: " + fuente.ToString());

            //SessionGlp(_GlpCallId[(int)fuente], fuente, false);
            ResetSessionGlp(fuente);
            //System.Threading.Thread.Sleep(200);
            //SessionGlp(fuente, true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSupervisorLengthRecordingTimerElapsed(object sender, ElapsedEventArgs e)
        {
            _SupervisorLengthRecording.Enabled = false;

            for (FuentesGlp i = FuentesGlp.RxRadio; i <= FuentesGlp.TxLc; i++)
            {
                if (_GlpSessionsStarted[(int)i] && _SessionsFileName[(int)i] != string.Empty)
                {
                    FileInfo fi = new FileInfo(_SessionsFileName[(int)i]);
                    _Logger.Info("Supervisor GLP: GLP session started. Recording file: " + fi.FullName);
                    int interval = (i == FuentesGlp.RxRadio || i == FuentesGlp.TxRadio) ? 1 : 30;
                    if (fi != null && fi.Exists && fi.Length > interval * 60 * 16000 /*interval minutos, aprox. */)
                    {
                        ResetRecording(i);
                    }
                }
            }

            _SupervisorLengthRecording.Enabled = true;
        }
        private void ResetSessionGlp(FuentesGlp fuente)
        {
            if (!this._LocalRecordingEnabled)
            {
                return;
            }

            // Recording off
            if (_GlpSessionsStarted[(int)fuente] && (_SessionsFile[(int)fuente] >= 0))
            {
                Top.Mixer.Unlink(_SessionsFile[(int)fuente]);
                SipAgent.DestroyWavRecorder(_SessionsFile[(int)fuente]);

                _SessionsFile[(int)fuente]       = -1;
                _GlpSessionsStarted[(int)fuente] = false;

                try
                {
                    File.Move(_SessionsFileName[(int)fuente], _SessionsFileName[(int)fuente].Replace("@", ""));
                }
                catch (System.IO.IOException /*e*/)
                {
                    File.Delete(_SessionsFileName[(int)fuente]);
                    _Logger.Warn("GLP.SesionGlp. El fichero ya existe.");
                }

                _SessionsFileName[(int)fuente] = string.Empty;

                if (fuente == FuentesGlp.Briefing && Settings.Default.SNMPEnabled == 1)
                {
                    Top.WorkingThread.Enqueue("SetSnmp", delegate()
                    {
                        string evento = Top.Cfg.PositionId + "_0";
                        General.SafeLaunchEvent(SetSnmpString, this, new SnmpStringMsg <string, string>(Settings.Default.StartingBriefingSessionOid, evento));
                    });
                }
            }

            // Recording on
            _GlpSessionsStarted[(int)fuente] = true;

            if (_SessionsFile[(int)fuente] == -1)
            {
                /* AGL.REC Directorio de Grabacion Local Configurable
                 * string dirName = "Recording/" + fuente.ToString();
                 * */
                string dirName = Settings.Default.DirectorioGLP + fuente.ToString();
                /* Fin Modificacion */

                if (!System.IO.Directory.Exists(dirName))
                {
                    System.IO.Directory.CreateDirectory(dirName);
                }

                string fileName = dirName + "/" + "@" + fuente.ToString() + "_" + Top.Cfg.MainId + "_" +
                                  DateTime.Now.TimeOfDay.Hours + "_" +
                                  DateTime.Now.TimeOfDay.Minutes + "_" +
                                  DateTime.Now.TimeOfDay.Seconds + ".wav";
                _SessionsFile[(int)fuente]     = SipAgent.CreateWavRecorder(fileName);
                _SessionsFileName[(int)fuente] = fileName;
                _Logger.Info("Recording GLP. Filename: " + _SessionsFileName[(int)fuente]);

                switch (fuente)
                {
                case FuentesGlp.Briefing:
                    Top.Mixer.LinkGlp(_SessionsFile[(int)fuente], MixerDev.MhpRd, fuente);
                    Top.Mixer.LinkGlp(_SessionsFile[(int)fuente], MixerDev.MhpTlf, fuente);
                    break;

                case FuentesGlp.TxRadio:
                    Top.Mixer.LinkGlp(_SessionsFile[(int)fuente], MixerDev.MhpRd, fuente);
                    break;

                case FuentesGlp.TxLc:
                    Top.Mixer.LinkGlp(_SessionsFile[(int)fuente], MixerDev.MhpLc, fuente);
                    break;

                case FuentesGlp.RxRadio:
                    lock (_GlpCallId)
                    {
                        foreach (int idCall in _GlpCallId[(int)fuente])
                        {
                            Top.Mixer.Link(idCall, _SessionsFile[(int)fuente], MixerDir.Send, fuente);
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="id"></param>
 /// <param name="fuente"></param>
 public void SetIdSession(int id, FuentesGlp fuente)
 {
     _SessionsId[(int)fuente] = id;
     //if (!_GlpCallId[(int)fuente].Contains(id))
     //  _GlpCallId[(int)fuente].Add(id);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="fuente"></param>
        /// <param name="iniciar"></param>
        internal void SessionGlp(FuentesGlp fuente, bool iniciar)
        {
            if (!this._LocalRecordingEnabled)
            {
                return;
            }

            lock (_Sync)
            {
                try {
                    if (iniciar != _GlpSessionsStarted[(int)fuente])
                    {
                        _GlpSessionsStarted[(int)fuente] = !_GlpSessionsStarted[(int)fuente];

                        if (fuente == FuentesGlp.Briefing)
                        {
                            General.SafeLaunchEvent(BriefingChanged, this, new StateMsg <bool>(Briefing));
                            _BriefingSessionTimer.Enabled = true;

                            if (Settings.Default.SNMPEnabled == 1 && iniciar)
                            {
                                Top.WorkingThread.Enqueue("SetSnmp", delegate()
                                {
                                    string evento = Top.Cfg.PositionId + "_1";
                                    General.SafeLaunchEvent(SetSnmpString, this, new SnmpStringMsg <string, string>(Settings.Default.StartingBriefingSessionOid, evento));
                                });
                            }
                        }

                        if (_GlpSessionsStarted[(int)fuente] && _SessionsFile[(int)fuente] == -1)
                        {
                            /* AGL.REC Directorio de Grabacion Local Configurable
                             * string dirName = "Recording/" + fuente.ToString();
                             * */
                            string dirName = Settings.Default.DirectorioGLP + fuente.ToString();
                            /* Fin Modificacion */

                            if (!System.IO.Directory.Exists(dirName))
                            {
                                System.IO.Directory.CreateDirectory(dirName);
                            }

                            string fileName = dirName + "/" + "@" + fuente.ToString() + "_" + Top.Cfg.MainId + "_" +
                                              DateTime.Now.TimeOfDay.Hours + "_" +
                                              DateTime.Now.TimeOfDay.Minutes + "_" +
                                              DateTime.Now.TimeOfDay.Seconds + ".wav";
                            _SessionsFile[(int)fuente]     = SipAgent.CreateWavRecorder(fileName);
                            _SessionsFileName[(int)fuente] = fileName;
                            _Logger.Info("Recording GLP. Filename: " + _SessionsFileName[(int)fuente]);

                            switch (fuente)
                            {
                            case FuentesGlp.Briefing:
                                Top.Mixer.LinkGlp(_SessionsFile[(int)fuente], MixerDev.MhpRd, fuente);
                                Top.Mixer.LinkGlp(_SessionsFile[(int)fuente], MixerDev.MhpTlf, fuente);
                                break;

                            case FuentesGlp.TxRadio:
                                Top.Mixer.LinkGlp(_SessionsFile[(int)fuente], MixerDev.MhpRd, fuente);
                                break;

                            case FuentesGlp.TxLc:
                                Top.Mixer.LinkGlp(_SessionsFile[(int)fuente], MixerDev.MhpLc, fuente);
                                break;

                            case FuentesGlp.RxRadio:
                                foreach (int idCall in _GlpCallId[(int)fuente])
                                {
                                    try
                                    {
                                        //Top.Mixer.Unlink(idCall);
                                        Top.Mixer.Link(idCall, _SessionsFile[(int)fuente], MixerDir.Send, fuente);
                                    }
                                    catch (Exception e)
                                    {
                                        _Logger.Error("SessionGLP-Rx: ", e);
                                    }
                                }

                                //if (_SessionsId[(int)FuentesGlp.RxRadio] != -1)
                                //    Top.Mixer.Link(_SessionsId[(int)FuentesGlp.RxRadio], _SessionsFile[(int)fuente], MixerDir.Send);
                                break;

                            default:
                                break;
                            }
                        }
                        else if (!_GlpSessionsStarted[(int)fuente] && (_SessionsFile[(int)fuente] >= 0))
                        {
                            _GlpCallId[(int)fuente].Clear();

                            Top.Mixer.Unlink(_SessionsFile[(int)fuente]);
                            if (_SessionsFile[(int)fuente] >= 0)
                            {
                                SipAgent.DestroyWavRecorder(_SessionsFile[(int)fuente]);
                                _SessionsFile[(int)fuente] = -1;
                                //_SessionsId[(int)fuente] = -1;
                                _GlpSessionsStarted[(int)fuente] = false;

                                try
                                {
                                    File.Move(_SessionsFileName[(int)fuente], _SessionsFileName[(int)fuente].Replace("@", ""));
                                }
                                catch (System.IO.IOException /*e*/)
                                {
                                    File.Delete(_SessionsFileName[(int)fuente]);
                                    _Logger.Warn("GLP.SesionGlp. El fichero ya existe.");
                                }

                                _SessionsFileName[(int)fuente] = string.Empty;
                            }

                            if (fuente == FuentesGlp.Briefing && Settings.Default.SNMPEnabled == 1)
                            {
                                Top.WorkingThread.Enqueue("SetSnmp", delegate()
                                {
                                    string evento = Top.Cfg.PositionId + "_0";
                                    General.SafeLaunchEvent(SetSnmpString, this, new SnmpStringMsg <string, string>(Settings.Default.StartingBriefingSessionOid, evento));
                                });
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    _Logger.Error("GLP.SesionGlp Excepcion " + exc.Message);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="idCall"></param>
        /// <param name="fuente"></param>
        /// <param name="iniciar"></param>
        internal void SessionGlp(int idCall, FuentesGlp fuente, bool iniciar)
        {
            if (!this._LocalRecordingEnabled)
            {
                return;
            }

            lock (_Sync)
            {
                try
                {
                    if (iniciar && !_GlpSessionsStarted[(int)fuente])
                    {
                        _GlpSessionsStarted[(int)fuente] = !_GlpSessionsStarted[(int)fuente];

                        if (_GlpSessionsStarted[(int)fuente] && _SessionsFile[(int)fuente] == -1)
                        {
                            /* AGL.REC Directorio de Grabacion Local Configurable
                             * string dirName = "Recording/" + fuente.ToString();
                             * */
                            string dirName = Settings.Default.DirectorioGLP + fuente.ToString();
                            /* Fin Modificacion */

                            if (!System.IO.Directory.Exists(dirName))
                            {
                                System.IO.Directory.CreateDirectory(dirName);
                            }

                            string fileName = dirName + "/" + "@" + fuente.ToString() + "_" + Top.Cfg.MainId + "_" +
                                              DateTime.Now.TimeOfDay.Hours + "_" +
                                              DateTime.Now.TimeOfDay.Minutes + "_" +
                                              DateTime.Now.TimeOfDay.Seconds + ".wav";
                            _SessionsFile[(int)fuente]     = SipAgent.CreateWavRecorder(fileName);
                            _SessionsFileName[(int)fuente] = fileName;
                            _Logger.Info("Recording GLP. Filename: " + _SessionsFileName[(int)fuente]);
                        }

                        Top.Mixer.Link(idCall, _SessionsFile[(int)fuente], MixerDir.Send, fuente);
                        _GlpCallId[(int)fuente].Add(idCall);

                        if (fuente == FuentesGlp.Telefonia)
                        {
                            Top.Mixer.LinkGlpTfl(_SessionsFile[(int)fuente]);
                        }
                    }
                    else if (iniciar && (fuente == FuentesGlp.RxRadio || fuente == FuentesGlp.Telefonia) && _SessionsFile[(int)fuente] != -1)
                    {
                        if (!_GlpCallId[(int)fuente].Contains(idCall))
                        {
                            Top.Mixer.Link(idCall, _SessionsFile[(int)fuente], MixerDir.Send, fuente);
                            _GlpCallId[(int)fuente].Add(idCall);
                        }
                    }
                    else if (!iniciar && _GlpSessionsStarted[(int)fuente])
                    {
                        if (_GlpCallId[(int)fuente].Contains(idCall))
                        {
                            _GlpCallId[(int)fuente].Remove(idCall);
                        }

                        if (_GlpCallId[(int)fuente].Count == 0)
                        {
                            Top.Mixer.Unlink(_SessionsFile[(int)fuente]);
                            if (_SessionsFile[(int)fuente] >= 0)
                            {
                                SipAgent.DestroyWavRecorder(_SessionsFile[(int)fuente]);
                                _SessionsFile[(int)fuente]       = -1;
                                _GlpSessionsStarted[(int)fuente] = false;

                                try
                                {
                                    File.Move(_SessionsFileName[(int)fuente], _SessionsFileName[(int)fuente].Replace("@", ""));
                                }
                                catch (System.IO.IOException /*e*/)
                                {
                                    File.Delete(_SessionsFileName[(int)fuente]);
                                    _Logger.Warn("GLP.SesionGlp. El fichero ya existe.");
                                }

                                _SessionsFileName[(int)fuente] = string.Empty;
                            }
                        }
                        //_GlpCallId[(int)fuente] = 0;
                    }
                }
                catch (Exception exc)
                {
                    _Logger.Error("GLP.SesionGlp Excepcion " + exc.Message);
                }
            }
        }