Ejemplo n.º 1
0
        /// <summary>
        /// Tries to get the current and next program for the given <paramref name="channel"/>.
        /// </summary>
        /// <param name="channel">Channel</param>
        /// <returns><c>true</c> if a program could be found</returns>
        public async Task <AsyncResult <IProgram[]> > GetNowNextProgramAsync(IChannel channel)
        {
            // TODO: caching from NativeProvider?
            IProgram[] programNowNext = new IProgram[2];
            Channel    indexChannel   = channel as Channel;

            if (indexChannel == null || !CheckConnection(indexChannel.ServerIndex))
            {
                return(new AsyncResult <IProgram[]>(false, null));
            }

            try
            {
                IList <WebProgramDetailed> tvPrograms = TvServer(indexChannel.ServerIndex).GetNowNextWebProgramDetailedForChannel(channel.ChannelId);
                if (tvPrograms.Count > 0 && tvPrograms[0] != null)
                {
                    programNowNext[0] = new Program(tvPrograms[0], indexChannel.ServerIndex);
                }
                if (tvPrograms.Count > 1 && tvPrograms[1] != null)
                {
                    programNowNext[1] = new Program(tvPrograms[1], indexChannel.ServerIndex);
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error(ex.Message);
                return(new AsyncResult <IProgram[]>(false, null));
            }
            return(new AsyncResult <IProgram[]>(programNowNext[0] != null, programNowNext));
        }
Ejemplo n.º 2
0
        public async Task <AsyncResult <MediaItem> > StartTimeshiftAsync(int slotIndex, IChannel channel)
        {
            Channel indexChannel = channel as Channel;

            if (indexChannel == null || !CheckConnection(indexChannel.ServerIndex))
            {
                return(new AsyncResult <MediaItem>(false, null));
            }

            try
            {
                ITVAccessService tvServer  = TvServer(indexChannel.ServerIndex);
                String           streamUrl = _tvServers[indexChannel.ServerIndex].IsLocalConnection ?
                                             // Prefer local timeshift file over RTSP streaming
                                             tvServer.SwitchTVServerToChannelAndGetTimeshiftFilename(GetTimeshiftUserName(slotIndex), channel.ChannelId) :
                                             tvServer.SwitchTVServerToChannelAndGetStreamingUrl(GetTimeshiftUserName(slotIndex), channel.ChannelId);

                if (String.IsNullOrEmpty(streamUrl))
                {
                    return(new AsyncResult <MediaItem>(false, null));
                }

                _channels[slotIndex] = channel;

                // assign a MediaItem, can be null if streamUrl is the same.
                var timeshiftMediaItem = CreateMediaItem(slotIndex, streamUrl, channel);
                return(new AsyncResult <MediaItem>(true, timeshiftMediaItem));
            }
            catch (Exception ex)
            {
                NotifyException(ex, indexChannel.ServerIndex);
                return(new AsyncResult <MediaItem>(false, null));
            }
        }
Ejemplo n.º 3
0
        public async Task <AsyncResult <IList <IProgram> > > GetProgramsAsync(IChannel channel, DateTime from, DateTime to)
        {
            Channel indexChannel = channel as Channel;

            if (indexChannel == null || !CheckConnection(indexChannel.ServerIndex))
            {
                return(new AsyncResult <IList <IProgram> >(false, null));
            }

            var programs = new List <IProgram>();

            try
            {
                IList <WebProgramDetailed> tvPrograms = TvServer(indexChannel.ServerIndex).GetProgramsDetailedForChannel(channel.ChannelId, from, to);
                foreach (WebProgramDetailed webProgram in tvPrograms)
                {
                    programs.Add(new Program(webProgram, indexChannel.ServerIndex));
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error(ex.Message);
                return(new AsyncResult <IList <IProgram> >(false, null));
            }
            return(new AsyncResult <IList <IProgram> >(programs.Count > 0, programs));
        }
Ejemplo n.º 4
0
        public override bool GetChannel(IProgram program, out IChannel channel)
        {
            IChannelService channelService = GlobalServiceProvider.Instance.Get <IChannelService>();

            channel = channelService.GetChannel(program.ChannelId).ToChannel();
            return(true);
        }
Ejemplo n.º 5
0
        public override bool GetChannel(int channelId, out IChannel channel)
        {
            IChannelService channelGroupService = GlobalServiceProvider.Instance.Get <IChannelService>();

            channel = channelGroupService.GetChannel(channelId).ToChannel();
            return(true);
        }
Ejemplo n.º 6
0
        public MediaItem CreateMediaItem(int slotIndex, string streamUrl, IChannel channel)
        {
            // Channel is usually only passed as placeholder with ID only, so query the details here
#if TVE3
            TvDatabase.Channel fullChannel = TvDatabase.Channel.Retrieve(channel.ChannelId);
            bool isTv = fullChannel.IsTv;
#else
            IChannelService channelService = GlobalServiceProvider.Instance.Get <IChannelService>();
            Channel         fullChannel    = channelService.GetChannel(channel.ChannelId);
            bool            isTv           = fullChannel.MediaType == 0;
#endif

            LiveTvMediaItem tvStream = isTv
        ? SlimTvMediaItemBuilder.CreateMediaItem(slotIndex, streamUrl, fullChannel.ToChannel())
        : SlimTvMediaItemBuilder.CreateRadioMediaItem(slotIndex, streamUrl, fullChannel.ToChannel());

            if (tvStream != null)
            {
                // Add program infos to the LiveTvMediaItem
                IProgram currentProgram;
                IProgram nextProgram;
                if (GetNowNextProgram(channel, out currentProgram, out nextProgram))
                {
                    tvStream.AdditionalProperties[LiveTvMediaItem.CURRENT_PROGRAM] = currentProgram;
                    tvStream.AdditionalProperties[LiveTvMediaItem.NEXT_PROGRAM]    = nextProgram;
                }
                return(tvStream);
            }
            return(null);
        }
        public bool StartTimeshift(string userName, int slotIndex, IChannel channel, out MediaItem timeshiftMediaItem)
        {
            string timeshiftFile = SwitchTVServerToChannel(GetUserName(userName, slotIndex), channel.ChannelId);

            timeshiftMediaItem = CreateMediaItem(slotIndex, timeshiftFile, channel);
            return(!string.IsNullOrEmpty(timeshiftFile));
        }
        public bool GetPrograms(IChannel channel, DateTime from, DateTime to, out IList <IProgram> programs)
        {
            programs = null;
            Channel indexChannel = channel as Channel;

            if (indexChannel == null)
            {
                return(false);
            }

            if (!CheckConnection(indexChannel.ServerIndex))
            {
                return(false);
            }

            programs = new List <IProgram>();
            try
            {
                IList <WebProgramDetailed> tvPrograms = TvServer(indexChannel.ServerIndex).GetProgramsDetailedForChannel(channel.ChannelId, from, to);
                foreach (WebProgramDetailed webProgram in tvPrograms)
                {
                    programs.Add(new Program(webProgram, indexChannel.ServerIndex));
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error(ex.Message);
                return(false);
            }
            return(programs.Count > 0);
        }
Ejemplo n.º 9
0
        public override Task <AsyncResult <ISchedule> > CreateScheduleDetailedAsync(IChannel channel, string title, DateTime from, DateTime to, ScheduleRecordingType recordingType, int preRecordInterval, int postRecordInterval, string directory, int priority)
        {
            IScheduleService scheduleService = GlobalServiceProvider.Get <IScheduleService>();
            Schedule         tvSchedule      = ScheduleFactory.CreateSchedule(channel.ChannelId, title, from, to);

            tvSchedule.PreRecordInterval  = preRecordInterval >= 0 ? preRecordInterval : ServiceAgents.Instance.SettingServiceAgent.GetValue("preRecordInterval", 5);
            tvSchedule.PostRecordInterval = postRecordInterval >= 0 ? postRecordInterval : ServiceAgents.Instance.SettingServiceAgent.GetValue("postRecordInterval", 5);
            if (!String.IsNullOrEmpty(directory))
            {
                tvSchedule.Directory = directory;
            }
            if (priority >= 0)
            {
                tvSchedule.Priority = priority;
            }
            tvSchedule.PreRecordInterval  = preRecordInterval;
            tvSchedule.PostRecordInterval = postRecordInterval;
            tvSchedule.ScheduleType       = (int)recordingType;
            tvSchedule.Directory          = directory;
            tvSchedule.Priority           = priority;
            scheduleService.SaveSchedule(tvSchedule);
            ISchedule schedule = tvSchedule.ToSchedule();

            return(Task.FromResult(new AsyncResult <ISchedule>(true, schedule)));
        }
        public bool GetChannel(IProgram program, out IChannel channel)
        {
            channel = null;
            Program indexProgram = program as Program;

            if (indexProgram == null)
            {
                return(false);
            }

            if (!CheckConnection(indexProgram.ServerIndex))
            {
                return(false);
            }

            try
            {
                WebChannelBasic tvChannel = TvServer(indexProgram.ServerIndex).GetChannelBasicById(indexProgram.ChannelId);
                if (tvChannel != null)
                {
                    channel = new Channel {
                        ChannelId = tvChannel.Id, Name = tvChannel.Title, ServerIndex = indexProgram.ServerIndex
                    };
                    return(true);
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error(ex.Message);
            }
            return(false);
        }
        public bool GetChannel(int channelId, out IChannel channel)
        {
            if (_channelCache.TryGetValue(channelId, out channel))
            {
                return(true);
            }

            // TODO: lookup by ID cannot guess which server might be adressed, so we force the first one.
            int serverIndex = 0;

            if (!CheckConnection(serverIndex))
            {
                return(false);
            }
            try
            {
                WebChannelBasic webChannel = TvServer(serverIndex).GetChannelBasicById(channelId);
                channel = new Channel {
                    ChannelId = webChannel.Id, Name = webChannel.Title, ServerIndex = serverIndex
                };
                _channelCache[channelId] = channel;
                return(true);
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error(ex.Message);
                return(false);
            }
        }
        public bool StartTimeshift(int slotIndex, IChannel channel, out MediaItem timeshiftMediaItem)
        {
            timeshiftMediaItem = null;
            Channel indexChannel = channel as Channel;

            if (indexChannel == null)
            {
                return(false);
            }

            if (!CheckConnection(indexChannel.ServerIndex))
            {
                return(false);
            }
            try
            {
                String streamUrl = TvServer(indexChannel.ServerIndex).SwitchTVServerToChannelAndGetStreamingUrl(GetTimeshiftUserName(slotIndex), channel.ChannelId);
                if (String.IsNullOrEmpty(streamUrl))
                {
                    return(false);
                }

                _channels[slotIndex] = channel;

                // assign a MediaItem, can be null if streamUrl is the same.
                timeshiftMediaItem = CreateMediaItem(slotIndex, streamUrl, channel);
                return(true);
            }
            catch (Exception ex)
            {
                NotifyException(ex, indexChannel.ServerIndex);
                return(false);
            }
        }
Ejemplo n.º 13
0
        public bool GetCurrentProgram(IChannel channel, out IProgram program)
        {
            program = null;

            Channel indexChannel = channel as Channel;

            if (indexChannel == null)
            {
                return(false);
            }

            if (!CheckConnection(indexChannel.ServerIndex))
            {
                return(false);
            }

            try
            {
                WebProgramDetailed tvProgram = TvServer(indexChannel.ServerIndex).GetCurrentProgramOnChannel(channel.ChannelId);
                if (tvProgram != null)
                {
                    program = new Program(tvProgram, indexChannel.ServerIndex);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error(ex.Message);
            }
            return(false);
        }
Ejemplo n.º 14
0
        public override MediaItem CreateMediaItem(int slotIndex, string streamUrl, IChannel channel)
        {
            // Channel is usually only passed as placeholder with ID only, so query the details here
            TvDatabase.Channel fullChannel = TvDatabase.Channel.Retrieve(channel.ChannelId);
            bool isTv = fullChannel.IsTv;

            return(CreateMediaItem(slotIndex, streamUrl, channel, isTv, fullChannel.ToChannel()));
        }
Ejemplo n.º 15
0
        public override bool GetNowNextProgram(IChannel channel, out IProgram programNow, out IProgram programNext)
        {
            var tvChannel = TvDatabase.Channel.Retrieve(channel.ChannelId);

            programNow  = tvChannel.CurrentProgram.ToProgram();
            programNext = tvChannel.NextProgram.ToProgram();
            return(programNow != null || programNext != null);
        }
Ejemplo n.º 16
0
 public override bool GetPrograms(IChannel channel, DateTime from, DateTime to, out IList <IProgram> programs)
 {
     programs = _tvBusiness.GetPrograms(TvDatabase.Channel.Retrieve(channel.ChannelId), from, to)
                .Select(tvProgram => tvProgram.ToProgram(true))
                .Distinct(ProgramComparer.Instance)
                .ToList();
     return(programs.Count > 0);
 }
Ejemplo n.º 17
0
        public override MediaItem CreateMediaItem(int slotIndex, string streamUrl, IChannel channel)
        {
            // Channel is usually only passed as placeholder with ID only, so query the details here
            IChannelService channelService = GlobalServiceProvider.Instance.Get <IChannelService>();
            Channel         fullChannel    = channelService.GetChannel(channel.ChannelId);
            bool            isTv           = fullChannel.MediaType == 0;

            return(CreateMediaItem(slotIndex, streamUrl, channel, isTv, fullChannel.ToChannel()));
        }
Ejemplo n.º 18
0
        public override Task <AsyncResult <IProgram[]> > GetNowNextProgramAsync(IChannel channel)
        {
            var tvChannel   = TvDatabase.Channel.Retrieve(channel.ChannelId);
            var programNow  = GetProgram(tvChannel.CurrentProgram);
            var programNext = GetProgram(tvChannel.NextProgram);
            var success     = programNow != null || programNext != null;

            return(Task.FromResult(new AsyncResult <IProgram[]>(success, new[] { programNow, programNext })));
        }
Ejemplo n.º 19
0
        public override Task <bool> EditScheduleAsync(ISchedule schedule, IChannel channel = null, string title = null, DateTime?from = null, DateTime?to = null, ScheduleRecordingType?recordingType = null, int?preRecordInterval = null, int?postRecordInterval = null, string directory = null, int?priority = null)
        {
            try
            {
                ServiceRegistration.Get <ILogger>().Debug("Editing schedule {0} on channel {1} for {2}, {3} till {4}, type {5}", schedule.ScheduleId, channel.ChannelId, title, from, to, recordingType);
                TvDatabase.Schedule tvSchedule = TvDatabase.Schedule.Retrieve(schedule.ScheduleId);

                tvSchedule.IdChannel = channel.ChannelId;
                if (title != null)
                {
                    tvSchedule.ProgramName = title;
                }
                if (from != null)
                {
                    tvSchedule.StartTime = from.Value;
                }
                if (to != null)
                {
                    tvSchedule.EndTime = to.Value;
                }

                if (recordingType != null)
                {
                    ScheduleRecordingType scheduleRecType = recordingType.Value;
                    tvSchedule.ScheduleType = (int)scheduleRecType;
                }

                if (preRecordInterval != null)
                {
                    tvSchedule.PreRecordInterval = preRecordInterval.Value;
                }
                if (postRecordInterval != null)
                {
                    tvSchedule.PostRecordInterval = postRecordInterval.Value;
                }

                if (directory != null)
                {
                    tvSchedule.Directory = directory;
                }
                if (priority != null)
                {
                    tvSchedule.Priority = priority.Value;
                }

                tvSchedule.Persist();

                _tvControl.OnNewSchedule(); // I don't think this is needed, but doesn't hurt either
                return(Task.FromResult(true));
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Warn(String.Format("Failed to edit schedule {0}", schedule.ScheduleId), ex);
                return(Task.FromResult(false));
            }
        }
Ejemplo n.º 20
0
        public override Task <bool> EditScheduleAsync(ISchedule schedule, IChannel channel = null, string title = null, DateTime?from = null, DateTime?to = null, ScheduleRecordingType?recordingType = null, int?preRecordInterval = null, int?postRecordInterval = null, string directory = null, int?priority = null)
        {
            try
            {
                ServiceRegistration.Get <ILogger>().Debug("Editing schedule {0} on channel {1} for {2}, {3} till {4}, type {5}", schedule.ScheduleId, channel.ChannelId, title, from, to, recordingType);
                IScheduleService scheduleService = GlobalServiceProvider.Get <IScheduleService>();
                Schedule         tvSchedule      = scheduleService.GetSchedule(schedule.ScheduleId);

                tvSchedule.IdChannel = channel.ChannelId;
                if (title != null)
                {
                    tvSchedule.ProgramName = title;
                }
                if (from != null)
                {
                    tvSchedule.StartTime = from.Value;
                }
                if (to != null)
                {
                    tvSchedule.EndTime = to.Value;
                }

                if (recordingType != null)
                {
                    ScheduleRecordingType scheduleRecType = recordingType.Value;
                    tvSchedule.ScheduleType = (int)scheduleRecType;
                }

                if (preRecordInterval != null)
                {
                    tvSchedule.PreRecordInterval = preRecordInterval.Value;
                }
                if (postRecordInterval != null)
                {
                    tvSchedule.PostRecordInterval = postRecordInterval.Value;
                }

                if (directory != null)
                {
                    tvSchedule.Directory = directory;
                }
                if (priority != null)
                {
                    tvSchedule.Priority = priority.Value;
                }

                scheduleService.SaveSchedule(tvSchedule);

                return(Task.FromResult(true));
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Warn(String.Format("Failed to edit schedule {0}", schedule.ScheduleId), ex);
                return(Task.FromResult(false));
            }
        }
Ejemplo n.º 21
0
 public override bool CreateScheduleByTime(IChannel channel, DateTime from, DateTime to, out ISchedule schedule)
 {
     TvDatabase.Schedule tvSchedule = _tvBusiness.AddSchedule(channel.ChannelId, "Manual", from, to, (int)ScheduleRecordingType.Once);
     tvSchedule.PreRecordInterval  = Int32.Parse(_tvBusiness.GetSetting("preRecordInterval", "5").Value);
     tvSchedule.PostRecordInterval = Int32.Parse(_tvBusiness.GetSetting("postRecordInterval", "5").Value);
     tvSchedule.Persist();
     _tvControl.OnNewSchedule();
     schedule = tvSchedule.ToSchedule();
     return(true);
 }
Ejemplo n.º 22
0
        public bool GetChannel(int channelId, out IChannel channel)
        {
#if TVE3
            channel = TvDatabase.Channel.Retrieve(channelId).ToChannel();
#else
            IChannelService channelGroupService = GlobalServiceProvider.Instance.Get <IChannelService>();
            channel = channelGroupService.GetChannel(channelId).ToChannel();
#endif
            return(true);
        }
Ejemplo n.º 23
0
        public override bool GetPrograms(IChannel channel, DateTime from, DateTime to, out IList <IProgram> programs)
        {
            IProgramService programService = GlobalServiceProvider.Instance.Get <IProgramService>();

            programs = programService.GetProgramsByChannelAndStartEndTimes(channel.ChannelId, from, to)
                       .Select(tvProgram => tvProgram.ToProgram(true))
                       .Distinct(ProgramComparer.Instance)
                       .ToList();
            return(programs.Count > 0);
        }
Ejemplo n.º 24
0
        public override Task <AsyncResult <IList <IProgram> > > GetProgramsAsync(IChannel channel, DateTime from, DateTime to)
        {
            IProgramService programService = GlobalServiceProvider.Instance.Get <IProgramService>();
            var             programs       = programService.GetProgramsByChannelAndStartEndTimes(channel.ChannelId, from, to)
                                             .Select(tvProgram => GetProgram(tvProgram, true))
                                             .Distinct(ProgramComparer.Instance)
                                             .ToList();
            var success = programs.Count > 0;

            return(Task.FromResult(new AsyncResult <IList <IProgram> >(success, programs)));
        }
Ejemplo n.º 25
0
        public override bool CreateScheduleByTime(IChannel channel, DateTime from, DateTime to, out ISchedule schedule)
        {
            IScheduleService scheduleService = GlobalServiceProvider.Get <IScheduleService>();
            Schedule         tvSchedule      = ScheduleFactory.CreateSchedule(channel.ChannelId, "Manual", from, to);

            tvSchedule.PreRecordInterval  = ServiceAgents.Instance.SettingServiceAgent.GetValue("preRecordInterval", 5);
            tvSchedule.PostRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("postRecordInterval", 5);
            tvSchedule.ScheduleType       = (int)ScheduleRecordingType.Once;
            scheduleService.SaveSchedule(tvSchedule);
            schedule = tvSchedule.ToSchedule();
            return(true);
        }
Ejemplo n.º 26
0
        public override Task <AsyncResult <ISchedule> > CreateScheduleByTimeAsync(IChannel channel, string title, DateTime from, DateTime to, ScheduleRecordingType recordingType)
        {
            IScheduleService scheduleService = GlobalServiceProvider.Get <IScheduleService>();
            Schedule         tvSchedule      = ScheduleFactory.CreateSchedule(channel.ChannelId, title, from, to);

            tvSchedule.PreRecordInterval  = ServiceAgents.Instance.SettingServiceAgent.GetValue("preRecordInterval", 5);
            tvSchedule.PostRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("postRecordInterval", 5);
            tvSchedule.ScheduleType       = (int)recordingType;
            scheduleService.SaveSchedule(tvSchedule);
            var schedule = tvSchedule.ToSchedule();

            return(Task.FromResult(new AsyncResult <ISchedule>(true, schedule)));
        }
Ejemplo n.º 27
0
        public bool GetPrograms(IChannel channel, DateTime from, DateTime to, out IList <IProgram> programs)
        {
#if TVE3
            programs = _tvBusiness.GetPrograms(TvDatabase.Channel.Retrieve(channel.ChannelId), from, to)
#else
            IProgramService programService = GlobalServiceProvider.Instance.Get <IProgramService>();
            programs = programService.GetProgramsByChannelAndStartEndTimes(channel.ChannelId, from, to)
#endif
                       .Select(tvProgram => tvProgram.ToProgram(true))
                       .Distinct(ProgramComparer.Instance)
                       .ToList();
            return(programs.Count > 0);
        }
Ejemplo n.º 28
0
        public override bool GetNowNextProgram(IChannel channel, out IProgram programNow, out IProgram programNext)
        {
            programNow  = null;
            programNext = null;
            IProgramService programService = GlobalServiceProvider.Instance.Get <IProgramService>();
            var             programs       = programService.GetNowAndNextProgramsForChannel(channel.ChannelId).Select(p => p.ToProgram()).Distinct(ProgramComparer.Instance).ToList();
            var             count          = programs.Count;

            if (count >= 1)
            {
                programNow = programs[0];
            }
            if (count >= 2)
            {
                programNext = programs[1];
            }
            return(programNow != null || programNext != null);
        }
Ejemplo n.º 29
0
        public bool CreateScheduleByTime(IChannel channel, DateTime from, DateTime to, out ISchedule schedule)
        {
#if TVE3
            TvDatabase.Schedule tvSchedule = _tvBusiness.AddSchedule(channel.ChannelId, "Manual", from, to, (int)ScheduleRecordingType.Once);
            tvSchedule.PreRecordInterval  = Int32.Parse(_tvBusiness.GetSetting("preRecordInterval", "5").Value);
            tvSchedule.PostRecordInterval = Int32.Parse(_tvBusiness.GetSetting("postRecordInterval", "5").Value);
            tvSchedule.Persist();
            _tvControl.OnNewSchedule();
#else
            IScheduleService scheduleService = GlobalServiceProvider.Get <IScheduleService>();
            Schedule         tvSchedule      = ScheduleFactory.CreateSchedule(channel.ChannelId, "Manual", from, to);
            tvSchedule.PreRecordInterval  = ServiceAgents.Instance.SettingServiceAgent.GetValue("preRecordInterval", 5);
            tvSchedule.PostRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("postRecordInterval", 5);
            tvSchedule.ScheduleType       = (int)ScheduleRecordingType.Once;
            scheduleService.SaveSchedule(tvSchedule);
#endif
            schedule = tvSchedule.ToSchedule();
            return(true);
        }
Ejemplo n.º 30
0
        public async Task <AsyncResult <ISchedule> > CreateScheduleByTimeAsync(IChannel channel, string title, DateTime from, DateTime to, ScheduleRecordingType recordingType)
        {
            Channel indexChannel = channel as Channel;

            if (indexChannel == null || !CheckConnection(indexChannel.ServerIndex))
            {
                return(new AsyncResult <ISchedule>(false, null));
            }

            try
            {
                var result = TvServer(indexChannel.ServerIndex).AddSchedule(channel.ChannelId, title, from, to, (WebScheduleType)recordingType);
                return(new AsyncResult <ISchedule>(true, null));
            }
            catch
            {
                return(new AsyncResult <ISchedule>(false, null));
            }
        }
    /// <summary>
    /// Tries to get the current and next program for the given <paramref name="channel"/>.
    /// </summary>
    /// <param name="channel">Channel</param>
    /// <param name="programNow">Returns current program</param>
    /// <param name="programNext">Returns next program</param>
    /// <returns><c>true</c> if a program could be found</returns>
    public bool GetNowNextProgram (IChannel channel, out IProgram programNow, out IProgram programNext)
    {
      // TODO: caching from NativeProvider?
      programNow = null;
      programNext = null;
      Channel indexChannel = channel as Channel;
      if (indexChannel == null)
        return false;

      if (!CheckConnection(indexChannel.ServerIndex))
        return false;

      try
      {
        IList<WebProgramDetailed> tvPrograms = TvServer(indexChannel.ServerIndex).GetNowNextWebProgramDetailedForChannel(channel.ChannelId);
        if (tvPrograms.Count > 0 && tvPrograms[0] != null)
          programNow = new Program(tvPrograms[0], indexChannel.ServerIndex);
        if (tvPrograms.Count > 1 && tvPrograms[1] != null)
          programNext = new Program(tvPrograms[1], indexChannel.ServerIndex);
      }
      catch (Exception ex)
      {
        ServiceRegistration.Get<ILogger>().Error(ex.Message);
        return false;
      }
      return programNow != null;
    }
Ejemplo n.º 32
0
 public override bool GetPrograms(IChannel channel, DateTime from, DateTime to, out IList<IProgram> programs)
 {
   programs = _tvBusiness.GetPrograms(TvDatabase.Channel.Retrieve(channel.ChannelId), from, to)
     .Select(tvProgram => tvProgram.ToProgram(true))
     .Distinct(ProgramComparer.Instance)
     .ToList();
   return programs.Count > 0;
 }
Ejemplo n.º 33
0
 public override MediaItem CreateMediaItem(int slotIndex, string streamUrl, IChannel channel)
 {
   // Channel is usually only passed as placeholder with ID only, so query the details here
   TvDatabase.Channel fullChannel = TvDatabase.Channel.Retrieve(channel.ChannelId);
   bool isTv = fullChannel.IsTv;
   return CreateMediaItem(slotIndex, streamUrl, channel, isTv, fullChannel.ToChannel());
 }
Ejemplo n.º 34
0
 public abstract bool GetChannel(IProgram program, out IChannel channel);
Ejemplo n.º 35
0
 public abstract bool CreateScheduleByTime(IChannel channel, DateTime from, DateTime to, out ISchedule schedule);
Ejemplo n.º 36
0
    protected virtual MediaItem CreateMediaItem(int slotIndex, string streamUrl, IChannel channel, bool isTv, IChannel fullChannel)
    {
      LiveTvMediaItem tvStream = isTv
        ? SlimTvMediaItemBuilder.CreateMediaItem(slotIndex, streamUrl, fullChannel)
        : SlimTvMediaItemBuilder.CreateRadioMediaItem(slotIndex, streamUrl, fullChannel);

      if (tvStream != null)
      {
        // Add program infos to the LiveTvMediaItem
        IProgram currentProgram;
        IProgram nextProgram;
        if (GetNowNextProgram(channel, out currentProgram, out nextProgram))
        {
          tvStream.AdditionalProperties[LiveTvMediaItem.CURRENT_PROGRAM] = currentProgram;
          tvStream.AdditionalProperties[LiveTvMediaItem.NEXT_PROGRAM] = nextProgram;
        }
        return tvStream;
      }
      return null;
    }
Ejemplo n.º 37
0
 public abstract bool GetPrograms(IChannel channel, DateTime from, DateTime to, out IList<IProgram> programs);
Ejemplo n.º 38
0
 public override bool CreateScheduleByTime(IChannel channel, DateTime from, DateTime to, out ISchedule schedule)
 {
   TvDatabase.Schedule tvSchedule = _tvBusiness.AddSchedule(channel.ChannelId, "Manual", from, to, (int)ScheduleRecordingType.Once);
   tvSchedule.PreRecordInterval = Int32.Parse(_tvBusiness.GetSetting("preRecordInterval", "5").Value);
   tvSchedule.PostRecordInterval = Int32.Parse(_tvBusiness.GetSetting("postRecordInterval", "5").Value);
   tvSchedule.Persist();
   _tvControl.OnNewSchedule();
   schedule = tvSchedule.ToSchedule();
   return true;
 }
Ejemplo n.º 39
0
 public override MediaItem CreateMediaItem(int slotIndex, string streamUrl, IChannel channel)
 {
   // Channel is usually only passed as placeholder with ID only, so query the details here
   IChannelService channelService = GlobalServiceProvider.Instance.Get<IChannelService>();
   Channel fullChannel = channelService.GetChannel(channel.ChannelId);
   bool isTv = fullChannel.MediaType == 0;
   return CreateMediaItem(slotIndex, streamUrl, channel, isTv, fullChannel.ToChannel());
 }
    public bool GetChannel(IProgram program, out IChannel channel)
    {
      channel = null;
      Program indexProgram = program as Program;
      if (indexProgram == null)
        return false;

      if (!CheckConnection(indexProgram.ServerIndex))
        return false;

      try
      {
        WebChannelBasic tvChannel = TvServer(indexProgram.ServerIndex).GetChannelBasicById(indexProgram.ChannelId);
        if (tvChannel != null)
        {
          channel = new Channel { ChannelId = tvChannel.Id, Name = tvChannel.Title, ServerIndex = indexProgram.ServerIndex };
          return true;
        }
      }
      catch (Exception ex)
      {
        ServiceRegistration.Get<ILogger>().Error(ex.Message);
      }
      return false;
    }
    public bool StartTimeshift(int slotIndex, IChannel channel, out MediaItem timeshiftMediaItem)
    {
      timeshiftMediaItem = null;
      Channel indexChannel = channel as Channel;
      if (indexChannel == null)
        return false;

      if (!CheckConnection(indexChannel.ServerIndex))
        return false;
      try
      {
        String streamUrl = TvServer(indexChannel.ServerIndex).SwitchTVServerToChannelAndGetStreamingUrl(GetTimeshiftUserName(slotIndex), channel.ChannelId);
        if (String.IsNullOrEmpty(streamUrl))
          return false;

        _channels[slotIndex] = channel;

        // assign a MediaItem, can be null if streamUrl is the same.
        timeshiftMediaItem = CreateMediaItem(slotIndex, streamUrl, channel);
        return true;
      }
      catch (Exception ex)
      {
        NotifyException(ex, indexChannel.ServerIndex);
        return false;
      }
    }
    public MediaItem CreateMediaItem(int slotIndex, string streamUrl, IChannel channel)
    {
      LiveTvMediaItem tvStream = SlimTvMediaItemBuilder.CreateMediaItem(slotIndex, streamUrl, channel);
      if (tvStream != null)
      {
        // Add program infos to the LiveTvMediaItem
        IProgram currentProgram;
        if (GetCurrentProgram(channel, out currentProgram))
          tvStream.AdditionalProperties[LiveTvMediaItem.CURRENT_PROGRAM] = currentProgram;

        IProgram nextProgram;
        if (GetNextProgram(channel, out nextProgram))
          tvStream.AdditionalProperties[LiveTvMediaItem.NEXT_PROGRAM] = nextProgram;

        return tvStream;
      }
      return null;
    }
    public bool GetCurrentProgram(IChannel channel, out IProgram program)
    {
      program = null;

      Channel indexChannel = channel as Channel;
      if (indexChannel == null)
        return false;

      if (!CheckConnection(indexChannel.ServerIndex))
        return false;

      try
      {
        WebProgramDetailed tvProgram = TvServer(indexChannel.ServerIndex).GetCurrentProgramOnChannel(channel.ChannelId);
        if (tvProgram != null)
        {
          program = new Program(tvProgram, indexChannel.ServerIndex);
          return true;
        }
      }
      catch (Exception ex)
      {
        ServiceRegistration.Get<ILogger>().Error(ex.Message);
      }
      return false;
    }
    public bool GetPrograms(IChannel channel, DateTime from, DateTime to, out IList<IProgram> programs)
    {
      programs = null;
      Channel indexChannel = channel as Channel;
      if (indexChannel == null)
        return false;

      if (!CheckConnection(indexChannel.ServerIndex))
        return false;

      programs = new List<IProgram>();
      try
      {
        IList<WebProgramDetailed> tvPrograms = TvServer(indexChannel.ServerIndex).GetProgramsDetailedForChannel(channel.ChannelId, from, to);
        foreach (WebProgramDetailed webProgram in tvPrograms)
          programs.Add(new Program(webProgram, indexChannel.ServerIndex));
      }
      catch (Exception ex)
      {
        ServiceRegistration.Get<ILogger>().Error(ex.Message);
        return false;
      }
      return programs.Count > 0;
    }
Ejemplo n.º 45
0
 public bool StartTimeshift(string userName, int slotIndex, IChannel channel, out MediaItem timeshiftMediaItem)
 {
   string timeshiftFile = SwitchTVServerToChannel(GetUserName(userName, slotIndex), channel.ChannelId);
   timeshiftMediaItem = CreateMediaItem(slotIndex, timeshiftFile, channel);
   return !string.IsNullOrEmpty(timeshiftFile);
 }
Ejemplo n.º 46
0
 public override bool GetNowNextProgram(IChannel channel, out IProgram programNow, out IProgram programNext)
 {
   programNow = null;
   programNext = null;
   IProgramService programService = GlobalServiceProvider.Instance.Get<IProgramService>();
   var programs = programService.GetNowAndNextProgramsForChannel(channel.ChannelId).Select(p => p.ToProgram()).Distinct(ProgramComparer.Instance).ToList();
   var count = programs.Count;
   if (count >= 1)
     programNow = programs[0];
   if (count >= 2)
     programNext = programs[1];
   return programNow != null || programNext != null;
 }
Ejemplo n.º 47
0
 public abstract MediaItem CreateMediaItem(int slotIndex, string streamUrl, IChannel channel);
Ejemplo n.º 48
0
 public override bool GetPrograms(IChannel channel, DateTime from, DateTime to, out IList<IProgram> programs)
 {
   IProgramService programService = GlobalServiceProvider.Instance.Get<IProgramService>();
   programs = programService.GetProgramsByChannelAndStartEndTimes(channel.ChannelId, from, to)
     .Select(tvProgram => tvProgram.ToProgram(true))
     .Distinct(ProgramComparer.Instance)
     .ToList();
   return programs.Count > 0;
 }
Ejemplo n.º 49
0
 public abstract bool GetNowNextProgram(IChannel channel, out IProgram programNow, out IProgram programNext);
Ejemplo n.º 50
0
 public override bool GetChannel(IProgram program, out IChannel channel)
 {
   IChannelService channelService = GlobalServiceProvider.Instance.Get<IChannelService>();
   channel = channelService.GetChannel(program.ChannelId).ToChannel();
   return true;
 }
Ejemplo n.º 51
0
 public virtual bool GetScheduledPrograms(IChannel channel, out IList<IProgram> programs)
 {
   throw new NotImplementedException();
 }
Ejemplo n.º 52
0
 public override bool GetChannel(int channelId, out IChannel channel)
 {
   IChannelService channelGroupService = GlobalServiceProvider.Instance.Get<IChannelService>();
   channel = channelGroupService.GetChannel(channelId).ToChannel();
   return true;
 }
Ejemplo n.º 53
0
 public abstract bool GetChannel(int channelId, out IChannel channel);
Ejemplo n.º 54
0
 public override bool CreateScheduleByTime(IChannel channel, DateTime from, DateTime to, out ISchedule schedule)
 {
   IScheduleService scheduleService = GlobalServiceProvider.Get<IScheduleService>();
   Schedule tvSchedule = ScheduleFactory.CreateSchedule(channel.ChannelId, "Manual", from, to);
   tvSchedule.PreRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("preRecordInterval", 5);
   tvSchedule.PostRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("postRecordInterval", 5);
   tvSchedule.ScheduleType = (int)ScheduleRecordingType.Once;
   scheduleService.SaveSchedule(tvSchedule);
   schedule = tvSchedule.ToSchedule();
   return true;
 }
Ejemplo n.º 55
0
 public override bool GetChannel(IProgram program, out IChannel channel)
 {
   channel = TvDatabase.Channel.Retrieve(program.ChannelId).ToChannel();
   return true;
 }
Ejemplo n.º 56
0
 public override bool GetChannel(int channelId, out IChannel channel)
 {
   channel = TvDatabase.Channel.Retrieve(channelId).ToChannel();
   return channel != null;
 }
Ejemplo n.º 57
0
 public override bool GetNowNextProgram(IChannel channel, out IProgram programNow, out IProgram programNext)
 {
   var tvChannel = TvDatabase.Channel.Retrieve(channel.ChannelId);
   programNow = tvChannel.CurrentProgram.ToProgram();
   programNext = tvChannel.NextProgram.ToProgram();
   return programNow != null || programNext != null;
 }
Ejemplo n.º 58
0
 public bool StartTimeshift(int slotIndex, IChannel channel, out MediaItem timeshiftMediaItem)
 {
   throw new NotImplementedException("Not available in server side implementation");
 }
    public bool GetNextProgram(IChannel channel, out IProgram program)
    {
      program = null;

      Channel indexChannel = channel as Channel;
      if (indexChannel == null)
        return false;

      if (!CheckConnection(indexChannel.ServerIndex))
        return false;

      IProgram currentProgram;
      try
      {
        if (GetCurrentProgram(channel, out currentProgram))
        {
          IList<WebProgramDetailed> nextPrograms = TvServer(indexChannel.ServerIndex).GetProgramsDetailedForChannel(channel.ChannelId,
                                                                                          currentProgram.EndTime.AddMinutes(1),
                                                                                          currentProgram.EndTime.AddMinutes(1));
          if (nextPrograms != null && nextPrograms.Count > 0)
          {
            program = new Program(nextPrograms[0], indexChannel.ServerIndex);
            return true;
          }
        }
      }
      catch (Exception ex)
      {
        ServiceRegistration.Get<ILogger>().Error(ex.Message);
      }
      return false;
    }
    public bool CreateScheduleByTime(IChannel channel, DateTime from, DateTime to, out ISchedule schedule)
    {
      Channel indexChannel = channel as Channel;
      schedule = null;
      if (indexChannel == null)
        return false;

      if (!CheckConnection(indexChannel.ServerIndex))
        return false;

      try
      {
        return TvServer(indexChannel.ServerIndex).AddSchedule(channel.ChannelId, "Manual", from, to, WebScheduleType.Once);
      }
      catch
      {
        return false;
      }
    }