public async Task <HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "viewer/locators")] HttpRequest req, ILogger log) { TelemetryClient.TrackEvent("Locators"); using (LoggerService.Init(log)) { try { ConfigurationModel config = ConfigurationService.GetConfiguration(); AzureMediaServicesClient client = await AuthenticationService.GetClientAsync(config); InputRequestService inputRequestService = new InputRequestService(client, config); LocatorsController locatorsController = new LocatorsController(client, config); InputRequestModel inputModel = await inputRequestService.GetInputRequestModelAsync(req); LocatorsOutputModel outputModel = await locatorsController.GetLocatorsAsync(inputModel); return(SuccessResponseService.CreateResponse(outputModel)); } catch (AppException e) { return(ReportError(e)); } catch (Exception e) { return(ReportError(e)); } } }
public async Task <LocatorsOutputModel> GetLocatorsAsync(InputRequestModel input) { bool didAbortBuildingUrl = false; LocatorsOutputModel allLocators = new LocatorsOutputModel { IsAllLive = false, IsAnyLive = false, LiveEvents = new List <LocatorsOutputModel.LiveEvent>() }; LoggerService.Info("Beginning the locators procedure", LoggerService.Locators); StreamingEndpoint streamingEndpoint = await GetStreamingEndpointAsync(input.StreamingEndpoint); LoggerService.Info($"Building {input.LiveEvents.Count} locator(s)", LoggerService.Locators); foreach (string liveEventName in input.LiveEvents) { List <LiveOutput> liveOutputs = await GetLiveOutputsAsync(liveEventName); if (!liveOutputs.Any()) { allLocators.LiveEvents.Add(GenerateEmptyLiveEvent(liveEventName)); didAbortBuildingUrl = true; LoggerService.Warn($"Could not find any live outputs for live event '{liveEventName}'", LoggerService.Locators); continue; } AssetStreamingLocator streamingLocator = await GetStreamingLocatorForAssetAsync(liveOutputs.First().AssetName); ListPathsResponse paths = await GetPathsForStreamingLocatorAsync(streamingLocator.Name); if (!paths.StreamingPaths.Any() || !paths.StreamingPaths.First().Paths.Any()) { allLocators.LiveEvents.Add(GenerateEmptyLiveEvent(liveEventName)); didAbortBuildingUrl = true; LoggerService.Warn($"Could not find any paths for the streaming locator '{streamingLocator.Name}' associated with the live event '{liveEventName}'", LoggerService.Locators); continue; } List <LocatorsOutputModel.LiveEvent.Locator> locators = MapStreamingPathsToLocatorUrls(streamingEndpoint.HostName, paths.StreamingPaths); allLocators.IsAnyLive = true; allLocators.LiveEvents.Add(new LocatorsOutputModel.LiveEvent { Name = liveEventName, IsLive = true, Locators = locators }); } LoggerService.Info($"Finished building {input.LiveEvents.Count} locator(s)", LoggerService.Locators); allLocators.IsAllLive = !didAbortBuildingUrl; return(allLocators); }