private void SetCurrentChannelLogo() { string strLogo = string.Empty; if (channelId != Guid.Empty && channelName != string.Empty) { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { strLogo = Utility.GetLogoImage(channelId, channelName, tvSchedulerAgent); } } if (string.IsNullOrEmpty(strLogo)) { if (imgTvChannelLogo != null) { imgTvChannelLogo.IsVisible = false; } } else { if (imgTvChannelLogo != null) { imgTvChannelLogo.SetFileName(strLogo); m_bNeedRefresh = true; imgTvChannelLogo.IsVisible = true; } } ShowPrograms(); }
private bool OnEditSchedule(UpcomingProgram upcoming) { if (upcoming != null) { Schedule sched = null; using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { sched = _tvSchedulerAgent.GetScheduleById(upcoming.ScheduleId); if (sched != null) { if (upcoming.GuideProgramId.HasValue && sched.Rules.FindRuleByType(ScheduleRuleType.ManualSchedule) == null) { TvProgramInfo.CurrentProgram = this.GuideAgent.GetProgramById(upcoming.GuideProgramId.Value); TvProgramInfo.Channel = upcoming.Channel; GUIWindowManager.ActivateWindow((int)WindowId.ProgramInfo); return(true); } else if (sched.Rules.FindRuleByType(ScheduleRuleType.ManualSchedule) != null) { ManualSchedule.channelType = upcoming.Channel.ChannelType; ManualSchedule.upcomingProgram = upcoming; GUIWindowManager.ActivateWindow((int)WindowId.ManualShedule); return(true); } } } } return(false); }
private void RefreshChannelsInGroup(ChannelType channelType) { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { RefreshChannelsInGroup(tvSchedulerAgent, channelType); } }
private string InternalGetScheduleNameById(Guid scheduleId) { lock (_scheduleNames) { if (!_scheduleNames.ContainsKey(scheduleId)) { try { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { _scheduleNames.Clear(); GetScheduleNames(tvSchedulerAgent, ScheduleType.Recording); GetScheduleNames(tvSchedulerAgent, ScheduleType.Alert); GetScheduleNames(tvSchedulerAgent, ScheduleType.Suggestion); } } catch { } } if (_scheduleNames.ContainsKey(scheduleId)) { return(_scheduleNames[scheduleId]); } return("?"); } }
public static void SetMusicProperties(string chanName, Guid channelId) { string logo = string.Empty; if (channelId != Guid.Empty && chanName != string.Empty) { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { logo = Utility.GetLogoImage(channelId, chanName, tvSchedulerAgent); } } else { chanName = string.Empty; } if (string.IsNullOrEmpty(logo)) { logo = "defaultMyRadioBig.png"; } GUIPropertyManager.RemovePlayerProperties(); GUIPropertyManager.SetProperty("#Play.Current.Thumb", logo); GUIPropertyManager.SetProperty("#Play.Current.ArtistThumb", chanName); GUIPropertyManager.SetProperty("#Play.Current.Album", chanName); GUIPropertyManager.SetProperty("#Play.Current.Title", chanName); GUIPropertyManager.SetProperty("#Play.Current.Artist", chanName); }
private void CacheMiniGuide() { lock (chacheLock) { System.Threading.Thread.Sleep(8000); while (!PluginMain.IsConnected()) { Thread.Sleep(2000); } Log.Debug("CacheChannelsThread: started"); using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { List <CurrentAndNextProgram> _currentAndNextPrograms = new List <CurrentAndNextProgram>(); try { ChannelGroup currgroup = PluginMain.Navigator.CurrentGroup; if (currgroup != null) { _currentAndNextPrograms = new List <CurrentAndNextProgram>(tvSchedulerAgent.GetCurrentAndNextForGroup(PluginMain.Navigator.CurrentGroup.ChannelGroupId, true, true, null)); } List <ChannelGroup> groups = PluginMain.Navigator.GetGroups(ChannelType.Television); foreach (ChannelGroup group in groups) { _currentAndNextPrograms = new List <CurrentAndNextProgram>(tvSchedulerAgent.GetCurrentAndNextForGroup(group.ChannelGroupId, true, true, null)); } } catch { Log.Error("CacheChannelsThread: error"); } _currentAndNextPrograms.Clear(); _currentAndNextPrograms = null; } Log.Debug("CacheChannelsThread: ended"); } }
public override bool OnFinish() { try { Cursor.Current = Cursors.WaitCursor; _destinationPanel.Enabled = false; _exportProgressBar.Minimum = 0; _exportProgressBar.Value = 0; _exportProgressBar.Maximum = this.Context.ImportChannels.Count; _exportProgressBar.Visible = true; Application.DoEvents(); using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent()) { _channelMembersByName.Clear(); _channelGroupsByName.Clear(); ChannelGroup[] allGroups = tvSchedulerAgent.GetAllChannelGroups(this.Context.ChannelType, false); foreach (ChannelGroup channelGroup in allGroups) { _channelGroupsByName[channelGroup.GroupName] = channelGroup; } int count = 0; foreach (ImportChannelsContext.ImportChannel importChannel in this.Context.ImportChannels) { _exportingFileLabel.Text = importChannel.Channel.DisplayName; Application.DoEvents(); ImportChannel(tvGuideAgent, tvSchedulerAgent, importChannel); _exportProgressBar.Value = ++count; } foreach (string groupName in _channelGroupsByName.Keys) { if (_channelMembersByName.ContainsKey(groupName)) { tvSchedulerAgent.SetChannelGroupMembers( _channelGroupsByName[groupName].ChannelGroupId, _channelMembersByName[groupName].ToArray()); } } Channels.ChannelLinks.Save(); } return(true); } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show(this, ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error); _destinationPanel.Enabled = true; _exportProgressBar.Visible = false; } finally { _exportingFileLabel.Text = String.Empty; Cursor.Current = Cursors.Default; } return(false); }
private void RefreshGroups(ChannelType channelType) { try { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { List <ChannelGroup> groups = new List <ChannelGroup>(tvSchedulerAgent.GetAllChannelGroups(channelType, true)); if (_currentChannelGroup != null && _currentChannelGroup.ChannelGroupId != ChannelGroup.AllTvChannelsGroupId && _currentChannelGroup.ChannelGroupId != ChannelGroup.AllRadioChannelsGroupId) { bool currentFound = false; foreach (ChannelGroup group in groups) { if (group.ChannelGroupId == _currentChannelGroup.ChannelGroupId) { currentFound = true; break; } } if (!currentFound) { _currentChannelGroup = null; } } bool hideAllChannelsGroup = false; using (Settings xmlreader = new MPSettings()) { hideAllChannelsGroup = xmlreader.GetValueAsBool("mytv", "hideAllChannelsGroup", false); } if (!hideAllChannelsGroup || groups.Count == 0) { groups.Add(new ChannelGroup() { ChannelGroupId = channelType == ChannelType.Television ? ChannelGroup.AllTvChannelsGroupId : ChannelGroup.AllRadioChannelsGroupId, ChannelType = channelType, GroupName = Utility.GetLocalizedText(TextId.AllChannels), Sequence = int.MaxValue, VisibleInGuide = true }); } _navigatorChannels[channelType].Groups = groups; if (_currentChannelGroup == null && _navigatorChannels[channelType].Groups.Count > 0) { _currentChannelGroup = _navigatorChannels[channelType].Groups[0]; RefreshChannelsInGroup(tvSchedulerAgent, channelType); } } } catch (Exception ex) { Log.Error("ChannelNavigator: Error in RefreshChannelGroups - {0}", ex.Message); } }
private IMBotMessage DoShowChannelsCommand(IMBotConversation conversation, IList <string> arguments) { if (arguments.Count == 0) { return(new IMBotMessage("Group name or number missing.", IMBotMessage.ErrorColor)); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { List <ChannelGroup> groups = GetAllGroups(tvSchedulerAgent, GetChannelType(conversation)); ChannelGroup group = null; int index; if (int.TryParse(arguments[0], out index)) { if (index < 1 || index > groups.Count) { return(new IMBotMessage("Unknown group number.", IMBotMessage.ErrorColor)); } group = groups[index - 1]; } else { foreach (ChannelGroup channelGroup in groups) { if (channelGroup.GroupName.Equals(arguments[0], StringComparison.CurrentCultureIgnoreCase)) { group = channelGroup; break; } } if (group == null) { return(new IMBotMessage("Unknown group name.", IMBotMessage.ErrorColor)); } } Channel[] channels = tvSchedulerAgent.GetChannelsInGroup(group.ChannelGroupId, true); StringBuilder replyText = new StringBuilder(); replyText.AppendFormat("Channels in {0}:", group.GroupName); foreach (Channel channel in channels) { replyText.AppendLine(); replyText.AppendFormat("{0,3} {1}", channel.LogicalChannelNumber.HasValue ? channel.LogicalChannelNumber.Value.ToString() : "-", channel.DisplayName); } return(new IMBotMessage(replyText.ToString(), true) { Footer = "Use 'show guide <number | name> [day-number]' to see the channel guide." }); } }
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); } } }
protected override void OnPaint(PaintEventArgs e) { Region clippingRegion = e.Graphics.Clip; using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { foreach (var cell in _channelCells) { Rectangle visibleRectangle = new Rectangle(cell.Rectangle.Location, cell.Rectangle.Size); visibleRectangle.Intersect(e.ClipRectangle); Region cellRegion = new Region(visibleRectangle); cellRegion.Intersect(clippingRegion); if (cellRegion.IsEmpty(e.Graphics)) { continue; } e.Graphics.SetClip(visibleRectangle); Padding innerPadding = new Padding(2, 2, 2, 2); if (cell.Channel != null) { Rectangle innerRectangle = new Rectangle(cell.Rectangle.Left + innerPadding.Left, cell.Rectangle.Top + innerPadding.Top, cell.Rectangle.Width - innerPadding.Horizontal, cell.Rectangle.Height - innerPadding.Vertical); Image logoImage = null; try { logoImage = ChannelLogosCache.GetLogoImage(tvSchedulerAgent, cell.Channel, (int)(64 * _widthFactor), (int)(64 * _heightFactor)); } catch { logoImage = null; } if (logoImage == null) { e.Graphics.DrawString(cell.Channel.DisplayName, _channelFont, _channelBrush, new RectangleF(innerRectangle.Left, innerRectangle.Top + 6, innerRectangle.Width, innerRectangle.Height)); } else { e.Graphics.DrawImage(logoImage, innerRectangle.Left + (int)Math.Round((innerRectangle.Width - logoImage.Width) / 2F), innerRectangle.Top + (int)Math.Round((innerRectangle.Height - logoImage.Height) / 2F), logoImage.Width, logoImage.Height); } } } } base.OnPaint(e); }
private void GetScheduleNames(SchedulerServiceAgent tvSchedulerAgent, ScheduleType type) { ScheduleSummary[] schedules = tvSchedulerAgent.GetAllSchedules(ChannelType.Television, type, false); foreach (ScheduleSummary schedule in schedules) { _scheduleNames.Add(schedule.ScheduleId, schedule.Name); } schedules = tvSchedulerAgent.GetAllSchedules(ChannelType.Radio, type, false); foreach (ScheduleSummary schedule in schedules) { _scheduleNames.Add(schedule.ScheduleId, schedule.Name); } }
private static void EnsureGuideChannelForDvbEpg(SchedulerServiceAgent tvSchedulerAgent, GuideServiceAgent tvGuideAgent, Channel channel, TvDatabase.Channel mpChannel) { if (!channel.GuideChannelId.HasValue) { string externalId = mpChannel.ExternalId; if (String.IsNullOrEmpty(externalId)) { externalId = mpChannel.DisplayName; } channel.GuideChannelId = tvGuideAgent.EnsureChannel(externalId, mpChannel.DisplayName, channel.ChannelType); tvSchedulerAgent.AttachChannelToGuide(channel.ChannelId, channel.GuideChannelId.Value); } }
private IMBotMessage DoSearchResults(IMBotConversation conversation, int resultNumber) { if (!conversation.Session.ContainsKey(SessionKey.FoundTitles)) { return(new IMBotMessage("No search results found, use search command.", IMBotMessage.ErrorColor)); } string[] titles = (string[])conversation.Session[SessionKey.FoundTitles]; if (resultNumber < 1 || resultNumber > titles.Length) { return(new IMBotMessage("Bad search result number.", IMBotMessage.ErrorColor)); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { 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)); ChannelProgram[] programs = tvSchedulerAgent.SearchGuideByTitle(GetChannelType(conversation), titles[resultNumber - 1], false); StringBuilder replyText = new StringBuilder(); int index = 0; foreach (ChannelProgram program in programs) { if (replyText.Length > 0) { replyText.AppendLine(); } replyText.AppendFormat("{0,3}» ", ++index); string appendText = AppendProgramIndicatorsPrefix(replyText, program.GetUniqueUpcomingProgramId(), upcomingRecordingsById, upcomingAlertsById, upcomingSuggestionsById); Utility.AppendProgramDetails(replyText, program.Channel, program); replyText.Append(appendText); } conversation.Session[SessionKey.Programs] = new Session.Programs(programs); return(new IMBotMessage(replyText.ToString(), true) { Footer = "Use 'record', 'cancel', 'uncancel' or 'delete schedule' with <number>." }); } }
private static IMBotMessage FindUpcomingRecording(SchedulerServiceAgent tvSchedulerAgent, IMBotConversation conversation, IList <string> arguments, out UpcomingProgram upcomingRecording) { upcomingRecording = null; IProgramSummary program = null; Channel channel = null; Guid? upcomingProgramId = null; int programNumber; if (!int.TryParse(arguments[0], out programNumber)) { return(new IMBotMessage("Bad program number.", IMBotMessage.ErrorColor)); } Session.Programs sessionPrograms = null; if (conversation.Session.ContainsKey(SessionKey.Programs)) { sessionPrograms = conversation.Session[SessionKey.Programs] as Session.Programs; } if (sessionPrograms != null) { program = sessionPrograms.GetProgramAt(programNumber, out channel, out upcomingProgramId); if (program == null) { return(new IMBotMessage("Bad program number.", IMBotMessage.ErrorColor)); } } else { return(new IMBotMessage("No programs.", IMBotMessage.ErrorColor)); } UpcomingProgram[] upcomingPrograms = tvSchedulerAgent.GetAllUpcomingPrograms(ScheduleType.Recording, true); foreach (UpcomingProgram upcomingProgram in upcomingPrograms) { bool idMatches = upcomingProgramId.HasValue && upcomingProgram.UpcomingProgramId == upcomingProgramId.Value; if ((idMatches || upcomingProgram.Title == program.Title) && upcomingProgram.Channel.ChannelId == channel.ChannelId && upcomingProgram.StartTime == program.StartTime) { upcomingRecording = upcomingProgram; return(null); } } return(new IMBotMessage("Program not found in upcoming recordings.", IMBotMessage.ErrorColor)); }
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); }
private void ConnectToArgusTV() { DisconnectFromArgusTV(); _plugin.InitializeArgusTVConnection(this); _notConnectedPanel.Visible = !_plugin.IsArgusTVConnectionInitialized; _channelsPanel.Visible = _plugin.IsArgusTVConnectionInitialized; LoadUncPaths(); if (_plugin.IsArgusTVConnectionInitialized) { _tvSchedulerAgent = new SchedulerServiceAgent(); } }
private static List <ChannelGroup> GetAllGroups(SchedulerServiceAgent tvSchedulerAgent, ChannelType channelType) { List <ChannelGroup> groups = new List <ChannelGroup>(tvSchedulerAgent.GetAllChannelGroups(channelType, true)); Guid allChannelsGroupId = (channelType == ChannelType.Television) ? ChannelGroup.AllTvChannelsGroupId : ChannelGroup.AllRadioChannelsGroupId; groups.Add(new ChannelGroup() { ChannelGroupId = allChannelsGroupId, ChannelType = channelType, GroupName = "All channels", Sequence = int.MaxValue, VisibleInGuide = true }); return(groups); }
private IMBotMessage DoCancelCommand(IMBotConversation conversation, IList <string> arguments, bool cancel) { if (arguments.Count == 0) { return(new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor)); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { UpcomingProgram upcomingRecording; IMBotMessage result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording); if (result == null) { StringBuilder replyText = new StringBuilder(); if (cancel) { if (upcomingRecording.IsPartOfSeries) { tvSchedulerAgent.CancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId, upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime); replyText.Append("Cancelled "); } else { tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId); replyText.Append("Deleted schedule for "); } } else { tvSchedulerAgent.UncancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId, upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime); replyText.Append("Uncancelled "); } Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording); replyText.Append("."); result = new IMBotMessage(replyText.ToString()); } return(result); } }
public Channel GetChannelByNumber(ChannelType channelType, int channelNr, out ChannelGroup channelGroup) { channelGroup = _currentChannelGroup; if (_navigatorChannels[channelType].ChannelsByNumber.ContainsKey(channelNr)) { channelGroup = _navigatorChannels[channelType].GroupsByChannelNumber[channelNr]; return(_navigatorChannels[channelType].ChannelsByNumber[channelNr]); } Channel channel = null; if (_navigatorChannels[channelType].Channels != null) { channel = FindChannelByNumber(_navigatorChannels[channelType].Channels, channelNr); if (channel == null) { try { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { foreach (ChannelGroup group in _navigatorChannels[channelType].Groups) { if (group != _currentChannelGroup) { channel = FindChannelInGroupByNumber(tvSchedulerAgent, group.ChannelGroupId, channelNr); if (channel != null) { channelGroup = group; break; } } } } } catch (Exception ex) { Log.Error("ChannelNavigator: Error in GetChannelByNumber - {0}", ex.Message); } } } _navigatorChannels[channelType].ChannelsByNumber[channelNr] = channel; _navigatorChannels[channelType].GroupsByChannelNumber[channelNr] = channelGroup; return(channel); }
private static void RefreshCurrentAndNext(Channel channel, bool forceUpdate) { TimeSpan ts = DateTime.Now - _programUpdateTimer; if (ts.TotalMilliseconds < 1000 && !forceUpdate) { return; } _programUpdateTimer = DateTime.Now; lock (_refreshCurrAndNextLock) { using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent()) using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { CurrentAndNextProgram currentAndNext = tvSchedulerAgent.GetCurrentAndNextForChannel(channel.ChannelId, false, null); if (currentAndNext != null) { if (currentAndNext.Current != null) { _currentProgram = tvGuideAgent.GetProgramById(currentAndNext.Current.GuideProgramId); } else { _currentProgram = null; } if (currentAndNext.Next != null) { _nextProgram = tvGuideAgent.GetProgramById(currentAndNext.Next.GuideProgramId); } else { _nextProgram = null; } } else { _nextProgram = null; _currentProgram = null; } } } }
private void HandleAlerts() { UpcomingProgram[] upcomingAlerts; AddressList alertContactFilter; lock (_alertsLock) { if (_upcomingAlerts == null) { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { _upcomingAlerts = tvSchedulerAgent.GetAllUpcomingPrograms(ScheduleType.Alert, false); } } EnsureAlertContactFilter(); upcomingAlerts = _upcomingAlerts; alertContactFilter = _alertContactFilter; } bool sentAlert = false; foreach (UpcomingProgram upcomingAlert in upcomingAlerts) { if (upcomingAlert.StopTime > DateTime.Now && upcomingAlert.StartTime.AddMinutes(-_alertMinutes) <= DateTime.Now) { if (!IsRecentlyAlerted(upcomingAlert)) { if (sentAlert) { // We just sent out an alert, seems this is needed to give the system // some extra time :-( Thread.Sleep(100); } if (BroadcastAlert(alertContactFilter, upcomingAlert)) { _recentlyAlerted.Add(upcomingAlert); sentAlert = true; } } } } }
private IMBotMessage DoSearchCommand(IMBotConversation conversation, IList <string> arguments) { if (arguments.Count == 0) { return(new IMBotMessage("Search text or result number is missing.", IMBotMessage.ErrorColor)); } int resultNumber; if (int.TryParse(arguments[0], out resultNumber)) { return(DoSearchResults(conversation, resultNumber)); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { string searchText = arguments[0]; if (searchText.StartsWith(@"\")) { searchText = searchText.Substring(1); } string[] titles = tvSchedulerAgent.GetTitlesByPartialTitle(GetChannelType(conversation), searchText, false); StringBuilder replyText = new StringBuilder(); replyText.AppendFormat("Found {0} in the following titles:", searchText); int index = 0; foreach (string title in titles) { replyText.AppendLine(); replyText.AppendFormat("{0,3}» {1}", ++index, title); } conversation.Session.Remove(SessionKey.Programs); conversation.Session[SessionKey.FoundTitles] = titles; return(new IMBotMessage(replyText.ToString(), true) { Footer = "Use 'search <number>' to see the programs." }); } }
private void RefreshChannelsInGroup(SchedulerServiceAgent tvSchedulerAgent, ChannelType channelType) { try { if (_currentChannelGroup != null) { _navigatorChannels[channelType].Channels = new List <Channel>( tvSchedulerAgent.GetChannelsInGroup(_currentChannelGroup.ChannelGroupId, true)); } else { _navigatorChannels[channelType].Channels = new List <Channel>(); } _navigatorChannels[channelType].ChannelsByNumber.Clear(); _navigatorChannels[channelType].GroupsByChannelNumber.Clear(); } catch (Exception ex) { Log.Error("ChannelNavigator: Error in RefreshChannelsInGroup - {0}", ex.Message); } }
public void SaveGuideDataInArgusTV(ImportGuideChannel channel, ChannelType channelType, GuideProgram[] guideProgramData, bool updateChannelName) { if (guideProgramData.Length > 0) { using (GuideServiceAgent guideServiceAgent = new GuideServiceAgent()) { using (SchedulerServiceAgent schedulerServiceAgent = new SchedulerServiceAgent()) { Guid guideChannelId = EnsureDefaultChannel(channel, channelType, updateChannelName); foreach (GuideProgram guideProgram in guideProgramData) { guideProgram.GuideChannelId = guideChannelId; try { guideServiceAgent.ImportProgram(guideProgram, GuideSource.XmlTv); } catch { } } } } } }
private void LoadGroups() { ChannelType channelType = this.ChannelType; if (!_channelGroups.ContainsKey(channelType)) { try { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { List <ChannelGroup> channelGroups = new List <ChannelGroup>(tvSchedulerAgent.GetAllChannelGroups(channelType, true)); ChannelGroup allChannelsGroup = new ChannelGroup() { ChannelGroupId = channelType == ChannelType.Television ? ChannelGroup.AllTvChannelsGroupId : ChannelGroup.AllRadioChannelsGroupId, ChannelType = channelType, GroupName = "All Channels", VisibleInGuide = true }; if (this.ShowAllChannelsOnTop) { channelGroups.Insert(0, allChannelsGroup); } else { channelGroups.Add(allChannelsGroup); } _channelGroups[channelType] = channelGroups; } } catch (Exception ex) { MessageBox.Show(this, ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error); } } _channelGroupsComboBox.DataSource = _channelGroups[channelType]; _channelGroupsComboBox.DisplayMember = "GroupName"; _channelGroupsComboBox.ValueMember = "ChannelGroupId"; }
private void ProcessAlerts(DateTime preNotifySecs) { using (SchedulerServiceAgent tvschedulerAgent = new SchedulerServiceAgent()) { List <UpcomingProgram> upcomingPrograms = new List <UpcomingProgram>( tvschedulerAgent.GetAllUpcomingPrograms(ScheduleType.Alert, false)); if (upcomingPrograms.Count > 0) { DateTime _now = DateTime.Now; foreach (UpcomingProgram program in upcomingPrograms) { if (preNotifySecs > program.StartTime && _now < program.StopTime && !AlreadyNotifiedAlerts.Contains(program.ScheduleId)) { NotifyProgram(program); AlreadyNotifiedAlerts.Add(program.ScheduleId); Log.Debug("NotifyManager: AlreadyNotifiedAlerts.Add {0}", program.Title); } else if (_now >= program.StopTime && AlreadyNotifiedConflict.Contains(program.ScheduleId)) { Log.Debug("NotifyManager: AlreadyNotifiedAlerts.Remove"); AlreadyNotifiedAlerts.Remove(program.ScheduleId); } if (program.StartTime < _nextCheckTimeAlerts && program.StartTime > _now) { _nextCheckTimeAlerts = program.StartTime; } if (program.StopTime < _nextCheckTimeAlerts && program.StopTime > _now) { _nextCheckTimeAlerts = program.StopTime; } } } } }
private IMBotMessage DoDeleteScheduleCommand(IMBotConversation conversation, IList <string> arguments) { if (arguments.Count == 0) { return(new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor)); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { UpcomingProgram upcomingRecording; IMBotMessage result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording); if (result == null) { StringBuilder replyText = new StringBuilder(); tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId); replyText.Append("Deleted schedule for "); Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording); replyText.Append("."); result = new IMBotMessage(replyText.ToString()); } return(result); } }
private IMBotMessage DoShowChannelGroupsCommand(IMBotConversation conversation, IList <string> arguments) { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { List <ChannelGroup> groups = GetAllGroups(tvSchedulerAgent, GetChannelType(conversation)); StringBuilder replyText = new StringBuilder(); int index = 1; foreach (ChannelGroup group in groups) { if (replyText.Length > 0) { replyText.AppendLine(); } replyText.AppendFormat("{0,3}» {1}", index++, group.GroupName); } return(new IMBotMessage(replyText.ToString(), true) { Footer = "Use 'show channels <number | name>' to see the programs in a group." }); } }
private void TuneLiveStream(Channel channel) { Log.Debug("ChannelNavigator: TuneLiveStream(), channel = {0}", channel.DisplayName); if (channel != null) { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { LiveStream liveStream = _liveStream; CurrentAndNextProgram currentAndNext = tvSchedulerAgent.GetCurrentAndNextForChannel(channel.ChannelId, true, _liveStream);//null); _currentChannel = channel; _doingChannelChange = true; RenderBlackImage(); if (liveStream != null) { try { g_Player.PauseGraph(); g_Player.OnZapping(0x80); result = this.ControlAgent.TuneLiveStream(channel, ref liveStream); Log.Debug("ChannelNavigator: First try to re-tune the existing TV stream (staying on the same card), result = {0}", result); if (result == LiveStreamResult.Succeeded) { if (_isAnalog) g_Player.OnZapping(-1); double duration = g_Player.Duration; if (g_Player.Duration < 0.0) result = LiveStreamResult.UnknownError; else { g_Player.SeekAbsolute(duration); g_Player.ContinueGraph(); } } else if (result == LiveStreamResult.NoRetunePossible)// not mapped to card, card in use by recorder or other user ---> start new stream { // Now re-try the new channel with a new stream. Log.Debug("ChannelNavigator: Seems a re-tune has failed, stop the current stream and start a new one"); SilentlyStopLiveStream(liveStream); result = StartAndPlayNewLiveStream(channel, liveStream); } } catch { result = LiveStreamResult.UnknownError; Log.Error("ChannelNavigator: TuneLiveStream error"); } } else { result = StartAndPlayNewLiveStream(channel,liveStream); } _doingChannelChange = false; if (result == LiveStreamResult.Succeeded) { _lastChannelChangeFailed = false; StopRenderBlackImage(); } else { _lastChannelChangeFailed = true; SilentlyStopLiveStream(liveStream); ChannelTuneFailedNotifyUser(result, channel); } } } }
public Channel GetChannelByNumber(ChannelType channelType, int channelNr, out ChannelGroup channelGroup) { channelGroup = _currentChannelGroup; if (_navigatorChannels[channelType].ChannelsByNumber.ContainsKey(channelNr)) { channelGroup = _navigatorChannels[channelType].GroupsByChannelNumber[channelNr]; return _navigatorChannels[channelType].ChannelsByNumber[channelNr]; } Channel channel = null; if (_navigatorChannels[channelType].Channels != null) { channel = FindChannelByNumber(_navigatorChannels[channelType].Channels, channelNr); if (channel == null) { try { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { foreach (ChannelGroup group in _navigatorChannels[channelType].Groups) { if (group != _currentChannelGroup) { channel = FindChannelInGroupByNumber(tvSchedulerAgent, group.ChannelGroupId, channelNr); if (channel != null) { channelGroup = group; break; } } } } } catch (Exception ex) { Log.Error("ChannelNavigator: Error in GetChannelByNumber - {0}", ex.Message); } } } _navigatorChannels[channelType].ChannelsByNumber[channelNr] = channel; _navigatorChannels[channelType].GroupsByChannelNumber[channelNr] = channelGroup; return channel; }
private IMBotMessage DoSearchResults(IMBotConversation conversation, int resultNumber) { if (!conversation.Session.ContainsKey(SessionKey.FoundTitles)) { return new IMBotMessage("No search results found, use search command.", IMBotMessage.ErrorColor); } string[] titles = (string[])conversation.Session[SessionKey.FoundTitles]; if (resultNumber < 1 || resultNumber > titles.Length) { return new IMBotMessage("Bad search result number.", IMBotMessage.ErrorColor); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { 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)); ChannelProgram[] programs = tvSchedulerAgent.SearchGuideByTitle(GetChannelType(conversation), titles[resultNumber - 1], false); StringBuilder replyText = new StringBuilder(); int index = 0; foreach (ChannelProgram program in programs) { if (replyText.Length > 0) { replyText.AppendLine(); } replyText.AppendFormat("{0,3}» ", ++index); string appendText = AppendProgramIndicatorsPrefix(replyText, program.GetUniqueUpcomingProgramId(), upcomingRecordingsById, upcomingAlertsById, upcomingSuggestionsById); Utility.AppendProgramDetails(replyText, program.Channel, program); replyText.Append(appendText); } conversation.Session[SessionKey.Programs] = new Session.Programs(programs); return new IMBotMessage(replyText.ToString(), true) { Footer = "Use 'record', 'cancel', 'uncancel' or 'delete schedule' with <number>." }; } }
private static void SetHomeChannelProperties(string guiPropertyPrefix, Guid channelId, string channelName) { string logo = String.Empty; if (channelId != Guid.Empty) { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { logo = Utility.GetLogoImage(channelId, channelName, tvSchedulerAgent); } if (String.IsNullOrEmpty(logo)) { logo = "defaultVideoBig.png"; } } GUIPropertyManager.SetProperty(guiPropertyPrefix + ".View.channel", channelName); GUIPropertyManager.SetProperty(guiPropertyPrefix + ".View.thumb", logo); }
private void RefreshGroups(ChannelType channelType) { try { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { List<ChannelGroup> groups = new List<ChannelGroup>(tvSchedulerAgent.GetAllChannelGroups(channelType, true)); if (_currentChannelGroup != null && _currentChannelGroup.ChannelGroupId != ChannelGroup.AllTvChannelsGroupId && _currentChannelGroup.ChannelGroupId != ChannelGroup.AllRadioChannelsGroupId) { bool currentFound = false; foreach (ChannelGroup group in groups) { if (group.ChannelGroupId == _currentChannelGroup.ChannelGroupId) { currentFound = true; break; } } if (!currentFound) { _currentChannelGroup = null; } } bool hideAllChannelsGroup = false; using (Settings xmlreader = new MPSettings()) { hideAllChannelsGroup = xmlreader.GetValueAsBool("mytv", "hideAllChannelsGroup", false); } if (!hideAllChannelsGroup || groups.Count == 0) { groups.Add(new ChannelGroup( channelType == ChannelType.Television ? ChannelGroup.AllTvChannelsGroupId : ChannelGroup.AllRadioChannelsGroupId, (int)channelType, Utility.GetLocalizedText(TextId.AllChannels), true, int.MaxValue, 0)); } _navigatorChannels[channelType].Groups = groups; if (_currentChannelGroup == null && _navigatorChannels[channelType].Groups.Count > 0) { _currentChannelGroup = _navigatorChannels[channelType].Groups[0]; RefreshChannelsInGroup(tvSchedulerAgent, channelType); } } } catch (Exception ex) { Log.Error("ChannelNavigator: Error in RefreshChannelGroups - {0}", ex.Message); } }
private void SetCurrentChannelLogo() { string strChannel = GetChannelName(); Guid _channelId = GetChannelId(); string strLogo = string.Empty; if (_channelId != Guid.Empty && strChannel != string.Empty) { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { strLogo = Utility.GetLogoImage(_channelId, strChannel, tvSchedulerAgent); } } if (imgTvChannelLogo != null) { if (!string.IsNullOrEmpty(strLogo)) { imgTvChannelLogo.SetFileName(strLogo); m_bNeedRefresh = true; imgTvChannelLogo.Visible = true; } else { imgTvChannelLogo.Visible = false; } } }
private IMBotMessage DoShowUpcomingCommand(IMBotConversation conversation, ScheduleType type) { if (type == ScheduleType.Recording) { using (ControlServiceAgent tvControlAgent = new ControlServiceAgent()) { UpcomingRecording[] upcomingRecordings = tvControlAgent.GetAllUpcomingRecordings(UpcomingRecordingsFilter.Recordings, false); StringBuilder replyText = new StringBuilder(); if (upcomingRecordings.Length > 0) { int index = 0; foreach (UpcomingRecording upcomingRecording in upcomingRecordings) { if (replyText.Length > 0) { replyText.AppendLine(); } PluginService pluginService = null; if (upcomingRecording.CardChannelAllocation != null) { pluginService = RecorderTunersCache.GetRecorderTunerById(upcomingRecording.CardChannelAllocation.RecorderTunerId); } replyText.AppendFormat("{0,3}» ", ++index); Utility.AppendProgramDetails(replyText, upcomingRecording.Program.Channel, upcomingRecording.Program); replyText.AppendFormat(" [{0}]", pluginService == null ? "-" : pluginService.Name); } conversation.Session[SessionKey.Programs] = new Session.Programs(upcomingRecordings); return new IMBotMessage(replyText.ToString(), true) { Footer = "Use 'cancel', 'uncancel' or 'delete schedule' with <number>." }; } } } else { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { UpcomingProgram[] upcomingPrograms = tvSchedulerAgent.GetAllUpcomingPrograms(type, false); StringBuilder replyText = new StringBuilder(); if (upcomingPrograms.Length > 0) { int index = 0; foreach (UpcomingProgram upcomingProgram in upcomingPrograms) { if (replyText.Length > 0) { replyText.AppendLine(); } replyText.AppendFormat("{0,3}» ", ++index); Utility.AppendProgramDetails(replyText, upcomingProgram.Channel, upcomingProgram); } conversation.Session[SessionKey.Programs] = new Session.Programs(upcomingPrograms); return new IMBotMessage(replyText.ToString(), true) { Footer = "Use 'record', 'cancel', 'uncancel' or 'delete schedule' with <number>." }; } } } return new IMBotMessage("There are no upcoming " + type.ToString().ToLowerInvariant() + "s."); }
/// <summary> /// Fill the list with channels /// </summary> private void FillChannelList() { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { _channelsListControl.Clear(); int i = 0; int SelectedID = 0; string ChannelLogo = string.Empty; if (_currentGroup != null) { _currentAndNextPrograms = new List<CurrentAndNextProgram>( tvSchedulerAgent.GetCurrentAndNextForGroup(_currentGroup.ChannelGroupId, true, true, PluginMain.Navigator.LiveStream)); } else { _currentAndNextPrograms = new List<CurrentAndNextProgram>(); } Channel currentChannel = PluginMain.Navigator.CurrentChannel; Channel prevChannel = PluginMain.Navigator.GetPreviousChannel(this.ChannelType); foreach (CurrentAndNextProgram currentAndNext in _currentAndNextPrograms) { i++; sb.Length = 0; GUIListItem item = new GUIListItem(""); item.TVTag = currentAndNext.Channel; sb.Append(currentAndNext.Channel.DisplayName); ChannelLogo = Utility.GetLogoImage(currentAndNext.Channel, tvSchedulerAgent); if (!string.IsNullOrEmpty(ChannelLogo)) { item.IconImageBig = ChannelLogo; item.IconImage = ChannelLogo; } else { item.IconImageBig = string.Empty; item.IconImage = string.Empty; } ActiveRecording activeRecording; if (PluginMain.IsChannelRecording(currentAndNext.Channel.ChannelId, out activeRecording)) { if (_showStateIcons) { item.PinImage = RecordingIcon; } else { sb.Append(" "); sb.Append(recordingText); } item.IsPlayed = (currentAndNext.LiveState == ChannelLiveState.NotTunable || currentAndNext.LiveState == ChannelLiveState.NoFreeCard); } else { switch (currentAndNext.LiveState) { case ChannelLiveState.NotTunable: case ChannelLiveState.NoFreeCard: item.IsPlayed = true; if (_showStateIcons) { item.PinImage = UnavailableIcon; } else { sb.Append(" "); sb.Append(unavailableText); } break; default: item.IsPlayed = false; if (_showStateIcons) { item.PinImage = AvailableIcon; } break; } } if (currentChannel != null) { if (currentChannel.ChannelId == currentAndNext.Channel.ChannelId) { item.IsRemote = true; SelectedID = _channelsListControl.Count; if (_showStateIcons && item.PinImage != RecordingIcon && item.PinImage != UnavailableIcon) { item.PinImage = TimeshiftingIcon; } else if (!_showStateIcons) { sb.Append(" "); sb.Append(timeshiftingText); } } } else if (prevChannel != null && prevChannel.ChannelId == currentAndNext.Channel.ChannelId) { item.IsRemote = true; SelectedID = _channelsListControl.Count; } sbTmp.Length = 0; bool hasNow = currentAndNext.Current != null; if (hasNow) { sbTmp.Append(currentAndNext.Current.CreateProgramTitle()); } else { sbTmp.Append(noDataAvailableText); } item.Label2 = sbTmp.ToString(); sbTmp.Insert(0, nowText); item.Label3 = sbTmp.ToString(); sbTmp.Length = 0; if (_showChannelNumber) { sb.Append(" - "); if (!_byIndex) { if (currentAndNext.Channel.LogicalChannelNumber.HasValue) { sb.Append(currentAndNext.Channel.LogicalChannelNumber.Value.ToString()); } } else { sb.Append(i); } } if (hasNow) { sb.Append(" - "); sb.Append(currentAndNext.CurrentPercentageComplete); sb.Append("%"); } if (currentAndNext.Next != null) { sbTmp.Append(/*currentAndNext.Next.StartTime.ToShortTimeString() + " " + */currentAndNext.Next.CreateProgramTitle()); } else { sbTmp.Append(noDataAvailableText); } item.Label2 = sb.ToString(); sbTmp.Insert(0, nextText); item.Label = sbTmp.ToString(); _channelsListControl.Add(item); } _channelsListControl.SelectedListItemIndex = SelectedID; Log.Debug("miniguide: state check + filling channel list completed"); if (_channelsListControl.GetID == 37) { GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SETFOCUS, GetID, 0, 37, 0, 0, null); OnMessage(msg); } sb.Length = 0; sbTmp.Length = 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); } } }
private IMBotMessage DoShowChannelsCommand(IMBotConversation conversation, IList<string> arguments) { if (arguments.Count == 0) { return new IMBotMessage("Group name or number missing.", IMBotMessage.ErrorColor); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { List<ChannelGroup> groups = GetAllGroups(tvSchedulerAgent, GetChannelType(conversation)); ChannelGroup group = null; int index; if (int.TryParse(arguments[0], out index)) { if (index < 1 || index > groups.Count) { return new IMBotMessage("Unknown group number.", IMBotMessage.ErrorColor); } group = groups[index - 1]; } else { foreach (ChannelGroup channelGroup in groups) { if (channelGroup.GroupName.Equals(arguments[0], StringComparison.CurrentCultureIgnoreCase)) { group = channelGroup; break; } } if (group == null) { return new IMBotMessage("Unknown group name.", IMBotMessage.ErrorColor); } } Channel[] channels = tvSchedulerAgent.GetChannelsInGroup(group.ChannelGroupId, true); StringBuilder replyText = new StringBuilder(); replyText.AppendFormat("Channels in {0}:", group.GroupName); foreach (Channel channel in channels) { replyText.AppendLine(); replyText.AppendFormat("{0,3} {1}", channel.LogicalChannelNumber.HasValue ? channel.LogicalChannelNumber.Value.ToString() : "-", channel.DisplayName); } return new IMBotMessage(replyText.ToString(), true) { Footer = "Use 'show guide <number | name> [day-number]' to see the channel guide." }; } }
private IMBotMessage DoShowChannelGroupsCommand(IMBotConversation conversation, IList<string> arguments) { using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { List<ChannelGroup> groups = GetAllGroups(tvSchedulerAgent, GetChannelType(conversation)); StringBuilder replyText = new StringBuilder(); int index = 1; foreach (ChannelGroup group in groups) { if (replyText.Length > 0) { replyText.AppendLine(); } replyText.AppendFormat("{0,3}» {1}", index++, group.GroupName); } return new IMBotMessage(replyText.ToString(), true) { Footer = "Use 'show channels <number | name>' to see the programs in a group." }; } }
private void ChannelTuneFailedNotifyUser(LiveStreamResult result, Channel channel) { string TuningResult = string.Empty; switch (result) { case LiveStreamResult.ChannelTuneFailed: TuningResult = (Utility.GetLocalizedText(TextId.ChannelTuneFailed)); break; case LiveStreamResult.NoFreeCardFound: TuningResult = (Utility.GetLocalizedText(TextId.NoFreeCardFound)); break; case LiveStreamResult.NotSupported: TuningResult = (Utility.GetLocalizedText(TextId.NotSupported)); break; case LiveStreamResult.NoRetunePossible: TuningResult = (Utility.GetLocalizedText(TextId.NoRetunePossible)); break; case LiveStreamResult.IsScrambled: TuningResult = (Utility.GetLocalizedText(TextId.IsScrambled)); break; case LiveStreamResult.UnknownError: TuningResult = (Utility.GetLocalizedText(TextId.UnknownError)); break; } if (GUIWindowManager.ActiveWindow == (int)(int)GUIWindow.Window.WINDOW_TVFULLSCREEN) { // If failed and wasPlaying TV, left screen as it is and show zaposd with error message GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_TV_ERROR_NOTIFY, GUIWindowManager.ActiveWindow, 0, 0, 0, 0, null); msg.SendToTargetWindow = true; msg.Object = TuningResult; // forward error info object msg.TargetWindowId = (int)(int)GUIWindow.Window.WINDOW_TVFULLSCREEN; GUIGraphicsContext.SendMessage(msg); } else { // if not fulscreen, show notify dialog with the error message string caption = string.Empty; string tvlogo = string.Empty; if (channel != null) { _navigatorChannels[_currentChannel.ChannelType].PreviousChannel = channel; _currentChannel = null; using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent()) { tvlogo = Utility.GetLogoImage(channel, SchedulerAgent); } if (channel.ChannelType == ChannelType.Television) caption = GUILocalizeStrings.Get(605) + " - " + channel.DisplayName; else caption = GUILocalizeStrings.Get(665) + " - " + channel.DisplayName; } GUIDialogNotify pDlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); if (pDlgNotify != null) { pDlgNotify.Reset(); pDlgNotify.ClearAll(); pDlgNotify.SetHeading(caption); if (!string.IsNullOrEmpty(TuningResult)) { pDlgNotify.SetText(TuningResult); } pDlgNotify.SetImage(tvlogo); pDlgNotify.TimeOut = 5; pDlgNotify.DoModal(GUIWindowManager.ActiveWindow); } } }
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; }
private Channel FindChannelInGroupByNumber(SchedulerServiceAgent tvSchedulerAgent, Guid channelGroupId, int channelNr) { return FindChannelByNumber(new List<Channel>(tvSchedulerAgent.GetChannelsInGroup(channelGroupId, true)), channelNr); }
private void ImportEpgPrograms(EpgChannel epgChannel) { if (!this.IsArgusTVConnectionInitialized) { InitializeArgusTVConnection(null); } if (this.IsArgusTVConnectionInitialized) { TvDatabase.TvBusinessLayer layer = new TvDatabase.TvBusinessLayer(); bool epgSyncOn = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncOn, false.ToString()).Value); if (epgSyncOn) { DVBBaseChannel dvbChannel = epgChannel.Channel as DVBBaseChannel; if (dvbChannel != null) { TvDatabase.Channel mpChannel = layer.GetChannelByTuningDetail(dvbChannel.NetworkId, dvbChannel.TransportId, dvbChannel.ServiceId); if (mpChannel != null) { Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms(): received {0} programs on {1}", epgChannel.Programs.Count, mpChannel.DisplayName); using (CoreServiceAgent coreAgent = new CoreServiceAgent()) using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent()) { bool epgSyncAutoCreateChannels = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncAutoCreateChannels, false.ToString()).Value); bool epgSyncAutoCreateChannelsWithGroup = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncAutoCreateChannelsWithGroup, false.ToString()).Value); string epgLanguages = layer.GetSetting("epgLanguages").Value; Channel channel = EnsureChannelForDvbEpg(tvSchedulerAgent, mpChannel, epgSyncAutoCreateChannels, epgSyncAutoCreateChannelsWithGroup); if (channel != null) { EnsureGuideChannelForDvbEpg(tvSchedulerAgent, tvGuideAgent, channel, mpChannel); List<GuideProgram> guidePrograms = new List<GuideProgram>(); foreach (EpgProgram epgProgram in epgChannel.Programs) { string title; string description; string genre; int starRating; string classification; int parentalRating; GetProgramInfoForLanguage(epgProgram.Text, epgLanguages, out title, out description, out genre, out starRating, out classification, out parentalRating); if (!String.IsNullOrEmpty(title)) { GuideProgram guideProgram = new GuideProgram(); guideProgram.GuideChannelId = channel.GuideChannelId.Value; guideProgram.StartTime = epgProgram.StartTime; guideProgram.StopTime = epgProgram.EndTime; guideProgram.StartTimeUtc = epgProgram.StartTime.ToUniversalTime(); guideProgram.StopTime = epgProgram.EndTime; guideProgram.StopTimeUtc = epgProgram.EndTime.ToUniversalTime(); guideProgram.Title = title; guideProgram.Description = description; guideProgram.Category = genre; guideProgram.Rating = classification; guideProgram.StarRating = starRating / 7.0; guidePrograms.Add(guideProgram); } } _dvbEpgThread.ImportProgramsAsync(guidePrograms); } else { Log.Info("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms() failed to ensure channel."); } } } else { Log.Info("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms() failed to find MP channel."); } } } } }
private void RefreshChannelsInGroup(SchedulerServiceAgent tvSchedulerAgent, ChannelType channelType) { try { if (_currentChannelGroup != null) { _navigatorChannels[channelType].Channels = new List<Channel>( tvSchedulerAgent.GetChannelsInGroup(_currentChannelGroup.ChannelGroupId, true)); } else { _navigatorChannels[channelType].Channels = new List<Channel>(); } _navigatorChannels[channelType].ChannelsByNumber.Clear(); _navigatorChannels[channelType].GroupsByChannelNumber.Clear(); } catch (Exception ex) { Log.Error("ChannelNavigator: Error in RefreshChannelsInGroup - {0}", ex.Message); } }
private void ImportEpgPrograms(EpgChannel epgChannel) { if (!this.IsArgusTVConnectionInitialized) { InitializeArgusTVConnection(null); } if (this.IsArgusTVConnectionInitialized) { TvDatabase.TvBusinessLayer layer = new TvDatabase.TvBusinessLayer(); bool epgSyncOn = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncOn, false.ToString()).Value); if (epgSyncOn) { DVBBaseChannel dvbChannel = epgChannel.Channel as DVBBaseChannel; if (dvbChannel != null) { TvDatabase.Channel mpChannel = layer.GetChannelByTuningDetail(dvbChannel.NetworkId, dvbChannel.TransportId, dvbChannel.ServiceId); if (mpChannel != null) { Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms(): received {0} programs on {1}", epgChannel.Programs.Count, mpChannel.DisplayName); using (CoreServiceAgent coreAgent = new CoreServiceAgent()) using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent()) { bool epgSyncAutoCreateChannels = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncAutoCreateChannels, false.ToString()).Value); bool epgSyncAutoCreateChannelsWithGroup = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncAutoCreateChannelsWithGroup, false.ToString()).Value); string epgLanguages = layer.GetSetting("epgLanguages").Value; Channel channel = EnsureChannelForDvbEpg(tvSchedulerAgent, mpChannel, epgSyncAutoCreateChannels, epgSyncAutoCreateChannelsWithGroup); if (channel != null) { EnsureGuideChannelForDvbEpg(tvSchedulerAgent, tvGuideAgent, channel, mpChannel); List <GuideProgram> guidePrograms = new List <GuideProgram>(); foreach (EpgProgram epgProgram in epgChannel.Programs) { string title; string description; string genre; int starRating; string classification; int parentalRating; GetProgramInfoForLanguage(epgProgram.Text, epgLanguages, out title, out description, out genre, out starRating, out classification, out parentalRating); if (!String.IsNullOrEmpty(title)) { GuideProgram guideProgram = new GuideProgram(); guideProgram.GuideChannelId = channel.GuideChannelId.Value; guideProgram.StartTime = epgProgram.StartTime; guideProgram.StopTime = epgProgram.EndTime; guideProgram.StartTimeUtc = epgProgram.StartTime.ToUniversalTime(); guideProgram.StopTime = epgProgram.EndTime; guideProgram.StopTimeUtc = epgProgram.EndTime.ToUniversalTime(); guideProgram.Title = title; guideProgram.Description = description; guideProgram.Category = genre; guideProgram.Rating = classification; guideProgram.StarRating = starRating / 7.0; guidePrograms.Add(guideProgram); } } _dvbEpgThread.ImportProgramsAsync(guidePrograms); } else { Log.Info("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms() failed to ensure channel."); } } } else { Log.Info("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms() failed to find MP channel."); } } } } }
private void OnActiveRecordings(List<Guid> ignoreActiveRecordings) { using (ControlServiceAgent tvControlAgent = new ControlServiceAgent()) { List<ActiveRecording> activeRecordings = new List<ActiveRecording>( tvControlAgent.GetActiveRecordings()); if (activeRecordings != null && activeRecordings.Count > 0) { GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU); if (dlg == null) { return; } dlg.Reset(); dlg.SetHeading(200052); // Active Recordings List<ActiveRecording> listedRecordings = new List<ActiveRecording>(); foreach (ActiveRecording activeRecording in activeRecordings) { if (!ignoreActiveRecordings.Contains(activeRecording.RecordingId)) { GUIListItem item = new GUIListItem(); string channelName = activeRecording.Program.Channel.DisplayName; string programTitle = activeRecording.Program.Title; string time = String.Format("{0}-{1}", activeRecording.Program.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat), activeRecording.Program.StopTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat)); item.Label = channelName; item.Label2 = programTitle + " " + time; string strLogo = string.Empty; using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { strLogo = Utility.GetLogoImage(activeRecording.Program.Channel, tvSchedulerAgent); } if (string.IsNullOrEmpty(strLogo)) { strLogo = "defaultVideoBig.png"; } item.IconImage = strLogo; item.IconImageBig = strLogo; dlg.Add(item); listedRecordings.Add(activeRecording); } } dlg.SelectedLabel = listedRecordings.Count - 1; dlg.DoModal(this.GetID); if (dlg.SelectedLabel < 0 || listedRecordings.Count == 0 || (dlg.SelectedLabel - 1 > listedRecordings.Count)) { return; } ActiveRecording selectedRecording = listedRecordings[dlg.SelectedLabel]; listedRecordings = null; bool deleted = OnAbortActiveRecording(selectedRecording); if (deleted && !ignoreActiveRecordings.Contains(selectedRecording.RecordingId)) { ignoreActiveRecordings.Add(selectedRecording.RecordingId); } if (deleted) { OnActiveRecordings(ignoreActiveRecordings); //keep on showing the list until --> 1) user leaves menu, 2) no more active recordings } } else if (ignoreActiveRecordings == null || ignoreActiveRecordings.Count == 0) { GUIDialogOK pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK); if (pDlgOK != null) { pDlgOK.SetHeading(200052); //my tv pDlgOK.SetLine(1, GUILocalizeStrings.Get(200053)); // No Active recordings pDlgOK.SetLine(2, ""); pDlgOK.DoModal(this.GetID); } } } }
private void ShowPrograms() { if (tbProgramDescription != null) { tbProgramDescription.Clear(); } if (tbOnTvNow != null) { tbOnTvNow.EnableUpDown = false; tbOnTvNow.Clear(); } if (tbOnTvNext != null) { tbOnTvNext.EnableUpDown = false; tbOnTvNext.Clear(); } SetRecorderStatus(true); // Channel icon if (imgTvChannelLogo != null) { SetCurrentChannelLogo(); } if (lblCurrentChannel != null) { lblCurrentChannel.Label = GetChannelName(); } GuideProgram prog = PluginMain.GetCurrentProgram(ChannelType.Television); //TVHome.Navigator.GetChannel(GetChannelName()).GetProgramAt(m_dateTime); if (prog != null && !g_Player.IsTVRecording) { string strTime = String.Format("{0}-{1}", prog.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat), prog.StopTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat)); if (lblCurrentTime != null) { lblCurrentTime.Label = strTime; } // On TV Now if (tbOnTvNow != null) { strTime = String.Format("{0} ", prog.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat)); tbOnTvNow.Label = strTime + prog.CreateProgramTitle(); GUIPropertyManager.SetProperty("#TV.View.start", strTime); strTime = String.Format("{0} ", prog.StopTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat)); GUIPropertyManager.SetProperty("#TV.View.stop", strTime); GUIPropertyManager.SetProperty("#TV.View.remaining", Utils.SecondsToHMSString(prog.StopTime - prog.StartTime)); } if (tbProgramDescription != null) { tbProgramDescription.Label = prog.Description; } // next program if (GetChannelId() != Guid.Empty) { prog = PluginMain.GetNextprogram(ChannelType.Television); if (prog != null) { if (tbOnTvNext != null) { tbOnTvNext.Label = strTime + " " + prog.CreateProgramTitle(); } } } } else if (g_Player.IsTVRecording) { Recording rec = null; string description = ""; string title = ""; string startTime = ""; // DateTime.MinValue; string endTime = ""; // DateTime.MaxValue; //string remaining = ""; rec = TvRecorded.GetPlayingRecording(); if (rec != null && rec.ChannelType == ChannelType.Television) { description = rec.CreateCombinedDescription(false); title = rec.Title; Guid _channelId = rec.ChannelId; string channelName = rec.ChannelDisplayName; if (_channelId != Guid.Empty && channelName != string.Empty) { string strLogo = string.Empty; using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { strLogo = Utility.GetLogoImage(_channelId, channelName, tvSchedulerAgent); } if (string.IsNullOrEmpty(strLogo)) { strLogo = "defaultVideoBig.png"; } GUIPropertyManager.SetProperty("#TV.View.thumb", strLogo); } long currentPosition = (long)(g_Player.CurrentPosition); startTime = Utils.SecondsToHMSString((int)currentPosition); long duration = (long)(g_Player.Duration); endTime = Utils.SecondsToHMSString((int)duration); //remaining = "0"; if (tbOnTvNow != null) { tbOnTvNow.Label = title; } GUIPropertyManager.SetProperty("#TV.View.compositetitle", title); GUIPropertyManager.SetProperty("#TV.View.start", startTime); GUIPropertyManager.SetProperty("#TV.View.stop", endTime); if (tbProgramDescription != null) { tbProgramDescription.Label = description; } } } else { if (tbOnTvNow != null) { tbOnTvNow.Label = GUILocalizeStrings.Get(736); // no epg for this channel } if (tbOnTvNext != null) { tbOnTvNext.Label = GUILocalizeStrings.Get(736); // no epg for this channel } GUIPropertyManager.SetProperty("#TV.View.start", string.Empty); GUIPropertyManager.SetProperty("#TV.View.stop", string.Empty); GUIPropertyManager.SetProperty("#TV.View.remaining", string.Empty); if (lblCurrentTime != null) { lblCurrentTime.Label = String.Empty; } } UpdateProgressBar(); }
private IMBotMessage DoSearchCommand(IMBotConversation conversation, IList<string> arguments) { if (arguments.Count == 0) { return new IMBotMessage("Search text or result number is missing.", IMBotMessage.ErrorColor); } int resultNumber; if (int.TryParse(arguments[0], out resultNumber)) { return DoSearchResults(conversation, resultNumber); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { string searchText = arguments[0]; if (searchText.StartsWith(@"\")) { searchText = searchText.Substring(1); } string[] titles = tvSchedulerAgent.GetTitlesByPartialTitle(GetChannelType(conversation), searchText, false); StringBuilder replyText = new StringBuilder(); replyText.AppendFormat("Found {0} in the following titles:", searchText); int index = 0; foreach (string title in titles) { replyText.AppendLine(); replyText.AppendFormat("{0,3}» {1}", ++index, title); } conversation.Session.Remove(SessionKey.Programs); conversation.Session[SessionKey.FoundTitles] = titles; return new IMBotMessage(replyText.ToString(), true) { Footer = "Use 'search <number>' to see the programs." }; } }
public void SaveGuideDataInArgusTV(ImportGuideChannel channel, ChannelType channelType, GuideProgram[] guideProgramData, bool updateChannelName ) { if (guideProgramData.Length > 0) { using (GuideServiceAgent guideServiceAgent = new GuideServiceAgent()) { using (SchedulerServiceAgent schedulerServiceAgent = new SchedulerServiceAgent()) { Guid guideChannelId = EnsureDefaultChannel(channel, channelType, updateChannelName); foreach (GuideProgram guideProgram in guideProgramData) { guideProgram.GuideChannelId = guideChannelId; try { guideServiceAgent.ImportProgram(guideProgram, GuideSource.XmlTv); } catch { } } } } } }
private IMBotMessage DoDeleteScheduleCommand(IMBotConversation conversation, IList<string> arguments) { if (arguments.Count == 0) { return new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { UpcomingProgram upcomingRecording; IMBotMessage result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording); if (result == null) { StringBuilder replyText = new StringBuilder(); tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId); replyText.Append("Deleted schedule for "); Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording); replyText.Append("."); result = new IMBotMessage(replyText.ToString()); } return result; } }
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 void ProcessAlerts(DateTime preNotifySecs) { using (SchedulerServiceAgent tvschedulerAgent = new SchedulerServiceAgent()) { List<UpcomingProgram> upcomingPrograms = new List<UpcomingProgram>( tvschedulerAgent.GetAllUpcomingPrograms(ScheduleType.Alert, false)); if (upcomingPrograms.Count > 0) { DateTime _now = DateTime.Now; foreach (UpcomingProgram program in upcomingPrograms) { if (preNotifySecs > program.StartTime && _now < program.StopTime && !AlreadyNotifiedAlerts.Contains(program.ScheduleId)) { NotifyProgram(program); AlreadyNotifiedAlerts.Add(program.ScheduleId); Log.Debug("NotifyManager: AlreadyNotifiedAlerts.Add {0}", program.Title); } else if (_now >= program.StopTime && AlreadyNotifiedConflict.Contains(program.ScheduleId)) { Log.Debug("NotifyManager: AlreadyNotifiedAlerts.Remove"); AlreadyNotifiedAlerts.Remove(program.ScheduleId); } if (program.StartTime < _nextCheckTimeAlerts && program.StartTime > _now) { _nextCheckTimeAlerts = program.StartTime; } if (program.StopTime < _nextCheckTimeAlerts && program.StopTime > _now) { _nextCheckTimeAlerts = program.StopTime; } } } } }
private IMBotMessage DoRecordCommand(IMBotConversation conversation, IList<string> arguments) { if (arguments.Count == 0) { return new IMBotMessage("Program number missing.", IMBotMessage.ErrorColor); } using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent()) { RepeatingType repeatingType = RepeatingType.None; if (arguments.Count > 1) { switch (arguments[1].ToLowerInvariant()) { case "once": case "o": repeatingType = RepeatingType.Once; break; case "daily": case "d": repeatingType = RepeatingType.Daily; break; case "weekly": case "w": repeatingType = RepeatingType.Weekly; break; case "workingdays": case "wd": repeatingType = RepeatingType.WorkingDays; break; case "weekends": case "we": repeatingType = RepeatingType.Weekends; break; case "anytime": case "a": repeatingType = RepeatingType.AnyTime; break; } } int programNumber; if (repeatingType == RepeatingType.None || !int.TryParse(arguments[0], out programNumber)) { return new IMBotMessage("Please specify program number and once, daily, weekly, workingdays, weekends or anytime.", IMBotMessage.ErrorColor); } Session.Programs sessionPrograms = null; if (conversation.Session.ContainsKey(SessionKey.Programs)) { sessionPrograms = conversation.Session[SessionKey.Programs] as Session.Programs; } IProgramSummary program = null; Channel channel = null; if (sessionPrograms != null) { program = sessionPrograms.GetProgramAt(programNumber, out channel); if (program == null) { return new IMBotMessage("Bad program number.", IMBotMessage.ErrorColor); } } else { return new IMBotMessage("No programs.", IMBotMessage.ErrorColor); } Schedule schedule = tvSchedulerAgent.CreateNewSchedule(GetChannelType(conversation), ScheduleType.Recording); bool newEpisodesOnly = arguments.Count > 2 && arguments[2].Equals("new", StringComparison.CurrentCultureIgnoreCase); string repeatingText = String.Empty; if (repeatingType == RepeatingType.Once) { schedule.Name = GuideProgram.CreateProgramTitle(program.Title, program.SubTitle, program.EpisodeNumberDisplay); schedule.Rules.Add(ScheduleRuleType.OnDate, program.StartTime.Date); schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay)); if (!String.IsNullOrEmpty(program.SubTitle)) { schedule.Rules.Add(ScheduleRuleType.SubTitleEquals, program.SubTitle); } else if (!String.IsNullOrEmpty(program.EpisodeNumberDisplay)) { schedule.Rules.Add(ScheduleRuleType.EpisodeNumberEquals, program.EpisodeNumberDisplay); } newEpisodesOnly = false; } else if (repeatingType == RepeatingType.AnyTime) { schedule.Name = program.Title + " (Any Time)"; repeatingText = " any time"; } else if (repeatingType == RepeatingType.Weekly) { schedule.Name = program.Title + " (Weekly)"; schedule.Rules.Add(ScheduleRuleType.DaysOfWeek, GetDaysOfWeek(program.StartTime)); schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay)); repeatingText = " weekly"; } else if (repeatingType == RepeatingType.WorkingDays) { schedule.Name = program.Title + " (Mon-Fri)"; schedule.Rules.Add(ScheduleRuleType.DaysOfWeek, ScheduleDaysOfWeek.WorkingDays); schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay)); repeatingText = " Mon-Fri"; } else if (repeatingType == RepeatingType.Weekends) { schedule.Name = program.Title + " (Sat-Sun)"; schedule.Rules.Add(ScheduleRuleType.DaysOfWeek, ScheduleDaysOfWeek.Weekends); schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay)); repeatingText = " Sat-Sun"; } else if (repeatingType == RepeatingType.Weekly) { schedule.Name = program.Title + " (Weekly)"; schedule.Rules.Add(ScheduleRuleType.DaysOfWeek, GetDaysOfWeek(program.StartTime)); schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay)); repeatingText = " weekly"; } else { schedule.Name = program.Title + " (Daily)"; schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay)); repeatingText = " daily"; } if (newEpisodesOnly) { schedule.Rules.Add(ScheduleRuleType.NewEpisodesOnly, true); } schedule.Rules.Add(ScheduleRuleType.Channels, channel.ChannelId); schedule.Rules.Add(ScheduleRuleType.TitleEquals, program.Title); tvSchedulerAgent.SaveSchedule(schedule); StringBuilder replyText = new StringBuilder(); replyText.Append("Created schedule to record "); Utility.AppendProgramDetails(replyText, channel, program); replyText.Append(repeatingText); if (newEpisodesOnly) { replyText.Append(" (record episodes once)"); } replyText.Append("."); return new IMBotMessage(replyText.ToString()); } }