internal static WebChannelDetailed ChannelDetailed(IChannel channel)
        {
            IProgramInfoAsync programInfo = ServiceRegistration.Get <ITvProvider>() as IProgramInfoAsync;

            var             programs        = programInfo.GetNowNextProgramAsync(channel).Result;
            WebChannelBasic webChannelBasic = BaseChannelBasic.ChannelBasic(channel);

            WebChannelDetailed webChannelDetailed = new WebChannelDetailed
            {
                // From Basic
                Id      = webChannelBasic.Id,
                IsRadio = webChannelBasic.IsRadio,
                IsTv    = webChannelBasic.IsTv,
                Title   = webChannelBasic.Title,

                CurrentProgram   = ProgramDetailed(programs.Result[0]),
                NextProgram      = ProgramDetailed(programs.Result[1]),
                EpgHasGaps       = channel.EpgHasGaps,
                ExternalId       = channel.ExternalId,
                GrabEpg          = channel.GrapEpg,
                GroupNames       = channel.GroupNames,
                LastGrabTime     = channel.LastGrabTime ?? DateTime.Now,
                TimesWatched     = channel.TimesWatched,
                TotalTimeWatched = channel.TotalTimeWatched ?? DateTime.Now,
                VisibleInGuide   = channel.VisibleInGuide,
            };

            return(webChannelDetailed);
        }
        public static async Task <IList <WebProgramBasic> > ProcessAsync(IOwinContext context, string channelId)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetNowNextWebProgramBasicForChannel: ITvProvider not found");
            }

            IChannelAndGroupInfoAsync channelAndGroupInfo = ServiceRegistration.Get <ITvProvider>() as IChannelAndGroupInfoAsync;
            IProgramInfoAsync         programInfo         = ServiceRegistration.Get <ITvProvider>() as IProgramInfoAsync;

            var programs = await TVAccess.GetChannelNowNextProgramAsync(context, int.Parse(channelId));

            if (programs == null)
            {
                throw new BadRequestException(string.Format("GetNowNextWebProgramBasicForChannel: Couldn't get Now/Next Info for channel with Id: {0}", channelId));
            }

            List <WebProgramBasic> output = new List <WebProgramBasic>
            {
                ProgramBasic(programs[0]),
                ProgramBasic(programs[1])
            };

            return(output);
        }
예제 #3
0
        private UPnPError OnGetRecordingFileOrStream(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context)
        {
            outParams = new List <object>();
            IProgramInfoAsync     programInfo     = ServiceRegistration.Get <ITvProvider>() as IProgramInfoAsync;
            IScheduleControlAsync scheduleControl = ServiceRegistration.Get <ITvProvider>() as IScheduleControlAsync;

            if (programInfo == null || scheduleControl == null)
            {
                return(new UPnPError(500, "IProgramInfo or IScheduleControl service not available"));
            }

            int      programId = (int)inParams[0];
            IProgram program;
            bool     result       = false;
            string   fileOrStream = null;

            if (programInfo.GetProgram(programId, out program))
            {
                var scheduleResult = scheduleControl.GetRecordingFileOrStreamAsync(program).Result;
                if (scheduleResult.Success)
                {
                    result       = true;
                    fileOrStream = scheduleResult.Result;
                }
            }

            outParams = new List <object> {
                result, fileOrStream
            };
            return(null);
        }
예제 #4
0
        public override async Task <bool> UpdateItemsAsync(int maxItems, UpdateReason updateReason)
        {
            IProgramInfoAsync programInfo = null;

            if (!TryInitTvHandler() || (programInfo = _tvHandler?.ProgramInfo) == null)
            {
                return(false);
            }

            if (!updateReason.HasFlag(UpdateReason.Forced) && !updateReason.HasFlag(UpdateReason.PlaybackComplete) && !updateReason.HasFlag(UpdateReason.PeriodicMinute))
            {
                return(true);
            }

            ICollection <IChannel> channels;

            if (_currentChannels == null || updateReason.HasFlag(UpdateReason.Forced) || updateReason.HasFlag(UpdateReason.PlaybackComplete))
            {
                channels = _currentChannels = await GetUserChannelList(maxItems, UserDataKeysKnown.KEY_CHANNEL_PLAY_COUNT, true);
            }
            else
            {
                channels = _currentChannels;
            }

            IList <Tuple <IProgram, IChannel> > programs = new List <Tuple <IProgram, IChannel> >();

            foreach (IChannel channel in channels)
            {
                var result = await programInfo.GetNowNextProgramAsync(channel);

                if (!result.Success)
                {
                    continue;
                }

                IProgram currentProgram = result.Result[0];

                if (currentProgram != null)
                {
                    programs.Add(new Tuple <IProgram, IChannel>(currentProgram, channel));
                }
            }

            lock (_allItems.SyncRoot)
            {
                if (_currentPrograms.Select(p => p.Item1.ProgramId).SequenceEqual(programs.Select(p => p.Item1.ProgramId)))
                {
                    return(true);
                }
                _currentPrograms = programs;
                _allItems.Clear();
                foreach (var program in programs)
                {
                    _allItems.Add(CreateProgramItem(program.Item1, program.Item2));
                }
            }
            _allItems.FireChange();
            return(true);
        }
예제 #5
0
        private UPnPError OnCreateSchedule(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context)
        {
            outParams = new List <object>();
            IProgramInfoAsync     programInfo     = ServiceRegistration.Get <ITvProvider>() as IProgramInfoAsync;
            IScheduleControlAsync scheduleControl = ServiceRegistration.Get <ITvProvider>() as IScheduleControlAsync;

            if (programInfo == null || scheduleControl == null)
            {
                return(new UPnPError(500, "IProgramInfo or IScheduleControl service not available"));
            }

            int programId = (int)inParams[0];
            ScheduleRecordingType recordingType = (ScheduleRecordingType)inParams[1];
            IProgram  program;
            ISchedule schedule = null;
            bool      result   = false;

            if (programInfo.GetProgram(programId, out program))
            {
                var scheduleResult = scheduleControl.CreateScheduleAsync(program, recordingType).Result;
                result   = scheduleResult.Success;
                schedule = scheduleResult.Result;
            }

            outParams = new List <object> {
                result, schedule
            };
            return(null);
        }
예제 #6
0
        private UPnPError OnGetNowNextProgramForGroup(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context)
        {
            outParams = new List <object>();
            IProgramInfoAsync programInfo = ServiceRegistration.Get <ITvProvider>() as IProgramInfoAsync;

            if (programInfo == null)
            {
                return(new UPnPError(500, "IProgramInfo service not available"));
            }

            int channelGroupId        = (int)inParams[0];
            IList <IProgram> programs = new List <IProgram>();
            // Flatten to simple list for UPnP transfer
            var result = programInfo.GetNowAndNextForChannelGroupAsync(new ChannelGroup {
                ChannelGroupId = channelGroupId
            }).Result;

            if (result.Success)
            {
                foreach (KeyValuePair <int, IProgram[]> nowNextProgram in result.Result)
                {
                    foreach (var program in nowNextProgram.Value)
                    {
                        if (program != null)
                        {
                            programs.Add(program);
                        }
                    }
                }
            }
            outParams = new List <object> {
                true, programs
            };
            return(null);
        }
예제 #7
0
        private UPnPError OnGetSchedules(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context)
        {
            outParams = new List <object>();
            IProgramInfoAsync     programInfo     = ServiceRegistration.Get <ITvProvider>() as IProgramInfoAsync;
            IScheduleControlAsync scheduleControl = ServiceRegistration.Get <ITvProvider>() as IScheduleControlAsync;

            if (programInfo == null || scheduleControl == null)
            {
                return(new UPnPError(500, "IProgramInfo or IScheduleControl service not available"));
            }

            AsyncResult <IList <ISchedule> > result = scheduleControl.GetSchedulesAsync().Result;

            outParams = new List <object> {
                result.Success, result.Result
            };
            return(null);
        }
예제 #8
0
        private UPnPError OnRemoveSchedule(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context)
        {
            outParams = new List <object>();
            IProgramInfoAsync     programInfo     = ServiceRegistration.Get <ITvProvider>() as IProgramInfoAsync;
            IScheduleControlAsync scheduleControl = ServiceRegistration.Get <ITvProvider>() as IScheduleControlAsync;

            if (programInfo == null || scheduleControl == null)
            {
                return(new UPnPError(500, "IProgramInfo or IScheduleControl service not available"));
            }

            ISchedule schedule = (ISchedule)inParams[0];
            bool      result   = scheduleControl.RemoveScheduleAsync(schedule).Result;

            outParams = new List <object> {
                result
            };
            return(null);
        }
예제 #9
0
        private UPnPError OnGetNowNextProgram(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context)
        {
            outParams = new List <object>();
            IProgramInfoAsync programInfo = ServiceRegistration.Get <ITvProvider>() as IProgramInfoAsync;

            if (programInfo == null)
            {
                return(new UPnPError(500, "IProgramInfo service not available"));
            }

            int channelId = (int)inParams[0];
            AsyncResult <IProgram[]> result = programInfo.GetNowNextProgramAsync(new Channel {
                ChannelId = channelId
            }).Result;

            outParams = new List <object> {
                result.Success, result.Result[0], result.Result[1]
            };
            return(null);
        }
예제 #10
0
        private UPnPError OnRemoveScheduleForProgram(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context)
        {
            outParams = new List <object>();
            IProgramInfoAsync     programInfo     = ServiceRegistration.Get <ITvProvider>() as IProgramInfoAsync;
            IScheduleControlAsync scheduleControl = ServiceRegistration.Get <ITvProvider>() as IScheduleControlAsync;

            if (programInfo == null || scheduleControl == null)
            {
                return(new UPnPError(500, "IProgramInfo or IScheduleControl service not available"));
            }

            int programId = (int)inParams[0];
            ScheduleRecordingType recordingType = (ScheduleRecordingType)inParams[1];
            IProgram program;
            var      result = programInfo.GetProgram(programId, out program) && scheduleControl.RemoveScheduleForProgramAsync(program, recordingType).Result;

            outParams = new List <object> {
                result
            };
            return(null);
        }
예제 #11
0
        private UPnPError OnGetProgramsByTitle(DvAction action, IList <object> inParams, out IList <object> outParams, CallContext context)
        {
            outParams = new List <object>();
            IProgramInfoAsync programInfo = ServiceRegistration.Get <ITvProvider>() as IProgramInfoAsync;

            if (programInfo == null)
            {
                return(new UPnPError(500, "IProgramInfo service not available"));
            }

            string   title    = (string)inParams[0];
            DateTime timeFrom = (DateTime)inParams[1];
            DateTime timeTo   = (DateTime)inParams[2];

            AsyncResult <IList <IProgram> > result = programInfo.GetProgramsAsync(title, timeFrom, timeTo).Result;

            outParams = new List <object> {
                result.Success, result.Result
            };
            return(null);
        }