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);
        }
Beispiel #2
0
        private Guid EnsureDefaultChannel(ImportGuideChannel channel, ChannelType channelType, bool updateChannelName)
        {
            using (GuideServiceAgent guideServiceAgent = new GuideServiceAgent())
            {
                using (SchedulerServiceAgent schedulerServiceAgent = new SchedulerServiceAgent())
                {
                    Guid guideChannelId = guideServiceAgent.EnsureChannel(channel.ExternalId, channel.ChannelName, channelType);

                    // If we have exactly one channel, check LCN and DisplayName :
                    Channel[] channels = schedulerServiceAgent.GetChannelsForGuideChannel(guideChannelId);
                    if (channels.Length == 1 && updateChannelName)
                    {
                        bool needsToBeSaved = false;
                        if (channels[0].LogicalChannelNumber == null && channel.LogicalChannelNumber.HasValue)
                        {
                            channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                            needsToBeSaved = true;
                        }
                        if (channels[0].DisplayName != channel.ChannelName)
                        {
                            channels[0].DisplayName = channel.ChannelName;
                            needsToBeSaved          = true;
                        }

                        if (needsToBeSaved)
                        {
                            schedulerServiceAgent.SaveChannel(channels[0]);
                        }
                    }
                    else if (channels.Length == 0)
                    {
                        // No channels linked to the GuideChannel. If we have an existing channel with the same name, then link it.
                        Channel existingChannel = schedulerServiceAgent.GetChannelByDisplayName(channelType, channel.ChannelName);
                        if (existingChannel != null)
                        {
                            existingChannel.LogicalChannelNumber = channel.LogicalChannelNumber;
                            schedulerServiceAgent.SaveChannel(existingChannel);
                        }
                        else
                        {
                            schedulerServiceAgent.EnsureDefaultChannel(guideChannelId, channelType, channel.ChannelName, null);
                            channels = schedulerServiceAgent.GetChannelsForGuideChannel(guideChannelId);
                            if (channels.Length == 1)
                            {
                                channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                                schedulerServiceAgent.SaveChannel(channels[0]);
                            }
                        }
                    }
                    return(guideChannelId);
                }
            }
        }
        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;
        }
Beispiel #4
0
        private Guid EnsureDefaultChannel(ImportGuideChannel channel, ChannelType channelType, bool updateChannelName)
        {
            using (GuideServiceAgent guideServiceAgent = new GuideServiceAgent())
            {
                using (SchedulerServiceAgent schedulerServiceAgent = new SchedulerServiceAgent())
                {
                    Guid guideChannelId = guideServiceAgent.EnsureChannel(channel.ExternalId, channel.ChannelName, channelType);

                    // If we have exactly one channel, check LCN and DisplayName :
                    Channel[] channels = schedulerServiceAgent.GetChannelsForGuideChannel(guideChannelId);
                    if (channels.Length == 1 && updateChannelName)
                    {
                        bool needsToBeSaved = false;
                        if (channels[0].LogicalChannelNumber == null && channel.LogicalChannelNumber.HasValue)
                        {
                            channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                            needsToBeSaved = true;
                        }
                        if (channels[0].DisplayName != channel.ChannelName)
                        {
                            channels[0].DisplayName = channel.ChannelName;
                            needsToBeSaved = true;
                        }

                        if (needsToBeSaved)
                        {
                            schedulerServiceAgent.SaveChannel(channels[0]);
                        }
                    }
                    else if(channels.Length == 0)
                    {
                        // No channels linked to the GuideChannel. If we have an existing channel with the same name, then link it.
                        Channel existingChannel = schedulerServiceAgent.GetChannelByDisplayName(channelType, channel.ChannelName);
                        if (existingChannel != null)
                        {
                            existingChannel.LogicalChannelNumber = channel.LogicalChannelNumber;
                            schedulerServiceAgent.SaveChannel(existingChannel);
                        }
                        else
                        {
                            schedulerServiceAgent.EnsureDefaultChannel(guideChannelId, channelType, channel.ChannelName, null);
                            channels = schedulerServiceAgent.GetChannelsForGuideChannel(guideChannelId);
                            if (channels.Length == 1)
                            {
                                channels[0].LogicalChannelNumber = channel.LogicalChannelNumber;
                                schedulerServiceAgent.SaveChannel(channels[0]);
                            }
                        }
                    }
                    return guideChannelId;
                }
            }
        }
Beispiel #5
0
        private IMBotMessage DoShowGuideCommand(IMBotConversation conversation, IList<string> arguments)
        {
            if (arguments.Count == 0)
            {
                return new IMBotMessage("Channel name or number missing.", IMBotMessage.ErrorColor);
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
            {
                Channel selectedChannel = null;
                ChannelType channelType = GetChannelType(conversation);

                int lcn;
                if (int.TryParse(arguments[0], out lcn))
                {
                    selectedChannel = tvSchedulerAgent.GetChannelByLogicalChannelNumber(channelType, lcn);
                    if (selectedChannel == null)
                    {
                        return new IMBotMessage("Unknown channel number.", IMBotMessage.ErrorColor);
                    }
                }
                else
                {
                    selectedChannel = tvSchedulerAgent.GetChannelByDisplayName(channelType, arguments[0]);
                    if (selectedChannel == null)
                    {
                        return new IMBotMessage("Unknown channel name.", IMBotMessage.ErrorColor);
                    }
                }

                if (selectedChannel.GuideChannelId.HasValue)
                {
                    DateTime lowerTime = DateTime.Today;
                    if (arguments.Count > 1)
                    {
                        int dayNumber;
                        if (!int.TryParse(arguments[1], out dayNumber))
                        {
                            return new IMBotMessage("Bad day number, use 0 for today, 1 for tomorrow, etc...", IMBotMessage.ErrorColor);
                        }
                        lowerTime = lowerTime.AddDays(dayNumber);
                    }

                    DateTime upperTime = lowerTime.AddDays(1);
                    if (lowerTime.Date == DateTime.Today)
                    {
                        lowerTime = DateTime.Now;
                    }

                    Dictionary<Guid, UpcomingGuideProgram> upcomingRecordingsById = BuildUpcomingDictionary(
                        tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Recording, true));
                    Dictionary<Guid, UpcomingGuideProgram> upcomingAlertsById = BuildUpcomingDictionary(
                        tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Alert, false));
                    Dictionary<Guid, UpcomingGuideProgram> upcomingSuggestionsById = BuildUpcomingDictionary(
                        tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Suggestion, false));

                    GuideProgramSummary[] programs = tvGuideAgent.GetChannelProgramsBetween(selectedChannel.GuideChannelId.Value, lowerTime, upperTime);
                    if (programs.Length == 0)
                    {
                        return new IMBotMessage(String.Format(CultureInfo.CurrentCulture, "No guide data for {0} on {1}.", selectedChannel.DisplayName, lowerTime.ToLongDateString()),
                            IMBotMessage.ErrorColor);
                    }
                    else
                    {
                        StringBuilder replyText = new StringBuilder();
                        replyText.AppendFormat("{0} on {1}:", lowerTime.ToLongDateString(), selectedChannel.DisplayName);
                        int index = 0;
                        foreach (GuideProgramSummary program in programs)
                        {
                            replyText.AppendLine();
                            replyText.AppendFormat("{0,3}» ", ++index);
                            string appendText = AppendProgramIndicatorsPrefix(replyText,
                                program.GetUniqueUpcomingProgramId(selectedChannel.ChannelId),
                                upcomingRecordingsById, upcomingAlertsById, upcomingSuggestionsById);
                            Utility.AppendProgramDetails(replyText, program);
                            replyText.Append(appendText);
                        }

                        conversation.Session[SessionKey.Programs] = new Session.Programs(selectedChannel, programs);

                        return new IMBotMessage(replyText.ToString(), true)
                        {
                            Footer = "Use 'record', 'cancel', 'uncancel' or 'delete schedule' with <number>."
                        };
                    }
                }
                else
                {
                    return new IMBotMessage("Channel has no guide data.", IMBotMessage.ErrorColor);
                }
            }
        }
Beispiel #6
0
        private IMBotMessage DoShowGuideCommand(IMBotConversation conversation, IList <string> arguments)
        {
            if (arguments.Count == 0)
            {
                return(new IMBotMessage("Channel name or number missing.", IMBotMessage.ErrorColor));
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                {
                    Channel     selectedChannel = null;
                    ChannelType channelType     = GetChannelType(conversation);

                    int lcn;
                    if (int.TryParse(arguments[0], out lcn))
                    {
                        selectedChannel = tvSchedulerAgent.GetChannelByLogicalChannelNumber(channelType, lcn);
                        if (selectedChannel == null)
                        {
                            return(new IMBotMessage("Unknown channel number.", IMBotMessage.ErrorColor));
                        }
                    }
                    else
                    {
                        selectedChannel = tvSchedulerAgent.GetChannelByDisplayName(channelType, arguments[0]);
                        if (selectedChannel == null)
                        {
                            return(new IMBotMessage("Unknown channel name.", IMBotMessage.ErrorColor));
                        }
                    }

                    if (selectedChannel.GuideChannelId.HasValue)
                    {
                        DateTime lowerTime = DateTime.Today;
                        if (arguments.Count > 1)
                        {
                            int dayNumber;
                            if (!int.TryParse(arguments[1], out dayNumber))
                            {
                                return(new IMBotMessage("Bad day number, use 0 for today, 1 for tomorrow, etc...", IMBotMessage.ErrorColor));
                            }
                            lowerTime = lowerTime.AddDays(dayNumber);
                        }

                        DateTime upperTime = lowerTime.AddDays(1);
                        if (lowerTime.Date == DateTime.Today)
                        {
                            lowerTime = DateTime.Now;
                        }

                        Dictionary <Guid, UpcomingGuideProgram> upcomingRecordingsById = BuildUpcomingDictionary(
                            tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Recording, true));
                        Dictionary <Guid, UpcomingGuideProgram> upcomingAlertsById = BuildUpcomingDictionary(
                            tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Alert, false));
                        Dictionary <Guid, UpcomingGuideProgram> upcomingSuggestionsById = BuildUpcomingDictionary(
                            tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Suggestion, false));

                        GuideProgramSummary[] programs = tvGuideAgent.GetChannelProgramsBetween(selectedChannel.GuideChannelId.Value, lowerTime, upperTime);
                        if (programs.Length == 0)
                        {
                            return(new IMBotMessage(String.Format(CultureInfo.CurrentCulture, "No guide data for {0} on {1}.", selectedChannel.DisplayName, lowerTime.ToLongDateString()),
                                                    IMBotMessage.ErrorColor));
                        }
                        else
                        {
                            StringBuilder replyText = new StringBuilder();
                            replyText.AppendFormat("{0} on {1}:", lowerTime.ToLongDateString(), selectedChannel.DisplayName);
                            int index = 0;
                            foreach (GuideProgramSummary program in programs)
                            {
                                replyText.AppendLine();
                                replyText.AppendFormat("{0,3}» ", ++index);
                                string appendText = AppendProgramIndicatorsPrefix(replyText,
                                                                                  program.GetUniqueUpcomingProgramId(selectedChannel.ChannelId),
                                                                                  upcomingRecordingsById, upcomingAlertsById, upcomingSuggestionsById);
                                Utility.AppendProgramDetails(replyText, program);
                                replyText.Append(appendText);
                            }

                            conversation.Session[SessionKey.Programs] = new Session.Programs(selectedChannel, programs);

                            return(new IMBotMessage(replyText.ToString(), true)
                            {
                                Footer = "Use 'record', 'cancel', 'uncancel' or 'delete schedule' with <number>."
                            });
                        }
                    }
                    else
                    {
                        return(new IMBotMessage("Channel has no guide data.", IMBotMessage.ErrorColor));
                    }
                }
        }