Exemplo n.º 1
0
        private void DoScan()
        {
            int tvChannelsNew        = 0;
            int radioChannelsNew     = 0;
            int tvChannelsUpdated    = 0;
            int radioChannelsUpdated = 0;

            string buttonText = mpButtonScanTv.Text;
            IUser  user       = new User();

            user.CardId = _cardNumber;
            try
            {
                // First lock the card, because so that other parts of a hybrid card can't be used at the same time
                _isScanning         = true;
                _stopScanning       = false;
                mpButtonScanTv.Text = "Cancel...";
                RemoteControl.Instance.EpgGrabberEnabled = false;
                listViewStatus.Items.Clear();

                PlayList playlist = new PlayList();
                if (mpComboBoxService.SelectedIndex == 0)
                {
                    //TODO read SAP announcements
                }
                else
                {
                    IPlayListIO playlistIO =
                        PlayListFactory.CreateIO(String.Format(@"{0}\TuningParameters\dvbip\{1}.m3u", PathManager.GetDataPath,
                                                               mpComboBoxService.SelectedItem));
                    playlistIO.Load(playlist,
                                    String.Format(@"{0}\TuningParameters\dvbip\{1}.m3u", PathManager.GetDataPath,
                                                  mpComboBoxService.SelectedItem));
                }
                if (playlist.Count == 0)
                {
                    return;
                }

                mpComboBoxService.Enabled    = false;
                checkBoxCreateGroups.Enabled = false;
                checkBoxEnableChannelMoveDetection.Enabled = false;
                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));

                int index = -1;
                IEnumerator <PlayListItem> enumerator = playlist.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    if (_stopScanning)
                    {
                        return;
                    }
                    index++;
                    float percent = ((float)(index)) / playlist.Count;
                    percent *= 100f;
                    if (percent > 100f)
                    {
                        percent = 100f;
                    }
                    progressBar1.Value = (int)percent;

                    string url  = enumerator.Current.FileName.Substring(enumerator.Current.FileName.LastIndexOf('\\') + 1);
                    string name = enumerator.Current.Description;

                    DVBIPChannel tuneChannel = new DVBIPChannel();
                    tuneChannel.Url  = url;
                    tuneChannel.Name = name;
                    string       line = String.Format("{0}- {1} - {2}", 1 + index, tuneChannel.Name, tuneChannel.Url);
                    ListViewItem item = listViewStatus.Items.Add(new ListViewItem(line));
                    item.EnsureVisible();
                    RemoteControl.Instance.Tune(ref user, tuneChannel, -1);
                    IChannel[] channels;
                    channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);
                    UpdateStatus();
                    if (channels == null || channels.Length == 0)
                    {
                        if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
                        {
                            line           = String.Format("{0}- {1} :No Signal", 1 + index, tuneChannel.Url);
                            item.Text      = line;
                            item.ForeColor = Color.Red;
                            continue;
                        }
                        else
                        {
                            line           = String.Format("{0}- {1} :Nothing found", 1 + index, tuneChannel.Url);
                            item.Text      = line;
                            item.ForeColor = Color.Red;
                            continue;
                        }
                    }

                    int newChannels     = 0;
                    int updatedChannels = 0;

                    for (int i = 0; i < channels.Length; ++i)
                    {
                        Channel      dbChannel;
                        DVBIPChannel channel = (DVBIPChannel)channels[i];
                        if (channels.Length > 1)
                        {
                            if (channel.Name.IndexOf("Unknown") == 0)
                            {
                                channel.Name = name + (i + 1);
                            }
                        }
                        else
                        {
                            channel.Name = name;
                        }
                        bool         exists;
                        TuningDetail currentDetail;
                        //Check if we already have this tuningdetail. According to DVB-IP specifications there are two ways to identify DVB-IP
                        //services: one ONID + SID based, the other domain/URL based. At this time we don't fully and properly implement the DVB-IP
                        //specifications, so the safest method for service identification is the URL. The user has the option to enable the use of
                        //ONID + SID identification and channel move detection...
                        if (checkBoxEnableChannelMoveDetection.Checked)
                        {
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }
                        else
                        {
                            currentDetail = layer.GetTuningDetail(channel.Url, 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();
                        }

                        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);

                        if (checkBoxCreateGroups.Checked)
                        {
                            layer.AddChannelToGroup(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)
                            {
                                tvChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                tvChannelsNew++;
                                newChannels++;
                            }
                        }
                        if (channel.IsRadio)
                        {
                            if (exists)
                            {
                                radioChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                radioChannelsNew++;
                                newChannels++;
                            }
                        }
                        layer.MapChannelToCard(card, dbChannel, false);
                        line = String.Format("{0}- {1} :New:{2} Updated:{3}", 1 + index, tuneChannel.Name, newChannels,
                                             updatedChannels);
                        item.Text = line;
                    }
                }
                //DatabaseManager.Instance.SaveChanges();
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            finally
            {
                RemoteControl.Instance.StopCard(user);
                RemoteControl.Instance.EpgGrabberEnabled = true;
                progressBar1.Value           = 100;
                mpComboBoxService.Enabled    = true;
                checkBoxCreateGroups.Enabled = true;
                checkBoxEnableChannelMoveDetection.Enabled = true;
                mpButtonScanTv.Text = buttonText;
                _isScanning         = false;
            }
            ListViewItem lastItem = listViewStatus.Items.Add(new ListViewItem("Scan done..."));

            lastItem =
                listViewStatus.Items.Add(
                    new ListViewItem(String.Format("Total radio channels new:{0} updated:{1}", radioChannelsNew,
                                                   radioChannelsUpdated)));
            lastItem =
                listViewStatus.Items.Add(
                    new ListViewItem(String.Format("Total tv channels new:{0} updated:{1}", tvChannelsNew, tvChannelsUpdated)));
            lastItem.EnsureVisible();
        }
Exemplo n.º 2
0
        private void DoScan()
        {
            int tvChannelsNew        = 0;
            int radioChannelsNew     = 0;
            int tvChannelsUpdated    = 0;
            int radioChannelsUpdated = 0;

            IUser user = new User();

            user.CardId = _cardNumber;
            try
            {
                // First lock the card, because so that other parts of a hybrid card can't be used at the same time
                RemoteControl.Instance.EpgGrabberEnabled = false;

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

                int index = -1;
                IEnumerator <PlayListItem> enumerator = playlist.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    string url  = enumerator.Current.FileName.Substring(enumerator.Current.FileName.LastIndexOf('\\') + 1);
                    string name = enumerator.Current.Description;

                    DVBIPChannel tuneChannel = new DVBIPChannel();
                    tuneChannel.Url  = url;
                    tuneChannel.Name = name;
                    string line = String.Format("{0}- {1} - {2}", 1 + index, tuneChannel.Name, tuneChannel.Url);
                    Log.Debug(line);

                    RemoteControl.Instance.Tune(ref user, tuneChannel, -1);
                    IChannel[] channels;
                    channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);

                    if (channels == null || channels.Length == 0)
                    {
                        if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
                        {
                            line = String.Format("{0}- {1} - {2} :No Signal", 1 + index, tuneChannel.Url, tuneChannel.Name);
                            Log.Debug(line);
                            continue;
                        }
                        else
                        {
                            line = String.Format("{0}- {1} - {2} :Nothing found", 1 + index, tuneChannel.Url, tuneChannel.Name);
                            Log.Debug(line);
                            continue;
                        }
                    }

                    int newChannels     = 0;
                    int updatedChannels = 0;

                    for (int i = 0; i < channels.Length; ++i)
                    {
                        Channel      dbChannel;
                        DVBIPChannel channel = (DVBIPChannel)channels[i];
                        if (channels.Length > 1)
                        {
                            if (channel.Name.IndexOf("Unknown") == 0)
                            {
                                channel.Name = name + (i + 1);
                            }
                        }
                        else
                        {
                            channel.Name = name;
                        }
                        bool         exists;
                        TuningDetail currentDetail;
                        //Check if we already have this tuningdetail. According to DVB-IP specifications there are two ways to identify DVB-IP
                        //services: one ONID + SID based, the other domain/URL based. At this time we don't fully and properly implement the DVB-IP
                        //specifications, so the safest method for service identification is the URL. The user has the option to enable the use of
                        //ONID + SID identification and channel move detection...
                        if (true)
                        {
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }
                        else
                        {
                            currentDetail = layer.GetTuningDetail(channel.Url, 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();
                        }

                        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);

                        if (_defaultTVGroup != "")
                        {
                            layer.AddChannelToGroup(dbChannel, _defaultTVGroup);
                        }
                        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)
                            {
                                tvChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                tvChannelsNew++;
                                newChannels++;
                            }
                        }
                        if (channel.IsRadio)
                        {
                            if (exists)
                            {
                                radioChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                radioChannelsNew++;
                                newChannels++;
                            }
                        }
                        layer.MapChannelToCard(card, dbChannel, false);
                        line = String.Format("{0}- {1} :New:{2} Updated:{3}", 1 + index, tuneChannel.Name, newChannels,
                                             updatedChannels);
                        Log.Debug(line);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            finally
            {
                RemoteControl.Instance.StopCard(user);
            }
        }
Exemplo n.º 3
0
    private void DoScan()
    {
      int tvChannelsNew = 0;
      int radioChannelsNew = 0;
      int tvChannelsUpdated = 0;
      int radioChannelsUpdated = 0;

      string buttonText = mpButtonScanTv.Text;
      IUser user = new User();
      user.CardId = _cardNumber;
      try
      {
        // First lock the card, because so that other parts of a hybrid card can't be used at the same time
        _isScanning = true;
        _stopScanning = false;
        mpButtonScanTv.Text = "Cancel...";
        RemoteControl.Instance.EpgGrabberEnabled = false;
        listViewStatus.Items.Clear();

        PlayList playlist = new PlayList();
        if (mpComboBoxService.SelectedIndex == 0)
        {
          //TODO read SAP announcements
        }
        else
        {
          IPlayListIO playlistIO =
            PlayListFactory.CreateIO(String.Format(@"{0}\TuningParameters\dvbip\{1}.m3u", PathManager.GetDataPath,
                                                   mpComboBoxService.SelectedItem));
          playlistIO.Load(playlist,
                          String.Format(@"{0}\TuningParameters\dvbip\{1}.m3u", PathManager.GetDataPath,
                                        mpComboBoxService.SelectedItem));
        }
        if (playlist.Count == 0) return;

        mpComboBoxService.Enabled = false;
        checkBoxCreateGroups.Enabled = false;
        checkBoxEnableChannelMoveDetection.Enabled = false;
        TvBusinessLayer layer = new TvBusinessLayer();
        Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));

        int index = -1;
        IEnumerator<PlayListItem> enumerator = playlist.GetEnumerator();

        while (enumerator.MoveNext())
        {
          if (_stopScanning) return;
          index++;
          float percent = ((float)(index)) / playlist.Count;
          percent *= 100f;
          if (percent > 100f) percent = 100f;
          progressBar1.Value = (int)percent;

          string url = enumerator.Current.FileName.Substring(enumerator.Current.FileName.LastIndexOf('\\') + 1);
          string name = enumerator.Current.Description;

          DVBIPChannel tuneChannel = new DVBIPChannel();
          tuneChannel.Url = url;
          tuneChannel.Name = name;
          string line = String.Format("{0}- {1} - {2}", 1 + index, tuneChannel.Name, tuneChannel.Url);
          ListViewItem item = listViewStatus.Items.Add(new ListViewItem(line));
          item.EnsureVisible();
          RemoteControl.Instance.Tune(ref user, tuneChannel, -1);
          IChannel[] channels;
          channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);
          UpdateStatus();
          if (channels == null || channels.Length == 0)
          {
            if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
            {
              line = String.Format("{0}- {1} - {2} :No Signal", 1 + index, tuneChannel.Url, tuneChannel.Name);
              item.Text = line;
              item.ForeColor = Color.Red;
              continue;
            }
            else
            {
              line = String.Format("{0}- {1} - {2} :Nothing found", 1 + index, tuneChannel.Url, tuneChannel.Name);
              item.Text = line;
              item.ForeColor = Color.Red;
              continue;
            }
          }

          int newChannels = 0;
          int updatedChannels = 0;

          for (int i = 0; i < channels.Length; ++i)
          {
            Channel dbChannel;
            DVBIPChannel channel = (DVBIPChannel)channels[i];
            if (channels.Length > 1)
            {
              if (channel.Name.IndexOf("Unknown") == 0)
              {
                channel.Name = name + (i + 1);
              }
            }
            else
            {
              channel.Name = name;
            }
            bool exists;
            TuningDetail currentDetail;
            //Check if we already have this tuningdetail. According to DVB-IP specifications there are two ways to identify DVB-IP
            //services: one ONID + SID based, the other domain/URL based. At this time we don't fully and properly implement the DVB-IP
            //specifications, so the safest method for service identification is the URL. The user has the option to enable the use of
            //ONID + SID identification and channel move detection...
            if (checkBoxEnableChannelMoveDetection.Checked)
            {
              currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.ServiceId,
                                                                 TvBusinessLayer.GetChannelType(channel));
            }
            else
            {
              currentDetail = layer.GetTuningDetail(channel.Url, 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();
            }

            layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);

            if (checkBoxCreateGroups.Checked)
            {
              layer.AddChannelToGroup(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)
              {
                tvChannelsUpdated++;
                updatedChannels++;
              }
              else
              {
                tvChannelsNew++;
                newChannels++;
              }
            }
            if (channel.IsRadio)
            {
              if (exists)
              {
                radioChannelsUpdated++;
                updatedChannels++;
              }
              else
              {
                radioChannelsNew++;
                newChannels++;
              }
            }
            layer.MapChannelToCard(card, dbChannel, false);
            line = String.Format("{0}- {1} :New:{2} Updated:{3}", 1 + index, tuneChannel.Name, newChannels,
                                 updatedChannels);
            item.Text = line;
          }
        }
        //DatabaseManager.Instance.SaveChanges();
      }
      catch (Exception ex)
      {
        Log.Write(ex);
      }
      finally
      {
        RemoteControl.Instance.StopCard(user);
        RemoteControl.Instance.EpgGrabberEnabled = true;
        progressBar1.Value = 100;
        mpComboBoxService.Enabled = true;
        checkBoxCreateGroups.Enabled = true;
        checkBoxEnableChannelMoveDetection.Enabled = true;
        mpButtonScanTv.Text = buttonText;
        _isScanning = false;
      }
      ListViewItem lastItem = listViewStatus.Items.Add(new ListViewItem("Scan done..."));
      lastItem =
        listViewStatus.Items.Add(
          new ListViewItem(String.Format("Total radio channels new:{0} updated:{1}", radioChannelsNew,
                                         radioChannelsUpdated)));
      lastItem =
        listViewStatus.Items.Add(
          new ListViewItem(String.Format("Total tv channels new:{0} updated:{1}", tvChannelsNew, tvChannelsUpdated)));
      lastItem.EnsureVisible();
    }