Пример #1
0
 private IQueryable <JobRecord> GetJobRecordsFor(CloudVideoPart part)
 {
     return
         (from jobRecord in _jobRepository.Table
          where jobRecord.CloudVideoPartId == part.Id
          select jobRecord);
 }
        public void UnpublishAssetsFor(CloudVideoPart part)
        {
            Logger.Debug("UnpublishAssetsFor() invoked for cloud video item with ID {0}.", part.Id);

            var publishedAssetsQuery =
                from asset in LoadAssetsFor(part)
                where asset.PublishState.Status == AssetPublishStatus.Published
                select asset;

            var unpublishTasks = new List <Task>();

            foreach (var asset in publishedAssetsQuery)
            {
                string wamsPublicSasLocatorId      = asset.WamsPublicLocatorId;
                string wamsPublicOnDemandLocatorId = null;
                string wamsManifestFilename        = null;
                if (asset is DynamicVideoAsset)
                {
                    var dynamicVideoAsset = (DynamicVideoAsset)asset;
                    wamsPublicOnDemandLocatorId = dynamicVideoAsset.WamsPublicOnDemandLocatorId;
                    wamsManifestFilename        = dynamicVideoAsset.WamsManifestFilename;
                }

                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));
                }

                var wamsLocators = new WamsLocators(new WamsLocatorInfo(wamsPublicSasLocatorId, null), new WamsLocatorInfo(wamsPublicOnDemandLocatorId, null), wamsManifestFilename);

                unpublishTasks.Add(_wamsClient.DeleteLocatorsAsync(wamsAsset, wamsLocators).ContinueWith((previousTask) => {
                    try {
                        asset.WamsPublicLocatorId  = null;
                        asset.WamsPublicLocatorUrl = null;
                        if (asset is DynamicVideoAsset)
                        {
                            var videoAsset = (DynamicVideoAsset)asset;
                            videoAsset.WamsPublicOnDemandLocatorId  = null;
                            videoAsset.WamsPublicOnDemandLocatorUrl = null;
                        }
                        asset.PublishState.PublishedUtc = null;
                        asset.PublishState.Status       = AssetPublishStatus.None;

                        Logger.Information("Assets with record ID {0} was unpublished.", asset.Record.Id);
                    }
                    catch (Exception ex) {
                        Logger.Error(ex, "Error while unpublishing asset with record ID {0}.", asset.Record.Id);
                        throw;
                    }
                }));
            }

            Task.WaitAll(unpublishTasks.ToArray());

            Logger.Information("Assets were unpublished for cloud video item with ID {0}.", part.Id);
        }
Пример #3
0
        public void CloseJobsFor(CloudVideoPart part)
        {
            var openJobs = GetJobRecordsFor(part).Select(Activate).Where(x => x.IsOpen);

            foreach (var job in openJobs)
            {
                job.Status = JobStatus.Archived;
            }
        }
Пример #4
0
        private void FillAssetRepository(CloudVideoPart videoPart) {
            var asset1 = CreateVideoAssetRecord(videoPart);
            var asset2 = CreateVideoAssetRecord(videoPart);

            asset1.PublishStatus = AssetPublishStatus.None;
            asset1.UploadStatus = AssetUploadStatus.Pending;
            asset2.PublishStatus = AssetPublishStatus.Published;
            asset2.UploadStatus = AssetUploadStatus.Uploading;
        }
        private void FillAssetRepository(CloudVideoPart videoPart)
        {
            var asset1 = CreateVideoAssetRecord(videoPart);
            var asset2 = CreateVideoAssetRecord(videoPart);

            asset1.PublishStatus = AssetPublishStatus.None;
            asset1.UploadStatus  = AssetUploadStatus.Pending;
            asset2.PublishStatus = AssetPublishStatus.Published;
            asset2.UploadStatus  = AssetUploadStatus.Uploading;
        }
Пример #6
0
        public IEnumerable <Job> GetJobsFor(CloudVideoPart part)
        {
            Logger.Debug("GetJobsFor() invoked for cloud video item with ID {0}.", part.Id);

            var jobsQuery =
                from jobRecord in GetJobRecordsFor(part)
                select Activate(jobRecord); // OK to call Activate() inline here because GetJobRecordsFor() contains an inner projection.

            return(jobsQuery.ToArray());
        }
        public void DeleteAssetsFor(CloudVideoPart part)
        {
            Logger.Debug("DeleteAssetsFor() invoked for cloud video item with ID {0}.", part.Id);

            var assetsQuery =
                from asset in LoadAssetsFor(part)
                where asset.PublishState.Status != AssetPublishStatus.Removed
                select asset;

            DeleteAssets(assetsQuery);
        }
Пример #8
0
        private AssetRecord CreateVideoAssetRecord(CloudVideoPart videoPart) {
            var asset = new AssetRecord {
                VideoPartRecord = videoPart.Record,
                PublishStatus = AssetPublishStatus.Published,
                UploadStatus = AssetUploadStatus.Uploading,
                Type = "Video"
            };

            _stubAssetRepository.Create(asset);
            return asset;
        }
        private AssetRecord CreateVideoAssetRecord(CloudVideoPart videoPart)
        {
            var asset = new AssetRecord {
                VideoPartRecord = videoPart.Record,
                PublishStatus   = AssetPublishStatus.Published,
                UploadStatus    = AssetUploadStatus.Uploading,
                Type            = "Video"
            };

            _stubAssetRepository.Create(asset);
            return(asset);
        }
        private ActionResult UpdateImplementation(CloudVideoPart part, string folderPath, LocalizedString notification, bool publish)
        {
            if (!_authorizer.Authorize(Permissions.ManageCloudMediaContent, T("You are not authorized to manage Microsoft Azure Media content.")))
            {
                return(new HttpUnauthorizedResult());
            }

            Logger.Debug("User requested to save cloud video item with ID {0}.", part.Id);

            var editorShape = _contentManager.UpdateEditor(part, this);

            if (!ModelState.IsValid)
            {
                _transactionManager.Cancel();

                var viewModel = New.ViewModel(FolderPath: folderPath, Editor: editorShape);
                return(View(viewModel));
            }

            var mediaPart = part.As <MediaPart>();

            mediaPart.LogicalType = "CloudVideo";

            if (String.IsNullOrWhiteSpace(mediaPart.MimeType))
            {
                var mezzanineAsset = _assetManager.LoadAssetsFor <MezzanineAsset>(part).Single();
                mediaPart.MimeType = mezzanineAsset.MimeType;
            }

            if (!String.IsNullOrWhiteSpace(folderPath))
            {
                mediaPart.FolderPath = folderPath;
            }

            try {
                if (publish)
                {
                    _contentManager.Publish(mediaPart.ContentItem);
                }

                Logger.Information("Cloud video item with ID {0} was saved.", part.Id);
                _notifier.Information(notification);
            }
            catch (Exception ex) {
                _transactionManager.Cancel();

                Logger.Error(ex, "Error while saving cloud video item with ID {0}.", part.Id);
                _notifier.Error(T("Ar error occurred while saving the cloud video item:\n{1}", ex.Message));
            }

            return(RedirectToAction("Edit", new { id = part.Id }));
        }
Пример #11
0
 private void DeferOrPublishAssets(PublishContentContext context, CloudVideoPart part)
 {
     if (part.MezzanineAsset != null && part.MezzanineAsset.UploadState.Status != AssetUploadStatus.Uploaded)
     {
         part.PublishOnUpload = true;
         _notifier.Warning(T("The cloud video item was saved, but will not be published until the primary video asset has finished uploading to Windows Azure Media Services."));
         context.Cancel = true;
     }
     else
     {
         _assetManager.PublishAssetsFor(part);
     }
 }
        public ThumbnailAsset GetThumbnailAssetFor(CloudVideoPart part)
        {
            Logger.Debug("GetThumbnailAssetFor() invoked for cloud video item with ID {0}.", part.Id);

            var thumbnailAssetQuery =
                from asset in part.Assets
                where asset is ThumbnailAsset
                let thumbnailAsset = (ThumbnailAsset)asset
                                     where thumbnailAsset.UploadState.Status == AssetUploadStatus.Uploaded && thumbnailAsset.PublishState.Status != AssetPublishStatus.Removed
                                     select thumbnailAsset;

            return(thumbnailAssetQuery.FirstOrDefault());
        }
Пример #13
0
        public void DeleteJobsFor(CloudVideoPart part)
        {
            Logger.Debug("DeleteJobsFor() invoked for cloud video item with ID {0}.", part.Id);

            var records = GetJobRecordsFor(part);

            foreach (var record in records)
            {
                _jobRepository.Delete(record);
                Logger.Information("Job with record ID {0} was deleted.", record.Id);
            }

            Logger.Information("Jobs were deleted for cloud video item with ID {0}.", part.Id);
        }
        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);
        }
Пример #15
0
        public Job CreateJobFor(CloudVideoPart part, Action <Job> initialize = null)
        {
            Logger.Debug("CreateJobFor() invoked for cloud video item with ID {0}.", part.Id);

            var newJob = Activate(new JobRecord {
                CloudVideoPartId = part.Id
            });

            if (initialize != null)
            {
                initialize(newJob);
            }

            _jobRepository.Create(newJob.Record);
            Logger.Information("New job was created with record ID {0} for cloud video item with ID {1}.", newJob.Record.Id, part.Id);

            return(newJob);
        }
        public Asset CreateAssetFor <T>(CloudVideoPart part, Action <T> initialize = null) where T : Asset, new()
        {
            Logger.Debug("CreateAssetFor() invoked for cloud video item with ID {0}.", part.Id);

            var newAsset = (T)Activate(typeof(T).FullName);

            newAsset.CreatedUtc = _clock.UtcNow;
            newAsset.VideoPart  = part;

            if (initialize != null)
            {
                initialize(newAsset);
            }

            _assetRepository.Create(newAsset.Record);
            Logger.Information("New asset was created with record ID {0} for cloud video item with ID {1}.", newAsset.Record.Id, part.Id);

            return(newAsset);
        }
Пример #17
0
        private IShape CreatePlayershape(CloudVideoPart part, HtmlNode node)
        {
            var playerWidth       = GetInt32(node, "data-player-width");
            var playerHeight      = GetInt32(node, "data-player-height");
            var applyMediaQueries = GetBoolean(node, "data-player-apply-media-queries");
            var autoPlay          = GetBoolean(node, "data-player-auto-play");

            var playerShape = _shapeFactory.Create("CloudVideoPlayer", Arguments.From(new {
                CloudVideoPart        = part,
                AssetId               = default(int?),
                IgnoreIncludeInPlayer = false,
                AllowPrivateUrls      = false,
                PlayerWidth           = playerWidth,
                PlayerHeight          = playerHeight,
                ApplyMediaQueries     = applyMediaQueries,
                AutoPlay              = autoPlay
            }));

            return(playerShape);
        }
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("CloudVideoPlayer").OnDisplaying(context => {
                var shape = context.Shape;
                CloudVideoPart cloudVideoPart = shape.ContentPart;        // The cloud video item to render a player for.
                int?assetId = shape.AssetId;                              // Set to limit the player to only one particular asset.
                bool ignoreIncludeInPlayer = shape.IgnoreIncludeInPlayer; // True to ignore the IncludeInPlayer property of assets.
                bool allowPrivateUrls      = shape.AllowPrivateUrls;      // True to allow private locator URLs to be used, otherwise false.

                Func <string, string, string> selectUrl = (privateUrl, publicUrl) => publicUrl ?? (allowPrivateUrls ? privateUrl : null);

                var videoAssetQuery =
                    from asset in cloudVideoPart.Assets
                    where
                    (asset.IncludeInPlayer || ignoreIncludeInPlayer) &&
                    asset is VideoAsset && !(asset is DynamicVideoAsset) &&
                    (!assetId.HasValue || asset.Record.Id == assetId.Value)
                    let videoAsset = asset as VideoAsset
                                     select new {
                    Type            = videoAsset.GetType().Name,
                    Id              = videoAsset.Record.Id,
                    Name            = videoAsset.Name,
                    MimeType        = videoAsset.MimeType,
                    MediaQuery      = videoAsset.MediaQuery,
                    EncodingPreset  = videoAsset.EncodingPreset,
                    EncoderMetadata = videoAsset.EncoderMetadata,
                    MainFileUrl     = selectUrl(videoAsset.PrivateMainFileUrl, videoAsset.PublicMainFileUrl)
                };

                var dynamicVideoAssetQuery =
                    from asset in cloudVideoPart.Assets
                    where
                    (asset.IncludeInPlayer || ignoreIncludeInPlayer) &&
                    asset is DynamicVideoAsset &&
                    (!assetId.HasValue || asset.Record.Id == assetId.Value)
                    let videoAsset = asset as DynamicVideoAsset
                                     select new {
                    Type               = videoAsset.GetType().Name,
                    Id                 = videoAsset.Record.Id,
                    Name               = videoAsset.Name,
                    MimeType           = videoAsset.MimeType,
                    MediaQuery         = videoAsset.MediaQuery,
                    EncodingPreset     = videoAsset.EncodingPreset,
                    EncoderMetadata    = videoAsset.EncoderMetadata,
                    MainFileUrl        = selectUrl(videoAsset.PrivateMainFileUrl, videoAsset.PublicMainFileUrl),
                    SmoothStreamingUrl = selectUrl(videoAsset.PrivateSmoothStreamingUrl, videoAsset.PublicSmoothStreamingUrl),
                    HlsUrl             = selectUrl(videoAsset.PrivateHlsUrl, videoAsset.PublicHlsUrl),
                    MpegDashUrl        = selectUrl(videoAsset.PrivateMpegDashUrl, videoAsset.PublicMpegDashUrl)
                };

                var thumbnailAssetQuery =
                    from asset in cloudVideoPart.Assets
                    where
                    (asset.IncludeInPlayer || ignoreIncludeInPlayer) &&
                    asset is ThumbnailAsset &&
                    (!assetId.HasValue || asset.Record.Id == assetId.Value)
                    let thumbnailAsset = asset as ThumbnailAsset
                                         select new {
                    Type        = thumbnailAsset.GetType().Name,
                    Id          = thumbnailAsset.Record.Id,
                    Name        = thumbnailAsset.Name,
                    MimeType    = thumbnailAsset.MimeType,
                    MediaQuery  = thumbnailAsset.MediaQuery,
                    MainFileUrl = selectUrl(thumbnailAsset.PrivateMainFileUrl, thumbnailAsset.PublicMainFileUrl)
                };

                var subtitleAssetQuery =
                    from asset in cloudVideoPart.Assets
                    where
                    (asset.IncludeInPlayer || ignoreIncludeInPlayer) &&
                    asset is SubtitleAsset &&
                    (!assetId.HasValue || asset.Record.Id == assetId.Value)
                    let subtitleAsset = asset as SubtitleAsset
                                        select new {
                    Type        = subtitleAsset.GetType().Name,
                    Id          = subtitleAsset.Record.Id,
                    Name        = subtitleAsset.Name,
                    MimeType    = subtitleAsset.MimeType,
                    MediaQuery  = subtitleAsset.MediaQuery,
                    Language    = subtitleAsset.Language,
                    MainFileUrl = selectUrl(subtitleAsset.PrivateMainFileUrl, subtitleAsset.PublicMainFileUrl)
                };

                var assetData = new {
                    VideoAssets        = videoAssetQuery.ToArray(),
                    DynamicVideoAssets = dynamicVideoAssetQuery.ToArray(),
                    ThumbnailAssets    = thumbnailAssetQuery.ToArray(),
                    SubtitleAssets     = subtitleAssetQuery.ToArray()
                };

                shape.AssetData = assetData;
            });
        }
Пример #19
0
 private void SetupFields(ActivatedContentContext context, CloudVideoPart part)
 {
     part._assetManager = _assetManager;
     part._jobManager   = _jobManager;
 }
Пример #20
0
 private void CancelAndUnpublishAssets(PublishContentContext context, CloudVideoPart part)
 {
     part.PublishOnUpload = false;
     _assetManager.UnpublishAssetsFor(part);
 }
Пример #21
0
 private void RemoveAssets(RemoveContentContext context, CloudVideoPart part)
 {
     _assetManager.DeleteAssetsFor(part);
     _jobManager.CloseJobsFor(part);
 }
        public IEnumerable <T> LoadAssetsFor <T>(CloudVideoPart part) where T : Asset
        {
            Logger.Debug("LoadAssetsFor<{0}>() invoked for cloud video item with ID {1}.", typeof(T).Name, part.Id);

            return(LoadAssetRecordsFor(part).Select(Activate).Where(x => x is T).Cast <T>());
        }
        public IEnumerable <Asset> LoadAssetsFor(CloudVideoPart part)
        {
            Logger.Debug("LoadAssetsFor() invoked for cloud video item with ID {0}.", part.Id);

            return(LoadAssetRecordsFor(part).Select(Activate));
        }
 private IEnumerable <AssetRecord> LoadAssetRecordsFor(CloudVideoPart part)
 {
     return(_assetRepository.Fetch(x => x.VideoContentItemId == part.Id && x.PublishStatus != AssetPublishStatus.Removed));
 }