示例#1
0
        public BroadcastResult Handle(VideoConvertedCommand command)
        {
            var media = _mediaService.GetById(command.MediaId);

            media.SetValue(UmbracoAliases.Video.ConvertInProcessPropertyAlias, false);

            if (!command.Success)
            {
                _videoConverterLogService.Log(false, command.Message.ToJson(), command.MediaId);

                media.SetValue(UmbracoAliases.Video.ThumbnailUrlPropertyAlias, _videoHelper.CreateConvertingFailureThumbnail());
                _mediaService.Save(media);

                return(BroadcastResult.Failure);
            }

            using (var fs = new FileStream(command.ConvertedFilePath, FileMode.Open, FileAccess.Read))
            {
                using (var ms = new MemoryStream())
                {
                    fs.CopyTo(ms);
                    media.SetValue(UmbracoFilePropertyAlias, Path.GetFileName(command.ConvertedFilePath), ms);
                }
            }

            File.Delete(command.ConvertedFilePath);

            SaveVideoAdditionProperties(media);

            _mediaService.Save(media);

            _videoConverterLogService.Log(true, "Converted succesfully", command.MediaId);

            return(BroadcastResult.Success);
        }
示例#2
0
        private BroadcastResult OnCreateSuccess(
            VideoConvertedCommand command,
            IMedia media,
            IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
            IMediaService mediaService
            )
        {
            var name = $"{Path.GetFileNameWithoutExtension(media.Name)}.mp4";

            using (var fileStream = new FileStream(command.ConvertedFilePath, FileMode.Open, FileAccess.Read))
                using (var memoryStream = new MemoryStream())
                {
                    fileStream.CopyTo(memoryStream);

                    media.SetValue(contentTypeBaseServiceProvider, UmbracoAliases.Media.UmbracoFilePropertyAlias, name, memoryStream);
                }

            File.Delete(command.ConvertedFilePath);
            SaveVideoAdditionProperties(media);
            media.Name = name;
            mediaService.Save(media);
            _videoConverterLogService.Log(true, "Converted successfully", command.MediaId);

            return(BroadcastResult.Success);
        }