コード例 #1
0
        public static async Task <IList <WebChannelState> > ProcessAsync(IOwinContext context, string groupId, string userName)
        {
            List <WebChannelState> output = new List <WebChannelState>();

            if (groupId == null)
            {
                throw new BadRequestException("GetAllRadioChannelStatesForGroup: groupId is null");
            }
            if (userName == null)
            {
                throw new BadRequestException("GetAllRadioChannelStatesForGroup: userName is null");
            }

            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetAllRadioChannelStatesForGroup: ITvProvider not found");
            }

            var channels = await TVAccess.GetGroupChannelsAsync(context, groupId != null?int.Parse(groupId) : (int?)null);

            output.AddRange(channels.Where(x => x.MediaType == MediaType.Radio).Select(channel => new WebChannelState
            {
                ChannelId = channel.ChannelId,
                State     = ChannelState.Tunable, // TODO: implement in SlimTv
            }));

            return(output);
        }
コード例 #2
0
        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
        public static async Task <WebBoolResult> ProcessAsync(IOwinContext context, string userName)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("CancelCurrentTimeShifting: ITvProvider not found");
            }

            if (userName == null)
            {
                throw new BadRequestException("CancelCurrentTimeShifting: userName is null");
            }

            int channelId = -1;

            if (userName.Contains("-"))
            {
                string channel = userName.Substring(userName.LastIndexOf("-") + 1);
                if (int.TryParse(channel, out channelId))
                {
                    userName = userName.Substring(0, userName.LastIndexOf("-")); //Channel needs to be removed
                }
            }

            bool result = await TVAccess.StopTimeshiftAsync(context, channelId, userName);

            return(new WebBoolResult {
                Result = result
            });
        }
コード例 #4
0
        public static async Task <IList <WebScheduleBasic> > ProcessAsync(IOwinContext context, string filter, WebSortField?sort, WebSortOrder?order)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetSchedules: ITvProvider not found");
            }

            IScheduleControlAsync scheduleControl = ServiceRegistration.Get <ITvProvider>() as IScheduleControlAsync;

            var schedules = await TVAccess.GetSchedulesAsync(context);

            List <WebScheduleBasic> output = schedules.Select(schedule => ScheduleBasic(schedule)).ToList();

            // sort and filter
            if (sort != null && order != null)
            {
                output = output.Filter(filter).SortScheduleList(sort, order).ToList();
            }
            else
            {
                output = output.Filter(filter).ToList();
            }

            return(output);
        }
コード例 #5
0
        public static async Task <IList <WebProgramBasic> > ProcessAsync(IOwinContext context, string searchTerm)
        {
            if (searchTerm == null)
            {
                throw new BadRequestException("SearchProgramsBasic: searchTerm is null");
            }

            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("SearchProgramsBasic: ITvProvider not found");
            }

            Regex regex = new Regex(@searchTerm);

            List <WebProgramBasic> output = new List <WebProgramBasic>();
            var programs = await TVAccess.GetGroupProgramsAsync(context, DateTime.Now, DateTime.Now.AddMonths(2));

            foreach (var program in programs)
            {
                if (regex.IsMatch(program.Title))
                {
                    output.Add(ProgramBasic(program));
                }
            }

            return(output);
        }
コード例 #6
0
        public static async Task <IList <WebChannelGroup> > ProcessAsync(IOwinContext context, int start, int end, WebSortField?sort, WebSortOrder?order)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetGroupsByRange: ITvProvider not found");
            }

            var groups = await TVAccess.GetGroupsAsync(context);

            List <WebChannelGroup> output = new List <WebChannelGroup>();

            foreach (var group in groups)
            {
                output.Add(ChannelGroup(group));
            }

            // sort
            if (sort != null && order != null)
            {
                output = output.SortGroupList(sort, order).ToList();
            }

            // get range
            output = output.TakeRange(start, end).ToList();

            return(output);
        }
コード例 #7
0
        public static async Task <IList <WebProgramDetailed> > ProcessAsync(IOwinContext context, string searchTerm)
        {
            if (searchTerm == null)
            {
                throw new BadRequestException("SearchProgramsDetailed: searchTerm is null");
            }

            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("SearchProgramsDetailed: ITvProvider not found");
            }

            Regex regex = new Regex(@searchTerm);

            var programs = await TVAccess.GetGroupProgramsAsync(context, DateTime.Now, DateTime.Now.AddMonths(2));

            if (programs.Count == 0)
            {
                Logger.Warn("SearchProgramsDetailed: Couldn't get Now/Next Info for channels");
            }

            List <WebProgramDetailed> output = new List <WebProgramDetailed>();

            foreach (var program in programs)
            {
                if (regex.IsMatch(program.Title))
                {
                    output.Add(ProgramDetailed(program));
                }
            }
            return(output);
        }
コード例 #8
0
        public static async Task <IList <WebChannelPrograms <WebProgramBasic> > > ProcessAsync(IOwinContext context, string groupId, DateTime startTime, DateTime endTime)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetProgramsBasicForGroup: ITvProvider not found");
            }

            var programs = await TVAccess.GetGroupProgramsAsync(context, startTime, endTime, int.Parse(groupId));

            if (programs.Count == 0)
            {
                Logger.Warn("GetProgramsDetailedForGroup: Couldn't get Now/Next Info for channel with Id: {0}", groupId);
            }

            List <WebChannelPrograms <WebProgramBasic> > output = new List <WebChannelPrograms <WebProgramBasic> >();

            foreach (var program in programs)
            {
                if (output.FindIndex(x => x.ChannelId == program.ChannelId) == -1)
                {
                    output.Add(new WebChannelPrograms <WebProgramBasic>
                    {
                        ChannelId = program.ChannelId,
                        Programs  = programs.Select(y => ProgramBasic(y)).Where(x => x.ChannelId == program.ChannelId).ToList()
                    });
                }
            }

            return(output);
        }
コード例 #9
0
        public static async Task <IList <WebCard> > ProcessAsync(IOwinContext context)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetCards: ITvProvider not found");
            }

            var cards = await TVAccess.GetTunerCardsAsync(context);

            return(cards.Select(card => Card(card)).ToList());
        }
コード例 #10
0
        public static async Task <WebBoolResult> ProcessAsync(IOwinContext context, string channelId, string programId)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetProgramIsScheduledOnChannel: ITvProvider not found");
            }

            return(new WebBoolResult {
                Result = await TVAccess.GetProgramIsScheduledOnChannel(context, int.Parse(channelId), int.Parse(programId))
            });
        }
コード例 #11
0
        public static async Task <WebDiskSpaceInformation> ProcessAsync(IOwinContext context, string id)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetRecordingDiskInformationForCard: ITvProvider not found");
            }

            IList <ICard> cards = await TVAccess.GetTunerCardsAsync(context);

            return(DiskSpaceInformation.GetSpaceInformation(cards.Select(card => Card(card)).Single(x => x.Id == int.Parse(id)).RecordingFolder));
        }
コード例 #12
0
        public static async Task <WebIntResult> ProcessAsync(IOwinContext context)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetScheduleCount: ITvProvider not found");
            }

            var schedules = await TVAccess.GetSchedulesAsync(context);

            return(new WebIntResult {
                Result = schedules.Count
            });
        }
コード例 #13
0
        public static async Task <WebIntResult> ProcessAsync(IOwinContext context, string groupId = null)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetRadioChannelCount: ITvProvider not found");
            }

            var channels = await TVAccess.GetGroupChannelsAsync(context, groupId != null?int.Parse(groupId) : (int?)null);

            return(new WebIntResult {
                Result = channels.Where(c => c.MediaType == MediaType.Radio).Count()
            });
        }
コード例 #14
0
        public static async Task <WebIntResult> ProcessAsync(IOwinContext context)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetChannelsBasic: ITvProvider not found");
            }

            var channelGroups = await TVAccess.GetGroupsAsync(context);

            return(new WebIntResult {
                Result = channelGroups.Count
            });
        }
コード例 #15
0
        public static async Task <WebBoolResult> ProcessAsync(IOwinContext context, string programId)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("CancelSchedule: ITvProvider not found");
            }

            bool result = await TVAccess.CancelScheduleAsync(context, int.Parse(programId));

            return(new WebBoolResult {
                Result = result
            });
        }
コード例 #16
0
        public static async Task <WebBoolResult> ProcessAsync(IOwinContext context, string channelId, string title, DateTime startTime, DateTime endTime, WebScheduleType scheduleType, int preRecordInterval, int postRecordInterval, string directory, int priority)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("AddScheduleDetailed: ITvProvider not found");
            }

            bool result = await TVAccess.CreateScheduleAsync(context, int.Parse(channelId), title, startTime, endTime, scheduleType, preRecordInterval, postRecordInterval, directory, priority);

            return(new WebBoolResult {
                Result = result
            });
        }
コード例 #17
0
        public static async Task <IList <WebDiskSpaceInformation> > ProcessAsync(IOwinContext context)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetAllRecordingDiskInformation: ITvProvider not found");
            }

            var cards = await TVAccess.GetTunerCardsAsync(context);

            return(cards.Select(card => Card(card)).Select(x => x.RecordingFolder).Distinct().AsQueryable()
                   .Select(x => DiskSpaceInformation.GetSpaceInformation(x))
                   .GroupBy(x => x.Disk, (key, list) => list.First())
                   .ToList());
        }
コード例 #18
0
        public static async Task <IList <WebProgramBasic> > ProcessAsync(IOwinContext context, string channelId, DateTime startTime, DateTime endTime)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetProgramsBasicForChannel: ITvProvider not found");
            }

            var programs = await TVAccess.GetGroupProgramsAsync(context, startTime, endTime, int.Parse(channelId));

            if (programs.Count == 0)
            {
                Logger.Warn("GetProgramsBasicForChannel: Couldn't get Now/Next Info for channel with Id: {0}", channelId);
            }

            return(programs.Select(program => ProgramBasic(program)).ToList());
        }
コード例 #19
0
        public static async Task <WebChannelDetailed> ProcessAsync(IOwinContext context, string channelId)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetChannelDetailedById: ITvProvider not found");
            }

            var channel = await TVAccess.GetChannelAsync(int.Parse(channelId));

            if (channel == null)
            {
                throw new NotFoundException(string.Format("GetChannelDetailedById: Couldn't get channel with Id: {0}", channelId));
            }

            return(ChannelDetailed(channel));
        }
コード例 #20
0
        public static async Task <WebProgramDetailed> ProcessAsync(IOwinContext context, string channelId)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetCurrentProgramOnChannel: ITvProvider not found");
            }

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

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

            WebProgramDetailed webProgramDetailed = ProgramDetailed(programs[0]);

            return(webProgramDetailed);
        }
コード例 #21
0
        public static async Task <WebScheduleBasic> ProcessAsync(IOwinContext context, string scheduleId)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetScheduleById: ITvProvider not found");
            }

            var schedule = await TVAccess.GetScheduleAsync(context, int.Parse(scheduleId));

            if (schedule == null)
            {
                throw new NotFoundException(string.Format("GetScheduleById: Couldn't get schedule with Id: {0}", scheduleId));
            }

            WebScheduleBasic output = ScheduleBasic(schedule);

            return(output);
        }
コード例 #22
0
        public static async Task <WebProgramDetailed> ProcessAsync(IOwinContext context, string programId)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetProgramDetailedById: ITvProvider not found");
            }

            IProgram program = await TVAccess.GetProgramAsync(context, int.Parse(programId));

            if (program == null)
            {
                throw new NotFoundException(string.Format("GetProgramDetailedById: Couldn't get Now/Next Info for channel with Id: {0}", programId));
            }

            WebProgramDetailed webProgramDetailed = ProgramDetailed(program);

            return(webProgramDetailed);
        }
コード例 #23
0
        public static async Task <WebChannelGroup> ProcessAsync(IOwinContext context, string groupId)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetRadioGroupById: ITvProvider not found");
            }

            // select the channel Group we are looking for
            var group = await TVAccess.GetGroupAsync(context, int.Parse(groupId));

            if (group == null)
            {
                throw new NotFoundException(string.Format("GetRadioGroupById: group with id: {0} not found", groupId));
            }

            WebChannelGroup webChannelGroup = ChannelGroup(group);

            return(webChannelGroup);
        }
コード例 #24
0
        public static async Task <IList <WebChannelDetailed> > ProcessAsync(IOwinContext context, string groupId, WebSortField?sort, WebSortOrder?order)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetChannelsDetailed: ITvProvider not found");
            }

            List <WebChannelDetailed> output = new List <WebChannelDetailed>();
            var channels = await TVAccess.GetGroupChannelsAsync(context, groupId != null?int.Parse(groupId) : (int?)null);

            output.AddRange(channels.Where(x => x.MediaType == MediaType.TV).Select(channel => ChannelDetailed(channel)));

            // sort
            if (sort != null && order != null)
            {
                output = output.SortChannelList(sort, order).ToList();
            }

            return(output);
        }
コード例 #25
0
        public static async Task <IList <WebUser> > ProcessAsync(IOwinContext context)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetActiveUsers: ITvProvider not found");
            }

            var cards = await TVAccess.GetVirtualCardsAsync(context);

            return(cards.Select(card => new WebUser
            {
                ChannelId = card.User.IdChannel,
                Name = card.User.Name,
                CardId = card.User.CardId,
                HeartBeat = card.User.HeartBeat,
                IsAdmin = card.User.IsAdmin,
                SubChannel = card.User.SubChannel,
                TvStoppedReason = (int)card.User.TvStoppedReason,
            }).ToList());
        }
コード例 #26
0
        public static async Task <WebBoolResult> ProcessAsync(IOwinContext context, string programId)
        {
            if (programId == null)
            {
                throw new BadRequestException("GetProgramIsScheduled: programId is null");
            }

            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetProgramIsScheduled: ITvProvider not found");
            }

            var recordingStatus = await TVAccess.GetProgramRecordingStatusAsync(context, int.Parse(programId));

            bool result = recordingStatus == RecordingStatus.Recording || recordingStatus == RecordingStatus.RuleScheduled ||
                          recordingStatus == RecordingStatus.Scheduled || recordingStatus == RecordingStatus.SeriesScheduled;

            return(new WebBoolResult {
                Result = result
            });
        }
コード例 #27
0
        public static async Task <WebBoolResult> ProcessAsync(IOwinContext context, string scheduleId, string channelId = null, string title = null, DateTime?startTime = null, DateTime?endTime = null, WebScheduleType?scheduleType = null, int?preRecordInterval = null, int?postRecordInterval = null, string directory = null, int?priority = null)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("EditSchedule: ITvProvider not found");
            }

            bool result = await TVAccess.EditScheduleAsync(context, int.Parse(scheduleId),
                                                           channelId != null?int.Parse(channelId) : (int?)null,
                                                           title,
                                                           startTime,
                                                           endTime,
                                                           scheduleType,
                                                           preRecordInterval,
                                                           postRecordInterval,
                                                           directory,
                                                           priority);

            return(new WebBoolResult {
                Result = result
            });
        }
コード例 #28
0
        public static async Task <IList <WebScheduledRecording> > ProcessAsync(IOwinContext context, DateTime date, WebSortField?sort, WebSortOrder?order, string filter = null)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetScheduledRecordingsForDate: ITvProvider not found");
            }

            var schedules = await TVAccess.GetSchedulesAsync(context);

            List <WebScheduledRecording> output = schedules.Select(schedule => ScheduledRecording(schedule)).Where(x => x.StartTime.Date == date.Date).ToList();

            // sort and filter
            if (sort != null && order != null)
            {
                output = output.Filter(filter).SortScheduledRecordingList(sort, order).ToList();
            }
            else
            {
                output = output.Filter(filter).ToList();
            }

            return(output);
        }
        public static async Task <WebStringResult> ProcessAsync(IOwinContext context, string userName, string channelId)
        {
            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("SwitchTVServerToChannelAndGetTimeshiftFilename: ITvProvider not found");
            }

            if (userName == null)
            {
                throw new BadRequestException("SwitchTVServerToChannelAndGetTimeshiftFilename: userName is null");
            }

            var item = await TVAccess.StartTimeshiftAsync(context, int.Parse(channelId), userName);

            if (item == null)
            {
                throw new BadRequestException("SwitchTVServerToChannelAndGetTimeshiftFilename: Couldn't start timeshifting");
            }

            string resourcePathStr = item.PrimaryProviderResourcePath();
            var    resourcePath    = ResourcePath.Deserialize(resourcePathStr);
            var    stra            = SlimTvResourceProvider.GetResourceAccessor(resourcePath.BasePathSegment.Path);
            string url             = "";

            if (stra is ILocalFsResourceAccessor)
            {
                url = ((ILocalFsResourceAccessor)stra).LocalFileSystemPath;
            }
            else
            {
                await TVAccess.StopTimeshiftAsync(context, int.Parse(channelId), userName);
            }

            return(new WebStringResult {
                Result = url
            });
        }
コード例 #30
0
        public static async Task <IList <WebChannelBasic> > ProcessAsync(IOwinContext context, int start, int end, string groupId, WebSortField?sort, WebSortOrder?order)
        {
            List <WebChannelBasic> output = new List <WebChannelBasic>();

            if (!ServiceRegistration.IsRegistered <ITvProvider>())
            {
                throw new BadRequestException("GetRadioChannelsBasicByRange: ITvProvider not found");
            }

            var channels = await TVAccess.GetGroupChannelsAsync(context, groupId != null?int.Parse(groupId) : (int?)null);

            output.AddRange(channels.Where(x => x.MediaType == MediaType.Radio).Select(channel => ChannelBasic(channel)));

            // sort
            if (sort != null && order != null)
            {
                output = output.SortChannelList(sort, order).ToList();
            }

            // get range
            output = output.TakeRange(start, end).ToList();

            return(output);
        }