Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
0
        public static bool ConvertList(String fileName)
        {
            List <DVBCTuning> _dvbcChannels = new List <DVBCTuning>();
            string            line;

            string[]             tpdata;
            System.IO.TextReader tin = System.IO.File.OpenText(fileName);
            do
            {
                line = tin.ReadLine();
                if (line != null)
                {
                    if (line.Length > 0)
                    {
                        if (line.StartsWith(";"))
                        {
                            continue;
                        }
                        tpdata = line.Split(new char[] { ',' });
                        if (tpdata.Length != 3)
                        {
                            tpdata = line.Split(new char[] { ';' });
                        }
                        if (tpdata.Length == 3)
                        {
                            try
                            {
                                DVBCTuning tuning = new DVBCTuning();
                                tuning.Frequency = Int32.Parse(tpdata[0]);
                                string mod = tpdata[1].ToUpper();
                                switch (mod)
                                {
                                case "1024QAM":
                                    tuning.ModulationType = ModulationType.Mod1024Qam;
                                    break;

                                case "112QAM":
                                    tuning.ModulationType = ModulationType.Mod112Qam;
                                    break;

                                case "128QAM":
                                    tuning.ModulationType = ModulationType.Mod128Qam;
                                    break;

                                case "160QAM":
                                    tuning.ModulationType = ModulationType.Mod160Qam;
                                    break;

                                case "16QAM":
                                    tuning.ModulationType = ModulationType.Mod16Qam;
                                    break;

                                case "16VSB":
                                    tuning.ModulationType = ModulationType.Mod16Vsb;
                                    break;

                                case "192QAM":
                                    tuning.ModulationType = ModulationType.Mod192Qam;
                                    break;

                                case "224QAM":
                                    tuning.ModulationType = ModulationType.Mod224Qam;
                                    break;

                                case "256QAM":
                                    tuning.ModulationType = ModulationType.Mod256Qam;
                                    break;

                                case "320QAM":
                                    tuning.ModulationType = ModulationType.Mod320Qam;
                                    break;

                                case "384QAM":
                                    tuning.ModulationType = ModulationType.Mod384Qam;
                                    break;

                                case "448QAM":
                                    tuning.ModulationType = ModulationType.Mod448Qam;
                                    break;

                                case "512QAM":
                                    tuning.ModulationType = ModulationType.Mod512Qam;
                                    break;

                                case "640QAM":
                                    tuning.ModulationType = ModulationType.Mod640Qam;
                                    break;

                                case "64QAM":
                                    tuning.ModulationType = ModulationType.Mod64Qam;
                                    break;

                                case "768QAM":
                                    tuning.ModulationType = ModulationType.Mod768Qam;
                                    break;

                                case "80QAM":
                                    tuning.ModulationType = ModulationType.Mod80Qam;
                                    break;

                                case "896QAM":
                                    tuning.ModulationType = ModulationType.Mod896Qam;
                                    break;

                                case "8VSB":
                                    tuning.ModulationType = ModulationType.Mod8Vsb;
                                    break;

                                case "96QAM":
                                    tuning.ModulationType = ModulationType.Mod96Qam;
                                    break;

                                case "AMPLITUDE":
                                    tuning.ModulationType = ModulationType.ModAnalogAmplitude;
                                    break;

                                case "FREQUENCY":
                                    tuning.ModulationType = ModulationType.ModAnalogFrequency;
                                    break;

                                case "BPSK":
                                    tuning.ModulationType = ModulationType.ModBpsk;
                                    break;

                                case "OQPSK":
                                    tuning.ModulationType = ModulationType.ModOqpsk;
                                    break;

                                case "QPSK":
                                    tuning.ModulationType = ModulationType.ModQpsk;
                                    break;

                                default:
                                    tuning.ModulationType = ModulationType.ModNotSet;
                                    break;
                                }
                                tuning.SymbolRate = Int32.Parse(tpdata[2]) / 1000;
                                _dvbcChannels.Add(tuning);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            } while (!(line == null));
            tin.Close();

            String newPath = String.Format("{0}\\dvbc\\{1}.xml", System.IO.Path.GetDirectoryName(fileName), MakeDVBCName(System.IO.Path.GetFileNameWithoutExtension(fileName)));

            System.IO.TextWriter parFileXML    = System.IO.File.CreateText(newPath);
            XmlSerializer        xmlSerializer = new XmlSerializer(typeof(List <DVBCTuning>));

            xmlSerializer.Serialize(parFileXML, _dvbcChannels);
            parFileXML.Close();
            return(true);
        }