public async Task <ActionResult> DeleteWamsAsset(string id) { var asset = _wamsClient.GetAssetById(id); await _wamsClient.DeleteAssetAsync(asset).ConfigureAwait(continueOnCapturedContext: false); return(new EmptyResult()); }
public void PublishAssetsFor(CloudVideoPart part) { Logger.Debug("PublishAssetsFor() invoked for cloud video item with ID {0}.", part.Id); var unpublishedAssetsQuery = from asset in LoadAssetsFor(part) where asset.PublishState.Status == AssetPublishStatus.None && asset.UploadState.Status == AssetUploadStatus.Uploaded select asset; var publishTasks = new List <Task>(); foreach (var asset in unpublishedAssetsQuery) { var wamsAsset = _wamsClient.GetAssetById(asset.WamsAssetId); if (wamsAsset == null) { throw new ApplicationException(String.Format("The asset record with ID {0} refers to a WAMS asset with ID '{1}' but no asset with that ID exists in the configured WAMS instance.", asset.Record.Id, asset.WamsAssetId)); } publishTasks.Add(_wamsClient.CreateLocatorsAsync(wamsAsset, WamsLocatorCategory.Public).ContinueWith((previousTask) => { try { var wamsLocators = previousTask.Result; asset.WamsPublicLocatorId = wamsLocators.SasLocator.Id; asset.WamsPublicLocatorUrl = wamsLocators.SasLocator.Url; if (wamsLocators.OnDemandLocator != null && asset is DynamicVideoAsset) { var videoAsset = (DynamicVideoAsset)asset; videoAsset.WamsPublicOnDemandLocatorId = wamsLocators.OnDemandLocator.Id; videoAsset.WamsPublicOnDemandLocatorUrl = wamsLocators.OnDemandLocator.Url; } asset.PublishState.PublishedUtc = _clock.UtcNow; asset.PublishState.Status = AssetPublishStatus.Published; Logger.Information("Assets with record ID {0} was published.", asset.Record.Id); } catch (Exception ex) { Logger.Error(ex, "Error while publishing asset with record ID {0}.", asset.Record.Id); throw; } })); } Task.WaitAll(publishTasks.ToArray()); Logger.Information("Assets were published for cloud video item with ID {0}.", part.Id); }
public void CreatePrivateLocatorFor(Asset asset) { var wamsAsset = _wamsClient.GetAssetById(asset.WamsAssetId); var wamsLocators = _wamsClient.CreateLocatorsAsync(wamsAsset, WamsLocatorCategory.Private).Result; asset.WamsPrivateLocatorId = wamsLocators.SasLocator.Id; asset.WamsPrivateLocatorUrl = wamsLocators.SasLocator.Url; }
public ActionResult Create(int id, string task, JobViewModel jobViewModel) { if (!_authorizer.Authorize(Permissions.ManageCloudMediaJobs, T("You are not authorized to manage cloud jobs."))) { return(new HttpUnauthorizedResult()); } Logger.Debug("User requested to create job with task of type {0} on cloud video item with ID {1}.", task, id); var cloudVideoPart = _contentManager.Get <CloudVideoPart>(id, VersionOptions.Latest); if (cloudVideoPart == null) { Logger.Warning("User requested to create job on cloud video item with ID {0} but no such cloud video item exists.", id); return(HttpNotFound(String.Format("No cloud video item with ID {0} was found.", id))); } var taskProvider = _taskProviders.Single(x => x.Name == task); var inputAsset = cloudVideoPart.Assets.Single(x => x.Record.Id == jobViewModel.SelectedInputAssetId); var videoName = _contentManager.GetItemMetadata(cloudVideoPart).DisplayText; var taskConfig = (TaskConfiguration)taskProvider.Editor(New, this); var taskConnections = taskProvider.GetConnections(taskConfig); var taskDisplayText = taskProvider.GetDisplayText(taskConfig); var jobName = !String.IsNullOrWhiteSpace(jobViewModel.Name) ? jobViewModel.Name.TrimSafe() : !String.IsNullOrWhiteSpace(taskDisplayText) ? taskDisplayText : String.Format("{0} ({1})", videoName, taskProvider.Name); var jobDescription = jobViewModel.Description.TrimSafe(); if (ModelState.IsValid) { try { var wamsJob = _wamsClient.CreateNewJob(jobName); var wamsInputAsset = _wamsClient.GetAssetById(inputAsset.WamsAssetId); var wamsTask = taskProvider.CreateTask(taskConfig, wamsJob.Tasks, new[] { wamsInputAsset }); wamsJob.Submit(); // Needs to be done here for job and tasks to get their WAMS ID values. var job = _jobManager.CreateJobFor(cloudVideoPart, j => { j.WamsJobId = wamsJob.Id; j.Name = jobName; j.Description = jobDescription; j.Status = JobStatus.Pending; j.CreatedUtc = _clock.UtcNow; j.OutputAssetName = jobViewModel.OutputAssetName.TrimSafe(); j.OutputAssetDescription = jobViewModel.OutputAssetDescription.TrimSafe(); }); _jobManager.CreateTaskFor(job, t => { t.HarvestAssetType = taskConnections.Outputs.First().AssetType; t.HarvestAssetName = taskConnections.Outputs.First().AssetName; t.Settings = taskProvider.Serialize(taskConfig.Settings); t.Index = 0; t.TaskProviderName = taskProvider.Name; t.WamsTaskId = wamsTask.Id; }); Logger.Information("Job was created with task of type {0} on cloud video item with ID {1}.", task, id); _notifier.Success(T("The job '{0}' was successfully created.", job.Name)); return(Redirect(Url.ItemEditUrl(cloudVideoPart))); } catch (Exception ex) { _transactionManager.Cancel(); Logger.Error(ex, "Error while creating job with task of type {0} on cloud video item with ID {1}.", task, id); _notifier.Error(T("Ar error occurred while creating the job:\n{0}", ex.Message)); } } return(View(jobViewModel)); }