public void StartFromControllerTest() { AzureMediaService svc = null; Dictionary <string, object> errorList = new Dictionary <string, object>(); foreach (var svcSet in App.Config.Content.ContentProviders[0].MediaServicesSets) { foreach (var svcAcct in svcSet.MediaServicesAccounts) { try { svc = new AzureMediaService(svcAcct.AccountName, svcAcct.AccountKey); MonitoringWorker mw = new MonitoringWorker(svc, svcSet.DataStorageConnections); mw.Run(); } catch (Exception ex) { if (!errorList.ContainsKey(ex.Message)) { errorList.Add(ex.Message, ex); } } } } Assert.IsTrue((errorList.Count == 0), "Media Service Account issues found!\r\nPlease use Debug Test to determine cause"); }
public void MonitoringControllerTest1() { List <AzureMediaService> _mediaServices = new List <AzureMediaService>(); // init AzureMediaService testMediaServices1 = new AzureMediaService("ENTER MEDIA ACCOUNT NAME 1", "ENTER MEDIA ACCOUNT KEY 1"); AzureMediaService testMediaServices2 = new AzureMediaService("ENTER MEDIA ACCOUNT NAME 2", "ENTER MEDIA ACCOUNT KEY 2"); testMediaServices1.Id = @"ENTER MEDIA SERVICE ACCOUNT ID 1"; testMediaServices2.Id = @"ENTER MEDIA SERVICE ACCOUNT ID 2"; _mediaServices.Add(testMediaServices1); _mediaServices.Add(testMediaServices2); MediaDashboard.Ingest.MonitoringWorker mw = new MonitoringWorker(_mediaServices[0]); mw.Run(); }
public static async Task Main() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddEnvironmentVariables(); var config = new ConfigWrapper(builder.Build()); // Injection mocking var _storage = new AzureStorage(null, new AzureBlobFactory(config.StorageConnectionString)); var _mediaServiceFactory = new AzureMediaServiceFactory(config); var _mediaService = new AzureMediaService(config, _storage, await _mediaServiceFactory.GetAzureMediaServicesClientAsync()); // Example specific code var fileGuid = Guid.NewGuid().ToString("N").ToLower(); string newFileName; var contentDisposition = $"filename=\"{HttpUtility.UrlEncode(inputMP4FileName)}\""; // Set filename of downloaded file to original name var fileExtension = Path.GetExtension(inputMP4FileName.ToLower()); var buffer = new FileStream(inputMP4FileName, FileMode.Open); var contentId = 0; try { var originalBackupFileName = $"{fileGuid}_original{fileExtension}"; newFileName = $"{fileGuid}{_mediaServiceFactory.GetEncodedFileExtension()}"; var originalBlob = _storage.GetContentContainer(contentId).GetContentBlob(originalBackupFileName); await originalBlob.UploadFromStreamAsync(buffer); var encodedBlob = _storage.GetContentContainer(contentId).GetContentBlob(newFileName); await encodedBlob.UploadTextAsync(""); // Create empty blob var job = await _mediaService.CreateEncodeJobAsync(originalBlob, encodedBlob.GetName(), contentId, CancellationToken.None); var message = new CompleteMediaEncodingQueueMessageDto { JobName = job.Name, ContentId = contentId, NewFileName = newFileName }; var blob = _storage.GetContentContainer(contentId).GetContentBlob(newFileName); await blob.SetContentDispositionAsync(contentDisposition); var fileUri = blob.GetReadSharedAccessUrl("1.1.1.1"); Console.WriteLine($"Uploaded original at {fileUri}"); // External API call: bool exit = false; bool startedCopying = false; do { var progress = await _mediaService.GetEncodeProgressAsync(message.JobName, encodedBlob); Console.WriteLine($"Status {progress.Status}, progress {progress.ProgressPercentage}%"); // Azure Function call: if (progress.Status == EncodeStatus.Copying && startedCopying == false) { await _mediaService.FinishEncodeJobAsync(message.JobName, message.ContentId, message.NewFileName, CancellationToken.None); } if (progress.Status == EncodeStatus.Finished || progress.Status == EncodeStatus.Error || progress.Status == EncodeStatus.NotFound) { exit = true; } Thread.Sleep(SleepInterval); }while (!exit); } catch (ApiErrorException ex) { string code = ex.Body.Error.Code; string message = ex.Body.Error.Message; Console.WriteLine("ERROR:API call failed with error code: {0} and message: {1}", code, message); } catch (Exception exception) { if (exception.Source.Contains("ActiveDirectory")) { Console.Error.WriteLine("TIP: Make sure that you have filled out the appsettings.json file before running this sample."); } Console.Error.WriteLine($"{exception.Message}"); ApiErrorException apiException = exception.GetBaseException() as ApiErrorException; if (apiException != null) { Console.Error.WriteLine( $"ERROR: API call failed with error code '{apiException.Body.Error.Code}' and message '{apiException.Body.Error.Message}'."); } } buffer.Close(); Console.WriteLine("Press Enter to continue."); Console.ReadLine(); }