private static async Task StoreBreakdownJsonInCosmos(VideoBreakdownPOCO videoBreakdownJson, TraceWriter log)
        {
            //string Cosmos_Collection_Name = ConfigurationManager.AppSettings["Cosmos_Collection_Name"];
            //if (String.IsNullOrEmpty(Cosmos_Collection_Name))
            //    throw new ApplicationException("Cosmos_Collection_Name app setting not set");

            var collectionName = "Breakdowns";
            var client         = Globals.GetCosmosClient(collectionName);


            // save the json as a new document
            try
            {
                Document r =
                    await client.UpsertDocumentAsync(
                        UriFactory.CreateDocumentCollectionUri(Globals.CosmosDatabasename, collectionName),
                        videoBreakdownJson);
            }
            catch (Exception e)
            {
                Globals.LogMessage(log, $"error inserting document in cosmos: {e.Message}");
                // ignore for now, but maybe should replace the document if it already exists..
                // seems to be caused by dev environment where queue items are being reprocesssed
            }
        }
        private static async Task StoreFacesAsync(int v, Face f, VideoBreakdownPOCO poco)
        {
            var faceStream = await DownloadWebResource(f.thumbnailFullUrl);

            var blob = await UploadFileToBlobStorage(faceStream, $"{poco.id}/faces/{f.shortId}.jpg", "image/jpg");

            f.thumbnailFullUrl = blob.Uri.ToString();
        }
        /// <summary>
        ///     Store the images referenced in the breakdown and update their location in the JSON prior to
        ///     storing in the database.
        /// </summary>
        /// <param name="poco"></param>
        /// <returns></returns>
        private static async Task ExtractImages(VideoBreakdownPOCO poco)
        {
            var pocoLock = new object();

            // download thumbnail and store in blob storage
            var newImageUrl = "";

            var memSreamOfResource = await DownloadWebResource(poco.summarizedInsights.thumbnailUrl);

            var newBlob = await UploadFileToBlobStorage(memSreamOfResource, $"{poco.id}/video-thumbnail.jpg",
                                                        "image/jpg");

            newImageUrl = newBlob.Uri.AbsoluteUri;

            // replace urls in breakdown
            poco.summarizedInsights.thumbnailUrl = newImageUrl;
            poco.breakdowns[0].thumbnailUrl      = newImageUrl;

            await Task.WhenAll(poco.summarizedInsights.faces.Select(f => StoreFacesAsync(1, f, poco)));
        }
        private static async Task GetCaptionsVttAsync(string id, VideoBreakdownPOCO videoBreakdownPoco, string language)
        {
            var client      = Globals.GetVideoIndexerHttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request parameters
            queryString["language"] = language;
            var uri = $"https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns/{id}/VttUrl?" +
                      queryString;

            // this returns a url to the captions file
            var response = await client.GetAsync(uri);

            var vttUrl =
                response.Content.ReadAsStringAsync().Result
                .Replace("\"", "");     // seems like the url is always wrapped in quotes

            // download actual vtt file and store in blob storage
            var vttStream = await DownloadWebResource(vttUrl);

            var blob = UploadFileToBlobStorage(vttStream, $"{videoBreakdownPoco.id}/{language}.vtt", "text/plain");

            //TODO: put reference to vtt in breakdown?
        }