Exemplo n.º 1
0
        public void Setup()
        {
            _ffmpegFileName    = "/usr/sbin/ffmpeg";
            _processRunner     = Substitute.For <IProcessRunner>();
            _argumentGenerator = Substitute.For <IFFmpegArgumentGenerator>();
            _configManager     = Substitute.For <IConfigManager <FFmpegConfig> >();
            _fileSystem        = Substitute.For <IFileSystem>();
            _fileService       = Substitute.For <IFile>();
            _pathService       = Substitute.For <IPath>();
            _imageCount        = 3;
            _timeout           = TimeSpan.FromMilliseconds(10);
            _imageGenerator    = new PreviewImageGenerator(_ffmpegFileName,
                                                           _processRunner,
                                                           _configManager,
                                                           _argumentGenerator,
                                                           _fileSystem,
                                                           _imageCount,
                                                           _timeout);
            _tempPath     = "/Users/fred/temp";
            _transcodeJob = new TranscodeJob()
            {
                SourceInfo = new MediaInfo()
                {
                    FileName = "source",
                    Duration = TimeSpan.FromHours(1),
                    Streams  = new StreamInfo[]
                    {
                        new VideoStreamInfo()
                        {
                            Index = 0
                        }
                    }
                },
                OutputFileName = "destination",
                Streams        = new OutputStream[]
                {
                    new VideoOutputStream()
                    {
                        SourceStreamIndex = 0
                    }
                }
            };
            _ffmpegJobs = new List <FFmpegJob>();

            _argumentGenerator.When(x => x.GenerateArguments(Arg.Any <FFmpegJob>()))
            .Do(x => _ffmpegJobs.Add(x[0] as FFmpegJob));
            _fileSystem.File.Returns(_fileService);
            _fileSystem.Path.Returns(_pathService);
            _pathService.GetTempPath().Returns(_tempPath);
            _pathService.Combine(Arg.Any <string>(), Arg.Any <string>()).Returns(x => string.Join('/', x.Args()));
        }
Exemplo n.º 2
0
        public override string[] GetSupportedTaskNames()
        {
            if (_supportedTaskNames == null)
            {
                // Collect custom task names from the generator implementations (e.g. name of
                // a dedicated task for generating preview images for 3ds files)
                var supportedTaskNames = PreviewImageGenerator.GetSupportedCustomTaskNames().ToList();

                // extend the list with the default task name
                supportedTaskNames.Add(DefaultPreviewGeneratorTaskName);
                supportedTaskNames.Sort();

                _supportedTaskNames = supportedTaskNames.Distinct().ToArray();
            }

            return(_supportedTaskNames);
        }
        private void ButtonPreviewPdf_Click(object sender, RoutedEventArgs e)
        {
            Subject selectedSubject = (Subject)listBoxSubjects.SelectedItem;

            if (selectedSubject == null)
            {
                return;
            }

            PreviewImageGenerator previewGenerator = new PreviewImageGenerator();

            previewGenerator.HtmlProvider = new HtmlProvider(selectedSubject);
            byte[] imageBytes = previewGenerator.ConvertHtmlToImage();

            PreviewWindow window = new PreviewWindow();

            window.PreviewKeyDown += (sender, e) =>
            {
                if (e.Key == Key.Escape)
                {
                    window.Close();
                }
            };
            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;

            BitmapSource bitmapSource = (BitmapSource) new ImageSourceConverter().ConvertFrom(imageBytes);

            window.previewScroll.Content = new Image
            {
                Source = bitmapSource
            };

            window.Height = bitmapSource.Height;
            window.Width  = bitmapSource.Width;
            window.ShowDialog();
        }
Exemplo n.º 4
0
 public override bool IsContentSupported(STORAGE.Node content)
 {
     return(PreviewImageGenerator.IsSupportedExtension(ContentNamingProvider.GetFileExtension(content.Name)));
 }
Exemplo n.º 5
0
        public override string GetPreviewGeneratorTaskTitle(string contentPath)
        {
            var ext = Path.GetExtension(STORAGE.RepositoryPath.GetFileName(contentPath));

            return(PreviewImageGenerator.GetTaskTitleByFileNameExtension(ext) ?? DefaultPreviewGeneratorTaskTitle);
        }
Exemplo n.º 6
0
        // ================================================================================================== Preview generation

        private static async Task GenerateImagesAsync(CancellationToken cancellationToken)
        {
            int    previewsFolderId;
            string contentPath;
            var    downloadingSubtask = new SnSubtask("Downloading", "Downloading file and other information");

            downloadingSubtask.Start();

            try
            {
                var fileInfo = await GetFileInfoAsync().ConfigureAwait(false);

                if (fileInfo == null)
                {
                    Logger.WriteWarning(ContentId, 0, "Content not found.");
                    downloadingSubtask.Finish();
                    return;
                }

                cancellationToken.ThrowIfCancellationRequested();

                previewsFolderId = await GetPreviewsFolderIdAsync();

                if (previewsFolderId < 1)
                {
                    Logger.WriteWarning(ContentId, 0, "Previews folder not found, maybe the content is missing.");
                    downloadingSubtask.Finish();
                    return;
                }

                downloadingSubtask.Progress(10, 100, 2, 110, "File info downloaded.");

                cancellationToken.ThrowIfCancellationRequested();

                contentPath = fileInfo.Path;

                if (Config.ImageGeneration.CheckLicense)
                {
                    CheckLicense(contentPath.Substring(contentPath.LastIndexOf('/') + 1));
                }
            }
            catch (Exception ex)
            {
                Logger.WriteError(ContentId, message: "Error during initialization. The process will exit without generating images.", ex: ex, startIndex: StartIndex, version: Version);
                return;
            }

            #region For tests
            //if (contentPath.EndsWith("freeze.txt", StringComparison.OrdinalIgnoreCase))
            //    Freeze();
            //if (contentPath.EndsWith("overflow.txt", StringComparison.OrdinalIgnoreCase))
            //    Overflow();
            #endregion

            await using var docStream = await GetBinaryAsync();

            if (docStream == null)
            {
                Logger.WriteWarning(ContentId, 0, $"Document not found; maybe the content or its version {Version} is missing.");
                downloadingSubtask.Finish();
                return;
            }

            downloadingSubtask.Progress(100, 100, 10, 110, "File downloaded.");

            cancellationToken.ThrowIfCancellationRequested();

            if (docStream.Length == 0)
            {
                await SetPreviewStatusAsync(0); // PreviewStatus.EmptyDocument

                downloadingSubtask.Finish();
                return;
            }
            downloadingSubtask.Finish();

            _generatingPreviewSubtask = new SnSubtask("Generating images");
            _generatingPreviewSubtask.Start();

            var extension = contentPath.Substring(contentPath.LastIndexOf('.'));

            await PreviewImageGenerator.GeneratePreviewAsync(extension, docStream, new PreviewGenerationContext(
                                                                 ContentId, previewsFolderId, StartIndex, MaxPreviewCount,
                                                                 Config.ImageGeneration.PreviewResolution, Version), cancellationToken).ConfigureAwait(false);

            _generatingPreviewSubtask.Finish();
        }
Exemplo n.º 7
0
        // ================================================================================================== Preview generation

        protected static void GenerateImages()
        {
            int    previewsFolderId;
            string contentPath;
            var    downloadingSubtask = new SnSubtask("Downloading", "Downloading file and other information");

            downloadingSubtask.Start();

            try
            {
                previewsFolderId = GetPreviewsFolderId();

                if (previewsFolderId < 1)
                {
                    Logger.WriteWarning(ContentId, 0, "Previews folder not found, maybe the content is missing.");
                    downloadingSubtask.Finish();
                    return;
                }

                var fileInfo = GetFileInfo();

                if (fileInfo == null)
                {
                    Logger.WriteWarning(ContentId, 0, "Content not found.");
                    downloadingSubtask.Finish();
                    return;
                }

                downloadingSubtask.Progress(10, 100, 2, 110, "File info downloaded.");

                contentPath = fileInfo["Path"].Value <string>();

                CheckLicense(contentPath.Substring(contentPath.LastIndexOf('/') + 1));
            }
            catch (Exception ex)
            {
                Logger.WriteError(ContentId, message: "Error during initialization. The process will exit without generating images.", ex: ex, startIndex: StartIndex, version: Version);
                return;
            }

//if (contentPath.EndsWith("freeze.txt", StringComparison.OrdinalIgnoreCase))
//    Freeze();
//if (contentPath.EndsWith("overflow.txt", StringComparison.OrdinalIgnoreCase))
//    Overflow();

            using (var docStream = GetBinary())
            {
                if (docStream == null)
                {
                    Logger.WriteWarning(ContentId, 0, string.Format("Document not found; maybe the content or its version {0} is missing.", Version));
                    downloadingSubtask.Finish();
                    return;
                }

                downloadingSubtask.Progress(100, 100, 10, 110, "File downloaded.");

                if (docStream.Length == 0)
                {
                    SetPreviewStatus(0); // PreviewStatus.EmptyDocument
                    downloadingSubtask.Finish();
                    return;
                }
                downloadingSubtask.Finish();

                _generatingPreviewSubtask = new SnSubtask("Generating images");
                _generatingPreviewSubtask.Start();

                var extension = contentPath.Substring(contentPath.LastIndexOf('.'));
                PreviewImageGenerator.GeneratePreview(extension, docStream, new PreviewGenerationContext(
                                                          ContentId, previewsFolderId, StartIndex, MaxPreviewCount, Configuration.PreviewResolution, Version));

                _generatingPreviewSubtask.Finish();
            }
        }