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