private static Channel EnsureChannelForDvbEpg(SchedulerServiceAgent tvSchedulerAgent, TvDatabase.Channel mpChannel,
                                                      bool epgSyncAutoCreateChannels, bool epgSyncAutoCreateChannelsWithGroup)
        {
            ChannelLink channelLink = ChannelLinks.GetChannelLinkForMediaPortalChannel(mpChannel);
            ChannelType channelType = mpChannel.IsTv ? ChannelType.Television : ChannelType.Radio;
            Channel     channel     = null;

            if (channelLink != null)
            {
                channel = tvSchedulerAgent.GetChannelById(channelLink.ChannelId);
                if (channel == null)
                {
                    channel = tvSchedulerAgent.GetChannelByDisplayName(channelType, channelLink.ChannelName);
                }
            }
            if (channel == null)
            {
                channel = tvSchedulerAgent.GetChannelByDisplayName(channelType, mpChannel.DisplayName);
            }
            if (channel == null &&
                (epgSyncAutoCreateChannels || epgSyncAutoCreateChannelsWithGroup))
            {
                string groupName = "DVB-EPG";
                if (epgSyncAutoCreateChannelsWithGroup)
                {
                    IList <TvDatabase.GroupMap> groupMaps = mpChannel.ReferringGroupMap();
                    foreach (TvDatabase.GroupMap groupMap in groupMaps)
                    {
                        TvDatabase.ChannelGroup channelGroup = TvDatabase.ChannelGroup.Retrieve(groupMap.IdGroup);
                        if (channelGroup != null)
                        {
                            groupName = channelGroup.GroupName;
                            break;
                        }
                    }
                }

                Guid channelId = tvSchedulerAgent.EnsureChannel(channelType, mpChannel.DisplayName, groupName);
                channel = tvSchedulerAgent.GetChannelById(channelId);

                if (!channel.LogicalChannelNumber.HasValue &&
                    mpChannel.ChannelNumber > 0)
                {
                    channel.LogicalChannelNumber = mpChannel.ChannelNumber;
                    tvSchedulerAgent.SaveChannel(channel);
                }
            }
            return(channel);
        }
Example #2
0
        private void EnsureChildren(TreeNode node)
        {
            try
            {
                if (node.Nodes.Count == 1 &&
                    String.IsNullOrEmpty(node.Nodes[0].Text))
                {
                    int    groupId;
                    string groupName;
                    int    groupSequence;
                    TvDatabase.ChannelGroup group = node.Tag as TvDatabase.ChannelGroup;
                    if (group == null)
                    {
                        TvDatabase.RadioChannelGroup radioGroup = node.Tag as TvDatabase.RadioChannelGroup;
                        groupId       = radioGroup.IdGroup;
                        groupName     = radioGroup.GroupName;
                        groupSequence = 0;
                    }
                    else
                    {
                        groupId       = group.IdGroup;
                        groupName     = group.GroupName;
                        groupSequence = group.SortOrder;
                    }

                    List <TvDatabase.Channel> channels = Utility.GetAllChannelsInGroup(this.Context.ChannelType, groupId);

                    node.Nodes.Clear();
                    foreach (TvDatabase.Channel channel in channels)
                    {
                        if (ChannelLinks.GetChannelLinkForMediaPortalChannel(channel) == null &&
                            !ChannelLinks.IsAutoLinked(channel))
                        {
                            TreeNode channelNode = new TreeNode(channel.DisplayName);
                            channelNode.Tag = new ImportChannelsContext.ImportChannel(channel, groupId < 0 ? null : groupName, groupSequence);
                            node.Nodes.Add(channelNode);
                        }
                    }
                    _recordingsTreeView.InitializeNodesState(node.Nodes);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }