public async Task <IEnumerable <ProgramInfo> > GetProgramsAsync(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) { int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.LogInformation("[TVHclient] GetProgramsAsync, call canceled or timed out - returning empty list."); return(new List <ProgramInfo>()); } GetEventsResponseHandler currGetEventsResponseHandler = new GetEventsResponseHandler(startDateUtc, endDateUtc, _logger, cancellationToken); HTSMessage queryEvents = new HTSMessage(); queryEvents.Method = "getEvents"; queryEvents.putField("channelId", Convert.ToInt32(channelId)); queryEvents.putField("maxTime", ((DateTimeOffset)endDateUtc).ToUnixTimeSeconds()); _htsConnectionHandler.SendMessage(queryEvents, currGetEventsResponseHandler); _logger.LogInformation("[TVHclient] GetProgramsAsync, ask TVH for events of channel '{chanid}'.", channelId); TaskWithTimeoutRunner <IEnumerable <ProgramInfo> > twtr = new TaskWithTimeoutRunner <IEnumerable <ProgramInfo> >(TIMEOUT); TaskWithTimeoutResult <IEnumerable <ProgramInfo> > twtRes = await twtr.RunWithTimeout(currGetEventsResponseHandler.GetEvents(cancellationToken, channelId)); if (twtRes.HasTimeout) { _logger.LogInformation("[TVHclient] GetProgramsAsync, timeout during call for events of channel '{chanid}'.", channelId); return(new List <ProgramInfo>()); } return(twtRes.Result); }
protected override async Task <List <ProgramInfo> > GetProgramsInternal(TunerHostInfo tuner, string tunerChannelId, DateTimeOffset startDateUtc, DateTimeOffset endDateUtc, CancellationToken cancellationToken) { var connectionHandler = GetConnectionHandler(tuner); GetEventsResponseHandler currGetEventsResponseHandler = new GetEventsResponseHandler(startDateUtc, endDateUtc, Logger); HTSMessage queryEvents = new HTSMessage(); queryEvents.Method = "getEvents"; queryEvents.putField("channelId", Convert.ToInt32(tunerChannelId)); queryEvents.putField("maxTime", (endDateUtc).ToUnixTimeSeconds()); cancellationToken = CancellationTokenSource.CreateLinkedTokenSource(new CancellationTokenSource(TIMEOUT).Token, cancellationToken).Token; Logger.Info("[TVHclient] GetProgramsAsync, ask TVH for events of channel '" + tunerChannelId + "'."); var list = await connectionHandler.SendMessage(queryEvents, currGetEventsResponseHandler.GetResponse, cancellationToken).ConfigureAwait(false); foreach (var item in list) { item.ChannelId = tunerChannelId; item.Id = GetProgramEntryId(item.ShowId, item.StartDate, item.ChannelId); } return(list); }
public async Task <IEnumerable <ProgramInfo> > GetProgramsAsync(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) { ensureConnection(); int timeOut = await WaitForInitialLoadTask(cancellationToken); if (timeOut == -1 || cancellationToken.IsCancellationRequested) { _logger.Info("[TVHclient] GetProgramsAsync, call canceled or timed out - returning empty list."); return(new List <ProgramInfo>()); } GetEventsResponseHandler currGetEventsResponseHandler = new GetEventsResponseHandler(startDateUtc, endDateUtc, _logger, cancellationToken); HTSMessage queryEvents = new HTSMessage(); queryEvents.Method = "getEvents"; queryEvents.putField("channelId", Convert.ToInt32(channelId)); _htsConnection.sendMessage(queryEvents, currGetEventsResponseHandler); //IEnumerable<ProgramInfo> pi = await currGetEventsResponseHandler.GetEvents(cancellationToken); //return pi; TaskWithTimeoutRunner <IEnumerable <ProgramInfo> > twtr = new TaskWithTimeoutRunner <IEnumerable <ProgramInfo> >(TIMEOUT); TaskWithTimeoutResult <IEnumerable <ProgramInfo> > twtRes = await twtr.RunWithTimeout(currGetEventsResponseHandler.GetEvents(cancellationToken)); if (twtRes.HasTimeout) { return(new List <ProgramInfo>()); } return(twtRes.Result); }