GetCardByDevicePath() public method

public GetCardByDevicePath ( string path ) : TvDatabase.Card
path string
return TvDatabase.Card
示例#1
0
    static void Main(string[] args)
    {
      TvBusinessLayer layer = new TvBusinessLayer();
      layer.AddCard("name1", "path1", 1);
      layer.AddCard("name2", "path2", 2);
      layer.AddCard("name3", "path3", 3);
      layer.AddCard("name4", "path4", 4);

      Card card = layer.GetCardByName("name2");
      card = layer.GetCardByDevicePath("path4");

      Channel channel = layer.AddChannel("provider", "name");
      channel = layer.AddChannel("provider", "name");
      

      DatabaseManager.Instance.SaveChanges();

    }
示例#2
0
    /// <summary>
    /// Initializes a new instance of the <see cref="TvCardDvbB2C2"/> class.
    /// </summary>
    /// <param name="device">The device.</param>
    public TvCardDvbB2C2(DsDevice device, DeviceInfo deviceInfo)
      : base(device)
    {
      _deviceInfo = deviceInfo;
      _devicePath = deviceInfo.DevicePath;
      _name = deviceInfo.Name;
      GetPreloadBitAndCardId();

      _useDISEqCMotor = false;
      TvBusinessLayer layer = new TvBusinessLayer();
      Card card = layer.GetCardByDevicePath(_devicePath);
      if (card != null)
      {
        Setting setting = layer.GetSetting("dvbs" + card.IdCard + "motorEnabled", "no");
        if (setting.Value == "yes")
          _useDISEqCMotor = true;
      }
      _conditionalAccess = new ConditionalAccess(null, null, null, this);
      _ptrDisEqc = Marshal.AllocCoTaskMem(20);
      _disEqcMotor = new DiSEqCMotor(this);
      GetTunerCapabilities();
    }
示例#3
0
    private void DoTvScan()
    {
      int channelsNew = 0;
      int channelsUpdated = 0;

      string buttonText = mpButtonScanTv.Text;
      checkButton.Enabled = false;
      try
      {
        _isScanning = true;
        _stopScanning = false;
        mpButtonScanTv.Text = "Cancel...";
        RemoteControl.Instance.EpgGrabberEnabled = false;
        TvBusinessLayer layer = new TvBusinessLayer();
        Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
        mpComboBoxCountry.Enabled = false;
        mpComboBoxSource.Enabled = false;
        mpComboBoxSensitivity.Enabled = false;
        checkBoxCreateSignalGroup.Enabled = false;
        checkBoxNoMerge.Enabled = false;
        mpButtonScanRadio.Enabled = false;
        mpButtonAddSvideoChannels.Enabled = false;
        mpListView1.Items.Clear();
        CountryCollection countries = new CountryCollection();
        IUser user = new User();
        user.CardId = _cardNumber;
        AnalogChannel temp = new AnalogChannel();
        temp.TunerSource = mpComboBoxSource.SelectedIndex == 0 ? TunerInputType.Antenna : TunerInputType.Cable;
        temp.VideoSource = AnalogChannel.VideoInputType.Tuner;
        temp.AudioSource = AnalogChannel.AudioInputType.Tuner;
        temp.Country = countries.Countries[mpComboBoxCountry.SelectedIndex];
        temp.IsRadio = false;
        temp.IsTv = true;
        TvResult tuneResult = RemoteControl.Instance.Tune(ref user, temp, -1);
        if (tuneResult == TvResult.SWEncoderMissing)
        {
          Log.Error("analog: DoTvScan error (missing software encoder)");
          MessageBox.Show("Please install a supported audio/video encoder for your software analog card",
                          "Unable to scan", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return;
        }
        if (tuneResult == TvResult.GraphBuildingFailed)
        {
          Log.Error("analog: DoTvScan error (missing software encoder)");
          MessageBox.Show(
            "The graph building. Mostly your card is not supported by TvServer. Please create a report in our forum",
            "Unable to scan", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return;
        }
        if (string.IsNullOrEmpty(_configuration.Graph.Capture.Name))
        {
          _configuration = Configuration.readConfiguration(_cardNumber, _cardName, _devicePath);
          ReCheckSettings();
        }
        int minChannel = RemoteControl.Instance.MinChannel(_cardNumber);
        int maxChannel = RemoteControl.Instance.MaxChannel(_cardNumber);
        if (maxChannel <= 0)
        {
          maxChannel = mpComboBoxSource.SelectedIndex == 0 ? 69 : 125;
        }
        if (minChannel < 0)
          minChannel = 1;
        Log.Info("Min channel = {0}. Max channel = {1}", minChannel, maxChannel);
        for (int channelNr = minChannel; channelNr <= maxChannel; channelNr++)
        {
          if (_stopScanning)
            return;
          float percent = ((float)((channelNr - minChannel)) / (maxChannel - minChannel));
          percent *= 100f;
          if (percent > 100f)
            percent = 100f;
          if (percent < 0)
            percent = 0f;
          progressBar1.Value = (int)percent;
          AnalogChannel channel = new AnalogChannel();
          channel.TunerSource = mpComboBoxSource.SelectedIndex == 0 ? TunerInputType.Antenna : TunerInputType.Cable;
          channel.Country = countries.Countries[mpComboBoxCountry.SelectedIndex];
          channel.ChannelNumber = channelNr;
          channel.IsTv = true;
          channel.IsRadio = false;
          channel.VideoSource = AnalogChannel.VideoInputType.Tuner;
          channel.AudioSource = AnalogChannel.AudioInputType.Automatic;
          string line = String.Format("channel:{0} source:{1} ", channel.ChannelNumber, mpComboBoxSource.SelectedItem);
          ListViewItem item = mpListView1.Items.Add(new ListViewItem(line));
          item.EnsureVisible();

          IChannel[] channels = RemoteControl.Instance.Scan(_cardNumber, channel);
          UpdateStatus();
          if (channels == null || channels.Length == 0)
          {
            if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
            {
              line = String.Format("channel:{0} source:{1} : No Signal", channel.ChannelNumber,
                                   mpComboBoxSource.SelectedItem);
              item.Text = line;
              item.ForeColor = Color.Red;
              continue;
            }
            line = String.Format("channel:{0} source:{1} : Nothing found", channel.ChannelNumber,
                                 mpComboBoxSource.SelectedItem);
            item.Text = line;
            item.ForeColor = Color.Red;
            continue;
          }
          bool exists = false;
          channel = (AnalogChannel)channels[0];
          if (channel.Name == "")
            channel.Name = String.Format(channel.ChannelNumber.ToString());
          Channel dbChannel = null;
          if (checkBoxNoMerge.Checked)
          {
            dbChannel = layer.AddNewChannel(channel.Name);
          }
          else
          {
            IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channel.Name, 0);
            if (tuningDetails != null && tuningDetails.Count > 0)
            {
              dbChannel = tuningDetails[0].ReferencedChannel();
            }

            if (dbChannel != null)
            {
              exists = true;
            }
            else
            {
              dbChannel = layer.AddNewChannel(channel.Name);
            }
          }
          dbChannel.IsTv = channel.IsTv;
          dbChannel.IsRadio = channel.IsRadio;
          dbChannel.Persist();
          layer.AddTuningDetails(dbChannel, channel);
          layer.MapChannelToCard(card, dbChannel, false);

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

          if (exists)
          {
            line = String.Format("channel:{0} source:{1} : Channel update found - {2}", channel.ChannelNumber,
                                 mpComboBoxSource.SelectedItem, channel.Name);
            channelsUpdated++;
          }
          else
          {
            line = String.Format("channel:{0} source:{1} : New channel found - {2}", channel.ChannelNumber,
                                 mpComboBoxSource.SelectedItem, channel.Name);
            channelsNew++;
          }
          item.Text = line;
        }
      }
      catch (TvExceptionSWEncoderMissing)
      {
        Log.Error("analog: DoTvScan error (missing software encoder)");
        MessageBox.Show("Please install a supported audio/video encoder for your software analog card", "Unable to scan",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
      catch (TvExceptionGraphBuildingFailed)
      {
        Log.Error("analog: DoTvScan error (missing software encoder)");
        MessageBox.Show(
          "The graph building. Mostly your card is not supported by TvServer. Please create a report in our forum",
          "Unable to scan", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
      catch (Exception ex)
      {
        Log.Error("analog: DoTvScan error ({0})", ex.StackTrace);
        MessageBox.Show(string.Format("Generic error: {0}", ex.Message), "Unable to scan", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
      }
      finally
      {
        IUser user = new User();
        user.CardId = _cardNumber;
        RemoteControl.Instance.StopCard(user);
        RemoteControl.Instance.EpgGrabberEnabled = true;
        mpButtonScanTv.Text = buttonText;
        progressBar1.Value = 100;
        mpComboBoxCountry.Enabled = true;
        mpComboBoxSource.Enabled = true;
        mpComboBoxSensitivity.Enabled = true;
        checkBoxCreateSignalGroup.Enabled = true;
        checkBoxNoMerge.Enabled = true;
        mpButtonScanTv.Enabled = true;
        mpButtonScanRadio.Enabled = true;
        mpButtonAddSvideoChannels.Enabled = true;
        _isScanning = false;
        checkButton.Enabled = true;
      }
      ListViewItem lastItem =
        mpListView1.Items.Add(
          new ListViewItem(String.Format("Total tv channels new:{0} updated:{1}", channelsNew, channelsUpdated)));
      lastItem.EnsureVisible();
    }
示例#4
0
 private void mpButtonScan_Click(object sender, EventArgs e)
 {
   if (_isScanning == false)
   {
     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;
     }
     Thread scanThread = new Thread(DoTvScan);
     scanThread.Name = "Analog TV scan thread";
     scanThread.Start();
   }
   else
   {
     _stopScanning = true;
   }
 }
示例#5
0
    public override void OnSectionDeActivated()
    {
      base.OnSectionDeActivated();
      TvBusinessLayer layer = new TvBusinessLayer();
      Setting setting = layer.GetSetting("analog" + _cardNumber + "Country", "0");
      setting.Value = mpComboBoxCountry.SelectedIndex.ToString();
      setting.Persist();
      setting = layer.GetSetting("analog" + _cardNumber + "Source", "0");
      setting.Value = mpComboBoxSource.SelectedIndex.ToString();
      setting.Persist();

      setting = layer.GetSetting("analog" + _cardNumber + "createsignalgroup", "false");
      setting.Value = checkBoxCreateSignalGroup.Checked ? "true" : "false";
      setting.Persist();

      UpdateConfiguration();
      Configuration.writeConfiguration(_configuration);
      Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
      if (card.Enabled)
      {
        try
        {
          RemoteControl.Instance.ReloadCardConfiguration(_cardNumber);
        }
        catch
        {
          Log.WriteFile("Could not reload card configuration");
        }
        return;
      }
    }
示例#6
0
 private void checkButton_Click(object sender, EventArgs e)
 {
   IUser user;
   try
   {
     TvBusinessLayer layer = new TvBusinessLayer();
     Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
     if (card.Enabled == false)
     {
       MessageBox.Show(this, "Card is disabled, please enable the card before checking quality control");
       return;
     }
     else if (!RemoteControl.Instance.CardPresent(card.IdCard))
     {
       MessageBox.Show(this, "Card is not found, please make sure card is present before checking quality control");
       return;
     }
     // Check if the card is locked for scanning.
     if (RemoteControl.Instance.IsCardInUse(_cardNumber, out user))
     {
       MessageBox.Show(this,
                       "Card is locked. Checking quality control not possible at the moment ! Perhaps you are scanning an other part of a hybrid card.");
       return;
     }
     user = new User();
     user.CardId = _cardNumber;
     AnalogChannel temp = new AnalogChannel();
     temp.VideoSource = AnalogChannel.VideoInputType.Tuner;
     temp.AudioSource = AnalogChannel.AudioInputType.Tuner;
     temp.IsRadio = false;
     temp.IsTv = true;
     RemoteControl.Instance.Tune(ref user, temp, -1);
     if (RemoteControl.Instance.SupportsQualityControl(_cardNumber))
     {
       _cardName = RemoteControl.Instance.CardName(_cardNumber);
       _devicePath = RemoteControl.Instance.CardDevice(_cardNumber);
       bitRateModeGroup.Enabled = RemoteControl.Instance.SupportsBitRateModes(_cardNumber);
       if (RemoteControl.Instance.SupportsPeakBitRateMode(_cardNumber))
       {
         vbrPeakPlayback.Enabled = true;
         vbrPeakRecord.Enabled = true;
       }
       else
       {
         vbrPeakPlayback.Enabled = false;
         vbrPeakRecord.Enabled = false;
       }
       if (RemoteControl.Instance.SupportsBitRate(_cardNumber))
       {
         bitRate.Enabled = true;
         customSettingsGroup.Enabled = true;
         customValue.Enabled = true;
         customValuePeak.Enabled = true;
       }
       else
       {
         bitRate.Enabled = false;
         customSettingsGroup.Enabled = false;
         customValue.Enabled = false;
         customValuePeak.Enabled = false;
       }
       _configuration = Configuration.readConfiguration(_cardNumber, _cardName, _devicePath);
       customValue.Value = _configuration.CustomQualityValue;
       customValuePeak.Value = _configuration.CustomPeakQualityValue;
       SetBitRateModes();
       SetBitRate();
       ReCheckSettings();
     }
     else
     {
       Log.WriteFile("Card doesn't support quality control");
       MessageBox.Show("The used encoder doesn't support quality control.",
                       "MediaPortal - TV Server management console", MessageBoxButtons.OK, MessageBoxIcon.Information);
       if (string.IsNullOrEmpty(_configuration.Graph.Capture.Name))
       {
         _configuration = Configuration.readConfiguration(_cardNumber, _cardName, _devicePath);
         ReCheckSettings();
       }
     }
   }
   finally
   {
     user = new User();
     user.CardId = _cardNumber;
     RemoteControl.Instance.StopCard(user);
   }
 }
示例#7
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;
      }
    }
示例#8
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");
              int chChannelNumber = Int32.Parse(GetNodeAttribute(nodeChannel, "ChannelNumber", "10000"));

              // 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, chChannelNumber);
              }

              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.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();
      }
    }
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TvCardDvbSS2"/> class.
 /// </summary>
 /// <param name="epgEvents">The EPG events interface.</param>
 /// <param name="device">The device.</param>
 public TvCardDvbSS2(IEpgEvents epgEvents, DsDevice device)
   : base(epgEvents, device)
 {
   _useDISEqCMotor = false;
   TvBusinessLayer layer = new TvBusinessLayer();
   Card card = layer.GetCardByDevicePath(device.DevicePath);
   if (card != null)
   {
     Setting setting = layer.GetSetting("dvbs" + card.IdCard + "motorEnabled", "no");
     if (setting.Value == "yes")
       _useDISEqCMotor = true;
   }
   _conditionalAccess = new ConditionalAccess(null, null, null, this);
   _ptrDisEqc = Marshal.AllocCoTaskMem(20);
   _disEqcMotor = new DiSEqCMotor(this);
   GetTunerCapabilities();
 }
示例#10
0
    public override void OnSectionActivated()
    {
      base.OnSectionActivated();
      UpdateStatus();
      TvBusinessLayer layer = new TvBusinessLayer();
      int index = Int32.Parse(layer.GetSetting("dvbip" + _cardNumber.ToString() + "Service", "0").Value);
      if (index < mpComboBoxService.Items.Count) mpComboBoxService.SelectedIndex = index;


      Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
      checkBoxCreateGroups.Checked =
        (layer.GetSetting("dvbip" + _cardNumber.ToString() + "creategroups", "false").Value == "true");
    }
示例#11
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();
    }
示例#12
0
    /// <summary>
    /// Initalizes the controller.
    /// It will update the database with the cards found on this system
    /// start the epg grabber and scheduler
    /// and check if its supposed to be a master or slave controller
    /// </summary>
    private bool InitController()
    {
      if (GlobalServiceProvider.Instance.IsRegistered<ITvServerEvent>())
      {
        GlobalServiceProvider.Instance.Remove<ITvServerEvent>();
      }
      GlobalServiceProvider.Instance.Add<ITvServerEvent>(this);
      try
      {
        //string threadname = Thread.CurrentThread.Name;
        //if (string.IsNullOrEmpty(threadname))
        //  Thread.CurrentThread.Name = "TVController";

        //load the database connection string from the config file
        Log.Info(@"{0}\gentle.config", PathManager.GetDataPath);
        string connectionString, provider;
        GetDatabaseConnectionString(out connectionString, out provider);
        string ConnectionLog = connectionString.Remove(connectionString.IndexOf(@"Password="******"Controller: using {0} database connection: {1}", provider, ConnectionLog);
        Gentle.Framework.ProviderFactory.SetDefaultProviderConnectionString(connectionString);

        _cards = new Dictionary<int, ITvCardHandler>();
        _localCardCollection = new TvCardCollection(this);

        //log all local ip adresses, usefull for debugging problems
        Log.Write("Controller: started at {0}", Dns.GetHostName());
        IPHostEntry local = Dns.GetHostEntry(Dns.GetHostName());
        foreach (IPAddress ipaddress in local.AddressList)
        {
          // Show only IPv4 family addresses
          if (ipaddress.AddressFamily == AddressFamily.InterNetwork)
          {
            Log.Info("Controller: local ip address:{0}", ipaddress.ToString());
          }
        }

        //get all registered servers from the database
        IList<Server> servers;
        try
        {
          servers = Server.ListAll();
        }
        catch (Exception ex)
        {
          Log.Error("Controller: Failed to fetch tv servers from database - {0}",
                    Utils.BlurConnectionStringPassword(ex.Message));
          return false;
        }

        // find ourself
        foreach (Server server in servers)
        {
          if (IsLocal(server.HostName))
          {
            Log.Info("Controller: server running on {0}", server.HostName);
            _ourServer = server;
            break;
          }
        }

        //we do not exist yet?
        if (_ourServer == null)
        {
          //then add ourself to the server
          if (servers.Count == 0)
          {
            //there are no other servers so we are the master one.
            Log.Info("Controller: create new server in database");
            _ourServer = new Server(false, Dns.GetHostName(), RtspStreaming.DefaultPort);
            _ourServer.IsMaster = true;
            _isMaster = true;
            _ourServer.Persist();
            Log.Info("Controller: new server created for {0} master:{1} ", Dns.GetHostName(), _isMaster);
          }
          else
          {
            Log.Error(
              "Controller: sorry, master/slave server setups are not supported. Since there is already another server in the db, we exit here.");
            return false;
          }
        }
        _isMaster = _ourServer.IsMaster;

        //enumerate all tv cards in this pc...
        TvBusinessLayer layer = new TvBusinessLayer();

        _maxFreeCardsToTry = Int32.Parse(layer.GetSetting("timeshiftMaxFreeCardsToTry", "0").Value);

        for (int i = 0; i < _localCardCollection.Cards.Count; ++i)
        {
          //for each card, check if its already mentioned in the database
          bool found = false;
          IList<Card> cards = _ourServer.ReferringCard();
          foreach (Card card in cards)
          {
            if (card.DevicePath == _localCardCollection.Cards[i].DevicePath)
            {
              found = true;
              break;
            }
          }
          if (!found)
          {
            // card is not yet in the database, so add it
            Log.Info("Controller: add card:{0}", _localCardCollection.Cards[i].Name);
            layer.AddCard(_localCardCollection.Cards[i].Name, _localCardCollection.Cards[i].DevicePath, _ourServer);
          }
        }
        //notify log about cards from the database which are removed from the pc
        IList<Card> cardsInDbs = Card.ListAll();
        int cardsInstalled = _localCardCollection.Cards.Count;
        foreach (Card dbsCard in cardsInDbs)
        {
          if (dbsCard.ReferencedServer().IdServer == _ourServer.IdServer)
          {
            bool found = false;
            for (int cardNumber = 0; cardNumber < cardsInstalled; ++cardNumber)
            {
              if (dbsCard.DevicePath == _localCardCollection.Cards[cardNumber].DevicePath)
              {
                Card cardDB = layer.GetCardByDevicePath(_localCardCollection.Cards[cardNumber].DevicePath);

                bool cardEnabled = cardDB.Enabled;
                bool cardPresent = _localCardCollection.Cards[cardNumber].CardPresent;

                if (cardEnabled && cardPresent)
                {
                  ITVCard unknownCard = _localCardCollection.Cards[cardNumber];

                  if (unknownCard is TvCardBase)
                  {
                    TvCardBase card = (TvCardBase)unknownCard;
                    if (card.PreloadCard)
                    {
                      try
                      {
                        Log.Info("Controller: preloading card :{0}", card.Name);
                        card.BuildGraph();
                        if (unknownCard is TvCardAnalog)
                        {
                          ((TvCardAnalog)unknownCard).ReloadCardConfiguration();
                        }
                      }
                      catch (Exception ex)
                      {
                        Log.Error("failed to preload card '{0}', ex = {1}", card.Name, ex);
                      }
                    }
                    else
                    {
                      Log.Info("Controller: NOT preloading card :{0}", card.Name);
                    }
                  }
                  else
                  {
                    Log.Info("Controller: NOT preloading card :{0}", unknownCard.Name);
                  }
                }

                found = true;
                break;
              }
            }
            if (!found)
            {
              Log.Info("Controller: card not found :{0}", dbsCard.Name);

              for (int i = 0; i < _localCardCollection.Cards.Count; ++i)
              {
                if (_localCardCollection.Cards[i].DevicePath == dbsCard.DevicePath)
                {
                  _localCardCollection.Cards[i].CardPresent = false;
                  break;
                }
              }

              // Fix mantis 0002790: Bad behavior when card count for IPTV = 0 
              if (dbsCard.Name.StartsWith("MediaPortal IPTV Source Filter"))
              {
                CardRemove(dbsCard.IdCard);
              }
            }
          }
        }

        Dictionary<int, ITVCard> localcards = new Dictionary<int, ITVCard>();

        cardsInDbs = Card.ListAll();
        foreach (Card card in cardsInDbs)
        {
          if (IsLocal(card.ReferencedServer().HostName))
          {
            for (int x = 0; x < _localCardCollection.Cards.Count; ++x)
            {
              if (_localCardCollection.Cards[x].DevicePath == card.DevicePath)
              {
                localcards[card.IdCard] = _localCardCollection.Cards[x];
                break;
              }
            }
          }
        }

        Log.Info("Controller: setup hybrid cards");
        IList<CardGroup> cardgroups = CardGroup.ListAll();
        foreach (CardGroup group in cardgroups)
        {
          IList<CardGroupMap> cards = group.CardGroupMaps();
          HybridCardGroup hybridCardGroup = new HybridCardGroup();
          foreach (CardGroupMap card in cards)
          {
            if (localcards.ContainsKey(card.IdCard))
            {
              localcards[card.IdCard].IsHybrid = true;
              Log.WriteFile("Hybrid card: " + localcards[card.IdCard].Name + " (" + group.Name + ")");
              HybridCard hybridCard = hybridCardGroup.Add(card.IdCard, localcards[card.IdCard]);
              localcards[card.IdCard] = hybridCard;
            }
          }
        }

        cardsInDbs = Card.ListAll();
        foreach (Card dbsCard in cardsInDbs)
        {
          if (localcards.ContainsKey(dbsCard.IdCard))
          {
            ITVCard card = localcards[dbsCard.IdCard];
            TvCardHandler tvcard = new TvCardHandler(dbsCard, card);
            _cards[dbsCard.IdCard] = tvcard;
          }

          // remove any old timeshifting TS files	
          try
          {
            string TimeShiftPath = dbsCard.TimeShiftFolder;
            if (string.IsNullOrEmpty(dbsCard.TimeShiftFolder))
            {
              TimeShiftPath = String.Format(@"{0}\Team MediaPortal\MediaPortal TV Server\timeshiftbuffer",
                                            Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
            }
            if (!Directory.Exists(TimeShiftPath))
            {
              Log.Info("Controller: creating timeshifting folder {0} for card \"{1}\"", TimeShiftPath, dbsCard.Name);
              Directory.CreateDirectory(TimeShiftPath);
            }

            Log.Debug("Controller: card {0}: current timeshiftpath = {1}", dbsCard.Name, TimeShiftPath);
            if (TimeShiftPath != null)
            {
              string[] files = Directory.GetFiles(TimeShiftPath);

              foreach (string file in files)
              {
                try
                {
                  FileInfo fInfo = new FileInfo(file);
                  bool delFile = (fInfo.Extension.ToUpperInvariant().IndexOf(".TSBUFFER") == 0);

                  if (!delFile)
                  {
                    delFile = (fInfo.Extension.ToUpperInvariant().IndexOf(".TS") == 0) &&
                              (fInfo.Name.ToUpperInvariant().IndexOf("TSBUFFER") > 0);
                  }
                  if (delFile)
                    File.Delete(fInfo.FullName);
                }
                catch (IOException) {}
              }
            }
          }
          catch (Exception exd)
          {
            Log.Info("Controller: Error cleaning old ts buffer - {0}", exd.Message);
          }
        }

        Log.Info("Controller: setup streaming");
        _streamer = new RtspStreaming(_ourServer.HostName, _ourServer.RtspPort);

        if (_isMaster)
        {
          _epgGrabber = new EpgGrabber(this);
          _epgGrabber.Start();
          _scheduler = new Scheduler(this);
          _scheduler.Start();
        }

        SetupHeartbeatThread();
        ExecutePendingDeletions();

        // Re-evaluate program states
        Log.Info("Controller: recalculating program states");
        TvDatabase.Program.ResetAllStates();
        Schedule.SynchProgramStatesForAll();
      }
      catch (Exception ex)
      {
        Log.Write("TvControllerException: {0}\r\n{1}", ex.ToString(), ex.StackTrace);
        return false;
      }

      Log.Info("Controller: initalized");
      return true;
    }
示例#13
0
 private void DoScan()
 {
   int tvChannelsNew = 0;
   int radioChannelsNew = 0;
   int tvChannelsUpdated = 0;
   int radioChannelsUpdated = 0;
   string buttonText = mpButtonScanTv.Text;
   try
   {
     _isScanning = true;
     _stopScanning = false;
     mpButtonScanTv.Text = "Cancel...";
     RemoteControl.Instance.EpgGrabberEnabled = false;
     if (_atscChannels.Count == 0)
       return;
     mpComboBoxFrequencies.Enabled = false;
     listViewStatus.Items.Clear();
     TvBusinessLayer layer = new TvBusinessLayer();
     Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
     IUser user = new User();
     user.CardId = _cardNumber;
     int minchan = 2;
     int maxchan = 69;
     //Check if QAM if so then the number of channels varies
     if (checkBoxQAM.Checked)
     {
       minchan = 0;
       maxchan = _atscChannels.Count;
     }
     for (int index = minchan; index < maxchan; ++index)
     {
       if (_stopScanning)
         return;
       float percent = ((float)(index)) / (maxchan - minchan);
       percent *= 100f;
       if (percent > 100f)
         percent = 100f;
       progressBar1.Value = (int)percent;
       ATSCChannel tuneChannel = new ATSCChannel();
       tuneChannel.NetworkId = -1;
       tuneChannel.TransportId = -1;
       tuneChannel.ServiceId = -1;
       tuneChannel.MinorChannel = -1;
       tuneChannel.MajorChannel = -1;
       if (checkBoxQAM.Checked)
       {
         Log.WriteFile("ATSC tune: QAM checkbox selected... using Modulation 256Qam");
         tuneChannel.PhysicalChannel = index + 1;
         tuneChannel.Frequency = _atscChannels[index].frequency;
         tuneChannel.ModulationType = ModulationType.Mod256Qam;
       }
       else
       {
         Log.WriteFile("ATSC tune: QAM checkbox not selected... using Modulation 8Vsb");
         tuneChannel.PhysicalChannel = index;
         tuneChannel.Frequency = -1;
         tuneChannel.ModulationType = ModulationType.Mod8Vsb;
       }
       Log.WriteFile("ATSC tune: PhysicalChannel: {0} Frequency: {1} Modulation: {2}", tuneChannel.PhysicalChannel,
                     tuneChannel.Frequency, tuneChannel.ModulationType);
       string line = String.Format("physical channel:{0} frequency:{1} modulation:{2}", tuneChannel.PhysicalChannel,
                                   tuneChannel.Frequency, tuneChannel.ModulationType);
       ListViewItem item = listViewStatus.Items.Add(new ListViewItem(line));
       item.EnsureVisible();
       if (index == minchan)
       {
         RemoteControl.Instance.Scan(ref user, tuneChannel, -1);
       }
       IChannel[] channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);
       UpdateStatus();
       /*if (channels == null || channels.Length == 0)
       {
         if (checkBoxQAM.Checked)
         {
           //try Modulation 64Qam now
           tuneChannel.PhysicalChannel = index + 1;
           tuneChannel.Frequency = _atscChannels[index].frequency;
           tuneChannel.ModulationType = ModulationType.Mod64Qam;
           line = String.Format("physical channel:{0} frequency:{1} modulation:{2}: No signal", tuneChannel.PhysicalChannel, tuneChannel.Frequency, tuneChannel.ModulationType);
           item.Text = line;
           channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);
         }
       }*/
       UpdateStatus();
       if (channels == null || channels.Length == 0)
       {
         if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
         {
           line = String.Format("physical channel:{0} frequency:{1} modulation:{2}: No signal",
                                tuneChannel.PhysicalChannel, tuneChannel.Frequency, tuneChannel.ModulationType);
           item.Text = line;
           item.ForeColor = Color.Red;
           continue;
         }
         line = String.Format("physical channel:{0} frequency:{1} modulation:{2}: Nothing found",
                              tuneChannel.PhysicalChannel, tuneChannel.Frequency, tuneChannel.ModulationType);
         item.Text = line;
         item.ForeColor = Color.Red;
         continue;
       }
       int newChannels = 0;
       int updatedChannels = 0;
       for (int i = 0; i < channels.Length; ++i)
       {
         Channel dbChannel;
         ATSCChannel channel = (ATSCChannel)channels[i];
         //No support for channel moving, or merging with existing channels here.
         //We do not know how ATSC works to correctly implement this.
         TuningDetail currentDetail = layer.GetTuningDetail(channel);
         if (currentDetail != null)
           if (channel.Frequency != currentDetail.Frequency)
             currentDetail = null;
         bool exists;
         if (currentDetail == null)
         {
           //add new channel
           exists = false;
           dbChannel = layer.AddNewChannel(channel.Name);
           dbChannel.SortOrder = 10000;
           if (channel.LogicalChannelNumber >= 1)
           {
             dbChannel.SortOrder = channel.LogicalChannelNumber;
           }
         }
         else
         {
           exists = true;
           dbChannel = currentDetail.ReferencedChannel();
         }
         dbChannel.IsTv = channel.IsTv;
         dbChannel.IsRadio = channel.IsRadio;
         dbChannel.Persist();
         if (dbChannel.IsTv)
         {
           layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
         }
         if (dbChannel.IsRadio)
         {
           layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels);
         }
         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("physical channel:{0} frequency:{1} modulation:{2} New:{3} Updated:{4}",
                              tuneChannel.PhysicalChannel, tuneChannel.Frequency, tuneChannel.ModulationType,
                              newChannels, updatedChannels);
         item.Text = line;
       }
     }
     //DatabaseManager.Instance.SaveChanges();
   }
   catch (Exception ex)
   {
     Log.Write(ex);
   }
   finally
   {
     IUser user = new User();
     user.CardId = _cardNumber;
     RemoteControl.Instance.StopCard(user);
     RemoteControl.Instance.EpgGrabberEnabled = true;
     progressBar1.Value = 100;
     checkBoxQAM.Enabled = true;
     mpComboBoxFrequencies.Enabled = true;
     mpButtonScanTv.Text = buttonText;
     _isScanning = false;
   }
   listViewStatus.Items.Add(
     new ListViewItem(String.Format("Total radio channels new:{0} updated:{1}", radioChannelsNew,
                                    radioChannelsUpdated)));
   listViewStatus.Items.Add(
     new ListViewItem(String.Format("Total tv channels new:{0} updated:{1}", tvChannelsNew, tvChannelsUpdated)));
   ListViewItem lastItem = listViewStatus.Items.Add(new ListViewItem("Scan done..."));
   lastItem.EnsureVisible();
 }
示例#14
0
    private void mpButtonScanTv_Click(object sender, EventArgs e)
    {
      if (_isScanning == false)
      {
        checkBoxQAM.Enabled = false;

        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;
        }
        SimpleFileName tuningFile = (SimpleFileName)mpComboBoxFrequencies.SelectedItem;
        _atscChannels = (List<ATSCTuning>)fileFilters.LoadList(tuningFile.FileName, typeof (List<ATSCTuning>));
        if (_atscChannels == null)
        {
          return;
        }
        Thread scanThread = new Thread(DoScan);
        scanThread.Name = "ATSC scan thread";
        scanThread.Start();
        listViewStatus.Items.Clear();
      }
      else
      {
        _stopScanning = true;
      }
    }
示例#15
0
    //anysee _anysee = null;

    #endregion

    //ctor
    /// <summary>
    /// Initializes a new instance of the <see cref="ConditionalAccess"/> class.
    /// </summary>
    /// <param name="tunerFilter">The tuner filter.</param>
    /// <param name="analyzerFilter">The capture filter.</param>
    /// <param name="winTvUsbCiFilter">The WinTV CI filter.</param>
    /// <param name="card">Determines the type of TV card</param>    
    public ConditionalAccess(IBaseFilter tunerFilter, IBaseFilter analyzerFilter, IBaseFilter winTvUsbCiFilter,
                             TvCardBase card)
    {
      try
      {
        //System.Diagnostics.Debugger.Launch();        
        if (card != null && card.DevicePath != null)
        {
          //fetch decrypt limit from DB and apply it.
          TvBusinessLayer layer = new TvBusinessLayer();
          Card c = layer.GetCardByDevicePath(card.DevicePath);
          _decryptLimit = c.DecryptLimit;
          _useCam = c.CAM;
          _CamType = (CamType)c.CamType;
          Log.Log.WriteFile("CAM is {0} model", _CamType);
        }

        _mapSubChannels = new Dictionary<int, ConditionalAccessContext>();
        TunerDri driTuner = card as TunerDri;
        if (driTuner != null)
        {
          _tunerDri = driTuner;
          _ciMenu = driTuner;
        }
        if (tunerFilter == null && analyzerFilter == null)
          return;
        //DVB checks. Conditional Access & DiSEqC etc.
        bool isDVBS = (card is TvCardDVBS);
        bool isDVBT = (card is TvCardDVBT);
        bool isDVBC = (card is TvCardDVBC);

        if (isDVBC || isDVBS || isDVBT)
        {
          Log.Log.WriteFile("Check for KNC");
          // Lookup device index of current card. only counting KNC cards by device path
          int DeviceIndex = KNCDeviceLookup.GetDeviceIndex(card);
          _knc = new KNCAPI(tunerFilter, (uint)DeviceIndex);
          if (_knc.IsKNC)
          {
            //if (_knc.IsCamReady()) 
            _ciMenu = _knc; // Register KNC CI Menu capabilities when CAM detected and ready
            Log.Log.WriteFile("KNC card detected");
            return;
          }
          Release.DisposeToNull(ref _knc);

          Log.Log.WriteFile("Check for Digital Everywhere");
          _digitalEveryWhere = new DigitalEverywhere(tunerFilter);
          if (_digitalEveryWhere.IsDigitalEverywhere)
          {
            Log.Log.WriteFile("Digital Everywhere card detected");
            _diSEqCMotor = new DiSEqCMotor(_digitalEveryWhere);

            if (_digitalEveryWhere.IsCamReady())
            {
              Log.Log.WriteFile("Digital Everywhere registering CI menu capabilities");
              _ciMenu = _digitalEveryWhere; // Register FireDTV CI Menu capabilities when CAM detected and ready
            }
            //_digitalEveryWhere.ResetCAM();
            return;
          }
          Release.DisposeToNull(ref _digitalEveryWhere);

          Log.Log.WriteFile("Check for Twinhan");
          _twinhan = new Twinhan(tunerFilter);
          if (_twinhan.IsTwinhan)
          {
            Log.Log.WriteFile("Twinhan card detected");
            _diSEqCMotor = new DiSEqCMotor(_twinhan);
            Log.Log.WriteFile("Twinhan registering CI menu capabilities");
            _ciMenu = _twinhan; // Register Twinhan CI Menu capabilities when CAM detected and ready
            return;
          }
          Release.DisposeToNull(ref _twinhan);

          Log.Log.WriteFile("Check for TechnoTrend");
          _technoTrend = new TechnoTrendAPI(tunerFilter);
          if (_technoTrend.IsTechnoTrend)
          {
            ////if (_technoTrend.IsCamPresent()) 
            _ciMenu = _technoTrend; // Register Technotrend CI Menu capabilities
            Log.Log.WriteFile("TechnoTrend card detected");
            return;
          }
          Release.DisposeToNull(ref _technoTrend);

          Log.Log.WriteFile("Check for Hauppauge");
          _hauppauge = new Hauppauge(tunerFilter);
          if (_hauppauge.IsHauppauge)
          {
            Log.Log.WriteFile("Hauppauge card detected");
            Log.Log.WriteFile("Check for Hauppauge WinTV CI");
            if (winTvUsbCiFilter != null)
            {
              Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
              _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);

              Log.Log.WriteFile("WinTV CI registering CI menu capabilities");
              _ciMenu = _winTvCiModule; // WinTv CI Menu capabilities 
            }
            _diSEqCMotor = new DiSEqCMotor(_hauppauge);
            return;
          }
          Release.DisposeToNull(ref _hauppauge);
          Release.DisposeToNull(ref _winTvCiModule);

          /*Log.Log.Info("Check for anysee");
          _anysee = new anysee(tunerFilter, analyzerFilter);
          if (_anysee.Isanysee)
          {
            Log.Log.Info("anysee device detected");
            return;
          }*/

          Log.Log.WriteFile("Check for ProfRed");
          _profred = new ProfRed(tunerFilter);
          if (_profred.IsProfRed)
          {
            Log.Log.WriteFile("ProfRed card detected");
            _diSEqCMotor = new DiSEqCMotor(_profred);
            return;
          }
          Release.DisposeToNull(ref _profred);

          // TeVii support
          _TeVii = new TeVii();
          _TeVii.Init(tunerFilter);
          _TeVii.DevicePath = card.DevicePath;
          Log.Log.WriteFile("Check for {0}", _TeVii.Provider);
          _TeVii.CheckAndOpen();
          if (_TeVii.IsSupported)
          {
            _diSEqCMotor = new DiSEqCMotor(_TeVii);
            _HWProvider = _TeVii;
            Log.Log.WriteFile("Check for Hauppauge WinTV CI");
            if (winTvUsbCiFilter != null)
            {
              Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
              _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
            }
            return;
          }
          Release.DisposeToNull(ref _TeVii);

          // DigitalDevices support
          _DigitalDevices = new DigitalDevices(tunerFilter);
          if (_DigitalDevices.IsGenericBDAS)
          {
            _genericbdas = _DigitalDevices;
            if (_DigitalDevices.IsSupported)
            {
              _ciMenu = _DigitalDevices;
            }
            return; // detected
          }
          Release.DisposeToNull(ref _DigitalDevices);

          Log.Log.WriteFile("Check for Conexant based card");
          _conexant = new ConexantBDA(tunerFilter);
          if (_conexant.IsConexant)
          {
            Log.Log.WriteFile("Conexant BDA card detected");
            Log.Log.WriteFile("Check for Hauppauge WinTV CI");
            if (winTvUsbCiFilter != null)
            {
              Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
              _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
            }
            return;
          }
          Release.DisposeToNull(ref _conexant);
          Release.DisposeToNull(ref _winTvCiModule);

          Log.Log.WriteFile("Check for GenPix BDA based card");
          _genpix = new GenPixBDA(tunerFilter);
          if (_genpix.IsGenPix)
          {
            Log.Log.WriteFile("GenPix BDA card detected");
            Log.Log.WriteFile("Check for Hauppauge WinTV CI");
            if (winTvUsbCiFilter != null)
            {
              Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
              _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
            }
            return;
          }
          Release.DisposeToNull(ref _genpix);
          Release.DisposeToNull(ref _winTvCiModule);

          Log.Log.WriteFile("Check for Generic DVB-S card");
          _genericbdas = new GenericBDAS(tunerFilter);
          if (_genericbdas.IsGenericBDAS)
          {
            Log.Log.WriteFile("Generic BDA card detected");
            Log.Log.WriteFile("Check for Hauppauge WinTV CI");
            if (winTvUsbCiFilter != null)
            {
              Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
              _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
            }
            return;
          }
          Release.DisposeToNull(ref _genericbdas);

          //Final WinTV-CI check for DVB-T hybrid cards
          Log.Log.WriteFile("Check for Hauppauge WinTV CI");
          if (winTvUsbCiFilter != null)
          {
            Log.Log.WriteFile("WinTV CI detected in graph - using capabilities...");
            _winTvCiModule = new WinTvCiModule(winTvUsbCiFilter);
            return;
          }
          Release.DisposeToNull(ref _winTvCiModule);
        }

        //ATSC checks
        bool isATSC = (card is TvCardATSC);
        if (isATSC)
        {
          Log.Log.WriteFile("Check for ViXS ATSC QAM card");
          _isvixsatsc = new ViXSATSC(tunerFilter);
          if (_isvixsatsc.IsViXSATSC)
          {
            Log.Log.WriteFile("ViXS ATSC QAM card detected");
            return;
          }
          Release.DisposeToNull(ref _isvixsatsc);

          Log.Log.WriteFile("Check for Generic ATSC QAM card");
          _isgenericatsc = new GenericATSC(tunerFilter);
          if (_isgenericatsc.IsGenericATSC)
          {
            Log.Log.WriteFile("Generic ATSC QAM card detected");
            return;
          }
          Release.DisposeToNull(ref _isgenericatsc);
        }
      }
      catch (Exception ex)
      {
        Log.Log.Write(ex);
      }
    }
示例#16
0
 private void mpButtonScanRadio_Click(object sender, EventArgs e)
 {
   if (_isScanning == false)
   {
     TvBusinessLayer layer = new TvBusinessLayer();
     Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
     if (card.Enabled == false)
     {
       MessageBox.Show(this, "Card is disabled, please enable the card before scanning");
       return;
     }
     if (!RemoteControl.Instance.CardPresent(card.IdCard))
     {
       MessageBox.Show(this, "Card is not found, please make sure card 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,
                       "Card is locked. Scanning not possible at the moment ! Perhaps you are scanning an other part of a hybrid card.");
       return;
     }
     AnalogChannel radioChannel = new AnalogChannel();
     radioChannel.Frequency = 96000000;
     radioChannel.IsRadio = true;
     radioChannel.VideoSource = AnalogChannel.VideoInputType.Tuner;
     radioChannel.AudioSource = AnalogChannel.AudioInputType.Automatic;
     if (!RemoteControl.Instance.CanTune(_cardNumber, radioChannel))
     {
       MessageBox.Show(this, "The Tv Card does not support radio");
       return;
     }
     if (string.IsNullOrEmpty(_configuration.Graph.Capture.Name))
     {
       _configuration = Configuration.readConfiguration(_cardNumber, _cardName, _devicePath);
       ReCheckSettings();
     }
     Thread scanThread = new Thread(DoRadioScan);
     scanThread.Name = "Analog Radio scan thread";
     scanThread.Start();
   }
   else
   {
     _stopScanning = true;
   }
 }
示例#17
0
    private void DoRadioScan()
    {
      int channelsNew = 0;
      int channelsUpdated = 0;

      checkButton.Enabled = false;
      int sensitivity = 1;
      switch (mpComboBoxSensitivity.Text)
      {
        case "High":
          sensitivity = 10;
          break;
        case "Medium":
          sensitivity = 2;
          break;
        case "Low":
          sensitivity = 1;
          break;
      }
      string buttonText = mpButtonScanRadio.Text;
      try
      {
        _isScanning = true;
        _stopScanning = false;
        mpButtonScanRadio.Text = "Cancel...";
        RemoteControl.Instance.EpgGrabberEnabled = false;
        TvBusinessLayer layer = new TvBusinessLayer();
        Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
        mpComboBoxCountry.Enabled = false;
        mpComboBoxSource.Enabled = false;
        mpComboBoxSensitivity.Enabled = false;
        checkBoxCreateSignalGroup.Enabled = false;
        checkBoxNoMerge.Enabled = false;
        mpButtonScanTv.Enabled = false;
        mpButtonAddSvideoChannels.Enabled = false;
        UpdateStatus();
        mpListView1.Items.Clear();
        CountryCollection countries = new CountryCollection();
        for (int freq = 87500000; freq < 108000000; freq += 100000)
        {
          if (_stopScanning)
            return;
          float percent = ((freq - 87500000)) / (108000000f - 87500000f);
          percent *= 100f;
          if (percent > 100f)
            percent = 100f;
          progressBar1.Value = (int)percent;
          AnalogChannel channel = new AnalogChannel();
          channel.IsRadio = true;
          channel.TunerSource = mpComboBoxSource.SelectedIndex == 0 ? TunerInputType.Antenna : TunerInputType.Cable;
          channel.VideoSource = AnalogChannel.VideoInputType.Tuner;
          channel.AudioSource = AnalogChannel.AudioInputType.Automatic;
          channel.Country = countries.Countries[mpComboBoxCountry.SelectedIndex];
          channel.Frequency = freq;
          channel.IsTv = false;
          channel.IsRadio = true;
          float freqMHz = channel.Frequency;
          freqMHz /= 1000000f;
          string line = String.Format("frequence:{0} MHz ", freqMHz.ToString("f2"));
          ListViewItem item = mpListView1.Items.Add(new ListViewItem(line));
          item.EnsureVisible();
          IUser user = new User();
          user.CardId = _cardNumber;
          TvResult tuneResult = RemoteControl.Instance.Tune(ref user, channel, -1);
          if (tuneResult == TvResult.SWEncoderMissing)
          {
            Log.Error("analog: DoTvScan error (missing software encoder)");
            MessageBox.Show("Please install a supported audio/video encoder for your software analog card",
                            "Unable to scan", MessageBoxButtons.OK, MessageBoxIcon.Error);
            break;
          }
          if (tuneResult == TvResult.GraphBuildingFailed)
          {
            Log.Error("analog: DoTvScan error (missing software encoder)");
            MessageBox.Show(
              "The graph building. Mostly your card is not supported by TvServer. Please create a report in our forum",
              "Unable to scan", MessageBoxButtons.OK, MessageBoxIcon.Error);
            break;
          }
          UpdateStatus();
          Thread.Sleep(2000);
          if (SignalStrength(sensitivity) == 100)
          {
            channel.Name = String.Format("{0}", freq);
            Channel dbChannel = null;
            IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channel.Name, 0);
            if (tuningDetails != null && tuningDetails.Count > 0)
            {
              dbChannel = tuningDetails[0].ReferencedChannel();
            }
            if (dbChannel != null)
            {
              line = String.Format("frequence:{0} MHz : Channel update found - {1}", freqMHz.ToString("f2"),
                                   channel.Name);
              channelsUpdated++;
            }
            else
            {
              dbChannel = layer.AddNewChannel(channel.Name);
              line = String.Format("frequence:{0} MHz : New channel found - {1}", freqMHz.ToString("f2"), channel.Name);
              channelsNew++;
            }
            item.Text = line;
            dbChannel.IsTv = channel.IsTv;
            dbChannel.IsRadio = channel.IsRadio;
            dbChannel.Persist();

            layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels);
            if (checkBoxCreateSignalGroup.Checked)
            {
              layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.Analog);
            }

            layer.AddTuningDetails(dbChannel, channel);
            layer.MapChannelToCard(card, dbChannel, false);
            freq += 300000;
          }
          else
          {
            line = String.Format("frequence:{0} MHz : No Signal", freqMHz.ToString("f2"));
            item.Text = line;
            item.ForeColor = Color.Red;
          }
        }
      }
      catch (Exception ex)
      {
        Log.Write(ex);
      }
      finally
      {
        checkButton.Enabled = true;
        IUser user = new User();
        user.CardId = _cardNumber;
        RemoteControl.Instance.StopCard(user);
        RemoteControl.Instance.EpgGrabberEnabled = true;
        mpButtonScanRadio.Text = buttonText;
        progressBar1.Value = 100;
        mpComboBoxCountry.Enabled = true;
        mpComboBoxSource.Enabled = true;
        mpComboBoxSensitivity.Enabled = true;
        checkBoxCreateSignalGroup.Enabled = true;
        checkBoxNoMerge.Enabled = true;
        mpButtonScanTv.Enabled = true;
        mpButtonScanRadio.Enabled = true;
        mpButtonAddSvideoChannels.Enabled = true;
        _isScanning = false;
      }
      ListViewItem lastItem =
        mpListView1.Items.Add(
          new ListViewItem(String.Format("Total radio channels new:{0} updated:{1}", channelsNew, channelsUpdated)));
      lastItem.EnsureVisible();
    }
示例#18
0
    /// <summary>
    /// This method adds the bda network provider filter to the graph
    /// </summary>
    protected void AddNetworkProviderFilter(Guid networkProviderClsId)
    {
      Log.Log.WriteFile("dvb:AddNetworkProviderFilter");
      if (useInternalNetworkProvider)
      {
        const string networkProviderName = "MediaPortal Network Provider";
        Guid internalNetworkProviderClsId = new Guid("{D7D42E5C-EB36-4aad-933B-B4C419429C98}");
        Log.Log.WriteFile("dvb:Add {0}", networkProviderName);
        _filterNetworkProvider = FilterGraphTools.AddFilterFromClsid(_graphBuilder, internalNetworkProviderClsId,
                                                                     networkProviderName);
        _interfaceNetworkProvider = (IDvbNetworkProvider)_filterNetworkProvider;
        string hash = DeviceDetector.GetHash(DevicePath);
        _interfaceNetworkProvider.ConfigureLogging(DeviceDetector.GetFileName(DevicePath), hash,
                                                   LogLevelOption.Debug);
        return;
      }
      _isATSC = false;
      _managedThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
      Log.Log.WriteFile("dvb:AddNetworkProviderFilter");
      TvBusinessLayer layer = new TvBusinessLayer();
      Card c = layer.GetCardByDevicePath(DevicePath);
      // generic network provider Guid.
      Guid genProviderClsId = new Guid("{B2F3A67C-29DA-4C78-8831-091ED509A475}");
      // First test if the Generic Network Provider is available (only on MCE 2005 + Update Rollup 2)
      // only if it is used in db, we need to change it
      // This check is because, "Genric network provider" is default value in Db
      // And we need to check if it's even installed.
      // If not, Then it must be changed automatically, to Network provider
      // based on Card type. It prevents users to run into problems
      // If Generic network provider is not available in Os.
      if (((TvDatabase.DbNetworkProvider)c.netProvider) == TvDatabase.DbNetworkProvider.Generic)
      {
        if (!FilterGraphTools.IsThisComObjectInstalled(genProviderClsId))
        {
          // it's not and we have it as default
          // change it per devtype.
          if (networkProviderClsId == typeof (DVBTNetworkProvider).GUID)
          {
            c.netProvider = (int)TvDatabase.DbNetworkProvider.DVBT;
            c.Persist();
          }
          else if (networkProviderClsId == typeof (DVBSNetworkProvider).GUID)
          {
            c.netProvider = (int)TvDatabase.DbNetworkProvider.DVBS;
            c.Persist();
          }
          else if (networkProviderClsId == typeof (ATSCNetworkProvider).GUID)
          {
            c.netProvider = (int)TvDatabase.DbNetworkProvider.ATSC;
            c.Persist();
          }
          else if (networkProviderClsId == typeof (DVBCNetworkProvider).GUID)
          {
            c.netProvider = (int)TvDatabase.DbNetworkProvider.DVBC;
            c.Persist();
          }
        }
      }

      // Final selecion for Network provider based on user selection.
      String NetworkProviderName = String.Empty;
      switch ((TvDatabase.DbNetworkProvider)c.netProvider)
      {
        case DbNetworkProvider.DVBT:
          NetworkProviderName = "DVBT Network Provider";
          break;
        case DbNetworkProvider.DVBS:
          NetworkProviderName = "DVBS Network Provider";
          break;
        case DbNetworkProvider.DVBC:
          NetworkProviderName = "DVBC Network Provider";
          break;
        case DbNetworkProvider.ATSC:
          _isATSC = true;
          NetworkProviderName = "ATSC Network Provider";
          break;
        case DbNetworkProvider.Generic:
          NetworkProviderName = "Generic Network Provider";
          networkProviderClsId = genProviderClsId;
          break;
        default:
          Log.Log.Error("dvb:This application doesn't support this Tuning Space");
          // Tuning Space can also describe Analog TV but this application don't support them
          throw new TvException("This application doesn't support this Tuning Space");
      }
      Log.Log.WriteFile("dvb:Add {0}", NetworkProviderName);
      _filterNetworkProvider = FilterGraphTools.AddFilterFromClsid(_graphBuilder, networkProviderClsId,
                                                                   NetworkProviderName);
    }
示例#19
0
    private void mpButton1_Click(object sender, EventArgs e)
    {
      if (string.IsNullOrEmpty(_configuration.Graph.Crossbar.Name))
      {
        IUser user = new User();
        user.CardId = _cardNumber;
        AnalogChannel temp = new AnalogChannel();
        temp.TunerSource = TunerInputType.Antenna;
        temp.VideoSource = AnalogChannel.VideoInputType.Tuner;
        temp.AudioSource = AnalogChannel.AudioInputType.Tuner;
        temp.IsRadio = false;
        temp.IsTv = true;
        RemoteControl.Instance.Tune(ref user, temp, -1);
        _configuration = Configuration.readConfiguration(_cardNumber, _cardName, _devicePath);
        if (string.IsNullOrEmpty(_configuration.Graph.Crossbar.Name))
        {
          MessageBox.Show(this, "The S-Video channels could not be detected.");
          return;
        }
        ReCheckSettings();
      }

      TvBusinessLayer layer = new TvBusinessLayer();
      Dictionary<AnalogChannel.VideoInputType, int> videoPinMap = _configuration.Graph.Crossbar.VideoPinMap;
      AnalogChannel tuningDetail;
      Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
      Channel dbChannel;
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.VideoInput1))
      {
        string channelName = "CVBS#1 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.VideoInput1;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.VideoInput2))
      {
        string channelName = "CVBS#2 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.VideoInput2;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.VideoInput3))
      {
        string channelName = "CVBS#3 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.VideoInput3;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.SvhsInput1))
      {
        string channelName = "S-Video#1 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.SvhsInput1;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.SvhsInput2))
      {
        string channelName = "S-Video#2 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.SvhsInput2;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.SvhsInput3))
      {
        string channelName = "S-Video#3 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.SvhsInput3;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.RgbInput1))
      {
        string channelName = "RGB#1 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.RgbInput1;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.RgbInput2))
      {
        string channelName = "RGB#2 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.RgbInput2;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.RgbInput3))
      {
        string channelName = "RGB#3 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.RgbInput3;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.YRYBYInput1))
      {
        string channelName = "YRYBY#1 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.YRYBYInput1;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.YRYBYInput2))
      {
        string channelName = "YRYBY#2 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.YRYBYInput2;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.YRYBYInput3))
      {
        string channelName = "YRYBY#3 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.YRYBYInput3;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.HdmiInput1))
      {
        string channelName = "HDMI#1 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.HdmiInput1;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.HdmiInput2))
      {
        string channelName = "HDMI#2 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.HdmiInput2;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      if (videoPinMap.ContainsKey(AnalogChannel.VideoInputType.HdmiInput3))
      {
        string channelName = "HDMI#3 on " + card.IdCard;
        IList<TuningDetail> tuningDetails = layer.GetTuningDetailsByName(channelName, 0);
        if (tuningDetails != null && tuningDetails.Count > 0)
        {
          dbChannel = tuningDetails[0].ReferencedChannel();
        }
        else
        {
          dbChannel = layer.AddNewChannel(channelName);
        }
        dbChannel.IsTv = true;
        dbChannel.Persist();
        tuningDetail = new AnalogChannel();
        tuningDetail.IsTv = true;
        tuningDetail.Name = dbChannel.DisplayName;
        tuningDetail.VideoSource = AnalogChannel.VideoInputType.HdmiInput3;
        layer.AddTuningDetails(dbChannel, tuningDetail);
        layer.MapChannelToCard(card, dbChannel, false);
        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
      }
      MessageBox.Show(this, "Channels added.");
    }
示例#20
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);
              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();
    }
示例#21
0
 private void DoScan()
 {
   int tvChannelsNew = 0;
   int radioChannelsNew = 0;
   int tvChannelsUpdated = 0;
   int radioChannelsUpdated = 0;
   string buttonText = mpButtonScanTv.Text;
   try
   {
     _isScanning = true;
     _stopScanning = false;
     mpButtonScanTv.Text = "Cancel...";
     RemoteControl.Instance.EpgGrabberEnabled = false;
     if (_atscChannels.Count == 0)
       return;
     mpComboBoxFrequencies.Enabled = false;
     listViewStatus.Items.Clear();
     TvBusinessLayer layer = new TvBusinessLayer();
     Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
     IUser user = new User();
     user.CardId = _cardNumber;
     int minchan = 2;
     int maxchan = 69 + 1;
     if ((string)mpComboBoxTuningMode.SelectedItem == "Clear QAM Cable")
     {
       minchan = 1;
       maxchan = _atscChannels.Count + 1;
     }
     else if ((string)mpComboBoxTuningMode.SelectedItem == "Digital Cable")
     {
       minchan = 0;
       maxchan = 1;
     }
     for (int index = minchan; index < maxchan; ++index)
     {
       if (_stopScanning)
         return;
       float percent = ((float)(index)) / (maxchan - minchan);
       percent *= 100f;
       if (percent > 100f)
         percent = 100f;
       progressBar1.Value = (int)percent;
       ATSCChannel tuneChannel = new ATSCChannel();
       tuneChannel.NetworkId = -1;
       tuneChannel.TransportId = -1;
       tuneChannel.ServiceId = -1;
       tuneChannel.MinorChannel = -1;
       tuneChannel.MajorChannel = -1;
       string line;
       if ((string)mpComboBoxTuningMode.SelectedItem == "Clear QAM Cable")
       {
         tuneChannel.PhysicalChannel = index;
         tuneChannel.Frequency = _atscChannels[index - 1].frequency;
         if (tuneChannel.Frequency < 10000)
         {
           continue;
         }
         tuneChannel.ModulationType = ModulationType.Mod256Qam;
         line = string.Format("physical channel = {0}, frequency = {1} kHz, modulation = 256 QAM", tuneChannel.PhysicalChannel, tuneChannel.Frequency);
         Log.Info("ATSC: scanning clear QAM cable, {0}, frequency plan = {1}", line, mpComboBoxFrequencies.SelectedItem);
       }
       else if ((string)mpComboBoxTuningMode.SelectedItem == "ATSC Digital Terrestrial")
       {
         tuneChannel.PhysicalChannel = index;
         tuneChannel.Frequency = -1;
         tuneChannel.ModulationType = ModulationType.Mod8Vsb;
         line = string.Format("physical channel = {0}, modulation = 8 VSB", tuneChannel.PhysicalChannel);
         Log.Info("ATSC: scanning ATSC over-the-air, {0}", line);
       }
       else
       {
         tuneChannel.PhysicalChannel = 0;
         tuneChannel.ModulationType = ModulationType.Mod256Qam;
         line = "out-of-band service information";
         Log.Info("ATSC: scanning digital cable, {0}", line);
       }
       line += "... ";
       ListViewItem item = listViewStatus.Items.Add(new ListViewItem(line));
       item.EnsureVisible();
       if (index == minchan)
       {
         RemoteControl.Instance.Scan(ref user, tuneChannel, -1);
       }
       IChannel[] channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);
       UpdateStatus();
       if (channels == null || channels.Length == 0)
       {
         if (tuneChannel.PhysicalChannel > 0 && !RemoteControl.Instance.TunerLocked(_cardNumber))
         {
           line += "no signal";
         }
         else
         {
           line += "signal locked, no channels found";
         }
         item.Text = line;
         item.ForeColor = Color.Red;
         continue;
       }
       int newChannels = 0;
       int updatedChannels = 0;
       for (int i = 0; i < channels.Length; ++i)
       {
         Channel dbChannel;
         ATSCChannel channel = (ATSCChannel)channels[i];
         //No support for channel moving, or merging with existing channels here.
         //We do not know how ATSC works to correctly implement this.
         TuningDetail currentDetail = layer.GetTuningDetail(channel);
         if (currentDetail != null)
         {
           if (channel.IsDifferentTransponder(layer.GetTuningChannel(currentDetail)))
           {
             currentDetail = null;
           }
         }
         bool exists;
         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;
           }
         }
         else
         {
           exists = true;
           dbChannel = currentDetail.ReferencedChannel();
         }
         dbChannel.IsTv = channel.IsTv;
         dbChannel.IsRadio = channel.IsRadio;
         dbChannel.Persist();
         if (dbChannel.IsTv)
         {
           layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
         }
         if (dbChannel.IsRadio)
         {
           layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels);
         }
         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("new = {0}, updated = {1}", newChannels, updatedChannels);
       item.Text = line;
       Log.Info("ATSC: scan result, new = {0}, updated = {1}", newChannels, updatedChannels);
     }
   }
   catch (Exception ex)
   {
     Log.Write(ex);
   }
   finally
   {
     IUser user = new User();
     user.CardId = _cardNumber;
     RemoteControl.Instance.StopCard(user);
     RemoteControl.Instance.EpgGrabberEnabled = true;
     progressBar1.Value = 100;
     mpComboBoxTuningMode.Enabled = true;
     UpdateQamFrequencyFieldAvailability();
     mpButtonScanTv.Text = buttonText;
     _isScanning = false;
   }
   listViewStatus.Items.Add(
     new ListViewItem(String.Format("Total radio channels, new = {0}, updated = {1}", radioChannelsNew,
                                    radioChannelsUpdated)));
   listViewStatus.Items.Add(
     new ListViewItem(String.Format("Total TV channels, new = {0} updated = {1}", tvChannelsNew, tvChannelsUpdated)));
   ListViewItem lastItem = listViewStatus.Items.Add(new ListViewItem("Scan done!"));
   lastItem.EnsureVisible();
   Log.Info("ATSC: scan summary, new TV = {0}, updated TV = {1}, new radio = {2}, updated radio = {3}", tvChannelsNew, tvChannelsUpdated, radioChannelsNew, radioChannelsUpdated);
 }