Exemple #1
0
        public async Task <ChannelVideoListResponse> FetchNextAsync()
        {
            if (!hasNext)
            {
                return(null);
            }

            ChannelVideoListResponse channelVideoListResponse = await _service.GetChannelVideoListAsync(_channelSeq, _count, currentPage);

            if (channelVideoListResponse.Videos.Count < _count)
            {
                hasNext = false;
            }

            currentPage++;

            return(channelVideoListResponse);
        }
Exemple #2
0
        public async Task <ChannelVideoListResponse> GetChannelVideoListAsync(int channelSeq, int count, int page, CancellationToken cancellationToken)
        {
            ValidateStrictlyPostiveInteger(channelSeq, nameof(channelSeq));
            ValidateStrictlyPostiveInteger(count, nameof(count));
            ValidateStrictlyPostiveInteger(page, nameof(page));

            count = Math.Min(count, 50);

            HttpRequestMessage  request  = new HttpRequestMessage(HttpMethod.Get, string.Format(_channelVideoListEndpoint, _appId, channelSeq, count, page, _locale.Value));
            HttpResponseMessage response = await _http.SendAsync(request, cancellationToken);

            if (!response.IsSuccessStatusCode)
            {
                await HandleNonSuccessStatusCodeAsync(response);
            }

            string responseText = await response.Content.ReadAsStringAsync();

            if (string.IsNullOrEmpty(responseText) || string.IsNullOrWhiteSpace(responseText))
            {
                throw new UnkownErrorException();
            }

            dynamic responseTextDynamic = JsonConvert.DeserializeObject <dynamic>(responseText);

            if (responseTextDynamic == null ||
                (responseTextDynamic != null && responseTextDynamic["result"] == null))
            {
                throw new UnkownErrorException();
            }

            ChannelVideoListResponse channelVideoListResponse = JsonConvert.DeserializeObject <ChannelVideoListResponse>(responseTextDynamic["result"].ToString());

            if (channelVideoListResponse == null)
            {
                throw new UnmappableResponseException();
            }

            return(channelVideoListResponse);
        }
Exemple #3
0
        public LiveMonitorTask(int channelSeq, int count, TimeSpan period, VSharpService service) : base(channelSeq, period, service)
        {
            _count = count;

            Timer = new Timer(async(s) =>
            {
                if (Checking)
                {
                    return;
                }

                // Set flag to prevent overlapping checks
                Checking = true;

                try
                {
                    ChannelVideoListResponse channelVideoListResponse = await Service.GetChannelVideoListAsync(ChannelSeq, _count, 1);
                    List <Video> videos = channelVideoListResponse.Videos;

                    videos = videos.Where(x => x.VideoType == "LIVE" && x.OnAirStartAt > lastLive).ToList();
                    for (int i = videos.Count - 1; i >= 0; i--)
                    {
                        LiveFound.Invoke(null, CreateLiveFoundEventArgs(videos[i], channelVideoListResponse.ChannelInfo));
                    }

                    if (videos.Any())
                    {
                        lastLive = videos.Max(x => x.OnAirStartAt);
                    }
                }
                catch (Exception e)
                {
                    ExceptionThrown.Invoke(null, e);
                }
                finally
                {
                    Checking = false;
                }
            }, null, Timeout.Infinite, Timeout.Infinite);
        }