private async Task <ActionResult> RunQueryVideoAsync(SearchDataVideo model) { // Retrieving the access token from the service string accessToken = await GetVideoIndexerAccessToken(); // Setting up HTTP client request HttpClient _httpClientSearchVideos = new HttpClient(); // Pulling off video indexer API information _builder = new ConfigurationBuilder().AddJsonFile("appsettings.json"); _configuration = _builder.Build(); string uriSearchVideos = _configuration["UriSearchVideos"]; string ocpApimSubscriptionKey = _configuration["OcpApimSubscriptionKey"]; // Setting up request headers _httpClientSearchVideos.DefaultRequestHeaders.Add("x-ms-client-request-id", ""); _httpClientSearchVideos.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", ocpApimSubscriptionKey); // Request parameters var queryString = HttpUtility.ParseQueryString(string.Empty); queryString["query"] = model.searchText; queryString["language"] = "pt-BR"; queryString["pageSize"] = "25"; queryString["skip"] = "0"; queryString["accessToken"] = accessToken; try { var response = await _httpClientSearchVideos.GetAsync(uriSearchVideos + queryString); var result = JsonConvert.DeserializeObject <RootVideo>(await response.Content.ReadAsStringAsync()); model.resultVideos = result.results; return(View(model)); } catch (Exception e) { throw; } }
public async Task <ActionResult> IndexVideo(SearchDataVideo model) { try { // Ensure the search string is valid. if (model.searchText == null) { model.searchText = ""; } // Make the Azure Video Indexer search call. await RunQueryVideoAsync(model); } catch (Exception e) { return(View("Error", new ErrorViewModel { RequestId = "1" })); } return(View(model)); }
public async Task <ActionResult> DetailsVideo(string id) { SearchDataVideo model = new SearchDataVideo(); // Retrieving the access token from the service string accessToken = await GetVideoIndexerAccessToken(); // Setting up HTTP client request HttpClient _httpClientSearchVideos = new HttpClient(); // Pulling off video indexer API information _builder = new ConfigurationBuilder().AddJsonFile("appsettings.json"); _configuration = _builder.Build(); string uriSearchVideos = _configuration["UriSearchVideos"]; string ocpApimSubscriptionKey = _configuration["OcpApimSubscriptionKey"]; // Setting up request headers _httpClientSearchVideos.DefaultRequestHeaders.Add("x-ms-client-request-id", ""); _httpClientSearchVideos.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", ocpApimSubscriptionKey); // Request parameters var queryString = HttpUtility.ParseQueryString(string.Empty); queryString["id"] = id; queryString["accessToken"] = accessToken; try { var response = await _httpClientSearchVideos.GetAsync(uriSearchVideos + queryString); var result = JsonConvert.DeserializeObject <RootVideo>(await response.Content.ReadAsStringAsync()); model.resultVideos = result.results; return(PartialView("_DetailsVideoModal", model)); } catch (Exception e) { throw new Exception(e.Message); } }