Exemplo n.º 1
0
 private void _programsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 3 &&
         e.RowIndex >= 0 &&
         e.RowIndex < _programsDataGridView.Rows.Count)
     {
         UpcomingOrActiveProgramView programView = _programsDataGridView.Rows[e.RowIndex].DataBoundItem as UpcomingOrActiveProgramView;
         if (programView.UpcomingProgram.GuideProgramId.HasValue)
         {
             using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
             {
                 GuideProgram guideProgram = tvGuideAgent.GetProgramById(programView.UpcomingProgram.GuideProgramId.Value);
                 using (ProgramDetailsPopup popup = new ProgramDetailsPopup())
                 {
                     popup.Channel      = programView.UpcomingProgram.Channel;
                     popup.GuideProgram = guideProgram;
                     Point location = Cursor.Position;
                     location.Offset(-250, -40);
                     popup.Location = location;
                     popup.ShowDialog(this);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
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);
                }
            }
        }
Exemplo n.º 4
0
        public void Import(string pluginName, ProgressCallback progressCallback, FeedbackCallback feedbackCallback)
        {
            try
            {
                LogMessageInArgusTV(String.Format("Guide import, using plugin {0} started.", pluginName), LogSeverity.Information);

                IGuideImportPlugin plugin = GetPluginByName(pluginName);
                if (plugin != null)
                {
                    if (!plugin.IsConfigured())
                    {
                        LogMessageInArgusTV(String.Format("Plugin {0} is not completely configured, check it's configuration.", pluginName), LogSeverity.Error);
                    }
                    else
                    {
                        plugin.PrepareImport(feedbackCallback, new KeepImportServiceAliveCallback(KeepImportServiceAlive));

                        using (GuideServiceAgent guideAgent = new GuideServiceAgent())
                        {
                            guideAgent.StartGuideImport();
                            try
                            {
                                PluginSetting pluginSetting = GetPluginSetting(pluginName);
                                plugin.Import(pluginSetting.ChannelsToSkip, new ImportDataCallback(SaveGuideDataInArgusTV), progressCallback, feedbackCallback, new KeepImportServiceAliveCallback(KeepImportServiceAlive));
                            }
                            finally
                            {
                                guideAgent.EndGuideImport();
                            }
                        }
                    }
                }
                else
                {
                    LogMessageInArgusTV(String.Format("Plugin {0} not found, check your configuration.", pluginName), LogSeverity.Error);
                }
            }
            catch (Exception ex)
            {
                LogMessageInArgusTV(String.Format("Guide import using plugin {0} failed, error : {1}", pluginName, ex.Message), LogSeverity.Error);
                throw;
            }
            finally
            {
                LogMessageInArgusTV(String.Format("Guide import using plugin {0} ended.", pluginName), LogSeverity.Information);
            }
        }
Exemplo n.º 5
0
 private static GuideProgram getProgramAt(Channel channel, DateTime time)
 {
     if (channel != null &&
         channel.GuideChannelId.HasValue)
     {
         using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
         {
             GuideProgramSummary[] programs =
                 tvGuideAgent.GetChannelProgramsBetween(channel.GuideChannelId.Value, time, time);
             if (programs.Length > 0)
             {
                 return(tvGuideAgent.GetProgramById(programs[0].GuideProgramId));
             }
         }
     }
     return(null);
 }
Exemplo n.º 6
0
        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;
                        }
                    }
            }
        }
Exemplo n.º 7
0
        private void OnDeleteAllGuideData()
        {
            using (GuideServiceAgent _tvGuideAgent = new GuideServiceAgent())
            {
                GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                if (dlgYesNo != null)
                {
                    dlgYesNo.Reset();
                    dlgYesNo.SetHeading(927);
                    dlgYesNo.SetLine(1, Utility.GetLocalizedText(TextId.DeleteAllGuideData));
                    dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.AreYouSure));
                    dlgYesNo.SetLine(3, string.Empty);
                    dlgYesNo.SetDefaultToYes(false);
                    dlgYesNo.DoModal(GetID);

                    if (dlgYesNo.IsConfirmed)
                    {
                        _tvGuideAgent.DeleteAllPrograms();
                    }
                }
            }
        }
Exemplo n.º 8
0
 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 { }
                 }
             }
         }
     }
 }
Exemplo n.º 9
0
        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.");
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
 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);
     }
 }
Exemplo n.º 11
0
 private static GuideProgram getProgramAt(Channel channel, DateTime time)
 {
     if (channel != null
         && channel.GuideChannelId.HasValue)
     {
         using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
         {
             GuideProgramSummary[] programs =
                 tvGuideAgent.GetChannelProgramsBetween(channel.GuideChannelId.Value, time, time);
             if (programs.Length > 0)
             {
                 return tvGuideAgent.GetProgramById(programs[0].GuideProgramId);
             }
         }
     }
     return null;
 }
        private void OnDeleteAllGuideData()
        {
            using (GuideServiceAgent _tvGuideAgent = new GuideServiceAgent())
            {
                GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                if (dlgYesNo != null)
                {
                    dlgYesNo.Reset();
                    dlgYesNo.SetHeading(927);
                    dlgYesNo.SetLine(1, Utility.GetLocalizedText(TextId.DeleteAllGuideData));
                    dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.AreYouSure));
                    dlgYesNo.SetLine(3, string.Empty);
                    dlgYesNo.SetDefaultToYes(false);
                    dlgYesNo.DoModal(GetID);

                    if (dlgYesNo.IsConfirmed)
                    {
                        _tvGuideAgent.DeleteAllPrograms();
                    }
                }
            }
        }
Exemplo n.º 13
0
 private void UpdateCurrentProgram(bool updateIcon)
 {
     if (_cursorX < 0)
     {
         return;
     }
     if (_cursorY < 0)
     {
         return;
     }
     if (_cursorY == 0)
     {
         SetProperties();
         SetFocus();
         return;
     }
     int iControlId = GUIDE_COMPONENTID_START + _cursorX * RowID + (_cursorY - 1) * ColID;
     GUIButton3PartControl img = GetControl(iControlId) as GUIButton3PartControl;
     if (null != img)
     {
         SetFocus();
         using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
         {
             _currentProgram = tvGuideAgent.GetProgramById(((GuideProgramSummary)img.Data).GuideProgramId);
         }
         if (updateIcon)
         {
             bool isRecording;
             bool isAlert;
             string recordIconImage = GetChannelProgramIcon(_currentChannel, _currentProgram.GuideProgramId, out isRecording, out isAlert);
             img.TexutureIcon = recordIconImage == null ? String.Empty : recordIconImage;
         }
         SetProperties();
     }
 }
Exemplo n.º 14
0
        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;
                    }
                }
            }
        }
Exemplo n.º 15
0
 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);
     }
 }
Exemplo n.º 16
0
        protected override void Run()
        {
            Thread.Sleep(5 * 1000);

            lock (_guideProgramsToImportLock)
            {
                _newProgramsToImportEvent = new AutoResetEvent(false);
            }
            try
            {
                int interval = 1 * 60 * 1000;
            #if DEBUG
                interval = 5000;
            #endif

                bool aborted = false;
                while (!aborted)
                {
                    try
                    {
                        List<GuideProgram> guidePrograms = GetProgramsToImport();
                        while (guidePrograms != null)
                        {
                            using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                            {
                                Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: ArgusTVDvbEpg: importing {0} programs into ARGUS TV", guidePrograms.Count);
                                foreach (GuideProgram guideProgram in guidePrograms)
                                {
                                    tvGuideAgent.ImportProgram(guideProgram, GuideSource.DvbEpg);
                                    aborted = this.StopThreadEvent.WaitOne(0, false);
                                    if (aborted)
                                    {
                                        break;
                                    }
                                }
                            }
                            aborted = this.StopThreadEvent.WaitOne(0);
                            if (aborted)
                            {
                                break;
                            }
                            guidePrograms = GetProgramsToImport();
                        }
                        if (!aborted)
                        {
                            aborted = (0 == WaitHandle.WaitAny(new WaitHandle[] { this.StopThreadEvent, _newProgramsToImportEvent }, interval, false));
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("ArgusTVDvbEpg error: {0}", ex.Message);
                        // Delay for a short while and then restart.
                        aborted = this.StopThreadEvent.WaitOne(30 * 1000, false);
                    }
                }
            }
            finally
            {
                lock (_guideProgramsToImportLock)
                {
                    _newProgramsToImportEvent.Close();
                    _newProgramsToImportEvent = null;
                }
            }
        }
Exemplo n.º 17
0
        public void Import(string pluginName, ProgressCallback progressCallback, FeedbackCallback feedbackCallback)
        {
            try
            {
                LogMessageInArgusTV(String.Format("Guide import, using plugin {0} started.", pluginName), LogSeverity.Information);

                IGuideImportPlugin plugin = GetPluginByName(pluginName);
                if (plugin != null)
                {
                    if (!plugin.IsConfigured())
                    {
                        LogMessageInArgusTV(String.Format("Plugin {0} is not completely configured, check it's configuration.", pluginName), LogSeverity.Error);
                    }
                    else
                    {
                        plugin.PrepareImport(feedbackCallback, new KeepImportServiceAliveCallback(KeepImportServiceAlive));

                        using (GuideServiceAgent guideAgent = new GuideServiceAgent())
                        {
                            guideAgent.StartGuideImport();
                            try
                            {
                                PluginSetting pluginSetting = GetPluginSetting(pluginName);
                                plugin.Import(pluginSetting.ChannelsToSkip, new ImportDataCallback(SaveGuideDataInArgusTV), progressCallback, feedbackCallback, new KeepImportServiceAliveCallback(KeepImportServiceAlive));
                            }
                            finally
                            {
                                guideAgent.EndGuideImport();
                            }
                        }
                    }
                }
                else
                {
                    LogMessageInArgusTV(String.Format("Plugin {0} not found, check your configuration.", pluginName), LogSeverity.Error);
                }
            }
            catch (Exception ex)
            {
                LogMessageInArgusTV(String.Format("Guide import using plugin {0} failed, error : {1}", pluginName, ex.Message), LogSeverity.Error);
                throw;
            }
            finally
            {
                LogMessageInArgusTV(String.Format("Guide import using plugin {0} ended.", pluginName), LogSeverity.Information);
            }
        }
Exemplo n.º 18
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;
                }
            }
        }
Exemplo n.º 19
0
        public static void OnGlobalMessage(GUIMessage message)
        {
            switch (message.Message)
            {
                /// <summary>
                /// We need to stop the player if our livestream ends unexpectedly.
                /// If the stream stopped for a recording, we show it in a message.
                /// Without this mediaportal can hang,crash (c++ error in tsreader).
                /// </summary>
                case GUIMessage.MessageType.GUI_MSG_STOP_SERVER_TIMESHIFTING:
                    {
                        Log.Debug("TvHome: GUI_MSG_STOP_SERVER_TIMESHIFTING, param1 = {0}",message.Param1);
                        if (PluginMain.Navigator.IsLiveStreamOn)
                        {
                            if (message.Param1 == 4321)//fired by eventlistener
                            {
                                LiveStream liveStream = message.Object as LiveStream;
                                LiveStream navigatorLiveStream = PluginMain.Navigator.LiveStream;
                                Channel channel = PluginMain.Navigator.CurrentChannel;

                                if (liveStream != null && channel != null
                                    && navigatorLiveStream.TimeshiftFile == liveStream.TimeshiftFile
                                    && liveStream.StreamStartedTime == navigatorLiveStream.StreamStartedTime)
                                {
                                    if (g_Player.Playing && (g_Player.IsTV || g_Player.IsRadio))
                                    {
                                        g_Player.Stop();
                                        Log.Info("TvHome: our live stream seems to be aborted, stop the playback now");
                                    }

                                    string text = GUILocalizeStrings.Get(1516);
                                    if (message.Label == LiveStreamAbortReason.RecordingStartedOnCard.ToString())
                                    {
                                        text = GUILocalizeStrings.Get(1513);
                                    }
                                    text = text.Replace("\\r", " ");

                                    string heading = string.Empty;
                                    string tvlogo = string.Empty;
                                    using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                                    {
                                        if (channel.ChannelType == ChannelType.Television)
                                            heading = GUILocalizeStrings.Get(605) + " - " + channel.DisplayName; //my tv
                                        else
                                            heading = GUILocalizeStrings.Get(665) + " - " + channel.DisplayName; //my radio

                                        tvlogo = Utility.GetLogoImage(channel, SchedulerAgent);
                                    }

                                    GUIDialogNotify pDlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                                    if (pDlgNotify != null)
                                    {
                                        pDlgNotify.Reset();
                                        pDlgNotify.ClearAll();
                                        pDlgNotify.SetHeading(heading);
                                        if (!string.IsNullOrEmpty(text))
                                        {
                                            pDlgNotify.SetText(text);
                                        }
                                        pDlgNotify.SetImage(tvlogo);
                                        pDlgNotify.TimeOut = 5;
                                        Utils.PlaySound("notify.wav", false, true);
                                        pDlgNotify.DoModal(GUIWindowManager.ActiveWindow);
                                    }
                                }
                            }
                            else//fired by mp player
                            {
                                PluginMain.Navigator.AsyncStopLiveStream();
                            }
                        }
                    }
                    break;

                case GUIMessage.MessageType.GUI_MSG_NOTIFY_REC:
                    {
                        if (_enableRecNotification)
                        {
                            Log.Debug("TvHome: GUI_MSG_NOTIFY_REC");
                            string head = string.Empty;
                            string logo = string.Empty;
                            Recording recording = message.Object as Recording;

                            if (message.Param1 == 1)
                                head = GUILocalizeStrings.Get(1446);
                            else
                                head = GUILocalizeStrings.Get(1447);

                            using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                            {
                                Channel chan = SchedulerAgent.GetChannelById(recording.ChannelId);
                                logo = Utility.GetLogoImage(chan, SchedulerAgent);
                            }

                            string _text = String.Format("{0} {1}-{2}",
                                                  recording.Title,
                                                  recording.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat),
                                                  recording.StopTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat));

                            GUIDialogNotify DlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                            if (DlgNotify != null)
                            {
                                DlgNotify.Reset();
                                DlgNotify.ClearAll();
                                DlgNotify.SetHeading(head);
                                if (!string.IsNullOrEmpty(_text))
                                {
                                    DlgNotify.SetText(_text);
                                }
                                DlgNotify.SetImage(logo);
                                DlgNotify.TimeOut = 5;
                                if (_playNotifyBeep)
                                {
                                    Utils.PlaySound("notify.wav", false, true);
                                }
                                DlgNotify.DoModal(GUIWindowManager.ActiveWindow);
                            }
                        }
                    }
                    break;

                case GUIMessage.MessageType.GUI_MSG_NOTIFY_TV_PROGRAM:
                    {
                        Log.Debug("TvHome: GUI_MSG_NOTIFY_TV_PROGRAM");
                        TVNotifyYesNoDialog tvNotifyDlg = (TVNotifyYesNoDialog)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TVNOTIFYYESNO);
                        UpcomingProgram prog = message.Object as UpcomingProgram;
                        if (tvNotifyDlg == null || prog == null)
                        {
                            return;
                        }

                        tvNotifyDlg.Reset();
                        if (prog.StartTime > DateTime.Now)
                        {
                            int minUntilStart = (prog.StartTime - DateTime.Now).Minutes;
                            if (minUntilStart > 1)
                            {
                                tvNotifyDlg.SetHeading(String.Format(GUILocalizeStrings.Get(1018), minUntilStart));
                            }
                            else
                            {
                                tvNotifyDlg.SetHeading(1019); // Program is about to begin
                            }
                        }
                        else
                        {
                            tvNotifyDlg.SetHeading(String.Format(GUILocalizeStrings.Get(1206), (DateTime.Now - prog.StartTime).Minutes.ToString()));
                        }

                        string description = GUILocalizeStrings.Get(736);
                        using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                        {
                            try
                            {
                                if (prog.GuideProgramId.HasValue)
                                {
                                    GuideProgram Program = tvGuideAgent.GetProgramById(prog.GuideProgramId.Value);
                                    description = Program.CreateCombinedDescription(false);
                                }
                            }
                            catch { }
                        }

                        tvNotifyDlg.SetLine(1, prog.Title);
                        tvNotifyDlg.SetLine(2, description);
                        tvNotifyDlg.SetLine(4, String.Format(GUILocalizeStrings.Get(1207), prog.Channel.DisplayName));
                        string strLogo = string.Empty;
                        using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                        {
                            strLogo = Utility.GetLogoImage(prog.Channel, SchedulerAgent);
                        }

                        tvNotifyDlg.SetImage(strLogo);
                        tvNotifyDlg.TimeOut = _notifyTVTimeout;
                        if (_playNotifyBeep)
                        {
                            Utils.PlaySound("notify.wav", false, true);
                        }
                        tvNotifyDlg.SetDefaultToYes(false);
                        tvNotifyDlg.DoModal(GUIWindowManager.ActiveWindow);

                        if (tvNotifyDlg.IsConfirmed)
                        {
                            try
                            {
                                if (prog.Channel.ChannelType == ChannelType.Television)
                                {
                                    if (g_Player.Playing && g_Player.IsTV && PluginMain.Navigator.IsLiveStreamOn)
                                        GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_TVFULLSCREEN);
                                    else
                                        GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_TV);

                                    PluginMain.Navigator.ZapToChannel(prog.Channel, false);
                                    if (PluginMain.Navigator.CheckChannelChange())
                                    {
                                        TvHome.UpdateProgressPercentageBar(true);
                                        if (!PluginMain.Navigator.LastChannelChangeFailed)
                                        {
                                            g_Player.ShowFullScreenWindow();
                                        }
                                    }
                                }
                                else
                                {
                                    PluginMain.Navigator.ZapToChannel(prog.Channel, false);
                                    GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_RADIO);
                                }
                            }
                            catch (Exception e)
                            {
                                Log.Error("TVHome: TVNotification: Error on starting channel {0} after notification: {1} {2} {3}", prog.Channel.DisplayName, e.Message, e.Source, e.StackTrace);
                            }
                        }
                    }
                    break;

                //this (GUI_MSG_RECORDER_VIEW_CHANNEL) event is used to let other plugins play a recording,
                //lastMediaHandler does this (with param1 = 5577 for indentification).
                case GUIMessage.MessageType.GUI_MSG_RECORDER_VIEW_CHANNEL:
                    {
                        if (message.Param1 == 5577)
                        {
                            try
                            {
                                Recording rec = message.Object as Recording;
                                RecordedBase.PlayRecording(rec, message.Param2);
                            }
                            catch { Log.Error("TVHome: GUI_MSG_RECORDER_VIEW_CHANNEL error"); }
                        }
                    }
                    break;
            }
        }
Exemplo n.º 20
0
        private void ImportChannel(GuideServiceAgent tvGuideAgent, SchedulerServiceAgent tvSchedulerAgent, ImportChannelsContext.ImportChannel importChannel)
        {
            Guid channelId;

            Channels.ChannelLink channelLink = Channels.ChannelLinks.GetChannelLinkForMediaPortalChannel(importChannel.Channel);
            if (channelLink == null)
            {
                Channel channel = new Channel();
                channel.ChannelType = this.Context.ChannelType;
                channel.VisibleInGuide = true;
                channel.DisplayName = importChannel.Channel.DisplayName;
                channel.LogicalChannelNumber = importChannel.LogicalChannelNumber;
                channel.Sequence = importChannel.Channel.SortOrder;
                channel = tvSchedulerAgent.SaveChannel(channel);
                Channels.ChannelLinks.SetLinkedMediaPortalChannel(channel, importChannel.Channel);

                channelId = channel.ChannelId;
            }
            else
            {
                channelId = channelLink.ChannelId;
            }

            if (!_importChannelsOnlyRadioButton.Checked)
            {
                string groupName;
                int groupSequence;
                if (_importChannelsAndGroupsRadioButton.Checked)
                {
                    groupName = importChannel.GroupName;
                    groupSequence = importChannel.GroupSequence;
                }
                else
                {
                    groupName = _groupNameTextBox.Text.Trim();
                    groupSequence = 0;
                }
                if (!String.IsNullOrEmpty(importChannel.GroupName))
                {
                    if (!_channelGroupsByName.ContainsKey(groupName))
                    {
                        ChannelGroup channelGroup = new ChannelGroup();
                        channelGroup.GroupName = groupName;
                        channelGroup.VisibleInGuide = true;
                        channelGroup.ChannelType = this.Context.ChannelType;
                        channelGroup.Sequence = groupSequence;
                        channelGroup = tvSchedulerAgent.SaveChannelGroup(channelGroup);
                        _channelGroupsByName[groupName] = channelGroup;
                        _channelMembersByName[groupName] = new List<Guid>();
                    }

                    if (!_channelMembersByName.ContainsKey(groupName))
                    {
                        _channelMembersByName[groupName] = new List<Guid>(
                            tvSchedulerAgent.GetChannelGroupMembers(_channelGroupsByName[groupName].ChannelGroupId));
                    }

                    _channelMembersByName[groupName].Add(channelId);
                }
            }
        }
Exemplo n.º 21
0
        private void ImportChannel(GuideServiceAgent tvGuideAgent, SchedulerServiceAgent tvSchedulerAgent, ImportChannelsContext.ImportChannel importChannel)
        {
            Guid channelId;

            Channels.ChannelLink channelLink = Channels.ChannelLinks.GetChannelLinkForMediaPortalChannel(importChannel.Channel);
            if (channelLink == null)
            {
                Channel channel = new Channel();
                channel.ChannelType          = this.Context.ChannelType;
                channel.VisibleInGuide       = true;
                channel.DisplayName          = importChannel.Channel.DisplayName;
                channel.LogicalChannelNumber = importChannel.LogicalChannelNumber;
                channel.Sequence             = importChannel.Channel.SortOrder;
                channel = tvSchedulerAgent.SaveChannel(channel);
                Channels.ChannelLinks.SetLinkedMediaPortalChannel(channel, importChannel.Channel);

                channelId = channel.ChannelId;
            }
            else
            {
                channelId = channelLink.ChannelId;
            }

            if (!_importChannelsOnlyRadioButton.Checked)
            {
                string groupName;
                int    groupSequence;
                if (_importChannelsAndGroupsRadioButton.Checked)
                {
                    groupName     = importChannel.GroupName;
                    groupSequence = importChannel.GroupSequence;
                }
                else
                {
                    groupName     = _groupNameTextBox.Text.Trim();
                    groupSequence = 0;
                }
                if (!String.IsNullOrEmpty(importChannel.GroupName))
                {
                    if (!_channelGroupsByName.ContainsKey(groupName))
                    {
                        ChannelGroup channelGroup = new ChannelGroup();
                        channelGroup.GroupName      = groupName;
                        channelGroup.VisibleInGuide = true;
                        channelGroup.ChannelType    = this.Context.ChannelType;
                        channelGroup.Sequence       = groupSequence;
                        channelGroup = tvSchedulerAgent.SaveChannelGroup(channelGroup);
                        _channelGroupsByName[groupName]  = channelGroup;
                        _channelMembersByName[groupName] = new List <Guid>();
                    }

                    if (!_channelMembersByName.ContainsKey(groupName))
                    {
                        _channelMembersByName[groupName] = new List <Guid>(
                            tvSchedulerAgent.GetChannelGroupMembers(_channelGroupsByName[groupName].ChannelGroupId));
                    }

                    _channelMembersByName[groupName].Add(channelId);
                }
            }
        }
Exemplo n.º 22
0
        public static void OnGlobalMessage(GUIMessage message)
        {
            switch (message.Message)
            {
            /// <summary>
            /// We need to stop the player if our livestream ends unexpectedly.
            /// If the stream stopped for a recording, we show it in a message.
            /// Without this mediaportal can hang,crash (c++ error in tsreader).
            /// </summary>
            case GUIMessage.MessageType.GUI_MSG_STOP_SERVER_TIMESHIFTING:
            {
                Log.Debug("TvHome: GUI_MSG_STOP_SERVER_TIMESHIFTING, param1 = {0}", message.Param1);
                if (PluginMain.Navigator.IsLiveStreamOn)
                {
                    if (message.Param1 == 4321)        //fired by eventlistener
                    {
                        LiveStream liveStream          = message.Object as LiveStream;
                        LiveStream navigatorLiveStream = PluginMain.Navigator.LiveStream;
                        Channel    channel             = PluginMain.Navigator.CurrentChannel;

                        if (liveStream != null && channel != null &&
                            navigatorLiveStream.TimeshiftFile == liveStream.TimeshiftFile &&
                            liveStream.StreamStartedTime == navigatorLiveStream.StreamStartedTime)
                        {
                            if (g_Player.Playing && (g_Player.IsTV || g_Player.IsRadio))
                            {
                                g_Player.Stop();
                                Log.Info("TvHome: our live stream seems to be aborted, stop the playback now");
                            }

                            string text = GUILocalizeStrings.Get(1516);
                            if (message.Label == LiveStreamAbortReason.RecordingStartedOnCard.ToString())
                            {
                                text = GUILocalizeStrings.Get(1513);
                            }
                            text = text.Replace("\\r", " ");

                            string heading = string.Empty;
                            string tvlogo  = string.Empty;
                            using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                            {
                                if (channel.ChannelType == ChannelType.Television)
                                {
                                    heading = GUILocalizeStrings.Get(605) + " - " + channel.DisplayName;         //my tv
                                }
                                else
                                {
                                    heading = GUILocalizeStrings.Get(665) + " - " + channel.DisplayName;         //my radio
                                }
                                tvlogo = Utility.GetLogoImage(channel, SchedulerAgent);
                            }

                            GUIDialogNotify pDlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                            if (pDlgNotify != null)
                            {
                                pDlgNotify.Reset();
                                pDlgNotify.ClearAll();
                                pDlgNotify.SetHeading(heading);
                                if (!string.IsNullOrEmpty(text))
                                {
                                    pDlgNotify.SetText(text);
                                }
                                pDlgNotify.SetImage(tvlogo);
                                pDlgNotify.TimeOut = 5;
                                Utils.PlaySound("notify.wav", false, true);
                                pDlgNotify.DoModal(GUIWindowManager.ActiveWindow);
                            }
                        }
                    }
                    else        //fired by mp player
                    {
                        PluginMain.Navigator.AsyncStopLiveStream();
                    }
                }
            }
            break;

            case GUIMessage.MessageType.GUI_MSG_NOTIFY_REC:
            {
                if (_enableRecNotification)
                {
                    Log.Debug("TvHome: GUI_MSG_NOTIFY_REC");
                    string    head      = string.Empty;
                    string    logo      = string.Empty;
                    Recording recording = message.Object as Recording;

                    if (message.Param1 == 1)
                    {
                        head = GUILocalizeStrings.Get(1446);
                    }
                    else
                    {
                        head = GUILocalizeStrings.Get(1447);
                    }

                    using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                    {
                        Channel chan = SchedulerAgent.GetChannelById(recording.ChannelId);
                        logo = Utility.GetLogoImage(chan, SchedulerAgent);
                    }

                    string _text = String.Format("{0} {1}-{2}",
                                                 recording.Title,
                                                 recording.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat),
                                                 recording.StopTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat));

                    GUIDialogNotify DlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                    if (DlgNotify != null)
                    {
                        DlgNotify.Reset();
                        DlgNotify.ClearAll();
                        DlgNotify.SetHeading(head);
                        if (!string.IsNullOrEmpty(_text))
                        {
                            DlgNotify.SetText(_text);
                        }
                        DlgNotify.SetImage(logo);
                        DlgNotify.TimeOut = 5;
                        if (_playNotifyBeep)
                        {
                            Utils.PlaySound("notify.wav", false, true);
                        }
                        DlgNotify.DoModal(GUIWindowManager.ActiveWindow);
                    }
                }
            }
            break;

            case GUIMessage.MessageType.GUI_MSG_NOTIFY_TV_PROGRAM:
            {
                Log.Debug("TvHome: GUI_MSG_NOTIFY_TV_PROGRAM");
                TVNotifyYesNoDialog tvNotifyDlg = (TVNotifyYesNoDialog)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TVNOTIFYYESNO);
                UpcomingProgram     prog        = message.Object as UpcomingProgram;
                if (tvNotifyDlg == null || prog == null)
                {
                    return;
                }

                tvNotifyDlg.Reset();
                if (prog.StartTime > DateTime.Now)
                {
                    int minUntilStart = (prog.StartTime - DateTime.Now).Minutes;
                    if (minUntilStart > 1)
                    {
                        tvNotifyDlg.SetHeading(String.Format(GUILocalizeStrings.Get(1018), minUntilStart));
                    }
                    else
                    {
                        tvNotifyDlg.SetHeading(1019);         // Program is about to begin
                    }
                }
                else
                {
                    tvNotifyDlg.SetHeading(String.Format(GUILocalizeStrings.Get(1206), (DateTime.Now - prog.StartTime).Minutes.ToString()));
                }

                string description = GUILocalizeStrings.Get(736);
                using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                {
                    try
                    {
                        if (prog.GuideProgramId.HasValue)
                        {
                            GuideProgram Program = tvGuideAgent.GetProgramById(prog.GuideProgramId.Value);
                            description = Program.CreateCombinedDescription(false);
                        }
                    }
                    catch { }
                }

                tvNotifyDlg.SetLine(1, prog.Title);
                tvNotifyDlg.SetLine(2, description);
                tvNotifyDlg.SetLine(4, String.Format(GUILocalizeStrings.Get(1207), prog.Channel.DisplayName));
                string strLogo = string.Empty;
                using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                {
                    strLogo = Utility.GetLogoImage(prog.Channel, SchedulerAgent);
                }

                tvNotifyDlg.SetImage(strLogo);
                tvNotifyDlg.TimeOut = _notifyTVTimeout;
                if (_playNotifyBeep)
                {
                    Utils.PlaySound("notify.wav", false, true);
                }
                tvNotifyDlg.SetDefaultToYes(false);
                tvNotifyDlg.DoModal(GUIWindowManager.ActiveWindow);

                if (tvNotifyDlg.IsConfirmed)
                {
                    try
                    {
                        if (prog.Channel.ChannelType == ChannelType.Television)
                        {
                            if (g_Player.Playing && g_Player.IsTV && PluginMain.Navigator.IsLiveStreamOn)
                            {
                                GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_TVFULLSCREEN);
                            }
                            else
                            {
                                GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_TV);
                            }

                            PluginMain.Navigator.ZapToChannel(prog.Channel, false);
                            if (PluginMain.Navigator.CheckChannelChange())
                            {
                                TvHome.UpdateProgressPercentageBar(true);
                                if (!PluginMain.Navigator.LastChannelChangeFailed)
                                {
                                    g_Player.ShowFullScreenWindow();
                                }
                            }
                        }
                        else
                        {
                            PluginMain.Navigator.ZapToChannel(prog.Channel, false);
                            GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_RADIO);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error("TVHome: TVNotification: Error on starting channel {0} after notification: {1} {2} {3}", prog.Channel.DisplayName, e.Message, e.Source, e.StackTrace);
                    }
                }
            }
            break;

            //this (GUI_MSG_RECORDER_VIEW_CHANNEL) event is used to let other plugins play a recording,
            //lastMediaHandler does this (with param1 = 5577 for indentification).
            case GUIMessage.MessageType.GUI_MSG_RECORDER_VIEW_CHANNEL:
            {
                if (message.Param1 == 5577)
                {
                    try
                    {
                        Recording rec = message.Object as Recording;
                        RecordedBase.PlayRecording(rec, message.Param2);
                    }
                    catch { Log.Error("TVHome: GUI_MSG_RECORDER_VIEW_CHANNEL error"); }
                }
            }
            break;
            }
        }
Exemplo n.º 23
0
        protected override void Run()
        {
            Thread.Sleep(5 * 1000);

            lock (_guideProgramsToImportLock)
            {
                _newProgramsToImportEvent = new AutoResetEvent(false);
            }
            try
            {
                int interval = 1 * 60 * 1000;
#if DEBUG
                interval = 5000;
#endif

                bool aborted = false;
                while (!aborted)
                {
                    try
                    {
                        List <GuideProgram> guidePrograms = GetProgramsToImport();
                        while (guidePrograms != null)
                        {
                            using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                            {
                                Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: ArgusTVDvbEpg: importing {0} programs into ARGUS TV", guidePrograms.Count);
                                foreach (GuideProgram guideProgram in guidePrograms)
                                {
                                    tvGuideAgent.ImportProgram(guideProgram, GuideSource.DvbEpg);
                                    aborted = this.StopThreadEvent.WaitOne(0, false);
                                    if (aborted)
                                    {
                                        break;
                                    }
                                }
                            }
                            aborted = this.StopThreadEvent.WaitOne(0);
                            if (aborted)
                            {
                                break;
                            }
                            guidePrograms = GetProgramsToImport();
                        }
                        if (!aborted)
                        {
                            aborted = (0 == WaitHandle.WaitAny(new WaitHandle[] { this.StopThreadEvent, _newProgramsToImportEvent }, interval, false));
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("ArgusTVDvbEpg error: {0}", ex.Message);
                        // Delay for a short while and then restart.
                        aborted = this.StopThreadEvent.WaitOne(30 * 1000, false);
                    }
                }
            }
            finally
            {
                lock (_guideProgramsToImportLock)
                {
                    _newProgramsToImportEvent.Close();
                    _newProgramsToImportEvent = null;
                }
            }
        }
Exemplo n.º 24
0
        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;
        }
Exemplo n.º 25
0
        private void RenderChannel(SchedulerServiceAgent tvSchedulerAgent, GuideServiceAgent tvGuideAgent,
            int iChannel, GuideBaseChannel tvGuideChannel, long iStart, long iEnd, bool selectCurrentShow)
        {
            Channel channel = tvGuideChannel.channel;
            int channelNum = 0;

            if (!_byIndex)
            {
                if (channel.LogicalChannelNumber.HasValue)
                {
                    channelNum = channel.LogicalChannelNumber.Value;
                }
            }
            else
            {
                channelNum = _channelList.IndexOf(tvGuideChannel) + 1;
            }

            GUIButton3PartControl img = GetControl(iChannel + (int)Controls.IMG_CHAN1) as GUIButton3PartControl;
            if (img != null)
            {
                if (_showChannelLogos)
                {
                    img.TexutureIcon = tvGuideChannel.strLogo;
                }
                if (channelNum > 0 && _showChannelNumber)
                {
                    img.Label1 = channelNum + " " + channel.DisplayName;
                }
                else
                {
                    img.Label1 = channel.DisplayName;
                }
                img.Data = channel;
                img.IsVisible = true;
            }

            IList<GuideProgramSummary> programs = new List<GuideProgramSummary>();
            if (_model.ProgramsByChannel.ContainsKey(channel.ChannelId))
            {
                programs = _model.ProgramsByChannel[channel.ChannelId].Programs;
            }

            bool noEPG = (programs == null || programs.Count == 0);
            if (noEPG)
            {
                DateTime dt = Utils.longtodate(iEnd);
                long iProgEnd = Utils.datetolong(dt);
                GuideProgramSummary prog = new GuideProgramSummary()
                {
                    GuideChannelId = channel.GuideChannelId.HasValue ? channel.GuideChannelId.Value : Guid.Empty,
                    StartTime = Utils.longtodate(iStart),
                    StopTime = Utils.longtodate(iProgEnd),
                    Title = Utility.GetLocalizedText(TextId.NoDataAvailable),
                    SubTitle = String.Empty,
                    Category = String.Empty
                };
                programs = new List<GuideProgramSummary>();
                programs.Add(prog);
            }

            int iProgram = 0;
            int iPreviousEndXPos = 0;

            int width = GetControl((int)Controls.LABEL_TIME1 + 1).XPosition;
            width -= GetControl((int)Controls.LABEL_TIME1).XPosition;

            int height = GetControl((int)Controls.IMG_CHAN1 + 1).YPosition;
            height -= GetControl((int)Controls.IMG_CHAN1).YPosition;

            foreach (GuideProgramSummary program in programs)
            {
                if (Utils.datetolong(program.StopTime) <= iStart
                    || Utils.datetolong(program.StartTime) >= iEnd)
                    continue;

                string strTitle = program.Title;
                bool bStartsBefore = false;
                bool bEndsAfter = false;

                if (Utils.datetolong(program.StartTime) < iStart)
                    bStartsBefore = true;

                if (Utils.datetolong(program.StopTime) > iEnd)
                    bEndsAfter = true;

                DateTime dtBlokStart = new DateTime();
                dtBlokStart = _viewingTime;
                dtBlokStart = dtBlokStart.AddMilliseconds(-dtBlokStart.Millisecond);
                dtBlokStart = dtBlokStart.AddSeconds(-dtBlokStart.Second);

                bool isAlert;
                bool isRecording;
                string recordIconImage = GetChannelProgramIcon(channel, program.GuideProgramId, out isRecording,out isAlert);

                if (noEPG && !isRecording)
                {
                    ActiveRecording rec;
                    isRecording = PluginMain.IsChannelRecording(channel.ChannelId, out rec);
                }

                bool bProgramIsHD = (program.Flags & GuideProgramFlags.HighDefinition) != 0;

                int iStartXPos = 0;
                int iEndXPos = 0;
                for (int iBlok = 0; iBlok < _numberOfBlocks; iBlok++)
                {
                    float fWidthEnd = (float)width;
                    DateTime dtBlokEnd = dtBlokStart.AddMinutes(_timePerBlock - 1);
                    if (IsRunningAt(program, dtBlokStart, dtBlokEnd))
                    {
                        //dtBlokEnd = dtBlokStart.AddSeconds(_timePerBlock * 60);
                        if (program.StopTime <= dtBlokEnd)
                        {
                            TimeSpan dtSpan = dtBlokEnd - program.StopTime;
                            int iEndMin = _timePerBlock - (dtSpan.Minutes);

                            fWidthEnd = (((float)iEndMin) / ((float)_timePerBlock)) * ((float)(width));
                            if (bEndsAfter)
                            {
                                fWidthEnd = (float)width;
                            }
                        }

                        if (iStartXPos == 0)
                        {
                            TimeSpan ts = program.StartTime - dtBlokStart;
                            int iStartMin = ts.Hours * 60;
                            iStartMin += ts.Minutes;
                            if (ts.Seconds == 59)
                            {
                                iStartMin += 1;
                            }
                            float fWidth = (((float)iStartMin) / ((float)_timePerBlock)) * ((float)(width));

                            if (bStartsBefore)
                            {
                                fWidth = 0;
                            }

                            iStartXPos = GetControl(iBlok + (int)Controls.LABEL_TIME1).XPosition;
                            iStartXPos += (int)fWidth;
                            iEndXPos = GetControl(iBlok + (int)Controls.LABEL_TIME1).XPosition + (int)fWidthEnd;
                        }
                        else
                        {
                            iEndXPos = GetControl(iBlok + (int)Controls.LABEL_TIME1).XPosition + (int)fWidthEnd;
                        }
                    }
                    dtBlokStart = dtBlokStart.AddMinutes(_timePerBlock);
                }

                if (iStartXPos >= 0)
                {
                    if (iPreviousEndXPos > iStartXPos)
                    {
                        iStartXPos = iPreviousEndXPos;
                    }
                    if (iEndXPos <= iStartXPos + 5)
                    {
                        iEndXPos = iStartXPos + 6; // at least 1 pixel width
                    }

                    int ypos = GetControl(iChannel + (int)Controls.IMG_CHAN1).YPosition;
                    int iControlId = GUIDE_COMPONENTID_START + iChannel * RowID + iProgram * ColID;
                    int iWidth = iEndXPos - iStartXPos;
                    if (iWidth > 3)
                    {
                        iWidth -= 3;
                    }
                    else
                    {
                        iWidth = 1;
                    }

                    string TexutureFocusLeftName = "tvguide_button_selected_left.png";
                    string TexutureFocusMidName = "tvguide_button_selected_middle.png";
                    string TexutureFocusRightName = "tvguide_button_selected_right.png";
                    string TexutureNoFocusLeftName = "tvguide_button_light_left.png";
                    string TexutureNoFocusMidName = "tvguide_button_light_middle.png";
                    string TexutureNoFocusRightName = "tvguide_button_light_right.png";

                    bool TileFillTFL = false;
                    bool TileFillTNFL = false;
                    bool TileFillTFM = false;
                    bool TileFillTNFM = false;
                    bool TileFillTFR = false;
                    bool TileFillTNFR = false;

                    if (_programNotRunningTemplate != null)
                    {
                        _programNotRunningTemplate.IsVisible = false;
                        TexutureFocusLeftName = _programNotRunningTemplate.TexutureFocusLeftName;
                        TexutureFocusMidName = _programNotRunningTemplate.TexutureFocusMidName;
                        TexutureFocusRightName = _programNotRunningTemplate.TexutureFocusRightName;
                        TexutureNoFocusLeftName = _programNotRunningTemplate.TexutureNoFocusLeftName;
                        TexutureNoFocusMidName = _programNotRunningTemplate.TexutureNoFocusMidName;
                        TexutureNoFocusRightName = _programNotRunningTemplate.TexutureNoFocusRightName;
                        TileFillTFL = _programNotRunningTemplate.TileFillTFL;
                        TileFillTNFL = _programNotRunningTemplate.TileFillTNFL;
                        TileFillTFM = _programNotRunningTemplate.TileFillTFM;
                        TileFillTNFM = _programNotRunningTemplate.TileFillTNFM;
                        TileFillTFR = _programNotRunningTemplate.TileFillTFR;
                        TileFillTNFR = _programNotRunningTemplate.TileFillTNFR;
                    }

                    img = GetControl(iControlId) as GUIButton3PartControl;
                    if (img == null)
                    {
                        img = new GUIButton3PartControl(GetID, iControlId, iStartXPos, ypos, iWidth, height - 2,
                                                        TexutureFocusLeftName,
                                                        TexutureFocusMidName,
                                                        TexutureFocusRightName,
                                                        TexutureNoFocusLeftName,
                                                        TexutureNoFocusMidName,
                                                        TexutureNoFocusRightName,
                                                        String.Empty);
                        img.AllocResources();
                        GUIControl cntl = (GUIControl)img;
                        Add(ref cntl);
                    }
                    else
                    {
                        img.Focus = false;
                        img.SetPosition(iStartXPos, ypos);
                        img.Width = iWidth;
                        img.IsVisible = true;
                        img.DoUpdate();
                    }

                    img.RenderLeft = false;
                    img.RenderRight = false;

                    img.TexutureIcon = String.Empty;
                    if (recordIconImage != null && isAlert)
                    {
                        if (_programNotifyTemplate != null)
                        {
                            _programNotifyTemplate.IsVisible = false;
                            TexutureFocusLeftName = _programNotifyTemplate.TexutureFocusLeftName;
                            TexutureFocusMidName = _programNotifyTemplate.TexutureFocusMidName;
                            TexutureFocusRightName = _programNotifyTemplate.TexutureFocusRightName;
                            TexutureNoFocusLeftName = _programNotifyTemplate.TexutureNoFocusLeftName;
                            TexutureNoFocusMidName = _programNotifyTemplate.TexutureNoFocusMidName;
                            TexutureNoFocusRightName = _programNotifyTemplate.TexutureNoFocusRightName;
                            TileFillTFL = _programNotifyTemplate.TileFillTFL;
                            TileFillTNFL = _programNotifyTemplate.TileFillTNFL;
                            TileFillTFM = _programNotifyTemplate.TileFillTFM;
                            TileFillTNFM = _programNotifyTemplate.TileFillTNFM;
                            TileFillTFR = _programNotifyTemplate.TileFillTFR;
                            TileFillTNFR = _programNotifyTemplate.TileFillTNFR;

                            // Use of the button template control implies use of the icon.  Use a blank image if the icon is not desired.
                            img.TexutureIcon = Thumbs.TvNotifyIcon;
                            img.IconOffsetX = _programNotifyTemplate.IconOffsetX;
                            img.IconOffsetY = _programNotifyTemplate.IconOffsetY;
                            img.IconAlign = _programNotifyTemplate.IconAlign;
                            img.IconVAlign = _programNotifyTemplate.IconVAlign;
                            img.IconInlineLabel1 = _programNotifyTemplate.IconInlineLabel1;
                        }
                        else
                        {
                            if (_useNewNotifyButtonColor)
                            {
                                TexutureFocusLeftName = "tvguide_notifyButton_Focus_left.png";
                                TexutureFocusMidName = "tvguide_notifyButton_Focus_middle.png";
                                TexutureFocusRightName = "tvguide_notifyButton_Focus_right.png";
                                TexutureNoFocusLeftName = "tvguide_notifyButton_noFocus_left.png";
                                TexutureNoFocusMidName = "tvguide_notifyButton_noFocus_middle.png";
                                TexutureNoFocusRightName = "tvguide_notifyButton_noFocus_right.png";
                            }
                            else
                            {
                                img.TexutureIcon = Thumbs.TvNotifyIcon;
                            }
                        }
                    }
                    if (recordIconImage != null)
                    {
                        // Select the partial recording template if needed.
                        //if (bPartialRecording)
                        //{
                        //    buttonRecordTemplate = _programPartialRecordTemplate;
                        //}

                        if (isRecording)
                        {
                            GUIButton3PartControl buttonRecordTemplate = _programRecordTemplate;
                            if (buttonRecordTemplate != null)
                            {
                                buttonRecordTemplate.IsVisible = false;
                                TexutureFocusLeftName = buttonRecordTemplate.TexutureFocusLeftName;
                                TexutureFocusMidName = buttonRecordTemplate.TexutureFocusMidName;
                                TexutureFocusRightName = buttonRecordTemplate.TexutureFocusRightName;
                                TexutureNoFocusLeftName = buttonRecordTemplate.TexutureNoFocusLeftName;
                                TexutureNoFocusMidName = buttonRecordTemplate.TexutureNoFocusMidName;
                                TexutureNoFocusRightName = buttonRecordTemplate.TexutureNoFocusRightName;
                                TileFillTFL = buttonRecordTemplate.TileFillTFL;
                                TileFillTNFL = buttonRecordTemplate.TileFillTNFL;
                                TileFillTFM = buttonRecordTemplate.TileFillTFM;
                                TileFillTNFM = buttonRecordTemplate.TileFillTNFM;
                                TileFillTFR = buttonRecordTemplate.TileFillTFR;
                                TileFillTNFR = buttonRecordTemplate.TileFillTNFR;

                                // Use of the button template control implies use of the icon.  Use a blank image if the icon is not desired.
                                //if (bConflict)
                                //{
                                //    TexutureFocusLeftName = "tvguide_recButton_Focus_left.png";
                                //    TexutureFocusMidName = "tvguide_recButton_Focus_middle.png";
                                //    TexutureFocusRightName = "tvguide_recButton_Focus_right.png";
                                //    TexutureNoFocusLeftName = "tvguide_recButton_noFocus_left.png";
                                //    TexutureNoFocusMidName = "tvguide_recButton_noFocus_middle.png";
                                //    TexutureNoFocusRightName = "tvguide_recButton_noFocus_right.png";
                                //}
                                img.IconOffsetX = buttonRecordTemplate.IconOffsetX;
                                img.IconOffsetY = buttonRecordTemplate.IconOffsetY;
                                img.IconAlign = buttonRecordTemplate.IconAlign;
                                img.IconVAlign = buttonRecordTemplate.IconVAlign;
                                img.IconInlineLabel1 = buttonRecordTemplate.IconInlineLabel1;
                            }
                            else
                            {
                                //if (bPartialRecording && _useNewPartialRecordingButtonColor)
                                //{
                                //    TexutureFocusLeftName = "tvguide_partRecButton_Focus_left.png";
                                //    TexutureFocusMidName = "tvguide_partRecButton_Focus_middle.png";
                                //    TexutureFocusRightName = "tvguide_partRecButton_Focus_right.png";
                                //    TexutureNoFocusLeftName = "tvguide_partRecButton_noFocus_left.png";
                                //    TexutureNoFocusMidName = "tvguide_partRecButton_noFocus_middle.png";
                                //    TexutureNoFocusRightName = "tvguide_partRecButton_noFocus_right.png";
                                //}
                                //else
                                {
                                    if (_useNewRecordingButtonColor)
                                    {
                                        TexutureFocusLeftName = "tvguide_recButton_Focus_left.png";
                                        TexutureFocusMidName = "tvguide_recButton_Focus_middle.png";
                                        TexutureFocusRightName = "tvguide_recButton_Focus_right.png";
                                        TexutureNoFocusLeftName = "tvguide_recButton_noFocus_left.png";
                                        TexutureNoFocusMidName = "tvguide_recButton_noFocus_middle.png";
                                        TexutureNoFocusRightName = "tvguide_recButton_noFocus_right.png";
                                    }
                                }
                            }
                        }
                        img.TexutureIcon = recordIconImage;
                    }

                    img.TexutureIcon2 = String.Empty;
                    if (bProgramIsHD)
                    {
                        if (_programNotRunningTemplate != null)
                        {
                            img.TexutureIcon2 = _programNotRunningTemplate.TexutureIcon2;
                        }
                        else
                        {
                            if (_useHdProgramIcon)
                            {
                                img.TexutureIcon2 = "tvguide_hd_program.png";
                            }
                        }
                        img.Icon2InlineLabel1 = true;
                        img.Icon2VAlign = GUIControl.VAlignment.ALIGN_MIDDLE;
                        img.Icon2OffsetX = 5;
                    }
                    img.Data = program;
                    img.ColourDiffuse = GetColorForGenre(program.Category);

                    iWidth = iEndXPos - iStartXPos;
                    if (iWidth > 10)
                    {
                        iWidth -= 10;
                    }
                    else
                    {
                        iWidth = 1;
                    }

                    DateTime dt = DateTime.Now;

                    img.TextOffsetX1 = 5;
                    img.TextOffsetY1 = 5;
                    img.FontName1 = "font13";
                    img.TextColor1 = 0xffffffff;
                    img.Label1 = strTitle;
                    GUILabelControl labelTemplate;
                    if (IsRunningAt(program, dt))
                    {
                        labelTemplate = _titleDarkTemplate;
                    }
                    else
                    {
                        labelTemplate = _titleTemplate;
                    }

                    if (labelTemplate != null)
                    {
                        img.FontName1 = labelTemplate.FontName;
                        img.TextColor1 = labelTemplate.TextColor;
                        img.TextColor2 = labelTemplate.TextColor;
                        img.TextOffsetX1 = labelTemplate.XPosition;
                        img.TextOffsetY1 = labelTemplate.YPosition;
                        img.SetShadow1(labelTemplate.ShadowAngle, labelTemplate.ShadowDistance, labelTemplate.ShadowColor);

                        // This is a legacy behavior check.  Adding labelTemplate.XPosition and labelTemplate.YPosition requires
                        // skinners to add these values to the skin xml unless this check exists.  Perform a sanity check on the
                        // x,y position to ensure it falls into the bounds of the button.  If it does not then fall back to use the
                        // legacy values.  This check is necessary because the x,y position (without skin file changes) will be taken
                        // from either the references.xml control template or the controls coded defaults.
                        if (img.TextOffsetY1 > img.Height)
                        {
                            // Set legacy values.
                            img.TextOffsetX1 = 5;
                            img.TextOffsetY1 = 5;
                        }
                    }
                    img.TextOffsetX2 = 5;
                    img.TextOffsetY2 = img.Height / 2;
                    img.FontName2 = "font13";
                    img.TextColor2 = 0xffffffff;

                    if (IsRunningAt(program, dt))
                    {
                        labelTemplate = _genreDarkTemplate;
                    }
                    else
                    {
                        labelTemplate = _genreTemplate;
                    }
                    if (labelTemplate != null)
                    {
                        img.FontName2 = labelTemplate.FontName;
                        img.TextColor2 = labelTemplate.TextColor;
                        img.Label2 = program.Category;
                        img.TextOffsetX2 = labelTemplate.XPosition;
                        img.TextOffsetY2 = labelTemplate.YPosition;
                        img.SetShadow2(labelTemplate.ShadowAngle, labelTemplate.ShadowDistance, labelTemplate.ShadowColor);

                        // This is a legacy behavior check.  Adding labelTemplate.XPosition and labelTemplate.YPosition requires
                        // skinners to add these values to the skin xml unless this check exists.  Perform a sanity check on the
                        // x,y position to ensure it falls into the bounds of the button.  If it does not then fall back to use the
                        // legacy values.  This check is necessary because the x,y position (without skin file changes) will be taken
                        // from either the references.xml control template or the controls coded defaults.
                        if (img.TextOffsetY2 > img.Height)
                        {
                            // Set legacy values.
                            img.TextOffsetX2 = 5;
                            img.TextOffsetY2 = 5;
                        }
                    }

                    if (IsRunningAt(program, dt))
                    {
                        GUIButton3PartControl buttonRunningTemplate = _programRunningTemplate;
                        if (!isRecording && !isAlert && buttonRunningTemplate != null)
                        {
                            buttonRunningTemplate.IsVisible = false;
                            TexutureFocusLeftName = buttonRunningTemplate.TexutureFocusLeftName;
                            TexutureFocusMidName = buttonRunningTemplate.TexutureFocusMidName;
                            TexutureFocusRightName = buttonRunningTemplate.TexutureFocusRightName;
                            TexutureNoFocusLeftName = buttonRunningTemplate.TexutureNoFocusLeftName;
                            TexutureNoFocusMidName = buttonRunningTemplate.TexutureNoFocusMidName;
                            TexutureNoFocusRightName = buttonRunningTemplate.TexutureNoFocusRightName;
                            TileFillTFL = buttonRunningTemplate.TileFillTFL;
                            TileFillTNFL = buttonRunningTemplate.TileFillTNFL;
                            TileFillTFM = buttonRunningTemplate.TileFillTFM;
                            TileFillTNFM = buttonRunningTemplate.TileFillTNFM;
                            TileFillTFR = buttonRunningTemplate.TileFillTFR;
                            TileFillTNFR = buttonRunningTemplate.TileFillTNFR;
                        }
                        else if (isRecording && _useNewRecordingButtonColor)
                        {
                            TexutureFocusLeftName = "tvguide_recButton_Focus_left.png";
                            TexutureFocusMidName = "tvguide_recButton_Focus_middle.png";
                            TexutureFocusRightName = "tvguide_recButton_Focus_right.png";
                            TexutureNoFocusLeftName = "tvguide_recButton_noFocus_left.png";
                            TexutureNoFocusMidName = "tvguide_recButton_noFocus_middle.png";
                            TexutureNoFocusRightName = "tvguide_recButton_noFocus_right.png";
                        }
                        else if (isAlert && _useNewRecordingButtonColor)
                        {
                            TexutureFocusLeftName = "tvguide_notifyButton_Focus_left.png";
                            TexutureFocusMidName = "tvguide_notifyButton_Focus_middle.png";
                            TexutureFocusRightName = "tvguide_notifyButton_Focus_right.png";
                            TexutureNoFocusLeftName = "tvguide_notifyButton_noFocus_left.png";
                            TexutureNoFocusMidName = "tvguide_notifyButton_noFocus_middle.png";
                            TexutureNoFocusRightName = "tvguide_notifyButton_noFocus_right.png";
                        }
                        else
                        {
                            TexutureFocusLeftName = "tvguide_button_selected_left.png";
                            TexutureFocusMidName = "tvguide_button_selected_middle.png";
                            TexutureFocusRightName = "tvguide_button_selected_right.png";
                            TexutureNoFocusLeftName = "tvguide_button_left.png";
                            TexutureNoFocusMidName = "tvguide_button_middle.png";
                            TexutureNoFocusRightName = "tvguide_button_right.png";
                        }

                        if (selectCurrentShow && iChannel == _cursorX)
                        {
                            _cursorY = iProgram + 1;
                            _currentProgram = tvGuideAgent.GetProgramById(program.GuideProgramId);
                            m_dtStartTime = program.StartTime;
                            SetProperties();
                        }
                    }

                    if (bEndsAfter)
                    {
                        img.RenderRight = true;

                        TexutureFocusRightName = "tvguide_arrow_selected_right.png";
                        TexutureNoFocusRightName = "tvguide_arrow_light_right.png";
                        if (IsRunningAt(program, dt))
                        {
                            TexutureNoFocusRightName = "tvguide_arrow_right.png";
                        }
                    }
                    if (bStartsBefore)
                    {
                        img.RenderLeft = true;
                        TexutureFocusLeftName = "tvguide_arrow_selected_left.png";
                        TexutureNoFocusLeftName = "tvguide_arrow_light_left.png";
                        if (IsRunningAt(program, dt))
                        {
                            TexutureNoFocusLeftName = "tvguide_arrow_left.png";
                        }
                    }

                    img.TexutureFocusLeftName = TexutureFocusLeftName;
                    img.TexutureFocusMidName = TexutureFocusMidName;
                    img.TexutureFocusRightName = TexutureFocusRightName;
                    img.TexutureNoFocusLeftName = TexutureNoFocusLeftName;
                    img.TexutureNoFocusMidName = TexutureNoFocusMidName;
                    img.TexutureNoFocusRightName = TexutureNoFocusRightName;

                    img.TileFillTFL = TileFillTFL;
                    img.TileFillTNFL = TileFillTNFL;
                    img.TileFillTFM = TileFillTFM;
                    img.TileFillTNFM = TileFillTNFM;
                    img.TileFillTFR = TileFillTFR;
                    img.TileFillTNFR = TileFillTNFR;

                    iProgram++;
                }
                iPreviousEndXPos = iEndXPos;
            }
        }
Exemplo n.º 26
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);
                }
            }
        }
Exemplo n.º 27
0
        private void RenderSingleChannel(SchedulerServiceAgent tvSchedulerAgent, GuideServiceAgent tvGuideAgent, Channel channel)
        {
            string strLogo;
            int chan = _channelOffset;
            for (int iChannel = 0; iChannel < _channelCount; iChannel++)
            {
                if (chan < _channelList.Count)
                {
                    Channel tvChan = _channelList[chan].channel;

                    strLogo = GetChannelLogo(tvChan);
                    GUIButton3PartControl img = GetControl(iChannel + (int)Controls.IMG_CHAN1) as GUIButton3PartControl;
                    if (img != null)
                    {
                        if (_showChannelLogos)
                        {
                            img.TexutureIcon = strLogo;
                        }
                        img.Label1 = tvChan.DisplayName;
                        img.Data = tvChan;
                        img.IsVisible = true;
                    }
                }
                chan++;
            }

            List<GuideProgramSummary> programs = new List<GuideProgramSummary>();
            DateTime dtStart = DateTime.Now;
            dtStart = dtStart.AddDays(-1);
            DateTime dtEnd = dtStart.AddDays(30);
            long iStart = Utils.datetolong(dtStart);
            long iEnd = Utils.datetolong(dtEnd);

            if (channel.GuideChannelId.HasValue)
            {
                programs = new List<GuideProgramSummary>(
                    tvGuideAgent.GetChannelProgramsBetween(channel.GuideChannelId.Value, Utils.longtodate(iStart), Utils.longtodate(iEnd)));
            }

            _totalProgramCount = programs.Count;
            if (_totalProgramCount == 0)
            {
                _totalProgramCount = _channelCount;
            }

            GUILabelControl channelLabel = GetControl((int)Controls.SINGLE_CHANNEL_LABEL) as GUILabelControl;
            GUIImage channelImage = GetControl((int)Controls.SINGLE_CHANNEL_IMAGE) as GUIImage;

            strLogo = GetChannelLogo(channel);
            if (channelImage == null)
            {
                if (strLogo.Length > 0)
                {
                    channelImage = new GUIImage(GetID, (int)Controls.SINGLE_CHANNEL_IMAGE,
                                                GetControl((int)Controls.LABEL_TIME1).XPosition,
                                                GetControl((int)Controls.LABEL_TIME1).YPosition - 15,
                                                40, 40, strLogo, Color.White);
                    channelImage.AllocResources();
                    GUIControl temp = (GUIControl)channelImage;
                    Add(ref temp);
                }
            }
            else
            {
                channelImage.SetFileName(strLogo);
            }

            if (channelLabel == null)
            {
                channelLabel = new GUILabelControl(GetID, (int)Controls.SINGLE_CHANNEL_LABEL,
                                                   channelImage.XPosition + 44,
                                                   channelImage.YPosition + 10,
                                                   300, 40, "font16", channel.DisplayName, 4294967295, GUIControl.Alignment.Left,
                                                   GUIControl.VAlignment.Top,
                                                   true, 0, 0, 0xFF000000);
                channelLabel.AllocResources();
                GUIControl temp = channelLabel;
                Add(ref temp);
            }

            SetSingleChannelLabelVisibility(true);

            channelLabel.Label = channel.DisplayName;
            if (strLogo.Length > 0)
            {
                channelImage.SetFileName(strLogo);
            }

            if (channelLabel != null)
            {
                channelLabel.Label = channel.DisplayName;
            }
            if (_recalculateProgramOffset)
            {
                _recalculateProgramOffset = false;
                bool found = false;
                for (int i = 0; i < programs.Count; i++)
                {
                    GuideProgramSummary program = programs[i];
                    if (program.StartTime <= _viewingTime && program.StopTime >= _viewingTime)
                    {
                        _programOffset = i;
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    _programOffset = 0;
                }
            }
            else if (_programOffset < programs.Count)
            {
                int day = programs[_programOffset].StartTime.DayOfYear;
                bool changed = false;
                while (day > _viewingTime.DayOfYear)
                {
                    _viewingTime = _viewingTime.AddDays(1.0);
                    changed = true;
                }
                while (day < _viewingTime.DayOfYear)
                {
                    _viewingTime = _viewingTime.AddDays(-1.0);
                    changed = true;
                }
                if (changed)
                {
                    GUISpinControl cntlDay = GetControl((int)Controls.SPINCONTROL_DAY) as GUISpinControl;

                    // Find first day in TVGuide and set spincontrol position
                    int iDay = CalcDays();
                    for (; iDay < 0; ++iDay)
                    {
                        _viewingTime = _viewingTime.AddDays(1.0);
                    }
                    for (; iDay >= MaxDaysInGuide; --iDay)
                    {
                        _viewingTime = _viewingTime.AddDays(-1.0);
                    }
                    cntlDay.Value = iDay;
                }
            }
            // ichan = number of rows
            for (int ichan = 0; ichan < _channelCount; ++ichan)
            {
                GUIButton3PartControl imgCh = GetControl(ichan + (int)Controls.IMG_CHAN1) as GUIButton3PartControl;
                imgCh.TexutureIcon = "";

                int iStartXPos = GetControl(0 + (int)Controls.LABEL_TIME1).XPosition;
                int height = GetControl((int)Controls.IMG_CHAN1 + 1).YPosition;
                height -= GetControl((int)Controls.IMG_CHAN1).YPosition;
                int width = GetControl((int)Controls.LABEL_TIME1 + 1).XPosition;
                width -= GetControl((int)Controls.LABEL_TIME1).XPosition;

                int iTotalWidth = width * _numberOfBlocks;

                GuideProgramSummary program;
                int offset = _programOffset;
                if (offset + ichan < programs.Count)
                {
                    program = programs[offset + ichan];
                }
                else
                {
                    // bugfix for 0 items
                    if (programs.Count == 0)
                    {
                        program = new GuideProgramSummary()
                        {
                            StartTime = _viewingTime,
                            StopTime = _viewingTime,
                            StartTimeUtc = _viewingTime.ToUniversalTime(),
                            StopTimeUtc = _viewingTime.ToUniversalTime(),
                            Title = String.Empty,
                            Category = String.Empty
                        };
                    }
                    else
                    {
                        program = programs[programs.Count - 1];
                        if (program.StopTime.DayOfYear == _viewingTime.DayOfYear)
                        {
                            program = new GuideProgramSummary()
                            {
                                StartTime = program.StopTime,
                                StopTime = program.StopTime,
                                StartTimeUtc = program.StartTimeUtc.ToUniversalTime(),
                                StopTimeUtc = program.StopTimeUtc.ToUniversalTime(),
                                Title = String.Empty,
                                Category = String.Empty
                            };
                        }
                        else
                        {
                            program = new GuideProgramSummary()
                            {
                                StartTime = _viewingTime,
                                StopTime = _viewingTime,
                                StartTimeUtc = _viewingTime.ToUniversalTime(),
                                StopTimeUtc = _viewingTime.ToUniversalTime(),
                                Title = String.Empty,
                                Category = String.Empty
                            };
                        }
                    }
                }

                int ypos = GetControl(ichan + (int)Controls.IMG_CHAN1).YPosition;
                int iControlId = GUIDE_COMPONENTID_START + ichan * RowID + 0 * ColID;
                GUIButton3PartControl img = GetControl(iControlId) as GUIButton3PartControl;
                GUIButton3PartControl buttonTemplate = GetControl((int)Controls.BUTTON_PROGRAM_NOT_RUNNING) as GUIButton3PartControl;

                if (img == null)
                {
                    if (buttonTemplate != null)
                    {
                        buttonTemplate.IsVisible = false;
                        img = new GUIButton3PartControl(GetID, iControlId, iStartXPos, ypos, iTotalWidth, height - 2,
                                                        buttonTemplate.TexutureFocusLeftName,
                                                        buttonTemplate.TexutureFocusMidName,
                                                        buttonTemplate.TexutureFocusRightName,
                                                        buttonTemplate.TexutureNoFocusLeftName,
                                                        buttonTemplate.TexutureNoFocusMidName,
                                                        buttonTemplate.TexutureNoFocusRightName,
                                                        String.Empty);

                        img.TileFillTFL = buttonTemplate.TileFillTFL;
                        img.TileFillTNFL = buttonTemplate.TileFillTNFL;
                        img.TileFillTFM = buttonTemplate.TileFillTFM;
                        img.TileFillTNFM = buttonTemplate.TileFillTNFM;
                        img.TileFillTFR = buttonTemplate.TileFillTFR;
                        img.TileFillTNFR = buttonTemplate.TileFillTNFR;
                    }
                    else
                    {
                        img = new GUIButton3PartControl(GetID, iControlId, iStartXPos, ypos, iTotalWidth, height - 2,
                                                        "tvguide_button_selected_left.png",
                                                        "tvguide_button_selected_middle.png",
                                                        "tvguide_button_selected_right.png",
                                                        "tvguide_button_light_left.png",
                                                        "tvguide_button_light_middle.png",
                                                        "tvguide_button_light_right.png",
                                                        String.Empty);
                    }
                    img.AllocResources();
                    img.ColourDiffuse = GetColorForGenre(program.Category);
                    GUIControl cntl = (GUIControl)img;
                    Add(ref cntl);
                }
                else
                {
                    if (buttonTemplate != null)
                    {
                        buttonTemplate.IsVisible = false;
                        img.TexutureFocusLeftName = buttonTemplate.TexutureFocusLeftName;
                        img.TexutureFocusMidName = buttonTemplate.TexutureFocusMidName;
                        img.TexutureFocusRightName = buttonTemplate.TexutureFocusRightName;
                        img.TexutureNoFocusLeftName = buttonTemplate.TexutureNoFocusLeftName;
                        img.TexutureNoFocusMidName = buttonTemplate.TexutureNoFocusMidName;
                        img.TexutureNoFocusRightName = buttonTemplate.TexutureNoFocusRightName;
                        img.TileFillTFL = buttonTemplate.TileFillTFL;
                        img.TileFillTNFL = buttonTemplate.TileFillTNFL;
                        img.TileFillTFM = buttonTemplate.TileFillTFM;
                        img.TileFillTNFM = buttonTemplate.TileFillTNFM;
                        img.TileFillTFR = buttonTemplate.TileFillTFR;
                        img.TileFillTNFR = buttonTemplate.TileFillTNFR;
                    }
                    else
                    {
                        img.TexutureFocusLeftName = "tvguide_button_selected_left.png";
                        img.TexutureFocusMidName = "tvguide_button_selected_middle.png";
                        img.TexutureFocusRightName = "tvguide_button_selected_right.png";
                        img.TexutureNoFocusLeftName = "tvguide_button_light_left.png";
                        img.TexutureNoFocusMidName = "tvguide_button_light_middle.png";
                        img.TexutureNoFocusRightName = "tvguide_button_light_right.png";
                    }
                    img.Focus = false;
                    img.SetPosition(iStartXPos, ypos);
                    img.Width = iTotalWidth;
                    img.ColourDiffuse = GetColorForGenre(program.Category);
                    img.IsVisible = true;
                    img.DoUpdate();
                }
                img.RenderLeft = false;
                img.RenderRight = false;

                bool isRecording;
                bool isAlert;
                string recordIconImage = GetChannelProgramIcon(channel, program.GuideProgramId, out isRecording,out isAlert);

                img.Data = program;
                img.ColourDiffuse = GetColorForGenre(program.Category);
                height = height - 10;
                height /= 2;
                int iWidth = iTotalWidth;
                if (iWidth > 10)
                {
                    iWidth -= 10;
                }
                else
                {
                    iWidth = 1;
                }

                DateTime dt = DateTime.Now;

                img.TextOffsetX1 = 5;
                img.TextOffsetY1 = 5;
                img.FontName1 = "font13";
                img.TextColor1 = 0xffffffff;

                img.Label1 = program.CreateProgramTitle();

                string strTimeSingle = String.Format("{0}",
                                                     program.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat));

                if (program.StartTime.DayOfYear != _viewingTime.DayOfYear)
                {
                    img.Label1 = String.Format("{0} {1}", Utility.GetShortDayDateString(program.StartTime), program.CreateProgramTitle());
                }

                GUILabelControl labelTemplate;
                if (IsRunningAt(program, dt))
                {
                    labelTemplate = _titleDarkTemplate;
                }
                else
                {
                    labelTemplate = _titleTemplate;
                }

                if (labelTemplate != null)
                {
                    img.FontName1 = labelTemplate.FontName;
                    img.TextColor1 = labelTemplate.TextColor;
                    img.TextOffsetX1 = labelTemplate.XPosition;
                    img.TextOffsetY1 = labelTemplate.YPosition;
                    img.SetShadow1(labelTemplate.ShadowAngle, labelTemplate.ShadowDistance, labelTemplate.ShadowColor);
                }
                img.TextOffsetX2 = 5;
                img.TextOffsetY2 = img.Height / 2;
                img.FontName2 = "font13";
                img.TextColor2 = 0xffffffff;
                img.Label2 = "";
                if (IsRunningAt(program, dt))
                {
                    img.TextColor2 = 0xff101010;
                    labelTemplate = _genreDarkTemplate;
                }
                else
                {
                    labelTemplate = _genreTemplate;
                }

                if (labelTemplate != null)
                {
                    img.FontName2 = labelTemplate.FontName;
                    img.TextColor2 = labelTemplate.TextColor;
                    img.Label2 = program.Category;
                    img.TextOffsetX2 = labelTemplate.XPosition;
                    img.TextOffsetY2 = labelTemplate.YPosition;
                    img.SetShadow2(labelTemplate.ShadowAngle, labelTemplate.ShadowDistance, labelTemplate.ShadowColor);
                }
                imgCh.Label1 = strTimeSingle;
                imgCh.TexutureIcon = "";

                if (IsRunningAt(program, dt))
                {
                    GUIButton3PartControl buttonRunningTemplate = _programRunningTemplate;
                    if (buttonRunningTemplate != null)
                    {
                        buttonRunningTemplate.IsVisible = false;
                        img.TexutureFocusLeftName = buttonRunningTemplate.TexutureFocusLeftName;
                        img.TexutureFocusMidName = buttonRunningTemplate.TexutureFocusMidName;
                        img.TexutureFocusRightName = buttonRunningTemplate.TexutureFocusRightName;
                        img.TexutureNoFocusLeftName = buttonRunningTemplate.TexutureNoFocusLeftName;
                        img.TexutureNoFocusMidName = buttonRunningTemplate.TexutureNoFocusMidName;
                        img.TexutureNoFocusRightName = buttonRunningTemplate.TexutureNoFocusRightName;
                        img.TileFillTFL = buttonRunningTemplate.TileFillTFL;
                        img.TileFillTNFL = buttonRunningTemplate.TileFillTNFL;
                        img.TileFillTFM = buttonRunningTemplate.TileFillTFM;
                        img.TileFillTNFM = buttonRunningTemplate.TileFillTNFM;
                        img.TileFillTFR = buttonRunningTemplate.TileFillTFR;
                        img.TileFillTNFR = buttonRunningTemplate.TileFillTNFR;
                    }
                    else
                    {
                        img.TexutureFocusLeftName = "tvguide_button_selected_left.png";
                        img.TexutureFocusMidName = "tvguide_button_selected_middle.png";
                        img.TexutureFocusRightName = "tvguide_button_selected_right.png";
                        img.TexutureNoFocusLeftName = "tvguide_button_left.png";
                        img.TexutureNoFocusMidName = "tvguide_button_middle.png";
                        img.TexutureNoFocusRightName = "tvguide_button_right.png";
                    }
                }

                img.SetPosition(img.XPosition, img.YPosition);

                img.TexutureIcon = String.Empty;

                if (recordIconImage != null && isAlert)
                {
                    GUIButton3PartControl buttonNotifyTemplate = GetControl((int)Controls.BUTTON_PROGRAM_NOTIFY) as GUIButton3PartControl;
                    if (buttonNotifyTemplate != null)
                    {
                        buttonNotifyTemplate.IsVisible = false;
                        img.TexutureFocusLeftName = buttonNotifyTemplate.TexutureFocusLeftName;
                        img.TexutureFocusMidName = buttonNotifyTemplate.TexutureFocusMidName;
                        img.TexutureFocusRightName = buttonNotifyTemplate.TexutureFocusRightName;
                        img.TexutureNoFocusLeftName = buttonNotifyTemplate.TexutureNoFocusLeftName;
                        img.TexutureNoFocusMidName = buttonNotifyTemplate.TexutureNoFocusMidName;
                        img.TexutureNoFocusRightName = buttonNotifyTemplate.TexutureNoFocusRightName;
                        img.TileFillTFL = buttonNotifyTemplate.TileFillTFL;
                        img.TileFillTNFL = buttonNotifyTemplate.TileFillTNFL;
                        img.TileFillTFM = buttonNotifyTemplate.TileFillTFM;
                        img.TileFillTNFM = buttonNotifyTemplate.TileFillTNFM;
                        img.TileFillTFR = buttonNotifyTemplate.TileFillTFR;
                        img.TileFillTNFR = buttonNotifyTemplate.TileFillTNFR;

                        // Use of the button template control implies use of the icon.  Use a blank image if the icon is not desired.
                        img.TexutureIcon = Thumbs.TvNotifyIcon;
                        img.IconOffsetX = buttonNotifyTemplate.IconOffsetX;
                        img.IconOffsetY = buttonNotifyTemplate.IconOffsetY;
                        img.IconAlign = buttonNotifyTemplate.IconAlign;
                        img.IconVAlign = buttonNotifyTemplate.IconVAlign;
                        img.IconInlineLabel1 = buttonNotifyTemplate.IconInlineLabel1;
                    }
                    else
                    {
                        if (_useNewNotifyButtonColor)
                        {
                            img.TexutureFocusLeftName = "tvguide_notifyButton_Focus_left.png";
                            img.TexutureFocusMidName = "tvguide_notifyButton_Focus_middle.png";
                            img.TexutureFocusRightName = "tvguide_notifyButton_Focus_right.png";
                            img.TexutureNoFocusLeftName = "tvguide_notifyButton_noFocus_left.png";
                            img.TexutureNoFocusMidName = "tvguide_notifyButton_noFocus_middle.png";
                            img.TexutureNoFocusRightName = "tvguide_notifyButton_noFocus_right.png";
                        }
                        else
                        {
                            img.TexutureIcon = Thumbs.TvNotifyIcon;
                        }
                    }
                }

                if (recordIconImage != null)
                {
                    //bool bPartialRecording = program.IsPartialRecordingSeriesPending;
                    GUIButton3PartControl buttonRecordTemplate = GetControl((int)Controls.BUTTON_PROGRAM_RECORD) as GUIButton3PartControl;

                    // Select the partial recording template if needed.
                    //if (bPartialRecording)
                    //{
                    //    buttonRecordTemplate = GetControl((int)Controls.BUTTON_PROGRAM_PARTIAL_RECORD) as GUIButton3PartControl;
                    //}

                    if (isRecording)
                    {
                        if (buttonRecordTemplate != null)
                        {
                            buttonRecordTemplate.IsVisible = false;
                            img.TexutureFocusLeftName = buttonRecordTemplate.TexutureFocusLeftName;
                            img.TexutureFocusMidName = buttonRecordTemplate.TexutureFocusMidName;
                            img.TexutureFocusRightName = buttonRecordTemplate.TexutureFocusRightName;
                            img.TexutureNoFocusLeftName = buttonRecordTemplate.TexutureNoFocusLeftName;
                            img.TexutureNoFocusMidName = buttonRecordTemplate.TexutureNoFocusMidName;
                            img.TexutureNoFocusRightName = buttonRecordTemplate.TexutureNoFocusRightName;
                            img.TileFillTFL = buttonRecordTemplate.TileFillTFL;
                            img.TileFillTNFL = buttonRecordTemplate.TileFillTNFL;
                            img.TileFillTFM = buttonRecordTemplate.TileFillTFM;
                            img.TileFillTNFM = buttonRecordTemplate.TileFillTNFM;
                            img.TileFillTFR = buttonRecordTemplate.TileFillTFR;
                            img.TileFillTNFR = buttonRecordTemplate.TileFillTNFR;

                            // Use of the button template control implies use of the icon.  Use a blank image if the icon is not desired.
                            //if (bConflict)
                            //{
                            //    img.TexutureFocusLeftName = "tvguide_recButton_Focus_left.png";
                            //    img.TexutureFocusMidName = "tvguide_recButton_Focus_middle.png";
                            //    img.TexutureFocusRightName = "tvguide_recButton_Focus_right.png";
                            //    img.TexutureNoFocusLeftName = "tvguide_recButton_noFocus_left.png";
                            //    img.TexutureNoFocusMidName = "tvguide_recButton_noFocus_middle.png";
                            //    img.TexutureNoFocusRightName = "tvguide_recButton_noFocus_right.png";
                            //}
                            img.IconOffsetX = buttonRecordTemplate.IconOffsetX;
                            img.IconOffsetY = buttonRecordTemplate.IconOffsetY;
                            img.IconAlign = buttonRecordTemplate.IconAlign;
                            img.IconVAlign = buttonRecordTemplate.IconVAlign;
                            img.IconInlineLabel1 = buttonRecordTemplate.IconInlineLabel1;
                        }
                        else
                        {
                            //if (bPartialRecording && _useNewPartialRecordingButtonColor)
                            //{
                            //    img.TexutureFocusLeftName = "tvguide_partRecButton_Focus_left.png";
                            //    img.TexutureFocusMidName = "tvguide_partRecButton_Focus_middle.png";
                            //    img.TexutureFocusRightName = "tvguide_partRecButton_Focus_right.png";
                            //    img.TexutureNoFocusLeftName = "tvguide_partRecButton_noFocus_left.png";
                            //    img.TexutureNoFocusMidName = "tvguide_partRecButton_noFocus_middle.png";
                            //    img.TexutureNoFocusRightName = "tvguide_partRecButton_noFocus_right.png";
                            //}
                            //else
                            {
                                if (_useNewRecordingButtonColor)
                                {
                                    img.TexutureFocusLeftName = "tvguide_recButton_Focus_left.png";
                                    img.TexutureFocusMidName = "tvguide_recButton_Focus_middle.png";
                                    img.TexutureFocusRightName = "tvguide_recButton_Focus_right.png";
                                    img.TexutureNoFocusLeftName = "tvguide_recButton_noFocus_left.png";
                                    img.TexutureNoFocusMidName = "tvguide_recButton_noFocus_middle.png";
                                    img.TexutureNoFocusRightName = "tvguide_recButton_noFocus_right.png";
                                }
                            }
                        }
                    }

                    img.TexutureIcon = recordIconImage;
                }
            }
        }
Exemplo n.º 28
0
 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 { }
                 }
             }
         }
     }
 }
Exemplo n.º 29
0
        private void SetFocus()
        {
            if (_cursorX < 0)
            {
                return;
            }
            if (_cursorY == 0 || _cursorY == MinYIndex) // either channel or group button
            {
                int controlid;
                GUIControl.UnfocusControl(GetID, (int)Controls.SPINCONTROL_DAY);
                GUIControl.UnfocusControl(GetID, (int)Controls.SPINCONTROL_TIME_INTERVAL);

                if (_cursorY == -1)
                    controlid = (int)Controls.CHANNEL_GROUP_BUTTON;
                else
                    controlid = (int)Controls.IMG_CHAN1 + _cursorX;

                GUIControl.FocusControl(GetID, controlid);
            }
            else
            {
                Correct();
                int iControlId = GUIDE_COMPONENTID_START + _cursorX * RowID + (_cursorY - 1) * ColID;
                GUIButton3PartControl img = GetControl(iControlId) as GUIButton3PartControl;
                if (null != img && img.IsVisible)
                {
                    img.ColourDiffuse = 0xffffffff;
                    using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                    {
                        _currentProgram = tvGuideAgent.GetProgramById(((GuideProgramSummary)img.Data).GuideProgramId);
                    }
                    SetProperties();
                }
                GUIControl.FocusControl(GetID, iControlId);
            }
        }
 private void _programsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 3
         && e.RowIndex >= 0
         && e.RowIndex < _programsDataGridView.Rows.Count)
     {
         UpcomingOrActiveProgramView programView = _programsDataGridView.Rows[e.RowIndex].DataBoundItem as UpcomingOrActiveProgramView;
         if (programView.UpcomingProgram.GuideProgramId.HasValue)
         {
             using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
             {
                 GuideProgram guideProgram = tvGuideAgent.GetProgramById(programView.UpcomingProgram.GuideProgramId.Value);
                 using (ProgramDetailsPopup popup = new ProgramDetailsPopup())
                 {
                     popup.Channel = programView.UpcomingProgram.Channel;
                     popup.GuideProgram = guideProgram;
                     Point location = Cursor.Position;
                     location.Offset(-250, -40);
                     popup.Location = location;
                     popup.ShowDialog(this);
                 }
             }
         }
     }
 }
Exemplo n.º 31
0
        private void Update(bool selectCurrentShow)
        {
            lock (this)
            {
                if (GUIWindowManager.ActiveWindowEx != this.GetID)
                {
                    return;
                }

                // sets button visible state
                UpdateGroupButton();

                _updateTimer = DateTime.Now;
                GUISpinControl cntlDay = GetControl((int)Controls.SPINCONTROL_DAY) as GUISpinControl;

                // Find first day in TVGuide and set spincontrol position
                int iDay = CalcDays();
                for (; iDay < 0; ++iDay)
                {
                    _viewingTime = _viewingTime.AddDays(1.0);
                }
                for (; iDay >= MaxDaysInGuide; --iDay)
                {
                    _viewingTime = _viewingTime.AddDays(-1.0);
                }
                cntlDay.Value = iDay;

                int xpos, ypos;
                GUIControl cntlPanel = GetControl((int)Controls.PANEL_BACKGROUND);
                GUIImage cntlChannelImg = (GUIImage)GetControl((int)Controls.CHANNEL_IMAGE_TEMPLATE);
                GUILabelControl cntlChannelLabel = (GUILabelControl)GetControl((int)Controls.CHANNEL_LABEL_TEMPLATE);
                GUILabelControl labelTime = (GUILabelControl)GetControl((int)Controls.LABEL_TIME1);
                GUIImage cntlHeaderBkgImg = (GUIImage)GetControl((int)Controls.IMG_TIME1);
                GUIImage cntlChannelTemplate = (GUIImage)GetControl((int)Controls.CHANNEL_TEMPLATE);

                _titleDarkTemplate = GetControl((int)Controls.LABEL_TITLE_DARK_TEMPLATE) as GUILabelControl;
                _titleTemplate = GetControl((int)Controls.LABEL_TITLE_TEMPLATE) as GUILabelControl;
                _genreDarkTemplate = GetControl((int)Controls.LABEL_GENRE_DARK_TEMPLATE) as GUILabelControl;
                _genreTemplate = GetControl((int)Controls.LABEL_GENRE_TEMPLATE) as GUILabelControl;

                _programPartialRecordTemplate = GetControl((int)Controls.BUTTON_PROGRAM_PARTIAL_RECORD) as GUIButton3PartControl;
                _programRecordTemplate = GetControl((int)Controls.BUTTON_PROGRAM_RECORD) as GUIButton3PartControl;
                _programNotifyTemplate = GetControl((int)Controls.BUTTON_PROGRAM_NOTIFY) as GUIButton3PartControl;
                _programNotRunningTemplate = GetControl((int)Controls.BUTTON_PROGRAM_NOT_RUNNING) as GUIButton3PartControl;
                _programRunningTemplate = GetControl((int)Controls.BUTTON_PROGRAM_RUNNING) as GUIButton3PartControl;

                _showChannelLogos = cntlChannelImg != null;
                if (_showChannelLogos)
                {
                    cntlChannelImg.IsVisible = false;
                }
                cntlChannelLabel.IsVisible = false;
                cntlHeaderBkgImg.IsVisible = false;
                labelTime.IsVisible = false;
                cntlChannelTemplate.IsVisible = false;
                int iLabelWidth = (cntlPanel.XPosition + cntlPanel.Width - labelTime.XPosition) / 4;

                // add labels for time blocks 1-4
                int iHour, iMin;
                iMin = _viewingTime.Minute;
                _viewingTime = _viewingTime.AddMinutes(-iMin);
                iMin = (iMin / _timePerBlock) * _timePerBlock;
                _viewingTime = _viewingTime.AddMinutes(iMin);

                DateTime dt = new DateTime();
                dt = _viewingTime;

                for (int iLabel = 0; iLabel < 4; iLabel++)
                {
                    xpos = iLabel * iLabelWidth + labelTime.XPosition;
                    ypos = labelTime.YPosition;

                    GUIImage img = GetControl((int)Controls.IMG_TIME1 + iLabel) as GUIImage;
                    if (img == null)
                    {
                        img = new GUIImage(GetID, (int)Controls.IMG_TIME1 + iLabel, xpos, ypos, iLabelWidth - 4,
                                           cntlHeaderBkgImg.RenderHeight, cntlHeaderBkgImg.FileName, 0x0);
                        img.AllocResources();
                        GUIControl cntl2 = (GUIControl)img;
                        Add(ref cntl2);
                    }

                    img.IsVisible = !_singleChannelView;
                    img.Width = iLabelWidth - 4;
                    img.Height = cntlHeaderBkgImg.RenderHeight;
                    img.SetFileName(cntlHeaderBkgImg.FileName);
                    img.SetPosition(xpos, ypos);
                    img.DoUpdate();

                    GUILabelControl label = GetControl((int)Controls.LABEL_TIME1 + iLabel) as GUILabelControl;
                    if (label == null)
                    {
                        label = new GUILabelControl(GetID, (int)Controls.LABEL_TIME1 + iLabel, xpos, ypos, iLabelWidth,
                                                    cntlHeaderBkgImg.RenderHeight, labelTime.FontName, String.Empty,
                                                    labelTime.TextColor, GuideBase.TimeAlignment, labelTime.TextVAlignment, false,
                                                    labelTime.ShadowAngle, labelTime.ShadowDistance, labelTime.ShadowColor);
                        label.AllocResources();
                        GUIControl cntl = (GUIControl)label;
                        this.Add(ref cntl);
                    }
                    iHour = dt.Hour;
                    iMin = dt.Minute;
                    string strTime = dt.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat);
                    label.Label = " " + strTime;
                    dt = dt.AddMinutes(_timePerBlock);

                    label.TextAlignment = GuideBase.TimeAlignment;
                    label.IsVisible = !_singleChannelView;
                    label.Width = iLabelWidth;
                    label.Height = cntlHeaderBkgImg.RenderHeight;
                    label.FontName = labelTime.FontName;
                    label.TextColor = labelTime.TextColor;
                    label.SetPosition(xpos, ypos);
                }

                // add channels...
                int iHeight = cntlPanel.Height + cntlPanel.YPosition - cntlChannelTemplate.YPosition;
                int iItemHeight = cntlChannelTemplate.Height;

                _channelCount = (int)(((float)iHeight) / ((float)iItemHeight));
                for (int iChan = 0; iChan < _channelCount; ++iChan)
                {
                    xpos = cntlChannelTemplate.XPosition;
                    ypos = cntlChannelTemplate.YPosition + iChan * iItemHeight;

                    //this.Remove((int)Controls.IMG_CHAN1+iChan);
                    GUIButton3PartControl imgBut = GetControl((int)Controls.IMG_CHAN1 + iChan) as GUIButton3PartControl;
                    if (imgBut == null)
                    {
                        string strChannelImageFileName = String.Empty;
                        if (_showChannelLogos)
                        {
                            strChannelImageFileName = cntlChannelImg.FileName;
                        }

                        // Use a template control if it exists, otherwise use default values.
                        GUIButton3PartControl buttonTemplate = GetControl((int)Controls.BUTTON_PROGRAM_NOT_RUNNING) as GUIButton3PartControl;
                        if (buttonTemplate != null)
                        {
                            buttonTemplate.IsVisible = false;
                            imgBut = new GUIButton3PartControl(GetID, (int)Controls.IMG_CHAN1 + iChan, xpos, ypos,
                                                               cntlChannelTemplate.Width - 2, cntlChannelTemplate.Height - 2,
                                                               buttonTemplate.TexutureFocusLeftName,
                                                               buttonTemplate.TexutureFocusMidName,
                                                               buttonTemplate.TexutureFocusRightName,
                                                               buttonTemplate.TexutureNoFocusLeftName,
                                                               buttonTemplate.TexutureNoFocusMidName,
                                                               buttonTemplate.TexutureNoFocusRightName,
                                                               strChannelImageFileName);

                            imgBut.TileFillTFL = buttonTemplate.TileFillTFL;
                            imgBut.TileFillTNFL = buttonTemplate.TileFillTNFL;
                            imgBut.TileFillTFM = buttonTemplate.TileFillTFM;
                            imgBut.TileFillTNFM = buttonTemplate.TileFillTNFM;
                            imgBut.TileFillTFR = buttonTemplate.TileFillTFR;
                            imgBut.TileFillTNFR = buttonTemplate.TileFillTNFR;
                        }
                        else
                        {
                            imgBut = new GUIButton3PartControl(GetID, (int)Controls.IMG_CHAN1 + iChan, xpos, ypos,
                                                               cntlChannelTemplate.Width - 2, cntlChannelTemplate.Height - 2,
                                                               "tvguide_button_selected_left.png",
                                                               "tvguide_button_selected_middle.png",
                                                               "tvguide_button_selected_right.png",
                                                               "tvguide_button_light_left.png",
                                                               "tvguide_button_light_middle.png",
                                                               "tvguide_button_light_right.png",
                                                               strChannelImageFileName);
                        }
                        imgBut.AllocResources();
                        GUIControl cntl = (GUIControl)imgBut;
                        Add(ref cntl);
                    }

                    imgBut.Width = cntlChannelTemplate.Width - 2; //labelTime.XPosition-cntlChannelImg.XPosition;
                    imgBut.Height = cntlChannelTemplate.Height - 2; //iItemHeight-2;
                    imgBut.SetPosition(xpos, ypos);
                    imgBut.FontName1 = cntlChannelLabel.FontName;
                    imgBut.TextColor1 = cntlChannelLabel.TextColor;
                    imgBut.Label1 = String.Empty;
                    imgBut.RenderLeft = false;
                    imgBut.RenderRight = false;
                    imgBut.SetShadow1(cntlChannelLabel.ShadowAngle, cntlChannelLabel.ShadowDistance, cntlChannelLabel.ShadowColor);

                    if (_showChannelLogos)
                    {
                        imgBut.TexutureIcon = cntlChannelImg.FileName;
                        imgBut.IconOffsetX = cntlChannelImg.XPosition;
                        imgBut.IconOffsetY = cntlChannelImg.YPosition;
                        imgBut.IconWidth = cntlChannelImg.RenderWidth;
                        imgBut.IconHeight = cntlChannelImg.RenderHeight;
                        imgBut.IconKeepAspectRatio = cntlChannelImg.KeepAspectRatio;
                        imgBut.IconCentered = cntlChannelImg.Centered;
                        imgBut.IconZoom = cntlChannelImg.Zoom;
                    }
                    imgBut.TextOffsetX1 = cntlChannelLabel.XPosition;
                    imgBut.TextOffsetY1 = cntlChannelLabel.YPosition;
                    imgBut.ColourDiffuse = 0xffffffff;
                    imgBut.DoUpdate();
                }

                UpdateHorizontalScrollbar();
                UpdateVerticalScrollbar();

                GetChannels(false);

                string day;
                switch (_viewingTime.DayOfWeek)
                {
                    case DayOfWeek.Monday:
                        day = GUILocalizeStrings.Get(657);
                        break;
                    case DayOfWeek.Tuesday:
                        day = GUILocalizeStrings.Get(658);
                        break;
                    case DayOfWeek.Wednesday:
                        day = GUILocalizeStrings.Get(659);
                        break;
                    case DayOfWeek.Thursday:
                        day = GUILocalizeStrings.Get(660);
                        break;
                    case DayOfWeek.Friday:
                        day = GUILocalizeStrings.Get(661);
                        break;
                    case DayOfWeek.Saturday:
                        day = GUILocalizeStrings.Get(662);
                        break;
                    default:
                        day = GUILocalizeStrings.Get(663);
                        break;
                }
                GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.View.SDOW", day);
                GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.View.Month", _viewingTime.Month.ToString());
                GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.View.Day", _viewingTime.Day.ToString());

                //day = String.Format("{0} {1}-{2}", day, _viewingTime.Day, _viewingTime.Month);
                day = Utils.GetShortDayString(_viewingTime);
                GUIPropertyManager.SetProperty(SkinPropertyPrefix + ".Guide.Day", day);

                //2004 03 31 22 20 00
                string strStart = String.Format("{0}{1:00}{2:00}{3:00}{4:00}{5:00}",
                                                _viewingTime.Year, _viewingTime.Month, _viewingTime.Day,
                                                _viewingTime.Hour, _viewingTime.Minute, 0);
                DateTime dtStop = new DateTime();
                dtStop = _viewingTime;
                dtStop = dtStop.AddMinutes(_numberOfBlocks * _timePerBlock - 1);
                iMin = dtStop.Minute;
                string strEnd = String.Format("{0}{1:00}{2:00}{3:00}{4:00}{5:00}",
                                              dtStop.Year, dtStop.Month, dtStop.Day,
                                              dtStop.Hour, iMin, 0);

                long iStart = Int64.Parse(strStart);
                long iEnd = Int64.Parse(strEnd);

                LoadSchedules(false);

                if (_channelOffset > _channelList.Count)
                {
                    _channelOffset = 0;
                    _cursorX = 0;
                }

                for (int i = 0; i < controlList.Count; ++i)
                {
                    GUIControl cntl = (GUIControl)controlList[i];
                    if (cntl.GetID >= GUIDE_COMPONENTID_START)
                    {
                        cntl.IsVisible = false;
                    }
                }

                if (_singleChannelView)
                {
                    // show all buttons (could be less visible if channels < rows)
                    for (int iChannel = 0; iChannel < _channelCount; iChannel++)
                    {
                        GUIButton3PartControl imgBut = GetControl((int)Controls.IMG_CHAN1 + iChannel) as GUIButton3PartControl;
                        if (imgBut != null)
                            imgBut.IsVisible = true;
                    }

                    Channel channel = (Channel)_channelList[_singleChannelNumber].channel;
                    setGuideHeadingVisibility(false);
                    using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                    using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                    {
                        RenderSingleChannel(tvSchedulerAgent, tvGuideAgent, channel);
                    }
                }
                else
                {
                    List<Channel> visibleChannels = new List<Channel>();

                    int chan = _channelOffset;
                    for (int iChannel = 0; iChannel < _channelCount; iChannel++)
                    {
                        if (chan < _channelList.Count)
                        {
                            visibleChannels.Add(_channelList[chan].channel);
                        }
                        chan++;
                        if (chan >= _channelList.Count && visibleChannels.Count < _channelList.Count)
                        {
                            chan = 0;
                        }
                    }
                    using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                    using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                    {
                        _controller.RefreshChannelsEpgData(tvGuideAgent, visibleChannels,
                            Utils.longtodate(iStart), Utils.longtodate(iEnd));

                        // make sure the TV Guide heading is visiable and the single channel labels are not.
                        setGuideHeadingVisibility(true);
                        SetSingleChannelLabelVisibility(false);
                        chan = _channelOffset;

                        int firstButtonYPos = 0;
                        int lastButtonYPos = 0;

                        for (int iChannel = 0; iChannel < _channelCount; iChannel++)
                        {
                            if (chan < _channelList.Count)
                            {
                                GuideBaseChannel tvGuideChannel = _channelList[chan];
                                RenderChannel(tvSchedulerAgent, tvGuideAgent, iChannel, tvGuideChannel, iStart, iEnd, selectCurrentShow);
                                // remember bottom y position from last visible button
                                GUIButton3PartControl imgBut = GetControl((int)Controls.IMG_CHAN1 + iChannel) as GUIButton3PartControl;
                                if (imgBut != null)
                                {
                                    if (iChannel == 0)
                                        firstButtonYPos = imgBut.YPosition;

                                    lastButtonYPos = imgBut.YPosition + imgBut.Height;
                                }
                            }
                            chan++;
                            if (chan >= _channelList.Count && _channelList.Count > _channelCount)
                            {
                                chan = 0;
                            }
                            if (chan > _channelList.Count)
                            {
                                GUIButton3PartControl imgBut = GetControl((int)Controls.IMG_CHAN1 + iChannel) as GUIButton3PartControl;
                                if (imgBut != null)
                                {
                                    imgBut.IsVisible = false;
                                }
                            }
                        }

                        GUIImage vertLine = GetControl((int)Controls.VERTICAL_LINE) as GUIImage;
                        if (vertLine != null)
                        {
                            // height taken from last button (bottom) minus the yposition of slider plus the offset of slider in relation to first button
                            vertLine.Height = lastButtonYPos - vertLine.YPosition + (firstButtonYPos - vertLine.YPosition);
                        }
                        // update selected channel
                        _singleChannelNumber = _cursorX + _channelOffset;
                        if (_singleChannelNumber >= _channelList.Count)
                        {
                            _singleChannelNumber -= _channelList.Count;
                        }

                        // instead of direct casting us "as"; else it fails for other controls!
                        GUIButton3PartControl img = GetControl(_cursorX + (int)Controls.IMG_CHAN1) as GUIButton3PartControl;
                        if (null != img)
                        {
                            _currentChannel = (Channel)img.Data;
                        }
                    }
                }
                UpdateVerticalScrollbar();
            }
        }
Exemplo n.º 32
0
        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.");
                        }
                    }
                }
            }
        }
Exemplo n.º 33
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));
                    }
                }
        }