Пример #1
0
        /// <summary>
        /// checks if a received EPGChannel should be filtered from the resultlist
        /// </summary>
        /// <value></value>
        protected override bool FilterOutEPGChannel(EpgChannel epgChannel)
        {
            TvBusinessLayer layer = new TvBusinessLayer();

            if (layer.GetSetting("generalGrapOnlyForSameTransponder", "no").Value == "yes")
            {
                DVBBaseChannel chan        = epgChannel.Channel as DVBBaseChannel;
                Channel        dbchannel   = layer.GetChannelByTuningDetail(chan.NetworkId, chan.TransportId, chan.ServiceId);
                DVBCChannel    dvbcchannel = new DVBCChannel();
                if (dbchannel == null)
                {
                    return(false);
                }
                foreach (TuningDetail detail in dbchannel.ReferringTuningDetail())
                {
                    if (detail.ChannelType == 2)
                    {
                        dvbcchannel.Frequency      = detail.Frequency;
                        dvbcchannel.ModulationType = (ModulationType)detail.Modulation;
                        dvbcchannel.SymbolRate     = detail.Symbolrate;
                    }
                }
                return(this.CurrentChannel.IsDifferentTransponder(dvbcchannel));
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Get Tuning details from manual scan section
        /// </summary>
        /// <returns></returns>
        private DVBCChannel GetManualTuning()
        {
            DVBCChannel tuneChannel = new DVBCChannel();

            tuneChannel.Frequency      = Int32.Parse(textBoxFreq.Text);
            tuneChannel.ModulationType = (ModulationType)mpComboBoxMod.SelectedIndex;
            tuneChannel.SymbolRate     = Int32.Parse(textBoxSymbolRate.Text);
            return(tuneChannel);
        }
Пример #3
0
        protected override DVBBaseChannel CreateChannel(int networkid, int transportid, int serviceid, string name)
        {
            DVBCChannel channel = new DVBCChannel();

            channel.NetworkId   = networkid;
            channel.TransportId = transportid;
            channel.ServiceId   = serviceid;
            channel.Name        = name;
            return(channel);
        }
Пример #4
0
        private bool BeforeTune(IChannel channel, ref int subChannelId)
        {
            DVBCChannel dvbcChannel = channel as DVBCChannel;

            if (dvbcChannel == null)
            {
                Log.Log.WriteFile("dvbc:Channel is not a DVBC channel!!! {0}", channel.GetType().ToString());
                return(false);
            }

            /*if (CurrentChannel != null)
             * {
             *  //@FIX this fails for back-2-back recordings
             *  //if (oldChannel.Equals(channel)) return _mapSubChannels[0];
             * }*/
            if (_graphState == GraphState.Idle)
            {
                BuildGraph();
                if (_mapSubChannels.ContainsKey(subChannelId) == false)
                {
                    subChannelId = GetNewSubChannel(channel);
                }
            }
            if (useInternalNetworkProvider)
            {
                return(true);
            }

            if (_previousChannel == null || _previousChannel.IsDifferentTransponder(dvbcChannel))
            {
                //_pmtPid = -1;
                ILocator locator;
                _tuningSpace.get_DefaultLocator(out locator);
                IDVBCLocator dvbcLocator = (IDVBCLocator)locator;
                dvbcLocator.put_InnerFEC(FECMethod.MethodNotSet);
                dvbcLocator.put_InnerFECRate(BinaryConvolutionCodeRate.RateNotSet);
                dvbcLocator.put_OuterFEC(FECMethod.MethodNotSet);
                dvbcLocator.put_OuterFECRate(BinaryConvolutionCodeRate.RateNotSet);
                dvbcLocator.put_Modulation(dvbcChannel.ModulationType);
                dvbcLocator.put_SymbolRate(dvbcChannel.SymbolRate);
                IDVBTuneRequest tuneRequest = (IDVBTuneRequest)_tuneRequest;
                tuneRequest.put_ONID(dvbcChannel.NetworkId);
                tuneRequest.put_SID(dvbcChannel.ServiceId);
                tuneRequest.put_TSID(dvbcChannel.TransportId);
                locator.put_CarrierFrequency((int)dvbcChannel.Frequency);
                _tuneRequest.put_Locator(locator);
                _tuneRequest = tuneRequest;
            }
            return(true);
        }
Пример #5
0
        /// <summary>
        /// Creates the new channel.
        /// </summary>
        /// <param name="channel">The high level tuning detail.</param>
        /// <param name="info">The subchannel detail.</param>
        /// <returns>The new channel.</returns>
        protected override IChannel CreateNewChannel(IChannel channel, ChannelInfo info)
        {
            DVBCChannel tuningChannel = (DVBCChannel)channel;
            DVBCChannel dvbcChannel   = new DVBCChannel();

            dvbcChannel.Name = info.service_name;
            dvbcChannel.LogicalChannelNumber = info.LCN;
            dvbcChannel.Provider             = info.service_provider_name;
            dvbcChannel.SymbolRate           = tuningChannel.SymbolRate;
            dvbcChannel.ModulationType       = tuningChannel.ModulationType;
            dvbcChannel.Frequency            = tuningChannel.Frequency;
            dvbcChannel.IsTv        = IsTvService(info.serviceType);
            dvbcChannel.IsRadio     = IsRadioService(info.serviceType);
            dvbcChannel.NetworkId   = info.networkID;
            dvbcChannel.ServiceId   = info.serviceID;
            dvbcChannel.TransportId = info.transportStreamID;
            dvbcChannel.PmtPid      = info.network_pmt_PID;
            dvbcChannel.FreeToAir   = !info.scrambled;
            Log.Log.Write("Found: {0}", dvbcChannel);
            return(dvbcChannel);
        }
Пример #6
0
        private bool BeforeTune(IChannel channel, ref int subChannelId, out int pmtPid)
        {
            int frequency  = 0;
            int symbolRate = 0;
            int modulation = (int)eModulationTAG.QAM_64;
            int bandWidth  = 0;
            LNBSelectionType lnbSelection = LNBSelectionType.Lnb0;
            const int        lnbKhzTone   = 22;
            const int        fec          = (int)FecType.Fec_Auto;
            int           polarity        = 0;
            SS2DisEqcType disType         = SS2DisEqcType.None;
            int           switchFreq      = 0;

            pmtPid = 0;
            int satelliteIndex = 0;

            Log.Log.WriteFile("ss2:Tune({0})", channel);
            if (_epgGrabbing)
            {
                _epgGrabbing = false;
                if (_epgGrabberCallback != null && _epgGrabbing)
                {
                    _epgGrabberCallback.OnEpgCancelled();
                }
            }
            switch (_cardType)
            {
            case CardType.DvbS:
                DVBSChannel dvbsChannel = channel as DVBSChannel;
                if (dvbsChannel == null)
                {
                    Log.Log.Error("Channel is not a DVBS channel!!! {0}", channel.GetType().ToString());
                    return(false);
                }
                if (CurrentChannel != null)
                {
                    DVBSChannel oldChannels = (DVBSChannel)CurrentChannel;
                    if (oldChannels.Equals(channel))
                    {
                        //@FIX this fails for back-2-back recordings
                        //Log.Log.WriteFile("ss2:already tuned on this channel");
                        //return _mapSubChannels[0];
                    }
                }
                frequency      = (int)dvbsChannel.Frequency;
                symbolRate     = dvbsChannel.SymbolRate;
                satelliteIndex = dvbsChannel.SatelliteIndex;
                bool hiBand = BandTypeConverter.IsHiBand(dvbsChannel, Parameters);
                int  lof1, lof2, sw;
                BandTypeConverter.GetDefaultLnbSetup(Parameters, dvbsChannel.BandType, out lof1, out lof2, out sw);
                int lnbFrequency;
                if (BandTypeConverter.IsHiBand(dvbsChannel, Parameters))
                {
                    lnbFrequency = lof2 * 1000;
                }
                else
                {
                    lnbFrequency = lof1 * 1000;
                }
                //0=horizontal or left, 1=vertical or right
                polarity = 0;
                if (dvbsChannel.Polarisation == Polarisation.LinearV)
                {
                    polarity = 1;
                }
                if (dvbsChannel.Polarisation == Polarisation.CircularR)
                {
                    polarity = 1;
                }
                Log.Log.WriteFile("ss2:  Polarity:{0} {1}", dvbsChannel.Polarisation, polarity);
                lnbSelection = LNBSelectionType.Lnb0;
                if (dvbsChannel.BandType == BandType.Universal)
                {
                    //only set the LNB (22,33,44) Khz tone when we use ku-band and are in hi-band
                    switch (lnbKhzTone)
                    {
                    case 22:
                        lnbSelection = LNBSelectionType.Lnb22kHz;
                        break;
                    }
                    if (hiBand == false)
                    {
                        lnbSelection = LNBSelectionType.Lnb0;
                    }
                }
                switch (dvbsChannel.DisEqc)
                {
                case DisEqcType.None: // none
                    disType = SS2DisEqcType.None;
                    break;

                case DisEqcType.SimpleA: // Simple A
                    disType = SS2DisEqcType.Simple_A;
                    break;

                case DisEqcType.SimpleB: // Simple B
                    disType = SS2DisEqcType.Simple_B;
                    break;

                case DisEqcType.Level1AA: // Level 1 A/A
                    disType = SS2DisEqcType.Level_1_A_A;
                    break;

                case DisEqcType.Level1BA: // Level 1 B/A
                    disType = SS2DisEqcType.Level_1_B_A;
                    break;

                case DisEqcType.Level1AB: // Level 1 A/B
                    disType = SS2DisEqcType.Level_1_A_B;
                    break;

                case DisEqcType.Level1BB: // Level 1 B/B
                    disType = SS2DisEqcType.Level_1_B_B;
                    break;
                }
                switchFreq = lnbFrequency / 1000; //in MHz
                pmtPid     = dvbsChannel.PmtPid;
                break;

            case CardType.DvbT:
                DVBTChannel dvbtChannel = channel as DVBTChannel;
                if (dvbtChannel == null)
                {
                    Log.Log.Error("Channel is not a DVBT channel!!! {0}", channel.GetType().ToString());
                    return(false);
                }
                if (CurrentChannel != null)
                {
                    DVBTChannel oldChannelt = (DVBTChannel)CurrentChannel;
                    if (oldChannelt.Equals(channel))
                    {
                        //@FIX this fails for back-2-back recordings
                        //Log.Log.WriteFile("ss2:already tuned on this channel");
                        //return _mapSubChannels[0];
                    }
                }
                frequency = (int)dvbtChannel.Frequency;
                bandWidth = dvbtChannel.BandWidth;
                pmtPid    = dvbtChannel.PmtPid;
                break;

            case CardType.DvbC:
                DVBCChannel dvbcChannel = channel as DVBCChannel;
                if (dvbcChannel == null)
                {
                    Log.Log.Error("Channel is not a DVBC channel!!! {0}", channel.GetType().ToString());
                    return(false);
                }
                if (CurrentChannel != null)
                {
                    DVBCChannel oldChannelc = (DVBCChannel)CurrentChannel;
                    if (oldChannelc.Equals(channel))
                    {
                        //@FIX this fails for back-2-back recordings
                        //Log.Log.WriteFile("ss2:already tuned on this channel");
                        //return _mapSubChannels[0];
                    }
                }
                frequency  = (int)dvbcChannel.Frequency;
                symbolRate = dvbcChannel.SymbolRate;
                switch (dvbcChannel.ModulationType)
                {
                case ModulationType.Mod16Qam:
                    modulation = (int)eModulationTAG.QAM_16;
                    break;

                case ModulationType.Mod32Qam:
                    modulation = (int)eModulationTAG.QAM_32;
                    break;

                case ModulationType.Mod64Qam:
                    modulation = (int)eModulationTAG.QAM_64;
                    break;

                case ModulationType.Mod128Qam:
                    modulation = (int)eModulationTAG.QAM_128;
                    break;

                case ModulationType.Mod256Qam:
                    modulation = (int)eModulationTAG.QAM_256;
                    break;
                }
                pmtPid = dvbcChannel.PmtPid;
                break;

            case CardType.Atsc:
                ATSCChannel dvbaChannel = channel as ATSCChannel;
                if (dvbaChannel == null)
                {
                    Log.Log.Error("Channel is not a ATSC channel!!! {0}", channel.GetType().ToString());
                    return(false);
                }
                if (CurrentChannel != null)
                {
                    ATSCChannel oldChannela = (ATSCChannel)CurrentChannel;
                    if (oldChannela.Equals(channel))
                    {
                        //@FIX this fails for back-2-back recordings
                        //Log.Log.WriteFile("ss2:already tuned on this channel");
                        //return _mapSubChannels[0];
                    }
                }
                //if modulation = 256QAM assume ATSC QAM for HD5000
                if (dvbaChannel.ModulationType == ModulationType.Mod256Qam)
                {
                    Log.Log.WriteFile("DVBGraphB2C2:  ATSC Channel:{0} Frequency:{1}", dvbaChannel.PhysicalChannel,
                                      dvbaChannel.Frequency);
                    frequency = (int)dvbaChannel.Frequency;
                    pmtPid    = dvbaChannel.PmtPid;
                }
                else
                {
                    Log.Log.WriteFile("DVBGraphSkyStar2:  ATSC Channel:{0}", dvbaChannel.PhysicalChannel);
                    //#DM B2C2 SDK says ATSC is tuned by frequency. Here we work the OTA frequency by channel number#
                    int atscfreq = 0;
                    if (dvbaChannel.PhysicalChannel <= 6)
                    {
                        atscfreq = 45 + (dvbaChannel.PhysicalChannel * 6);
                    }
                    if (dvbaChannel.PhysicalChannel >= 7 && dvbaChannel.PhysicalChannel <= 13)
                    {
                        atscfreq = 177 + ((dvbaChannel.PhysicalChannel - 7) * 6);
                    }
                    if (dvbaChannel.PhysicalChannel >= 14)
                    {
                        atscfreq = 473 + ((dvbaChannel.PhysicalChannel - 14) * 6);
                    }
                    //#DM changed tuning parameter from physical channel to calculated frequency above.
                    frequency = atscfreq;
                    Log.Log.WriteFile("ss2:  ATSC Frequency:{0} MHz", frequency);
                    pmtPid = dvbaChannel.PmtPid;
                }
                break;
            }
            if (_graphState == GraphState.Idle)
            {
                BuildGraph();
            }
            if (_mapSubChannels.ContainsKey(subChannelId) == false)
            {
                subChannelId = GetNewSubChannel(channel);
            }
            _mapSubChannels[subChannelId].CurrentChannel = channel;
            _mapSubChannels[subChannelId].OnBeforeTune();
            if (_interfaceEpgGrabber != null)
            {
                _interfaceEpgGrabber.Reset();
            }
            if (frequency > 13000)
            {
                frequency /= 1000;
            }
            Log.Log.WriteFile("ss2:  Transponder Frequency:{0} MHz", frequency);
            int hr = _interfaceB2C2TunerCtrl.SetFrequency(frequency);

            if (hr != 0)
            {
                Log.Log.Error("ss2:SetFrequencyKHz() failed:0x{0:X}", hr);
                return(false);
            }
            switch (_cardType)
            {
            case CardType.DvbC:
                Log.Log.WriteFile("ss2:  SymbolRate:{0} KS/s", symbolRate);
                hr = _interfaceB2C2TunerCtrl.SetSymbolRate(symbolRate);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetSymbolRate() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  Modulation:{0}", ((eModulationTAG)modulation));
                hr = _interfaceB2C2TunerCtrl.SetModulation(modulation);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetModulation() failed:0x{0:X}", hr);
                    return(false);
                }
                break;

            case CardType.DvbT:
                Log.Log.WriteFile("ss2:  GuardInterval:auto");
                hr = _interfaceB2C2TunerCtrl.SetGuardInterval((int)GuardIntervalType.Interval_Auto);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetGuardInterval() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  Bandwidth:{0} MHz", bandWidth);
                //hr = _interfaceB2C2TunerCtrl.SetBandwidth((int)dvbtChannel.BandWidth);
                // Set Channel Bandwidth (NOTE: Temporarily use polarity function to avoid having to
                // change SDK interface for SetBandwidth)
                // from Technisat SDK 03/2006
                hr = _interfaceB2C2TunerCtrl.SetPolarity(bandWidth);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetBandwidth() failed:0x{0:X}", hr);
                    return(false);
                }
                break;

            case CardType.DvbS:
                Log.Log.WriteFile("ss2:  SymbolRate:{0} KS/s", symbolRate);
                hr = _interfaceB2C2TunerCtrl.SetSymbolRate(symbolRate);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetSymbolRate() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  Fec:{0} {1}", ((FecType)fec), fec);
                hr = _interfaceB2C2TunerCtrl.SetFec(fec);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetFec() failed:0x{0:X}", hr);
                    return(false);
                }
                hr = _interfaceB2C2TunerCtrl.SetPolarity(polarity);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetPolarity() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  Lnb:{0}", lnbSelection);
                hr = _interfaceB2C2TunerCtrl.SetLnbKHz((int)lnbSelection);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetLnbKHz() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  Diseqc:{0} {1}", disType, disType);
                hr = _interfaceB2C2TunerCtrl.SetDiseqc((int)disType);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetDiseqc() failed:0x{0:X}", hr);
                    return(false);
                }
                Log.Log.WriteFile("ss2:  LNBFrequency:{0} MHz", switchFreq);
                hr = _interfaceB2C2TunerCtrl.SetLnbFrequency(switchFreq);
                if (hr != 0)
                {
                    Log.Log.Error("ss2:SetLnbFrequency() failed:0x{0:X}", hr);
                    return(false);
                }
                if (_useDISEqCMotor)
                {
                    if (satelliteIndex > 0)
                    {
                        DisEqcGotoPosition((byte)satelliteIndex);
                    }
                }
                break;
            }
            return(true);
        }
Пример #7
0
        ///<summary>
        /// Scan NIT channel
        ///</summary>
        ///<param name="channel">Channel</param>
        ///<param name="settings">Scan Parameters</param>
        ///<returns>Found channels</returns>
        public List <IChannel> ScanNIT(IChannel channel, ScanParameters settings)
        {
            try
            {
                _card.IsScanning = true;
                _card.Scan(0, channel);
                _analyzer = GetAnalyzer();
                if (_analyzer == null)
                {
                    Log.Log.WriteFile("Scan: no analyzer interface available");
                    return(new List <IChannel>());
                }
                _analyzer.SetCallBack(null);
                _analyzer.ScanNIT();
                Thread.Sleep(settings.TimeOutTune * 1000);
                ResetSignalUpdate();
                Log.Log.WriteFile("ScanNIT: tuner locked:{0} signal:{1} quality:{2}", _card.IsTunerLocked, _card.SignalLevel,
                                  _card.SignalQuality);
                if (_card.IsTunerLocked || _card.SignalLevel > 0 || _card.SignalQuality > 0)
                {
                    int count;

                    _event = new ManualResetEvent(false);
                    _event.WaitOne(16000, true);
                    _event.Close();
                    List <IChannel> channelsFound = new List <IChannel>();
                    _analyzer.GetNITCount(out count);
                    for (int i = 0; i < count; ++i)
                    {
                        int    freq, pol, mod, symbolrate, bandwidth, innerfec, rollOff, chType;
                        IntPtr ptrName;
                        _analyzer.GetNITChannel((short)i, out chType, out freq, out pol, out mod, out symbolrate, out bandwidth,
                                                out innerfec, out rollOff, out ptrName);
                        string name = DvbTextConverter.Convert(ptrName, "");
                        if (chType == 0)
                        {
                            DVBSChannel ch = new DVBSChannel();
                            ch.Name      = name;
                            ch.Frequency = freq;
                            Log.Log.Debug("{0},{1},{2},{3}", freq, mod, pol, symbolrate);
                            switch (mod)
                            {
                            default:
                            case 0:
                                ch.ModulationType = ModulationType.ModNotSet;
                                break;

                            //case 1: ch.ModulationType = ModulationType.ModQpsk; break;
                            case 2:
                                ch.ModulationType = ModulationType.Mod8Psk;
                                break;

                            case 3:
                                ch.ModulationType = ModulationType.Mod16Qam;
                                break;
                            }
                            ch.SymbolRate   = symbolrate;
                            ch.InnerFecRate = (BinaryConvolutionCodeRate)innerfec;
                            ch.Polarisation = (Polarisation)pol;
                            ch.Rolloff      = (RollOff)rollOff;
                            channelsFound.Add(ch);
                        }
                        else if (chType == 1)
                        {
                            DVBCChannel ch = new DVBCChannel();
                            ch.Name           = name;
                            ch.Frequency      = freq;
                            ch.ModulationType = (ModulationType)mod;
                            ch.SymbolRate     = symbolrate;
                            channelsFound.Add(ch);
                        }
                        else if (chType == 2)
                        {
                            DVBTChannel ch = new DVBTChannel();
                            ch.Name      = name;
                            ch.Frequency = freq;
                            ch.BandWidth = bandwidth;
                            channelsFound.Add(ch);
                        }
                    }
                    _analyzer.StopNIT();
                    return(channelsFound);
                }
                else
                {
                    Log.Log.WriteFile("Scan: no signal detected");
                    return(new List <IChannel>());
                }
            }
            finally
            {
                if (_analyzer != null)
                {
                    _analyzer.StopNIT();
                }
                _card.IsScanning = false;
            }
        }
Пример #8
0
        /// <summary>
        /// Scan Thread
        /// </summary>
        private void DoScan()
        {
            suminfo tv    = new suminfo();
            suminfo radio = new suminfo();
            IUser   user  = new User();

            user.CardId = _cardNumber;
            try
            {
                scanState = ScanState.Scanning;
                if (_dvbcChannels.Count == 0)
                {
                    return;
                }

                RemoteControl.Instance.EpgGrabberEnabled = false;

                SetButtonState();
                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));

                for (int index = 0; index < _dvbcChannels.Count; ++index)
                {
                    if (scanState == ScanState.Cancel)
                    {
                        return;
                    }

                    float percent = ((float)(index)) / _dvbcChannels.Count;
                    percent *= 100f;
                    if (percent > 100f)
                    {
                        percent = 100f;
                    }
                    progressBar1.Value = (int)percent;

                    Application.DoEvents();

                    DVBCChannel  tuneChannel = new DVBCChannel(_dvbcChannels[index]); // new DVBCChannel();
                    string       line        = String.Format("{0}tp- {1}", 1 + index, tuneChannel.TuningInfo.ToString());
                    ListViewItem item        = listViewStatus.Items.Add(new ListViewItem(line));
                    item.EnsureVisible();

                    if (index == 0)
                    {
                        RemoteControl.Instance.Scan(ref user, tuneChannel, -1);
                    }

                    IChannel[] channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);
                    UpdateStatus();

                    if (channels == null || channels.Length == 0)
                    {
                        if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
                        {
                            line = String.Format("{0}tp- {1} {2} {3}:No signal", 1 + index, tuneChannel.Frequency,
                                                 tuneChannel.ModulationType, tuneChannel.SymbolRate);
                            item.Text      = line;
                            item.ForeColor = Color.Red;
                            continue;
                        }
                        line = String.Format("{0}tp- {1} {2} {3}:Nothing found", 1 + index, tuneChannel.Frequency,
                                             tuneChannel.ModulationType, tuneChannel.SymbolRate);
                        item.Text      = line;
                        item.ForeColor = Color.Red;
                        continue;
                    }

                    radio.newChannel = 0;
                    radio.updChannel = 0;
                    tv.newChannel    = 0;
                    tv.updChannel    = 0;
                    for (int i = 0; i < channels.Length; ++i)
                    {
                        Channel      dbChannel;
                        DVBCChannel  channel = (DVBCChannel)channels[i];
                        bool         exists;
                        TuningDetail currentDetail;
                        //Check if we already have this tuningdetail. The user has the option to enable channel move detection...
                        if (checkBoxEnableChannelMoveDetection.Checked)
                        {
                            //According to the DVB specs ONID + SID is unique, therefore we do not need to use the TSID to identify a service.
                            //The DVB spec recommends that the SID should not change if a service moves. This theoretically allows us to
                            //track channel movements.
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }
                        else
                        {
                            //There are certain providers that do not maintain unique ONID + SID combinations.
                            //In those cases, ONID + TSID + SID is generally unique. The consequence of using the TSID to identify
                            //a service is that channel movement tracking won't work (each transponder/mux should have its own TSID).
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.TransportId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }

                        if (currentDetail == null)
                        {
                            //add new channel
                            exists              = false;
                            dbChannel           = layer.AddNewChannel(channel.Name, channel.LogicalChannelNumber);
                            dbChannel.SortOrder = 10000;
                            if (channel.LogicalChannelNumber >= 1)
                            {
                                dbChannel.SortOrder = channel.LogicalChannelNumber;
                            }
                            dbChannel.IsTv    = channel.IsTv;
                            dbChannel.IsRadio = channel.IsRadio;
                            dbChannel.Persist();
                        }
                        else
                        {
                            exists    = true;
                            dbChannel = currentDetail.ReferencedChannel();
                        }

                        if (dbChannel.IsTv)
                        {
                            layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
                            if (checkBoxCreateSignalGroup.Checked)
                            {
                                layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.DVBC);
                            }
                            if (checkBoxCreateGroups.Checked)
                            {
                                layer.AddChannelToGroup(dbChannel, channel.Provider);
                            }
                        }
                        if (dbChannel.IsRadio)
                        {
                            layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels);
                            if (checkBoxCreateSignalGroup.Checked)
                            {
                                layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.DVBC);
                            }
                            if (checkBoxCreateGroups.Checked)
                            {
                                layer.AddChannelToRadioGroup(dbChannel, channel.Provider);
                            }
                        }

                        if (currentDetail == null)
                        {
                            layer.AddTuningDetails(dbChannel, channel);
                        }
                        else
                        {
                            //update tuning details...
                            TuningDetail td = layer.UpdateTuningDetails(dbChannel, channel, currentDetail);
                            td.Persist();
                        }

                        if (channel.IsTv)
                        {
                            if (exists)
                            {
                                tv.updChannel++;
                            }
                            else
                            {
                                tv.newChannel++;
                                tv.newChannels.Add(channel);
                            }
                        }
                        if (channel.IsRadio)
                        {
                            if (exists)
                            {
                                radio.updChannel++;
                            }
                            else
                            {
                                radio.newChannel++;
                                radio.newChannels.Add(channel);
                            }
                        }
                        layer.MapChannelToCard(card, dbChannel, false);
                        line = String.Format("{0}tp- {1} {2} {3}:New TV/Radio:{4}/{5} Updated TV/Radio:{6}/{7}", 1 + index,
                                             tuneChannel.Frequency, tuneChannel.ModulationType, tuneChannel.SymbolRate,
                                             tv.newChannel, radio.newChannel, tv.updChannel, radio.updChannel);
                        item.Text = line;
                    }
                    tv.updChannelSum    += tv.updChannel;
                    radio.updChannelSum += radio.updChannel;
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            finally
            {
                RemoteControl.Instance.StopCard(user);
                RemoteControl.Instance.EpgGrabberEnabled = true;
                progressBar1.Value = 100;

                scanState = ScanState.Done;
                SetButtonState();
            }
            listViewStatus.Items.Add(
                new ListViewItem(String.Format("Total radio channels updated:{0}, new:{1}", radio.updChannelSum,
                                               radio.newChannelSum)));
            foreach (IChannel newChannel in radio.newChannels)
            {
                listViewStatus.Items.Add(new ListViewItem(String.Format("  -> new channel: {0}", newChannel.Name)));
            }

            listViewStatus.Items.Add(
                new ListViewItem(String.Format("Total tv channels updated:{0}, new:{1}", tv.updChannelSum, tv.newChannelSum)));
            foreach (IChannel newChannel in tv.newChannels)
            {
                listViewStatus.Items.Add(new ListViewItem(String.Format("  -> new channel: {0}", newChannel.Name)));
            }
            ListViewItem lastItem = listViewStatus.Items.Add(new ListViewItem("Scan done..."));

            lastItem.EnsureVisible();
        }
Пример #9
0
        private void InitScanProcess()
        {
            // once completed reset to new beginning
            switch (scanState)
            {
            case ScanState.Done:
                scanState = ScanState.Initialized;
                listViewStatus.Items.Clear();
                SetButtonState();
                return;

            case ScanState.Initialized:
                // common checks
                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
                if (card.Enabled == false)
                {
                    MessageBox.Show(this, "Tuner is disabled. Please enable the tuner before scanning.");
                    return;
                }
                if (!RemoteControl.Instance.CardPresent(card.IdCard))
                {
                    MessageBox.Show(this, "Tuner is not found. Please make sure the tuner is present before scanning.");
                    return;
                }
                // Check if the card is locked for scanning.
                IUser user;
                if (RemoteControl.Instance.IsCardInUse(_cardNumber, out user))
                {
                    MessageBox.Show(this,
                                    "Tuner is locked. Scanning is not possible at the moment. Perhaps you are using another part of a hybrid card?");
                    return;
                }
                SetButtonState();
                ShowActiveGroup(1); // force progess visible
                // End common checks

                listViewStatus.Items.Clear();

                // Scan type dependent handling
                _dvbcChannels.Clear();
                switch (ActiveScanType)
                {
                // use tuning details from file
                case ScanTypes.Predefined:
                    CustomFileName tuningFile = (CustomFileName)mpComboBoxRegion.SelectedItem;
                    _dvbcChannels = (List <DVBCTuning>)fileFilters.LoadList(tuningFile.FileName, typeof(List <DVBCTuning>));
                    if (_dvbcChannels == null)
                    {
                        _dvbcChannels = new List <DVBCTuning>();
                    }
                    break;

                // scan Network Information Table for transponder info
                case ScanTypes.NIT:
                    _dvbcChannels.Clear();
                    DVBCChannel tuneChannel = GetManualTuning();

                    listViewStatus.Items.Clear();
                    string line = String.Format("Scan freq:{0} {1} symbolrate:{2} ...", tuneChannel.Frequency,
                                                tuneChannel.ModulationType, tuneChannel.SymbolRate);
                    ListViewItem item = listViewStatus.Items.Add(new ListViewItem(line));
                    item.EnsureVisible();

                    IChannel[] channels = RemoteControl.Instance.ScanNIT(_cardNumber, tuneChannel);
                    if (channels != null)
                    {
                        for (int i = 0; i < channels.Length; ++i)
                        {
                            DVBCChannel ch = (DVBCChannel)channels[i];
                            _dvbcChannels.Add(ch.TuningInfo);
                            item = listViewStatus.Items.Add(new ListViewItem(ch.TuningInfo.ToString()));
                            item.EnsureVisible();
                        }
                    }

                    ListViewItem lastItem =
                        listViewStatus.Items.Add(
                            new ListViewItem(String.Format("Scan done, found {0} transponders...", _dvbcChannels.Count)));
                    lastItem.EnsureVisible();

                    // automatically save list for re-use
                    SaveTransponderList();
                    break;

                // scan only single inputted transponder
                case ScanTypes.SingleTransponder:
                    DVBCChannel singleTuneChannel = GetManualTuning();
                    _dvbcChannels.Add(singleTuneChannel.TuningInfo);
                    break;
                }
                if (_dvbcChannels.Count != 0)
                {
                    StartScanThread();
                }
                else
                {
                    scanState = ScanState.Done;
                    SetButtonState();
                }
                break;

            case ScanState.Scanning:
                scanState = ScanState.Cancel;
                SetButtonState();
                break;

            case ScanState.Cancel:
                return;
            }
        }
Пример #10
0
        /// <summary>
        /// This method will try to start the epg grabber for the channel and tuning details specified
        /// Epg grabbing can only be started if there is a card idle which can receive the channel specified
        /// </summary>
        /// <param name="channel">channel to grab/param>
        /// <param name="tuning">tuning information</param>
        /// <param name="card">card to use for grabbing</param>
        /// <returns>true if grabbing has started else false</returns>
        private bool GrabEpgForChannel(Channel channel, IChannel tuning, Card card)
        {
            if (channel == null)
            {
                Log.Error("Epg: invalid channel");
                return(false);
            }
            if (tuning == null)
            {
                Log.Error("Epg: invalid tuning");
                return(false);
            }
            if (card == null)
            {
                Log.Error("Epg: invalid card");
                return(false);
            }
            if (_tvController == null)
            {
                Log.Error("Epg: invalid tvcontroller");
                return(false);
            }
            if (_user == null)
            {
                Log.Error("Epg: invalid user");
                return(false);
            }
            //remove following check to enable multi-card epg grabbing (still beta)
            if (_tvController.AllCardsIdle == false)
            {
                Log.Epg("Epg: card:{0} cards are not idle", Card.IdCard);
                return(false);
            }

            TvResult result = TvResult.UnknownError;
            //handle ATSC
            ATSCChannel atscChannel = tuning as ATSCChannel;

            if (atscChannel != null)
            {
                if (_tvController.Type(Card.IdCard) == CardType.Atsc)
                {
                    if (IsCardIdle(Card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} atsc card is not idle", Card.IdCard);
                        return(false); //card is busy
                    }
                    return(TuneEPGgrabber(channel, tuning, card, result));
                }
                Log.Epg("Epg: card:{0} could not tune to atsc channel:{1}", Card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBC
            DVBCChannel dvbcChannel = tuning as DVBCChannel;

            if (dvbcChannel != null)
            {
                if (_tvController.Type(Card.IdCard) == CardType.DvbC)
                {
                    if (IsCardIdle(Card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbc card is not idle", Card.IdCard);
                        return(false); //card is busy
                    }
                    return(TuneEPGgrabber(channel, tuning, card, result));
                }
                Log.Epg("Epg: card:{0} could not tune to dvbc channel:{1}", Card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBS
            DVBSChannel dvbsChannel = tuning as DVBSChannel;

            if (dvbsChannel != null)
            {
                if (_tvController.Type(Card.IdCard) == CardType.DvbS)
                {
                    if (IsCardIdle(Card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbs card is not idle", Card.IdCard);
                        return(false); //card is busy
                    }
                    return(TuneEPGgrabber(channel, tuning, card, result));
                }
                Log.Epg("Epg: card:{0} could not tune to dvbs channel:{1}", Card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBT
            DVBTChannel dvbtChannel = tuning as DVBTChannel;

            if (dvbtChannel != null)
            {
                if (_tvController.Type(Card.IdCard) == CardType.DvbT)
                {
                    if (IsCardIdle(Card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbt card is not idle", Card.IdCard);
                        return(false); //card is busy
                    }

                    return(TuneEPGgrabber(channel, tuning, card, result));
                }
                Log.Epg("Epg: card:{0} could not tune to dvbt channel:{1}", Card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBIP
            DVBIPChannel dvbipChannel = tuning as DVBIPChannel;

            if (dvbipChannel != null)
            {
                if (_tvController.Type(Card.IdCard) == CardType.DvbIP)
                {
                    if (IsCardIdle(Card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbip card is not idle", Card.IdCard);
                        return(false); //card is busy
                    }
                    return(TuneEPGgrabber(channel, tuning, card, result));
                }
                else
                {
                    Log.Epg("Epg: card:{0} could not tune to dvbip channel:{1}", Card.IdCard, tuning.ToString());
                }
                return(false);
            }
            Log.Epg("Epg: card:{0} could not tune to channel:{1}", Card.IdCard, tuning.ToString());
            return(false);
        }
Пример #11
0
        private void importButton_Click(object sender, EventArgs e)
        {
            bool importtv          = imCheckTvChannels.Checked;
            bool importtvgroups    = imCheckTvGroups.Checked;
            bool importradio       = imCheckRadioChannels.Checked;
            bool importradiogroups = imCheckRadioGroups.Checked;
            bool importschedules   = imCheckSchedules.Checked;

            openFileDialog1.CheckFileExists  = true;
            openFileDialog1.DefaultExt       = "xml";
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.Title            = "Load channels, channel groups and schedules";
            openFileDialog1.InitialDirectory = String.Format(@"{0}\Team MediaPortal\MediaPortal TV Server",
                                                             Environment.GetFolderPath(
                                                                 Environment.SpecialFolder.CommonApplicationData));
            openFileDialog1.FileName     = "export.xml";
            openFileDialog1.AddExtension = true;
            openFileDialog1.Multiselect  = false;
            if (openFileDialog1.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }
            NotifyForm dlg = new NotifyForm("Importing tv channels...", "This can take some time\n\nPlease be patient...");

            try
            {
                dlg.Show();
                dlg.WaitForDisplay();
                CountryCollection collection = new CountryCollection();
                TvBusinessLayer   layer      = new TvBusinessLayer();
                bool mergeChannels           = false; // every exported channel will be imported on its own.
                int  channelCount            = 0;
                int  scheduleCount           = 0;
                int  tvChannelGroupCount     = 0;
                int  radioChannelGroupCount  = 0;

                if (layer.Channels.Count > 0 && (importtv || importradio))
                {
                    // rtv: we could offer to set a "merge" property here so tuningdetails would be updated for existing channels.
                    if (
                        MessageBox.Show(
                            "Existing channels detected! \nIf you continue to import your old backup then all identically named channels will be treated equal - there is a risk of duplicate entries. \nDo you really want to go on?",
                            "Channels found", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                    {
                        return;
                    }
                    else
                    {
                        mergeChannels = true;
                    }
                }

                XmlDocument doc = new XmlDocument();
                Log.Info("TvChannels: Trying to import channels from {0}", openFileDialog1.FileName);
                doc.Load(openFileDialog1.FileName);
                XmlNodeList channelList           = doc.SelectNodes("/tvserver/channels/channel");
                XmlNodeList tvChannelGroupList    = doc.SelectNodes("/tvserver/channelgroups/channelgroup");
                XmlNodeList radioChannelGroupList = doc.SelectNodes("/tvserver/radiochannelgroups/radiochannelgroup");
                XmlNodeList scheduleList          = doc.SelectNodes("/tvserver/schedules/schedule");
                if (channelList != null)
                {
                    foreach (XmlNode nodeChannel in channelList)
                    {
                        try
                        {
                            Channel     dbChannel;
                            XmlNodeList tuningList   = nodeChannel.SelectNodes("TuningDetails/tune");
                            XmlNodeList mappingList  = nodeChannel.SelectNodes("mappings/map");
                            bool        grabEpg      = (GetNodeAttribute(nodeChannel, "GrabEpg", "True") == "True");
                            bool        isRadio      = (GetNodeAttribute(nodeChannel, "IsRadio", "False") == "True");
                            bool        isTv         = (GetNodeAttribute(nodeChannel, "IsTv", "True") == "True");
                            DateTime    lastGrabTime = DateTime.ParseExact(GetNodeAttribute(nodeChannel, "LastGrabTime", "01.01.1900"),
                                                                           "yyyy-M-d H:m:s", CultureInfo.InvariantCulture);
                            int      sortOrder        = Int32.Parse(GetNodeAttribute(nodeChannel, "SortOrder", "0"));
                            int      timesWatched     = Int32.Parse(GetNodeAttribute(nodeChannel, "TimesWatched", "0"));
                            DateTime totalTimeWatched =
                                DateTime.ParseExact(GetNodeAttribute(nodeChannel, "TotalTimeWatched", "01.01.1900"), "yyyy-M-d H:m:s",
                                                    CultureInfo.InvariantCulture);
                            bool   visibileInGuide = (GetNodeAttribute(nodeChannel, "VisibleInGuide", "True") == "True");
                            bool   FreeToAir       = (GetNodeAttribute(nodeChannel, "FreeToAir", "True") == "True");
                            string displayName     = GetNodeAttribute(nodeChannel, "DisplayName", "Unkown");

                            // Only import TV or radio channels if the corresponding checkbox was checked
                            if ((isTv && !importtv) || (isRadio && !importradio))
                            {
                                continue;
                            }

                            channelCount++;

                            // rtv: since analog allows NOT to merge channels we need to take care of this. US users e.g. have multiple stations named "Sport" with different tuningdetails.
                            // using AddChannel would incorrectly "merge" these totally different channels.
                            // see this: http://forum.team-mediaportal.com/1-0-rc1-svn-builds-271/importing-exported-channel-list-groups-channels-39368/
                            Log.Info("TvChannels: Adding {0}. channel: {1}", channelCount, displayName);
                            IList <Channel> foundExistingChannels = layer.GetChannelsByName(displayName);
                            if (mergeChannels && (foundExistingChannels != null && foundExistingChannels.Count > 0))
                            {
                                dbChannel = foundExistingChannels[0];
                            }
                            else
                            {
                                dbChannel = layer.AddNewChannel(displayName);
                            }

                            dbChannel.GrabEpg          = grabEpg;
                            dbChannel.IsRadio          = isRadio;
                            dbChannel.IsTv             = isTv;
                            dbChannel.LastGrabTime     = lastGrabTime;
                            dbChannel.SortOrder        = sortOrder;
                            dbChannel.TimesWatched     = timesWatched;
                            dbChannel.TotalTimeWatched = totalTimeWatched;
                            dbChannel.VisibleInGuide   = visibileInGuide;
                            dbChannel.DisplayName      = displayName;
                            dbChannel.Persist();

                            //
                            // chemelli: When we import channels we need to add those to the "AllChannels" group
                            //
                            if (isTv)
                            {
                                layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
                            }
                            else
                            {
                                layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels);
                            }

                            foreach (XmlNode nodeMap in mappingList)
                            {
                                int     idCard   = Int32.Parse(nodeMap.Attributes["IdCard"].Value);
                                XmlNode nodeCard =
                                    doc.SelectSingleNode(String.Format("/tvserver/servers/server/cards/card[@IdCard={0}]", idCard));
                                Card dbCard = layer.GetCardByDevicePath(nodeCard.Attributes["DevicePath"].Value);
                                if (dbCard != null)
                                {
                                    layer.MapChannelToCard(dbCard, dbChannel, false);
                                }
                            }
                            foreach (XmlNode nodeTune in tuningList)
                            {
                                int    bandwidth          = Int32.Parse(nodeTune.Attributes["Bandwidth"].Value);
                                int    channelNumber      = Int32.Parse(nodeTune.Attributes["ChannelNumber"].Value);
                                int    channelType        = Int32.Parse(nodeTune.Attributes["ChannelType"].Value);
                                int    countryId          = Int32.Parse(nodeTune.Attributes["CountryId"].Value);
                                int    diseqc             = Int32.Parse(nodeTune.Attributes["Diseqc"].Value);
                                bool   fta                = (nodeTune.Attributes["FreeToAir"].Value == "True");
                                int    frequency          = Int32.Parse(nodeTune.Attributes["Frequency"].Value);
                                int    majorChannel       = Int32.Parse(nodeTune.Attributes["MajorChannel"].Value);
                                int    minorChannel       = Int32.Parse(nodeTune.Attributes["MinorChannel"].Value);
                                int    modulation         = Int32.Parse(nodeTune.Attributes["Modulation"].Value);
                                string name               = nodeTune.Attributes["Name"].Value;
                                int    networkId          = Int32.Parse(nodeTune.Attributes["NetworkId"].Value);
                                int    pmtPid             = Int32.Parse(nodeTune.Attributes["PmtPid"].Value);
                                int    polarisation       = Int32.Parse(nodeTune.Attributes["Polarisation"].Value);
                                string provider           = GetNodeAttribute(nodeTune, "Provider", "");
                                int    serviceId          = Int32.Parse(nodeTune.Attributes["ServiceId"].Value);
                                int    switchingFrequency = Int32.Parse(nodeTune.Attributes["SwitchingFrequency"].Value);
                                int    symbolrate         = Int32.Parse(nodeTune.Attributes["Symbolrate"].Value);
                                int    transportId        = Int32.Parse(nodeTune.Attributes["TransportId"].Value);
                                int    tuningSource       = Int32.Parse(GetNodeAttribute(nodeTune, "TuningSource", "0"));
                                int    videoSource        = Int32.Parse(GetNodeAttribute(nodeTune, "VideoSource", "0"));
                                int    audioSource        = Int32.Parse(GetNodeAttribute(nodeTune, "AudioSource", "0"));
                                bool   isVCRSignal        = (GetNodeAttribute(nodeChannel, "IsVCRSignal", "False") == "True");
                                int    SatIndex           = Int32.Parse(GetNodeAttribute(nodeTune, "SatIndex", "-1"));
                                int    InnerFecRate       = Int32.Parse(GetNodeAttribute(nodeTune, "InnerFecRate", "-1"));
                                int    band               = Int32.Parse(GetNodeAttribute(nodeTune, "Band", "0"));
                                int    pilot              = Int32.Parse(GetNodeAttribute(nodeTune, "Pilot", "-1"));
                                int    rollOff            = Int32.Parse(GetNodeAttribute(nodeTune, "RollOff", "-1"));
                                string url                = GetNodeAttribute(nodeTune, "Url", "");
                                int    bitrate            = Int32.Parse(GetNodeAttribute(nodeTune, "Bitrate", "0"));

                                switch (channelType)
                                {
                                case 0: //AnalogChannel
                                    AnalogChannel analogChannel = new AnalogChannel();
                                    analogChannel.ChannelNumber = channelNumber;
                                    analogChannel.Country       = collection.Countries[countryId];
                                    analogChannel.Frequency     = frequency;
                                    analogChannel.IsRadio       = isRadio;
                                    analogChannel.IsTv          = isTv;
                                    analogChannel.Name          = name;
                                    analogChannel.TunerSource   = (TunerInputType)tuningSource;
                                    analogChannel.AudioSource   = (AnalogChannel.AudioInputType)audioSource;
                                    analogChannel.VideoSource   = (AnalogChannel.VideoInputType)videoSource;
                                    analogChannel.IsVCRSignal   = isVCRSignal;
                                    layer.AddTuningDetails(dbChannel, analogChannel);
                                    Log.Info("TvChannels: Added tuning details for analog channel: {0} number: {1}", name, channelNumber);
                                    break;

                                case 1: //ATSCChannel
                                    ATSCChannel atscChannel = new ATSCChannel();
                                    atscChannel.MajorChannel    = majorChannel;
                                    atscChannel.MinorChannel    = minorChannel;
                                    atscChannel.PhysicalChannel = channelNumber;
                                    atscChannel.FreeToAir       = fta;
                                    atscChannel.Frequency       = frequency;
                                    atscChannel.IsRadio         = isRadio;
                                    atscChannel.IsTv            = isTv;
                                    atscChannel.Name            = name;
                                    atscChannel.NetworkId       = networkId;
                                    atscChannel.PmtPid          = pmtPid;
                                    atscChannel.Provider        = provider;
                                    atscChannel.ServiceId       = serviceId;
                                    atscChannel.TransportId     = transportId;
                                    atscChannel.ModulationType  = (ModulationType)modulation;
                                    layer.AddTuningDetails(dbChannel, atscChannel);
                                    Log.Info("TvChannels: Added tuning details for ATSC channel: {0} number: {1} provider: {2}", name,
                                             channelNumber, provider);
                                    break;

                                case 2: //DVBCChannel
                                    DVBCChannel dvbcChannel = new DVBCChannel();
                                    dvbcChannel.ModulationType       = (ModulationType)modulation;
                                    dvbcChannel.FreeToAir            = fta;
                                    dvbcChannel.Frequency            = frequency;
                                    dvbcChannel.IsRadio              = isRadio;
                                    dvbcChannel.IsTv                 = isTv;
                                    dvbcChannel.Name                 = name;
                                    dvbcChannel.NetworkId            = networkId;
                                    dvbcChannel.PmtPid               = pmtPid;
                                    dvbcChannel.Provider             = provider;
                                    dvbcChannel.ServiceId            = serviceId;
                                    dvbcChannel.SymbolRate           = symbolrate;
                                    dvbcChannel.TransportId          = transportId;
                                    dvbcChannel.LogicalChannelNumber = channelNumber;
                                    layer.AddTuningDetails(dbChannel, dvbcChannel);
                                    Log.Info("TvChannels: Added tuning details for DVB-C channel: {0} provider: {1}", name, provider);
                                    break;

                                case 3: //DVBSChannel
                                    DVBSChannel dvbsChannel = new DVBSChannel();
                                    dvbsChannel.DisEqc             = (DisEqcType)diseqc;
                                    dvbsChannel.Polarisation       = (Polarisation)polarisation;
                                    dvbsChannel.SwitchingFrequency = switchingFrequency;
                                    dvbsChannel.FreeToAir          = fta;
                                    dvbsChannel.Frequency          = frequency;
                                    dvbsChannel.IsRadio            = isRadio;
                                    dvbsChannel.IsTv                 = isTv;
                                    dvbsChannel.Name                 = name;
                                    dvbsChannel.NetworkId            = networkId;
                                    dvbsChannel.PmtPid               = pmtPid;
                                    dvbsChannel.Provider             = provider;
                                    dvbsChannel.ServiceId            = serviceId;
                                    dvbsChannel.SymbolRate           = symbolrate;
                                    dvbsChannel.TransportId          = transportId;
                                    dvbsChannel.SatelliteIndex       = SatIndex;
                                    dvbsChannel.ModulationType       = (ModulationType)modulation;
                                    dvbsChannel.InnerFecRate         = (BinaryConvolutionCodeRate)InnerFecRate;
                                    dvbsChannel.BandType             = (BandType)band;
                                    dvbsChannel.Pilot                = (Pilot)pilot;
                                    dvbsChannel.Rolloff              = (RollOff)rollOff;
                                    dvbsChannel.LogicalChannelNumber = channelNumber;
                                    layer.AddTuningDetails(dbChannel, dvbsChannel);
                                    Log.Info("TvChannels: Added tuning details for DVB-S channel: {0} provider: {1}", name, provider);
                                    break;

                                case 4: //DVBTChannel
                                    DVBTChannel dvbtChannel = new DVBTChannel();
                                    dvbtChannel.BandWidth            = bandwidth;
                                    dvbtChannel.FreeToAir            = fta;
                                    dvbtChannel.Frequency            = frequency;
                                    dvbtChannel.IsRadio              = isRadio;
                                    dvbtChannel.IsTv                 = isTv;
                                    dvbtChannel.Name                 = name;
                                    dvbtChannel.NetworkId            = networkId;
                                    dvbtChannel.PmtPid               = pmtPid;
                                    dvbtChannel.Provider             = provider;
                                    dvbtChannel.ServiceId            = serviceId;
                                    dvbtChannel.TransportId          = transportId;
                                    dvbtChannel.LogicalChannelNumber = channelNumber;
                                    layer.AddTuningDetails(dbChannel, dvbtChannel);
                                    Log.Info("TvChannels: Added tuning details for DVB-T channel: {0} provider: {1}", name, provider);
                                    break;

                                case 5: //Webstream
                                    layer.AddWebStreamTuningDetails(dbChannel, url, bitrate);
                                    break;

                                case 7: //DVBIPChannel
                                    DVBIPChannel dvbipChannel = new DVBIPChannel();
                                    dvbipChannel.FreeToAir            = fta;
                                    dvbipChannel.Frequency            = frequency;
                                    dvbipChannel.IsRadio              = isRadio;
                                    dvbipChannel.IsTv                 = isTv;
                                    dvbipChannel.LogicalChannelNumber = channelNumber;
                                    dvbipChannel.Name                 = name;
                                    dvbipChannel.NetworkId            = networkId;
                                    dvbipChannel.PmtPid               = pmtPid;
                                    dvbipChannel.Provider             = provider;
                                    dvbipChannel.ServiceId            = serviceId;
                                    dvbipChannel.TransportId          = transportId;
                                    dvbipChannel.Url = url;
                                    layer.AddTuningDetails(dbChannel, dvbipChannel);
                                    Log.Info("TvChannels: Added tuning details for DVB-IP channel: {0} provider: {1}", name, provider);
                                    break;
                                }
                            }
                        }
                        catch (Exception exc)
                        {
                            Log.Error("TvChannels: Failed to add channel - {0}", exc.Message);
                        }
                    }
                }

                if (tvChannelGroupList != null && importtvgroups)
                {
                    // Import tv channel groups
                    foreach (XmlNode nodeChannelGroup in tvChannelGroupList)
                    {
                        try
                        {
                            tvChannelGroupCount++;
                            string       groupName      = nodeChannelGroup.Attributes["GroupName"].Value;
                            int          groupSortOrder = Int32.Parse(nodeChannelGroup.Attributes["SortOrder"].Value);
                            ChannelGroup group          = null;
                            if (groupName == TvConstants.TvGroupNames.AllChannels)
                            {
                                group = layer.GetGroupByName(groupName) ??
                                        new ChannelGroup(groupName, groupSortOrder);
                            }
                            else
                            {
                                group = layer.GetGroupByName(groupName, groupSortOrder) ??
                                        new ChannelGroup(groupName, groupSortOrder);
                            }
                            group.Persist();
                            XmlNodeList mappingList = nodeChannelGroup.SelectNodes("mappings/map");
                            foreach (XmlNode nodeMap in mappingList)
                            {
                                IList <Channel> channels  = layer.GetChannelsByName(nodeMap.Attributes["ChannelName"].Value);
                                int             sortOrder = Int32.Parse(GetNodeAttribute(nodeMap, "SortOrder", "9999"));
                                if (channels != null && channels.Count > 0)
                                {
                                    Channel channel = channels[0];
                                    if (!channel.GroupNames.Contains(group.GroupName))
                                    {
                                        GroupMap map = new GroupMap(group.IdGroup, channel.IdChannel, sortOrder);
                                        map.Persist();
                                    }
                                    else
                                    {
                                        foreach (GroupMap map in channel.ReferringGroupMap())
                                        {
                                            if (map.IdGroup == group.IdGroup)
                                            {
                                                map.SortOrder = sortOrder;
                                                map.Persist();
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception exg)
                        {
                            Log.Error("TvChannels: Failed to add group - {0}", exg.Message);
                        }
                    }
                }

                if (radioChannelGroupList != null && importradiogroups)
                {
                    // Import radio channel groups
                    foreach (XmlNode nodeChannelGroup in radioChannelGroupList)
                    {
                        try
                        {
                            radioChannelGroupCount++;
                            string            groupName      = nodeChannelGroup.Attributes["GroupName"].Value;
                            int               groupSortOrder = Int32.Parse(nodeChannelGroup.Attributes["SortOrder"].Value);
                            RadioChannelGroup group          = layer.GetRadioChannelGroupByName(groupName) ??
                                                               new RadioChannelGroup(groupName, groupSortOrder);
                            group.Persist();
                            XmlNodeList mappingList = nodeChannelGroup.SelectNodes("mappings/map");
                            foreach (XmlNode nodeMap in mappingList)
                            {
                                IList <Channel> channels  = layer.GetChannelsByName(nodeMap.Attributes["ChannelName"].Value);
                                int             sortOrder = Int32.Parse(GetNodeAttribute(nodeMap, "SortOrder", "9999"));
                                if (channels != null && channels.Count > 0)
                                {
                                    Channel channel = channels[0];
                                    if (!channel.GroupNames.Contains(group.GroupName))
                                    {
                                        RadioGroupMap map = new RadioGroupMap(group.IdGroup, channel.IdChannel, sortOrder);
                                        map.Persist();
                                    }
                                    else
                                    {
                                        foreach (RadioGroupMap map in channel.ReferringRadioGroupMap())
                                        {
                                            if (map.IdGroup == group.IdGroup)
                                            {
                                                map.SortOrder = sortOrder;
                                                map.Persist();
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception exg)
                        {
                            Log.Error("Radio Channels: Failed to add group - {0}", exg.Message);
                        }
                    }
                }

                if (scheduleList != null && importschedules)
                {
                    // Import schedules
                    foreach (XmlNode nodeSchedule in scheduleList)
                    {
                        try
                        {
                            int idChannel = -1;

                            string programName = nodeSchedule.Attributes["ProgramName"].Value;
                            string channel     = nodeSchedule.Attributes["ChannelName"].Value;
                            if (!string.IsNullOrEmpty(channel))
                            {
                                IList <Channel> channels = layer.GetChannelsByName(channel);
                                if (channels != null && channels.Count > 0)
                                {
                                    idChannel = channels[0].IdChannel;
                                }
                            }
                            DateTime startTime = DateTime.ParseExact(nodeSchedule.Attributes["StartTime"].Value, "yyyy-M-d H:m:s",
                                                                     CultureInfo.InvariantCulture);
                            DateTime endTime = DateTime.ParseExact(nodeSchedule.Attributes["EndTime"].Value, "yyyy-M-d H:m:s",
                                                                   CultureInfo.InvariantCulture);
                            int      scheduleType = Int32.Parse(nodeSchedule.Attributes["ScheduleType"].Value);
                            Schedule schedule     = layer.AddSchedule(idChannel, programName, startTime, endTime, scheduleType);

                            schedule.ScheduleType = scheduleType;
                            schedule.KeepDate     = DateTime.ParseExact(nodeSchedule.Attributes["KeepDate"].Value, "yyyy-M-d H:m:s",
                                                                        CultureInfo.InvariantCulture);
                            schedule.PreRecordInterval  = Int32.Parse(nodeSchedule.Attributes["PreRecordInterval"].Value);
                            schedule.PostRecordInterval = Int32.Parse(nodeSchedule.Attributes["PostRecordInterval"].Value);
                            schedule.Priority           = Int32.Parse(nodeSchedule.Attributes["Priority"].Value);
                            schedule.Quality            = Int32.Parse(nodeSchedule.Attributes["Quality"].Value);
                            schedule.Directory          = nodeSchedule.Attributes["Directory"].Value;
                            schedule.KeepMethod         = Int32.Parse(nodeSchedule.Attributes["KeepMethod"].Value);
                            schedule.MaxAirings         = Int32.Parse(nodeSchedule.Attributes["MaxAirings"].Value);
                            schedule.RecommendedCard    = Int32.Parse(nodeSchedule.Attributes["RecommendedCard"].Value);
                            schedule.ScheduleType       = Int32.Parse(nodeSchedule.Attributes["ScheduleType"].Value);
                            schedule.Series             = (GetNodeAttribute(nodeSchedule, "Series", "False") == "True");
                            if (idChannel > -1)
                            {
                                schedule.Persist();
                                scheduleCount++;
                                Log.Info("TvChannels: Added schedule: {0} on channel: {1}", programName, channel);
                            }
                            else
                            {
                                Log.Info("TvChannels: Skipped schedule: {0} because the channel was unknown: {1}", programName, channel);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error("TvChannels: Failed to add schedule - {0}", ex.Message);
                        }
                    }
                }

                dlg.Close();
                Log.Info(
                    "TvChannels: Imported {0} channels, {1} tv channel groups, {2} radio channel groups and {3} schedules",
                    channelCount, tvChannelGroupCount, radioChannelGroupCount, scheduleCount);
                MessageBox.Show(
                    String.Format("Imported {0} channels, {1} tv channel groups, {2} radio channel groups and {3} schedules",
                                  channelCount, tvChannelGroupCount, radioChannelGroupCount, scheduleCount));
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Error while importing:\n\n" + ex + " " + ex.StackTrace);
            }
            finally
            {
                dlg.Close();
                OnSectionActivated();
            }
        }
Пример #12
0
        private void DoScan()
        {
            suminfo tv    = new suminfo();
            suminfo radio = new suminfo();
            IUser   user  = new User();

            user.CardId = _cardNumber;

            try
            {
                if (_DVBCChannels.Count == 0)
                {
                    return;
                }

                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));

                for (int index = 0; index < _DVBCChannels.Count; ++index)
                {
                    DVBCTuning  curTuning   = _DVBCChannels[index];
                    DVBCChannel tuneChannel = new DVBCChannel(curTuning);
                    string      line        = String.Format("{0}tp- {1}", 1 + index, tuneChannel.TuningInfo.ToString());
                    Log.Debug(line);

                    if (index == 0)
                    {
                        RemoteControl.Instance.Scan(ref user, tuneChannel, -1);
                    }

                    IChannel[] channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);

                    if (channels == null || channels.Length == 0)
                    {
                        if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
                        {
                            line = String.Format("{0}tp- {1} {2} {3}:No signal", 1 + index, tuneChannel.Frequency,
                                                 tuneChannel.ModulationType, tuneChannel.SymbolRate);

                            Log.Error(line);
                            continue;
                        }
                        line = String.Format("{0}tp- {1} {2} {3}:Nothing found", 1 + index, tuneChannel.Frequency,
                                             tuneChannel.ModulationType, tuneChannel.SymbolRate);

                        Log.Error(line);
                        continue;
                    }

                    radio.newChannel = 0;
                    radio.updChannel = 0;
                    tv.newChannel    = 0;
                    tv.updChannel    = 0;

                    for (int i = 0; i < channels.Length; ++i)
                    {
                        Channel      dbChannel;
                        DVBCChannel  channel = (DVBCChannel)channels[i];
                        bool         exists;
                        TuningDetail currentDetail;
                        //Check if we already have this tuningdetail. The user has the option to enable channel move detection...
                        if (true)
                        {
                            //According to the DVB specs ONID + SID is unique, therefore we do not need to use the TSID to identify a service.
                            //The DVB spec recommends that the SID should not change if a service moves. This theoretically allows us to
                            //track channel movements.
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }
                        else
                        {
                            //There are certain providers that do not maintain unique ONID + SID combinations.
                            //In those cases, ONID + TSID + SID is generally unique. The consequence of using the TSID to identify
                            //a service is that channel movement tracking won't work (each transponder/mux should have its own TSID).
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.TransportId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }

                        if (currentDetail == null)
                        {
                            //add new channel
                            exists              = false;
                            dbChannel           = layer.AddNewChannel(channel.Name, channel.LogicalChannelNumber);
                            dbChannel.SortOrder = 10000;
                            if (channel.LogicalChannelNumber >= 1)
                            {
                                dbChannel.SortOrder = channel.LogicalChannelNumber;
                            }
                            dbChannel.IsTv    = channel.IsTv;
                            dbChannel.IsRadio = channel.IsRadio;
                            dbChannel.GrabEpg = true;
                            dbChannel.Persist();

                            if (dbChannel.IsTv)
                            {
                                layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);

                                if (_defaultTVGroup != "")
                                {
                                    layer.AddChannelToGroup(dbChannel, _defaultTVGroup);
                                }
                            }
                            if (dbChannel.IsRadio)
                            {
                                layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels);

                                if (_defaultTVGroup != "")
                                {
                                    layer.AddChannelToRadioGroup(dbChannel, _defaultTVGroup);
                                }
                            }
                        }
                        else
                        {
                            exists    = true;
                            dbChannel = currentDetail.ReferencedChannel();
                        }

                        if (currentDetail == null)
                        {
                            layer.AddTuningDetails(dbChannel, channel);
                        }
                        else
                        {
                            //update tuning details...
                            TuningDetail td = layer.UpdateTuningDetails(dbChannel, channel, currentDetail);
                            td.Persist();
                        }

                        if (channel.IsTv)
                        {
                            if (exists)
                            {
                                tv.updChannel++;
                            }
                            else
                            {
                                tv.newChannel++;
                                tv.newChannels.Add(channel);
                            }
                        }
                        if (channel.IsRadio)
                        {
                            if (exists)
                            {
                                radio.updChannel++;
                            }
                            else
                            {
                                radio.newChannel++;
                                radio.newChannels.Add(channel);
                            }
                        }
                        layer.MapChannelToCard(card, dbChannel, false);
                        line = String.Format("{0}tp- {1} {2} {3}:New TV/Radio:{4}/{5} Updated TV/Radio:{6}/{7}", 1 + index,
                                             tuneChannel.Frequency, tuneChannel.ModulationType, tuneChannel.SymbolRate,
                                             tv.newChannel, radio.newChannel, tv.updChannel, radio.updChannel);
                        Log.Debug(line);
                    }
                    tv.updChannelSum    += tv.updChannel;
                    radio.updChannelSum += radio.updChannel;
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            finally
            {
                RemoteControl.Instance.StopCard(user);
            }

            if (radio.newChannels.Count == 0)
            {
                Log.Debug("No new radio channels");
            }
            else
            {
                foreach (IChannel newChannel in radio.newChannels)
                {
                    String line = String.Format("Radio  -> new channel: {0}", newChannel.Name);
                    Log.Debug(line);
                }
            }

            if (tv.newChannels.Count == 0)
            {
                Log.Debug("No new TV channels");
            }
            else
            {
                foreach (IChannel newChannel in tv.newChannels)
                {
                    String line = String.Format("TV  -> new channel: {0}", newChannel.Name);
                    Log.Debug(line);
                }
            }
        }
Пример #13
0
        /// <summary>
        /// This method will try to start the epg grabber for the channel and tuning details specified
        /// Epg grabbing can only be started if there is a card idle which can receive the channel specified
        /// </summary>
        /// <param name="channel">channel to grab/param>
        /// <param name="tuning">tuning information</param>
        /// <param name="card">card to use for grabbing</param>
        /// <returns>true if grabbing has started else false</returns>
        private bool GrabEpgForChannel(Channel channel, IChannel tuning, Card card)
        {
            if (channel == null)
            {
                Log.Error("Epg: invalid channel");
                return(false);
            }
            if (tuning == null)
            {
                Log.Error("Epg: invalid tuning");
                return(false);
            }
            if (card == null)
            {
                Log.Error("Epg: invalid card");
                return(false);
            }
            if (_tvController == null)
            {
                Log.Error("Epg: invalid tvcontroller");
                return(false);
            }
            if (_user == null)
            {
                Log.Error("Epg: invalid user");
                return(false);
            }
            //remove following check to enable multi-card epg grabbing (still beta)
            if (_tvController.AllCardsIdle == false)
            {
                Log.Epg("Epg: card:{0} cards are not idle", card.IdCard);
                return(false);
            }

            TvResult result;
            //handle ATSC
            ATSCChannel atscChannel = tuning as ATSCChannel;

            if (atscChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.Atsc)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} atsc card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        IUser cardUser;
                        if (_tvController.IsCardInUse(card.IdCard, out cardUser) == false)
                        {
                            _user.CardId = card.IdCard;
                            result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                            if (result == TvResult.Succeeded)
                            {
                                if (!_isRunning || false == _tvController.GrabEpg(this, card.IdCard))
                                {
                                    if (!_isRunning)
                                    {
                                        Log.Epg("Tuning finished but EpgGrabber no longer enabled");
                                    }
                                    _tvController.StopGrabbingEpg(_user);
                                    _user.CardId = -1;
                                    Log.Epg("Epg: card:{0} could not start atsc epg grabbing", card.IdCard);
                                    return(false);
                                }
                                _user.CardId = card.IdCard;
                                return(true);
                            }
                            _user.CardId = -1;
                            Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, result.ToString());
                            return(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        throw;
                    }
                    return(false);
                }
                Log.Epg("Epg: card:{0} could not tune to atsc channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBC
            DVBCChannel dvbcChannel = tuning as DVBCChannel;

            if (dvbcChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbC)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbc card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        if (result == TvResult.Succeeded)
                        {
                            if (!_isRunning || false == _tvController.GrabEpg(this, card.IdCard))
                            {
                                if (!_isRunning)
                                {
                                    Log.Epg("Tuning finished but EpgGrabber no longer enabled");
                                }
                                _tvController.StopGrabbingEpg(_user);
                                _user.CardId = -1;
                                Log.Epg("Epg: card:{0} could not start dvbc epg grabbing", card.IdCard);
                                return(false);
                            }
                            _user.CardId = card.IdCard;
                            return(true);
                        }
                        _user.CardId = -1;
                        Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, result.ToString());
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        throw;
                    }
                    //unreachable return false;
                }
                Log.Epg("Epg: card:{0} could not tune to dvbc channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBS
            DVBSChannel dvbsChannel = tuning as DVBSChannel;

            if (dvbsChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbS)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbs card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        if (result == TvResult.Succeeded)
                        {
                            if (!_isRunning || false == _tvController.GrabEpg(this, card.IdCard))
                            {
                                if (!_isRunning)
                                {
                                    Log.Epg("Tuning finished but EpgGrabber no longer enabled");
                                }
                                _tvController.StopGrabbingEpg(_user);
                                _user.CardId = -1;
                                Log.Epg("Epg: card:{0} could not start dvbs epg grabbing", card.IdCard);
                                return(false);
                            }
                            _user.CardId = card.IdCard;
                            return(true);
                        }
                        _user.CardId = -1;
                        Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, result.ToString());
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        throw;
                    }
                    //unreachable return false;
                }
                Log.Epg("Epg: card:{0} could not tune to dvbs channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBT
            DVBTChannel dvbtChannel = tuning as DVBTChannel;

            if (dvbtChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbT)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbt card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        if (result == TvResult.Succeeded)
                        {
                            if (!_isRunning || false == _tvController.GrabEpg(this, card.IdCard))
                            {
                                if (!_isRunning)
                                {
                                    Log.Epg("Tuning finished but EpgGrabber no longer enabled");
                                }
                                _tvController.StopGrabbingEpg(_user);
                                _user.CardId = -1;
                                Log.Epg("Epg: card:{0} could not start dvbt grabbing", card.IdCard);
                                return(false);
                            }
                            _user.CardId = card.IdCard;
                            return(true);
                        }
                        _user.CardId = -1;
                        Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, result.ToString());
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        throw;
                    }
                    //unreachable return false;
                }
                Log.Epg("Epg: card:{0} could not tune to dvbt channel:{1}", card.IdCard, tuning.ToString());
                return(false);
            }

            //handle DVBIP
            DVBIPChannel dvbipChannel = tuning as DVBIPChannel;

            if (dvbipChannel != null)
            {
                if (_tvController.Type(card.IdCard) == CardType.DvbIP)
                {
                    if (IsCardIdle(card.IdCard) == false)
                    {
                        Log.Epg("Epg: card:{0} dvbip card is not idle", card.IdCard);
                        return(false); //card is busy
                    }
                    try
                    {
                        _user.CardId = card.IdCard;
                        result       = RemoteControl.Instance.Tune(ref _user, tuning, channel.IdChannel);
                        if (result == TvResult.Succeeded)
                        {
                            if (!_isRunning || false == _tvController.GrabEpg(this, card.IdCard))
                            {
                                if (!_isRunning)
                                {
                                    Log.Epg("Tuning finished but EpgGrabber no longer enabled");
                                }
                                _tvController.StopGrabbingEpg(_user);
                                _user.CardId = -1;
                                Log.Epg("Epg: card:{0} could not start dvbip grabbing", card.IdCard);
                                return(false);
                            }
                            _user.CardId = card.IdCard;
                            return(true);
                        }
                        else
                        {
                            _user.CardId = -1;
                            Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, result.ToString());
                            return(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        throw ex;
                    }
                    //unreachable return false;
                }
                else
                {
                    Log.Epg("Epg: card:{0} could not tune to dvbip channel:{1}", card.IdCard, tuning.ToString());
                }
                return(false);
            }
            Log.Epg("Epg: card:{0} could not tune to channel:{1}", card.IdCard, tuning.ToString());
            return(false);
        }