private void mpButtonUnmap_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Unmapping selected channels from TV-Card...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); mpListViewChannels.BeginUpdate(); mpListViewMapped.BeginUpdate(); try { ListView.SelectedListViewItemCollection selectedItems = mpListViewMapped.SelectedItems; foreach (ListViewItem item in selectedItems) { ChannelMap map = (ChannelMap)item.Tag; mpListViewMapped.Items.Remove(item); Channel referencedChannel = map.ReferencedChannel(); ListViewItem newItem = mpListViewChannels.Items.Add(referencedChannel.DisplayName, item.ImageIndex); newItem.Tag = referencedChannel; map.Remove(); } mpListViewChannels.Sort(); mpListViewMapped.Sort(); dlg.Close(); } finally { mpListViewChannels.EndUpdate(); mpListViewMapped.EndUpdate(); } // DatabaseManager.Instance.SaveChanges(); }
private void mpButtonUncheckEncrypted_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Unchecking all scrambled tv channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ListViewItem item in mpListView1.Items) { Channel channel = (Channel)item.Tag; bool hasFTA = false; foreach (TuningDetail tuningDetail in channel.ReferringTuningDetail()) { if (tuningDetail.FreeToAir) { hasFTA = true; break; } } if (!hasFTA) { item.Checked = false; } } dlg.Close(); }
private void mpButtonMap_Click_1(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Mapping selected channels to TV-Card...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); Card card = ((CardInfo)mpComboBoxCard.SelectedItem).Card; mpListViewChannels.BeginUpdate(); mpListViewMapped.BeginUpdate(); try { ListView.SelectedListViewItemCollection selectedItems = mpListViewChannels.SelectedItems; TvBusinessLayer layer = new TvBusinessLayer(); foreach (ListViewItem item in selectedItems) { Channel channel = (Channel)item.Tag; ChannelMap map = layer.MapChannelToCard(card, channel, false); mpListViewChannels.Items.Remove(item); ListViewItem newItem = mpListViewMapped.Items.Add(channel.DisplayName, item.ImageIndex); newItem.Tag = map; } dlg.Close(); } finally { mpListViewChannels.EndUpdate(); mpListViewMapped.EndUpdate(); } }
private void mpButtonDel_Click(object sender, EventArgs e) { mpListView1.BeginUpdate(); try { IList <Schedule> schedules = Schedule.ListAll(); TvServer server = new TvServer(); //Since it takes a very long time to add channels, make sure the user really wants to delete them if (mpListView1.SelectedItems.Count > 0) { string holder = String.Format("Are you sure you want to delete these {0:d} channels?", mpListView1.SelectedItems.Count); if (MessageBox.Show(holder, "", MessageBoxButtons.YesNo) == DialogResult.No) { //mpListView1.EndUpdate(); return; } } NotifyForm dlg = new NotifyForm("Deleting selected tv channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ListViewItem item in mpListView1.SelectedItems) { Channel channel = (Channel)item.Tag; //also delete any still active schedules if (schedules != null) { for (int i = schedules.Count - 1; i > -1; i--) { Schedule schedule = schedules[i]; if (schedule.IdChannel == channel.IdChannel) { server.StopRecordingSchedule(schedule.IdSchedule); schedule.Delete(); schedules.RemoveAt(i); } } } channel.Delete(); mpListView1.Items.Remove(item); } dlg.Close(); ReOrder(); mpListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } finally { mpListView1.EndUpdate(); } }
private void button1_Click(object sender, EventArgs e) { NotifyForm frm = new NotifyForm(); frm.Show(); // MsgForm frm = new MsgForm(); // frm.DueSecond = 5; // frm.Show(); }
private void ServiceNeedsToRestart() { if ( MessageBox.Show(this, "Changes made require TvService to restart. Restart it now?", "TvService", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { NotifyForm dlgNotify = new NotifyForm("Restart TvService...", "This can take some time\n\nPlease be patient..."); dlgNotify.Show(); dlgNotify.WaitForDisplay(); RemoteControl.Instance.Restart(); dlgNotify.Close(); } }
private void mpButtonDel_Click(object sender, EventArgs e) { mpListView1.BeginUpdate(); try { if (mpListView1.SelectedItems.Count > 0) { string holder = String.Format("Are you sure you want to delete these {0:d} radio channels?", mpListView1.SelectedItems.Count); if (MessageBox.Show(holder, "", MessageBoxButtons.YesNo) == DialogResult.No) { //mpListView1.EndUpdate(); return; } } NotifyForm dlg = new NotifyForm("Deleting selected radio channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ListViewItem item in mpListView1.SelectedItems) { Channel channel = (Channel)item.Tag; IList <RadioGroupMap> mapsRadio = channel.ReferringRadioGroupMap(); // Bav: fixing Mantis bug 1178: Can't delete Radio channels in SetupTV foreach (RadioGroupMap map in mapsRadio) { map.Remove(); } IList <GroupMap> maps = channel.ReferringGroupMap(); foreach (GroupMap map in maps) { map.Remove(); } // Bav - End of fix channel.Delete(); mpListView1.Items.Remove(item); } dlg.Close(); ReOrder(); } finally { mpListView1.EndUpdate(); } }
private void ScanForUsableChannels() { _abortScanning = false; _isScanning = true; NotifyForm dlg = new NotifyForm("Testing all checked tv channels...", "Please be patient..."); dlg.Show(this); dlg.WaitForDisplay(); // Create tunning objects Server, User and Card TvServer _server = new TvServer(); IUser _user = new User(); VirtualCard _card; foreach (ListViewItem item in mpListView1.Items) { if (item.Checked == false) { continue; // do not test "un-checked" channels } Channel _channel = (Channel)item.Tag; // get channel dlg.SetMessage( string.Format("Please be patient...\n\nTesting channel {0} ( {1} of {2} )", _channel.DisplayName, item.Index + 1, mpListView1.Items.Count)); Application.DoEvents(); TvResult result = _server.StartTimeShifting(ref _user, _channel.IdChannel, out _card); if (result == TvResult.Succeeded) { _card.StopTimeShifting(); } else { item.Checked = false; _channel.VisibleInGuide = false; _channel.Persist(); } if (_abortScanning) { break; } } mpButtonTestAvailable.Text = "Test"; dlg.Close(); _isScanning = false; _abortScanning = false; }
private void renumberChannelsBySIDToolStripMenuItem_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Renumbering radio channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ListViewItem item in mpListView1.SelectedItems) { Channel channel = (Channel)item.Tag; IList <TuningDetail> details = channel.ReferringTuningDetail(); foreach (TuningDetail detail in details) { detail.ChannelNumber = detail.ServiceId; detail.Persist(); } } dlg.Close(); }
private void renameMarkedChannelsBySIDToolStripMenuItem_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Renaming selected tv channels by SID ...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ListViewItem item in mpListView1.SelectedItems) { Channel channel = (Channel)item.Tag; IList <TuningDetail> details = channel.ReferringTuningDetail(); if (details.Count > 0) { channel.DisplayName = (details[0]).ServiceId.ToString(); channel.Persist(); item.Tag = channel; } } dlg.Close(); OnSectionActivated(); }
private void exportButton_Click(object sender, EventArgs e) { saveFileDialog1.CheckFileExists = false; saveFileDialog1.DefaultExt = "xml"; saveFileDialog1.RestoreDirectory = true; saveFileDialog1.Title = "Save channels, channel groups and schedules"; saveFileDialog1.InitialDirectory = String.Format(@"{0}\Team MediaPortal\MediaPortal TV Server", Environment.GetFolderPath( Environment.SpecialFolder.CommonApplicationData)); saveFileDialog1.FileName = "export.xml"; saveFileDialog1.AddExtension = true; if (saveFileDialog1.ShowDialog(this) == DialogResult.OK) { NotifyForm dlg = new NotifyForm("Exporting tv channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(); dlg.WaitForDisplay(); Export(saveFileDialog1.FileName, exCheckTVChannels.Checked, exCheckTVGroups.Checked, exCheckRadioChannels.Checked, exCheckRadioGroups.Checked, exCheckSchedules.Checked); dlg.Close(); } }
private void deleteThisChannelToolStripMenuItem_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { string holder = String.Format("Are you sure you want to delete these {0:d} channels?", listView1.SelectedItems.Count); if (MessageBox.Show(holder, "", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } ListView.SelectedIndexCollection indexes = listView1.SelectedIndices; if (indexes.Count == 0) { return; } NotifyForm dlg = new NotifyForm("Deleting selected tv channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(); dlg.WaitForDisplay(); for (int i = indexes.Count - 1; i >= 0; i--) { int index = indexes[i]; if (index >= 0 && index < listView1.Items.Count) { ListViewItem item = listView1.Items[index]; listView1.Items.RemoveAt(index); GroupMap map = (GroupMap)item.Tag; Channel channel = map.ReferencedChannel(); channel.Delete(); } } dlg.Close(); ReOrder(); OnActivated(); }
private void addSIDInFrontOfNameToolStripMenuItem_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Adding SID in front of name...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ListViewItem item in mpListView1.SelectedItems) { Channel channel = (Channel)item.Tag; IList <TuningDetail> details = channel.ReferringTuningDetail(); if (details.Count > 0) { channel.DisplayName = (details[0]).ServiceId + " " + channel.DisplayName; channel.Persist(); item.Tag = channel; } } dlg.Close(); OnSectionActivated(); }
private void mpButtonMap_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Mapping selected channels to TV-Card...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); Card card = ((CardInfo)mpComboBoxCard.SelectedItem).Card; mpListViewChannels.BeginUpdate(); mpListViewMapped.BeginUpdate(); try { ListView.SelectedListViewItemCollection selectedItems = mpListViewChannels.SelectedItems; TvBusinessLayer layer = new TvBusinessLayer(); foreach (ListViewItem item in selectedItems) { Channel channel = (Channel)item.Tag; ChannelMap map = layer.MapChannelToCard(card, channel, mpCheckBoxMapForEpgOnly.Checked); mpListViewChannels.Items.Remove(item); string displayName = channel.DisplayName; if (mpCheckBoxMapForEpgOnly.Checked) { displayName = channel.DisplayName + " (EPG Only)"; } ListViewItem newItem = mpListViewMapped.Items.Add(displayName, item.ImageIndex); newItem.Tag = map; } mpListViewMapped.Sort(); dlg.Close(); } finally { mpListViewChannels.EndUpdate(); mpListViewMapped.EndUpdate(); } //DatabaseManager.Instance.SaveChanges(); }
public override void OnSectionDeActivated() { base.OnSectionDeActivated(); MatroskaTagHandler.OnTagLookupCompleted -= OnLookupCompleted; SaveSettings(); if (_needRestart) { if (MessageBox.Show(this, "Changes made require TvService to restart. Restart it now?", "TvService", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var dlgNotify = new NotifyForm("Restart TvService...", "This can take some time\n\nPlease be patient..."); dlgNotify.Show(); dlgNotify.WaitForDisplay(); RemoteControl.Instance.ClearCache(); RemoteControl.Instance.Restart(); dlgNotify.Close(); } } }
private void mpButtonDel_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { string holder = String.Format("Are you sure you want to remove these {0:d} channels?", listView1.SelectedItems.Count); if (MessageBox.Show(holder, "", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } ListView.SelectedIndexCollection indexes = listView1.SelectedIndices; if (indexes.Count == 0) { return; } NotifyForm dlg = new NotifyForm("Removing radio channels from group...", "This can take some time\n\nPlease be patient..."); dlg.Show(); dlg.WaitForDisplay(); for (int i = indexes.Count - 1; i >= 0; i--) { int index = indexes[i]; if (index >= 0 && index < listView1.Items.Count) { ListViewItem item = listView1.Items[index]; listView1.Items.RemoveAt(index); RadioGroupMap map = (RadioGroupMap)item.Tag; map.Remove(); } } dlg.Close(); ReOrder(); }
private void mpButtonDeleteEncrypted_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Deleting all scrambled tv channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); List <ListViewItem> itemsToRemove = new List <ListViewItem>(); foreach (ListViewItem item in mpListView1.Items) { Channel channel = (Channel)item.Tag; bool hasFTA = false; foreach (TuningDetail tuningDetail in channel.ReferringTuningDetail()) { if (tuningDetail.FreeToAir) { hasFTA = true; break; } } if (!hasFTA) { channel.Delete(); itemsToRemove.Add(item); } } foreach (ListViewItem item in itemsToRemove) { mpListView1.Items.Remove(item); } dlg.Close(); ReOrder(); RemoteControl.Instance.OnNewSchedule(); mpListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }
private void mpListViewChannels_SelectedIndexChanged(object sender, EventArgs e) { mpListViewMapped.BeginUpdate(); try { mpListViewMapped.Items.Clear(); if (mpListViewChannels.SelectedIndices == null) return; if (mpListViewChannels.SelectedIndices.Count != 1) return; Card card = ((CardInfo)mpComboBoxCard.SelectedItem).Card; ListViewItem selectedItem = mpListViewChannels.Items[mpListViewChannels.SelectedIndices[0]]; Channel selectedChannel = (Channel)selectedItem.Tag; IList<Channel> allChannels = Channel.ListAll(); List<ListViewItem> items = new List<ListViewItem>(); NotifyForm dlg = new NotifyForm("Searching for Similar Channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (Channel channel in allChannels) { if (channel.IsRadio == false) continue; bool isMapped = false; IList<ChannelMap> list = channel.ReferringChannelMap(); foreach (ChannelMap map in list) { if (map.IdCard == card.IdCard) { isMapped = true; break; } } if (isMapped) continue; Levenstein comparer = new Levenstein(); float result = comparer.getSimilarity(selectedChannel.DisplayName, channel.DisplayName); IList<TuningDetail> details = channel.ReferringTuningDetail(); int imageIndex = GetImageIndex(details); ListViewItem item = new ListViewItem((result * 100f).ToString("f2") + "%", imageIndex); item.Tag = channel; item.SubItems.Add(channel.DisplayName); items.Add(item); } mpListViewMapped.Items.AddRange(items.ToArray()); mpListViewMapped.Sort(); dlg.Close(); } finally { mpListViewMapped.EndUpdate(); } }
private void mpButtonClear_Click(object sender, EventArgs e) { string holder = String.Format("Are you sure you want to clear all channels?"); if (MessageBox.Show(holder, "", MessageBoxButtons.YesNo) == DialogResult.No) { return; } NotifyForm dlg = new NotifyForm("Clearing all tv channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); IList<Channel> channels = Channel.ListAll(); foreach (Channel channel in channels) { if (channel.IsTv) { Broker.Execute("delete from TvMovieMapping WHERE idChannel=" + channel.IdChannel); channel.Delete(); } } dlg.Close(); /*Gentle.Framework.Broker.Execute("delete from history"); Gentle.Framework.Broker.Execute("delete from tuningdetail"); Gentle.Framework.Broker.Execute("delete from GroupMap"); Gentle.Framework.Broker.Execute("delete from Channelmap"); Gentle.Framework.Broker.Execute("delete from Recording"); Gentle.Framework.Broker.Execute("delete from CanceledSchedule"); Gentle.Framework.Broker.Execute("delete from Schedule"); Gentle.Framework.Broker.Execute("delete from Program"); Gentle.Framework.Broker.Execute("delete from Channel"); mpListView1.BeginUpdate();*/ /* IList details = TuningDetail.ListAll(); foreach (TuningDetail detail in details) detail.Remove(); IList groupmaps = GroupMap.ListAll(); foreach (GroupMap groupmap in groupmaps) groupmap.Remove(); IList channelMaps = ChannelMap.ListAll(); foreach (ChannelMap channelMap in channelMaps) channelMap.Remove(); IList recordings = Recording.ListAll(); foreach (Recording recording in recordings) recording.Remove(); IList canceledSchedules = CanceledSchedule.ListAll(); foreach (CanceledSchedule canceledSchedule in canceledSchedules) canceledSchedule.Remove(); IList schedules = Schedule.ListAll(); foreach (Schedule schedule in schedules) schedule.Remove(); IList programs = Program.ListAll(); foreach (Program program in programs) program.Remove(); IList channels = Channel.ListAll(); foreach (Channel channel in channels) channel.Remove(); */ //mpListView1.EndUpdate(); OnSectionActivated(); }
private void mpButtonDel_Click(object sender, EventArgs e) { mpListView1.BeginUpdate(); try { IList<Schedule> schedules = Schedule.ListAll(); TvServer server = new TvServer(); //Since it takes a very long time to add channels, make sure the user really wants to delete them if (mpListView1.SelectedItems.Count > 0) { string holder = String.Format("Are you sure you want to delete these {0:d} channels?", mpListView1.SelectedItems.Count); if (MessageBox.Show(holder, "", MessageBoxButtons.YesNo) == DialogResult.No) { //mpListView1.EndUpdate(); return; } } NotifyForm dlg = new NotifyForm("Deleting selected tv channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ListViewItem item in mpListView1.SelectedItems) { Channel channel = (Channel)item.Tag; //also delete any still active schedules if (schedules != null) { for (int i = schedules.Count - 1; i > -1; i--) { Schedule schedule = schedules[i]; if (schedule.IdChannel == channel.IdChannel) { server.StopRecordingSchedule(schedule.IdSchedule); schedule.Delete(); schedules.RemoveAt(i); } } } channel.Delete(); mpListView1.Items.Remove(item); } dlg.Close(); ReOrder(); mpListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } finally { mpListView1.EndUpdate(); } }
private void mpButtonDeleteEncrypted_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Deleting all scrambled tv channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); List<ListViewItem> itemsToRemove = new List<ListViewItem>(); foreach (ListViewItem item in mpListView1.Items) { Channel channel = (Channel)item.Tag; bool hasFTA = false; foreach (TuningDetail tuningDetail in channel.ReferringTuningDetail()) { if (tuningDetail.FreeToAir) { hasFTA = true; break; } } if (!hasFTA) { channel.Delete(); itemsToRemove.Add(item); } } foreach (ListViewItem item in itemsToRemove) mpListView1.Items.Remove(item); dlg.Close(); ReOrder(); RemoteControl.Instance.OnNewSchedule(); mpListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }
private void mpButtonDel_Click(object sender, EventArgs e) { mpListView1.BeginUpdate(); try { if (mpListView1.SelectedItems.Count > 0) { string holder = String.Format("Are you sure you want to delete these {0:d} radio channels?", mpListView1.SelectedItems.Count); if (MessageBox.Show(holder, "", MessageBoxButtons.YesNo) == DialogResult.No) { //mpListView1.EndUpdate(); return; } } NotifyForm dlg = new NotifyForm("Deleting selected radio channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ListViewItem item in mpListView1.SelectedItems) { Channel channel = (Channel)item.Tag; IList<RadioGroupMap> mapsRadio = channel.ReferringRadioGroupMap(); // Bav: fixing Mantis bug 1178: Can't delete Radio channels in SetupTV foreach (RadioGroupMap map in mapsRadio) { map.Remove(); } IList<GroupMap> maps = channel.ReferringGroupMap(); foreach (GroupMap map in maps) { map.Remove(); } // Bav - End of fix channel.Delete(); mpListView1.Items.Remove(item); } dlg.Close(); ReOrder(); } finally { mpListView1.EndUpdate(); } }
private void mpButtonDel_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { string holder = String.Format("Are you sure you want to remove these {0:d} channels?", listView1.SelectedItems.Count); if (MessageBox.Show(holder, "", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } ListView.SelectedIndexCollection indexes = listView1.SelectedIndices; if (indexes.Count == 0) return; NotifyForm dlg = new NotifyForm("Removing radio channels from group...", "This can take some time\n\nPlease be patient..."); dlg.Show(); dlg.WaitForDisplay(); for (int i = indexes.Count - 1; i >= 0; i--) { int index = indexes[i]; if (index >= 0 && index < listView1.Items.Count) { ListViewItem item = listView1.Items[index]; listView1.Items.RemoveAt(index); RadioGroupMap map = (RadioGroupMap)item.Tag; map.Remove(); } } dlg.Close(); ReOrder(); }
private void renameMarkedChannelsBySIDToolStripMenuItem_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Renaming selected tv channels by SID ...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ListViewItem item in mpListView1.SelectedItems) { Channel channel = (Channel)item.Tag; IList<TuningDetail> details = channel.ReferringTuningDetail(); if (details.Count > 0) { channel.DisplayName = (details[0]).ServiceId.ToString(); channel.Persist(); item.Tag = channel; } } dlg.Close(); OnSectionActivated(); }
private void addSIDInFrontOfNameToolStripMenuItem_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Adding SID in front of name...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ListViewItem item in mpListView1.SelectedItems) { Channel channel = (Channel)item.Tag; IList<TuningDetail> details = channel.ReferringTuningDetail(); if (details.Count > 0) { channel.DisplayName = (details[0]).ServiceId + " " + channel.DisplayName; channel.Persist(); item.Tag = channel; } } dlg.Close(); OnSectionActivated(); }
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"); // 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); } 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.RecommendedCard = Int32.Parse(nodeSchedule.Attributes["RecommendedCard"].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(); } }
private void renumberChannelsBySIDToolStripMenuItem_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Renumbering tv channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ListViewItem item in mpListView1.SelectedItems) { Channel channel = (Channel)item.Tag; IList<TuningDetail> details = channel.ReferringTuningDetail(); foreach (TuningDetail detail in details) { if (detail.ChannelType != 0) // SID is not relevant for analog channels { channel.ChannelNumber = detail.ServiceId; channel.Persist(); item.Tag = channel; break; } } } dlg.Close(); }
private void deleteThisChannelToolStripMenuItem_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { string holder = String.Format("Are you sure you want to delete these {0:d} channels?", listView1.SelectedItems.Count); if (MessageBox.Show(holder, "", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } ListView.SelectedIndexCollection indexes = listView1.SelectedIndices; if (indexes.Count == 0) return; NotifyForm dlg = new NotifyForm("Deleting selected tv channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(); dlg.WaitForDisplay(); for (int i = indexes.Count - 1; i >= 0; i--) { int index = indexes[i]; if (index >= 0 && index < listView1.Items.Count) { ListViewItem item = listView1.Items[index]; listView1.Items.RemoveAt(index); GroupMap map = (GroupMap)item.Tag; Channel channel = map.ReferencedChannel(); channel.Delete(); } } dlg.Close(); ReOrder(); OnActivated(); }
private void mpListViewChannels_SelectedIndexChanged(object sender, EventArgs e) { mpListViewMapped.BeginUpdate(); try { mpListViewMapped.Items.Clear(); if (mpListViewChannels.SelectedIndices == null) { return; } if (mpListViewChannels.SelectedIndices.Count != 1) { return; } Card card = ((CardInfo)mpComboBoxCard.SelectedItem).Card; ListViewItem selectedItem = mpListViewChannels.Items[mpListViewChannels.SelectedIndices[0]]; Channel selectedChannel = (Channel)selectedItem.Tag; IList <Channel> allChannels = Channel.ListAll(); List <ListViewItem> items = new List <ListViewItem>(); NotifyForm dlg = new NotifyForm("Searching for Similar Channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (Channel channel in allChannels) { if (channel.IsRadio == false) { continue; } bool isMapped = false; IList <ChannelMap> list = channel.ReferringChannelMap(); foreach (ChannelMap map in list) { if (map.IdCard == card.IdCard) { isMapped = true; break; } } if (isMapped) { continue; } Levenstein comparer = new Levenstein(); float result = comparer.getSimilarity(selectedChannel.DisplayName, channel.DisplayName); IList <TuningDetail> details = channel.ReferringTuningDetail(); int imageIndex = GetImageIndex(details); ListViewItem item = new ListViewItem((result * 100f).ToString("f2") + "%", imageIndex); item.Tag = channel; item.SubItems.Add(channel.DisplayName); items.Add(item); } mpListViewMapped.Items.AddRange(items.ToArray()); mpListViewMapped.Sort(); dlg.Close(); } finally { mpListViewMapped.EndUpdate(); } }
private void mpButtonClear_Click(object sender, EventArgs e) { string holder = String.Format("Are you sure you want to clear all channels?"); if (MessageBox.Show(holder, "", MessageBoxButtons.YesNo) == DialogResult.No) { return; } NotifyForm dlg = new NotifyForm("Clearing all tv channels...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); IList <Channel> channels = Channel.ListAll(); foreach (Channel channel in channels) { if (channel.IsTv) { Broker.Execute("delete from TvMovieMapping WHERE idChannel=" + channel.IdChannel); channel.Delete(); } } dlg.Close(); /*Gentle.Framework.Broker.Execute("delete from history"); * Gentle.Framework.Broker.Execute("delete from tuningdetail"); * Gentle.Framework.Broker.Execute("delete from GroupMap"); * Gentle.Framework.Broker.Execute("delete from Channelmap"); * Gentle.Framework.Broker.Execute("delete from Recording"); * Gentle.Framework.Broker.Execute("delete from CanceledSchedule"); * Gentle.Framework.Broker.Execute("delete from Schedule"); * Gentle.Framework.Broker.Execute("delete from Program"); * Gentle.Framework.Broker.Execute("delete from Channel"); * mpListView1.BeginUpdate();*/ /* * IList details = TuningDetail.ListAll(); * foreach (TuningDetail detail in details) detail.Remove(); * * IList groupmaps = GroupMap.ListAll(); * foreach (GroupMap groupmap in groupmaps) groupmap.Remove(); * * IList channelMaps = ChannelMap.ListAll(); * foreach (ChannelMap channelMap in channelMaps) channelMap.Remove(); * * IList recordings = Recording.ListAll(); * foreach (Recording recording in recordings) recording.Remove(); * * IList canceledSchedules = CanceledSchedule.ListAll(); * foreach (CanceledSchedule canceledSchedule in canceledSchedules) canceledSchedule.Remove(); * * IList schedules = Schedule.ListAll(); * foreach (Schedule schedule in schedules) schedule.Remove(); * * IList programs = Program.ListAll(); * foreach (Program program in programs) program.Remove(); * * IList channels = Channel.ListAll(); * foreach (Channel channel in channels) channel.Remove(); */ //mpListView1.EndUpdate(); OnSectionActivated(); }
private void mpButtonMap_Click(object sender, EventArgs e) { NotifyForm dlg = new NotifyForm("Mapping selected channels to TV-Card...", "This can take some time\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); Card card = ((CardInfo)mpComboBoxCard.SelectedItem).Card; mpListViewChannels.BeginUpdate(); mpListViewMapped.BeginUpdate(); try { ListView.SelectedListViewItemCollection selectedItems = mpListViewChannels.SelectedItems; TvBusinessLayer layer = new TvBusinessLayer(); foreach (ListViewItem item in selectedItems) { Channel channel = (Channel)item.Tag; ChannelMap map = layer.MapChannelToCard(card, channel, mpCheckBoxMapForEpgOnly.Checked); mpListViewChannels.Items.Remove(item); string displayName = channel.DisplayName; if (mpCheckBoxMapForEpgOnly.Checked) displayName = channel.DisplayName + " (EPG Only)"; ListViewItem newItem = mpListViewMapped.Items.Add(displayName, item.ImageIndex); newItem.Tag = map; } mpListViewMapped.Sort(); dlg.Close(); } finally { mpListViewChannels.EndUpdate(); mpListViewMapped.EndUpdate(); } //DatabaseManager.Instance.SaveChanges(); }
private void btnCombine_Click(object sender, EventArgs e) { if (mpListViewChannels.SelectedIndices == null) return; if (mpListViewChannels.SelectedIndices.Count != 1) return; if (mpListViewMapped.SelectedIndices == null) return; ListViewItem selectedItem = mpListViewChannels.Items[mpListViewChannels.SelectedIndices[0]]; Channel selectedChannel = (Channel)selectedItem.Tag; ListView.SelectedListViewItemCollection selectedItemsToCombine = mpListViewMapped.SelectedItems; foreach (ListViewItem listViewItem in selectedItemsToCombine) { Channel selectedChannel2 = (Channel)listViewItem.Tag; NotifyForm dlg = new NotifyForm("Combining Channels...", "Updating TuningDetail Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (TuningDetail detail in selectedChannel2.ReferringTuningDetail()) { detail.IdChannel = selectedChannel.IdChannel; detail.Persist(); } dlg.Close(); dlg = new NotifyForm("Combining Channels...", "Updating ChannelMap Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ChannelMap map in selectedChannel2.ReferringChannelMap()) { map.IdChannel = selectedChannel.IdChannel; map.Persist(); } dlg.Close(); dlg = new NotifyForm("Combining Channels...", "Updating RadioGroupMap Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (RadioGroupMap groupMap in selectedChannel2.ReferringRadioGroupMap()) { bool alreadyExistsInGroup = false; foreach (RadioGroupMap groupMapMaster in selectedChannel.ReferringRadioGroupMap()) { if (groupMapMaster.IdGroup == groupMap.IdGroup) { groupMap.Remove(); alreadyExistsInGroup = true; continue; } } if (!alreadyExistsInGroup) { groupMap.IdChannel = selectedChannel.IdChannel; groupMap.Persist(); } } dlg.Close(); dlg = new NotifyForm("Combining Channels...", "Updating Program Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (Program program in selectedChannel2.ReferringProgram()) { program.IdChannel = selectedChannel.IdChannel; program.Persist(); } dlg.Close(); dlg = new NotifyForm("Combining Channels...", "Updating Recording Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (Recording recording in selectedChannel2.ReferringRecording()) { recording.IdChannel = selectedChannel.IdChannel; recording.Persist(); } dlg.Close(); dlg = new NotifyForm("Combining Channels...", "Updating Schedule Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (Schedule schedule in selectedChannel2.ReferringSchedule()) { schedule.IdChannel = selectedChannel.IdChannel; schedule.Persist(); } dlg.Close(); selectedChannel2.Remove(); mpListViewMapped.Items.Remove(listViewItem); } }
private void btnCombine_Click(object sender, EventArgs e) { if (mpListViewChannels.SelectedIndices == null) { return; } if (mpListViewChannels.SelectedIndices.Count != 1) { return; } if (mpListViewMapped.SelectedIndices == null) { return; } ListViewItem selectedItem = mpListViewChannels.Items[mpListViewChannels.SelectedIndices[0]]; Channel selectedChannel = (Channel)selectedItem.Tag; ListView.SelectedListViewItemCollection selectedItemsToCombine = mpListViewMapped.SelectedItems; foreach (ListViewItem listViewItem in selectedItemsToCombine) { Channel selectedChannel2 = (Channel)listViewItem.Tag; NotifyForm dlg = new NotifyForm("Combining Channels...", "Updating TuningDetail Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (TuningDetail detail in selectedChannel2.ReferringTuningDetail()) { detail.IdChannel = selectedChannel.IdChannel; detail.Persist(); } dlg.Close(); dlg = new NotifyForm("Combining Channels...", "Updating ChannelMap Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (ChannelMap map in selectedChannel2.ReferringChannelMap()) { map.IdChannel = selectedChannel.IdChannel; map.Persist(); } dlg.Close(); dlg = new NotifyForm("Combining Channels...", "Updating RadioGroupMap Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (RadioGroupMap groupMap in selectedChannel2.ReferringRadioGroupMap()) { bool alreadyExistsInGroup = false; foreach (RadioGroupMap groupMapMaster in selectedChannel.ReferringRadioGroupMap()) { if (groupMapMaster.IdGroup == groupMap.IdGroup) { groupMap.Remove(); alreadyExistsInGroup = true; continue; } } if (!alreadyExistsInGroup) { groupMap.IdChannel = selectedChannel.IdChannel; groupMap.Persist(); } } dlg.Close(); dlg = new NotifyForm("Combining Channels...", "Updating Program Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (Program program in selectedChannel2.ReferringProgram()) { program.IdChannel = selectedChannel.IdChannel; program.Persist(); } dlg.Close(); dlg = new NotifyForm("Combining Channels...", "Updating Recording Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (Recording recording in selectedChannel2.ReferringRecording()) { recording.IdChannel = selectedChannel.IdChannel; recording.Persist(); } dlg.Close(); dlg = new NotifyForm("Combining Channels...", "Updating Schedule Table\n\nPlease be patient..."); dlg.Show(this); dlg.WaitForDisplay(); foreach (Schedule schedule in selectedChannel2.ReferringSchedule()) { schedule.IdChannel = selectedChannel.IdChannel; schedule.Persist(); } dlg.Close(); selectedChannel2.Remove(); mpListViewMapped.Items.Remove(listViewItem); } }
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(); } }