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);
        }
Esempio n. 2
0
        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);
        }