public static async void BlobTriggerStart(
            [BlobTrigger("holomaintenance-video/{name}", Connection = "VideoStorage")] Stream myBlob, string name, Uri Uri,
            [OrchestrationClient] DurableOrchestrationClient starter,
            ILogger log)
        {
            string apiUrl    = Environment.GetEnvironmentVariable("VideoIndexerApiUrl");
            string location  = Environment.GetEnvironmentVariable("VideoIndexerLocation");
            string apiKey    = Environment.GetEnvironmentVariable("VideoIndexerApiKey");
            string accountId = Environment.GetEnvironmentVariable("VideoIndexerAccountId");

            System.Net.ServicePointManager.SecurityProtocol = System.Net.ServicePointManager.SecurityProtocol | System.Net.SecurityProtocolType.Tls12;
            string videoId = "";

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);

                var accountAccessTokenRequestResult = await client.GetAsync($"{apiUrl}/auth/{location}/Accounts/{accountId}/AccessToken?allowEdit=true");

                var accountAccessToken = accountAccessTokenRequestResult.Content.ReadAsStringAsync().Result.Replace("\"", "");

                //Generate SAS TOKEN for the BLOB
                string containerUrl  = $"https://{Environment.GetEnvironmentVariable("VideoBlobAccountName")}.blob.core.windows.net/{Environment.GetEnvironmentVariable("VideoBlobContainerName")}";
                var    blobContainer = new CloudBlobContainer(new Uri(containerUrl),
                                                              new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(Environment.GetEnvironmentVariable("VideoBlobAccountName"), Environment.GetEnvironmentVariable("VideoBlobKey")));

                var videoUrlWithSasToken = BlobHelpers.GetBlobSasUri(blobContainer, name);

                // upload a video from URL
                Console.WriteLine("Uploading...");
                var videoUrl = HttpUtility.UrlEncode(videoUrlWithSasToken); // video URL

                var uploadRequestResult = await client.PostAsync($"{apiUrl}/{location}/Accounts/{accountId}/Videos?accessToken={accountAccessToken}&name={name}&description=uploaded_by_HoloMaintenance&privacy=private&partition=some_partition&videoUrl={videoUrl}", null);

                var uploadResult = await uploadRequestResult.Content.ReadAsStringAsync();


                // get the video id from the upload result
                videoId = JsonConvert.DeserializeObject <dynamic>(uploadResult)["id"];
                Console.WriteLine("Uploaded");
                Console.WriteLine("Video ID: " + videoId);
            }

            //call orchestrator with the video id
            string instanceId = null;

            if (!string.IsNullOrEmpty(videoId))
            {
                instanceId = await starter.StartNewAsync("VideoIndexerCheckState", videoId);

                log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
            }
        }
Beispiel #2
0
        public async Task <ActionResult> Upload(IFormFile photo)
        {
            var imageUrl = string.Empty;

            var azureHelper = new BlobHelpers("connection-string");

            var filePath = Path.GetTempFileName();

            if (photo.Length > 0)
            {
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await photo.CopyToAsync(stream);

                    var result = await azureHelper.UploadBlob("sampleimage", photo.FileName, stream);

                    imageUrl = result.FileUrl;
                }
            }

            TempData["LatestImage"] = imageUrl.ToString();
            return(RedirectToAction("LatestImage"));
        }
        public static async void Run(
            [TimerTrigger("0 */5 * * * *")] TimerInfo myTimer,
            ExecutionContext context,
            ILogger log)
        {
            config = Helpers.GetConfig(context);

            WarningThreshold  = Int32.Parse(config["WarningThreshold"]);
            CriticalThreshold = Int32.Parse(config["CriticalThreshold"]);
            DownThreshold     = Int32.Parse(config["DownThreshold"]);

            var gameBlob = Helpers.GetBlob(context, log, config["CloudStorageContainer"], config["CloudStorageBlobFile"]);
            var gameList = Helpers.GetBlobAsList(gameBlob, log);

            CloudStorageAccount storageAccount = Helpers.GetCloudStorageAccount(context);
            CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer  container      = blobClient.GetContainerReference(config["CloudStorageBlobFile"]);

            var blobs = container.ListBlobs(prefix: "loginEvents", useFlatBlobListing: true).OfType <CloudBlockBlob>().ToList();

            if (blobs.Count == 0)
            {
                foreach (Game savedGame in gameList)
                {
                    UpdateStatus(savedGame.LoginAlert, new AverageLoginEvent()
                    {
                        TitleId = savedGame.TitleId
                    }, savedGame.Title, log);
                    UpdateAverageStatus(savedGame.LoginAlert, new AverageLoginEvent()
                    {
                        TitleId = savedGame.TitleId
                    }, savedGame.Title, log);
                }
            }
            else
            {
                foreach (var blobEvent in blobs)
                {
                    List <AverageLoginEvent> currentList = BlobHelpers <AverageLoginEvent> .GetBlobContentLineByLine(blobEvent, log);

                    foreach (Game savedGame in gameList)
                    {
                        log.LogInformation($"{DateTime.UtcNow} - Processing game {savedGame.Title}");

                        if (currentList.Exists(requestGame => requestGame.TitleId == savedGame.TitleId))
                        {
                            AverageLoginEvent currentStatus = currentList.Find(x => x.TitleId == savedGame.TitleId);
                            log.LogInformation($"{DateTime.UtcNow} - Game {savedGame.Title} has recorded events. Updating persisted status.");
                            UpdateStatus(savedGame.LoginAlert, currentStatus, savedGame.Title, log);
                            UpdateAverageStatus(savedGame.LoginAlert, currentStatus, savedGame.Title, log);
                        }
                        else
                        {
                            log.LogInformation($"{DateTime.UtcNow} - Game {savedGame.Title} does not have any recorded events. Updating persisted status.");
                            UpdateStatus(savedGame.LoginAlert, new AverageLoginEvent()
                            {
                                TitleId = savedGame.TitleId
                            }, savedGame.Title, log);
                            UpdateAverageStatus(savedGame.LoginAlert, new AverageLoginEvent()
                            {
                                TitleId = savedGame.TitleId
                            }, savedGame.Title, log);
                        }
                    }

                    blobEvent.Delete();
                }
            }

            await Helpers.UploadGame(gameBlob, gameList, log);
        }