public static bool ConvertList(String fileName) { string path = System.IO.Path.GetDirectoryName(fileName); string saveName; int frequencyOffset = 0; List <DVBTTuning> _dvbtChannels = new List <DVBTTuning>(); Dictionary <int, int> frequencies = new Dictionary <int, int>(); XmlDocument doc = new XmlDocument(); doc.Load(fileName); XmlNodeList countryList = doc.SelectNodes("/dvbt/country"); if (countryList != null) { foreach (XmlNode nodeCountry in countryList) { XmlNode nodeName = nodeCountry.Attributes.GetNamedItem("name"); saveName = MakeDVBTName(nodeName.Value); XmlNode nodeOffset = nodeCountry.Attributes.GetNamedItem("offset"); if (nodeOffset != null) { if (nodeOffset.Value != null) { if (Int32.TryParse(nodeOffset.Value, out frequencyOffset) == false) { frequencyOffset = 0; } } } XmlNodeList nodeFrequencyList = nodeCountry.SelectNodes("carrier"); if (nodeFrequencyList != null) { foreach (XmlNode nodeFrequency in nodeFrequencyList) { string frequencyText = nodeFrequency.Attributes.GetNamedItem("frequency").Value; string bandwidthText = "8"; if (nodeFrequency.Attributes.GetNamedItem("bandwidth") != null) { bandwidthText = nodeFrequency.Attributes.GetNamedItem("bandwidth").Value; } int frequency = Int32.Parse(frequencyText); int bandWidth = Int32.Parse(bandwidthText); DVBTTuning tuning = new DVBTTuning(frequency, bandWidth, frequencyOffset); _dvbtChannels.Add(tuning); } } String newPath = String.Format("{0}\\dvbt\\{1}.xml", System.IO.Path.GetDirectoryName(fileName), saveName); System.IO.TextWriter parFileXML = System.IO.File.CreateText(newPath); XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <DVBTTuning>)); xmlSerializer.Serialize(parFileXML, _dvbtChannels); parFileXML.Close(); _dvbtChannels.Clear(); } } return(true); }
/// <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 (_dvbtChannels.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 < _dvbtChannels.Count; ++index) { if (scanState == ScanState.Cancel) { return; } float percent = ((float)(index)) / _dvbtChannels.Count; percent *= 100f; if (percent > 100f) { percent = 100f; } progressBar1.Value = (int)percent; Application.DoEvents(); DVBTTuning curTuning = _dvbtChannels[index]; DVBTChannel tuneChannel = new DVBTChannel(curTuning); 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); if (channels == null || channels.Length == 0) { /// try frequency - offset tuneChannel.Frequency = curTuning.Frequency - curTuning.Offset; item.Text = String.Format("{0}tp- {1} {2}MHz ", 1 + index, tuneChannel.Frequency, tuneChannel.BandWidth); channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel); if (channels == null || channels.Length == 0) { /// try frequency + offset tuneChannel.Frequency = curTuning.Frequency + curTuning.Offset; item.Text = String.Format("{0}tp- {1} {2}MHz ", 1 + index, tuneChannel.Frequency, tuneChannel.BandWidth); 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}:No signal", 1 + index, tuneChannel.Frequency, tuneChannel.BandWidth); item.Text = line; item.ForeColor = Color.Red; continue; } line = String.Format("{0}tp- {1} {2}:Nothing found", 1 + index, tuneChannel.Frequency, tuneChannel.BandWidth); 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; DVBTChannel channel = (DVBTChannel)channels[i]; bool exists; TuningDetail currentDetail; //Check if we already have this tuningdetail. The user has the option to enable channel move detection... if (checkBoxEnableChannelMoveDetection.Checked) { //According to the DVB specs ONID + SID is unique, therefore we do not need to use the TSID to identify a service. //The DVB spec recommends that the SID should not change if a service moves. This theoretically allows us to //track channel movements. currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.ServiceId, TvBusinessLayer.GetChannelType(channel)); } else { //There are certain providers that do not maintain unique ONID + SID combinations. //In those cases, ONID + TSID + SID is generally unique. The consequence of using the TSID to identify //a service is that channel movement tracking won't work (each transponder/mux should have its own TSID). currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.TransportId, channel.ServiceId, TvBusinessLayer.GetChannelType(channel)); } if (currentDetail == null) { //add new channel exists = false; dbChannel = layer.AddNewChannel(channel.Name, channel.LogicalChannelNumber); dbChannel.SortOrder = 10000; if (channel.LogicalChannelNumber >= 1) { dbChannel.SortOrder = channel.LogicalChannelNumber; } dbChannel.IsTv = channel.IsTv; dbChannel.IsRadio = channel.IsRadio; dbChannel.Persist(); } else { exists = true; dbChannel = currentDetail.ReferencedChannel(); } if (dbChannel.IsTv) { layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels); if (checkBoxCreateSignalGroup.Checked) { layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.DVBT); } 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.DVBT); } 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}:New TV/Radio:{3}/{4} Updated TV/Radio:{5}/{6}", 1 + index, tuneChannel.Frequency, tuneChannel.BandWidth, 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(); }
private void DoScan() { suminfo tv = new suminfo(); suminfo radio = new suminfo(); IUser user = new User(); user.CardId = _cardNumber; try { if (_dvbtChannels.Count == 0) { return; } TvBusinessLayer layer = new TvBusinessLayer(); Card card = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber)); for (int index = 0; index < _dvbtChannels.Count; ++index) { DVBTTuning curTuning = _dvbtChannels[index]; DVBTChannel tuneChannel = new DVBTChannel(curTuning); string line = String.Format("{0}tp- {1}", 1 + index, tuneChannel.TuningInfo.ToString()); Log.Debug(line); if (index == 0) { RemoteControl.Instance.Scan(ref user, tuneChannel, -1); } IChannel[] channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel); if (channels == null || channels.Length == 0) { /// try frequency - offset tuneChannel.Frequency = curTuning.Frequency - curTuning.Offset; line = String.Format("{0}tp- {1} {2}MHz ", 1 + index, tuneChannel.Frequency, tuneChannel.BandWidth); Log.Debug(line); channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel); if (channels == null || channels.Length == 0) { /// try frequency + offset tuneChannel.Frequency = curTuning.Frequency + curTuning.Offset; line = String.Format("{0}tp- {1} {2}MHz ", 1 + index, tuneChannel.Frequency, tuneChannel.BandWidth); Log.Debug(line); channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel); } } if (channels == null || channels.Length == 0) { if (RemoteControl.Instance.TunerLocked(_cardNumber) == false) { line = String.Format("{0}tp- {1} {2}:No signal", 1 + index, tuneChannel.Frequency, tuneChannel.BandWidth); Log.Error(line); continue; } line = String.Format("{0}tp- {1} {2}:Nothing found", 1 + index, tuneChannel.Frequency, tuneChannel.BandWidth); Log.Error(line); continue; } radio.newChannel = 0; radio.updChannel = 0; tv.newChannel = 0; tv.updChannel = 0; for (int i = 0; i < channels.Length; ++i) { Channel dbChannel; DVBTChannel channel = (DVBTChannel)channels[i]; bool exists; TuningDetail currentDetail; //Check if we already have this tuningdetail. The user has the option to enable channel move detection... if (true) { //According to the DVB specs ONID + SID is unique, therefore we do not need to use the TSID to identify a service. //The DVB spec recommends that the SID should not change if a service moves. This theoretically allows us to //track channel movements. currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.ServiceId, TvBusinessLayer.GetChannelType(channel)); } else { //There are certain providers that do not maintain unique ONID + SID combinations. //In those cases, ONID + TSID + SID is generally unique. The consequence of using the TSID to identify //a service is that channel movement tracking won't work (each transponder/mux should have its own TSID). currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.TransportId, channel.ServiceId, TvBusinessLayer.GetChannelType(channel)); } if (currentDetail == null) { //add new channel exists = false; dbChannel = layer.AddNewChannel(channel.Name, channel.LogicalChannelNumber); dbChannel.SortOrder = 10000; if (channel.LogicalChannelNumber >= 1) { dbChannel.SortOrder = channel.LogicalChannelNumber; } dbChannel.IsTv = channel.IsTv; dbChannel.IsRadio = channel.IsRadio; dbChannel.GrabEpg = true; dbChannel.Persist(); if (dbChannel.IsTv) { layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels); if (_defaultTVGroup != "") { layer.AddChannelToGroup(dbChannel, _defaultTVGroup); } } if (dbChannel.IsRadio) { layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels); if (_defaultTVGroup != "") { layer.AddChannelToRadioGroup(dbChannel, _defaultTVGroup); } } } else { exists = true; dbChannel = currentDetail.ReferencedChannel(); } if (currentDetail == null) { layer.AddTuningDetails(dbChannel, channel); } else { //update tuning details... TuningDetail td = layer.UpdateTuningDetails(dbChannel, channel, currentDetail); td.Persist(); } if (channel.IsTv) { if (exists) { tv.updChannel++; } else { tv.newChannel++; tv.newChannels.Add(channel); } } if (channel.IsRadio) { if (exists) { radio.updChannel++; } else { radio.newChannel++; radio.newChannels.Add(channel); } } layer.MapChannelToCard(card, dbChannel, false); line = String.Format("{0}tp- {1} {2}:New TV/Radio:{3}/{4} Updated TV/Radio:{5}/{6}", 1 + index, tuneChannel.Frequency, tuneChannel.BandWidth, tv.newChannel, radio.newChannel, tv.updChannel, radio.updChannel); Log.Debug(line); } tv.updChannelSum += tv.updChannel; radio.updChannelSum += radio.updChannel; } } catch (Exception ex) { Log.Write(ex); } finally { RemoteControl.Instance.StopCard(user); } if (radio.newChannels.Count == 0) { Log.Debug("No new radio channels"); } else { foreach (IChannel newChannel in radio.newChannels) { String line = String.Format("Radio -> new channel: {0}", newChannel.Name); Log.Debug(line); } } if (tv.newChannels.Count == 0) { Log.Debug("No new TV channels"); } else { foreach (IChannel newChannel in tv.newChannels) { String line = String.Format("TV -> new channel: {0}", newChannel.Name); Log.Debug(line); } } }