public static async Task CallAsync(this DbCommand command, Action <MultiResults> results, CommandBehavior commandBehaviour = CommandBehavior.Default, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (results == null)
            {
                throw new ArgumentNullException(nameof(results));
            }

            using (command)
            {
                if (command.Connection.State == ConnectionState.Closed)
                {
                    await command.Connection.OpenAsync(cancellationToken).ConfigureAwait(false);
                }
                try
                {
                    using (var reader = await command.ExecuteReaderAsync(commandBehaviour, cancellationToken).ConfigureAwait(false))
                    {
                        var result = new MultiResults(reader);
                        results(result);
                    }
                }
                finally
                {
                    command.Connection.Close();
                }
            }
        }
        public static void Call(this DbCommand command, Action <MultiResults> results, CommandBehavior commandBehaviour = CommandBehavior.Default)
        {
            if (results == null)
            {
                throw new ArgumentNullException(nameof(results));
            }

            using (command)
            {
                if (command.Connection.State == ConnectionState.Closed)
                {
                    command.Connection.Open();
                }
                try
                {
                    using (var reader = command.ExecuteReader(commandBehaviour))
                    {
                        var result = new MultiResults(reader);
                        results(result);
                    }
                }
                finally
                {
                    command.Connection.Close();
                }
            }
        }
Exemple #3
0
        private MultiResults ParseMultiResponse(string jsonResultsString)
        {
            JObject searchResult = JObject.Parse(jsonResultsString);

            var movieQuery = from r in searchResult["results"]
                             where (string)r["media_type"] == "movie"
                             select new MovieDetails()
            {
                overview       = (string)r["overview"],
                overview_short = ((string)r["overview"]).Length > 100 ? ((string)r["overview"]).Substring(0, 100) + "..." : (string)r["overview"],
                release_date   = (string)r["release_date"],
                backdrop_path  = config.images.base_url + config.images.backdrop_sizes[1] + (string)r["backdrop_path"],
                poster_path    = config.images.base_url + config.images.poster_sizes[1] + (string)r["poster_path"],
                vote_count     = (int)r["vote_count"],
                vote_average   = (float)r["vote_average"],
                title          = (string)r["title"]
            };

            var personQuery = from r in searchResult["results"]
                              where (string)r["media_type"] == "person"
                              select new PersonDetails()
            {
                name = (string)r["name"],
                id   = (int)r["id"]
            };

            var tvShowQuery = from r in searchResult["results"]
                              where (string)r["media_type"] == "tv"
                              select new TvShowDetails()
            {
                overview      = (string)r["overview"],
                backdrop_path = config.images.base_url + config.images.backdrop_sizes[1] + (string)r["backdrop_path"],
                poster_path   = config.images.base_url + config.images.poster_sizes[1] + (string)r["poster_path"],
                vote_count    = (int)r["vote_count"],
                vote_average  = (float)r["vote_average"],
                name          = (string)r["name"]
            };

            MultiResults results = new MultiResults();

            results.Movies  = movieQuery;
            results.People  = personQuery;
            results.TvShows = tvShowQuery;

            return(results);
        }