Esempio n. 1
0
        public static async Task <ShowsPage> Run(
            [ActivityTrigger] int pageNumber,
            [Inject(typeof(IDownloadService))] IDownloadService downloadService,
            [Inject(typeof(IConfiguration))] IConfiguration configuration)
        {
            string uri = $"{configuration.BaseTvMazeApiUri}/shows?page={pageNumber}";
            ServerResponse <ICollection <Show> > sr = await downloadService.GetAsync <ICollection <Show> >(uri);

            return(new ShowsPage {
                Shows = sr.Content, IsLastPage = !sr.StatusCode.IsSuccessStatusCode()
            });
        }
        public static async Task <CastInfo> Run(
            [ActivityTrigger] int showId,
            [Inject(typeof(IDownloadService))] IDownloadService downloadService,
            [Inject(typeof(IConfiguration))] IConfiguration configuration)
        {
            string uri = $"{configuration.BaseTvMazeApiUri}/shows/{showId}/cast";
            ServerResponse <ICollection <Role> > sr = await downloadService.GetAsync <ICollection <Role> >(uri);

            return(new CastInfo {
                ShowId = showId, Cast = sr.Content?.Select(role => role.Person).ToList()
            });
        }
        public static async Task <IEnumerable <ShowUpdate> > Run(
            [ActivityTrigger] DurableActivityContext context,
            [Inject(typeof(IDownloadService))] IDownloadService downloadService,
            [Inject(typeof(IConfiguration))] IConfiguration configuration,
            ILogger logger)
        {
            logger.LogInformation("Checking updates");

            string uri = $"{configuration.BaseTvMazeApiUri}/updates/shows";
            ServerResponse <Dictionary <int, int> > sr = await downloadService.GetAsync <Dictionary <int, int> >(uri);

            return(sr.Content.Select(pair => new ShowUpdate {
                ShowId = pair.Key, Timespamp = pair.Value
            }));
        }
        public static async Task <ShowWithCast> Run(
            [ActivityTrigger] int showId,
            [Inject(typeof(IDownloadService))] IDownloadService downloadService,
            [Inject(typeof(IConfiguration))] IConfiguration configuration)
        {
            string uri = $"{configuration.BaseTvMazeApiUri}/shows/{showId}?embed=cast";
            ServerResponse <EmbeddedShowInfo <CastServerModel> > sr = await downloadService.GetAsync <EmbeddedShowInfo <CastServerModel> >(uri);

            return(new ShowWithCast
            {
                Id = sr.Content.Id,
                Name = sr.Content.Name,
                Updated = sr.Content.Updated,
                Cast = sr.Content.Embedded.Cast.Select(role => role.Person)
            });
        }