示例#1
0
        /// <inheritdoc/>
        public async Task <ProcessResultModel> ProcessAsync(ProcessPathCommand command, CancellationToken ct)
        {
            if (string.IsNullOrWhiteSpace(command.SourcePath))
            {
                throw new UnexpectedNullException("Empty source path.");
            }

            if (string.IsNullOrWhiteSpace(command.DestinationPath))
            {
                throw new UnexpectedNullException("Empty destination path.");
            }

            var sourceFs    = fileSystemStrategy.Create(command.SourcePath);
            var destFs      = fileSystemStrategy.Create(command.DestinationPath);
            var watermarkFs = fileSystemStrategy.Create(command.WatermarkSourcePath);

            var commandClone = command.DeepClone();

            commandClone.SourcePath          = sourceFs.BuildAbsolutePath(command.SourcePath);
            commandClone.DestinationPath     = destFs.BuildAbsolutePath(command.DestinationPath);
            commandClone.WatermarkSourcePath = watermarkFs.BuildAbsolutePath(command.WatermarkSourcePath);

            // Creates all directories and subdirectories in the specified path unless they already exist.
            destFs.Directory.CreateDirectory(commandClone.DestinationPath);

            // TODO: support zip files
            var result = await imageExtractor.ProcessAsync(commandClone, ct);

            // Set GIFs
            result.Gifs = await gifImageWriter.WriteAsync(
                command.DestinationPath, result.Images, command.BezierEasingTypePerAxis, ct);

            result.CombinedGif = await gifImageWriter.WriteAsync(
                command.DestinationPath, result.Images, "combined", command.BezierEasingTypeCombined, ct);

            // Set application version
            var appInfo = appInfoFactory.Create();

            result.Version = appInfo.AppVersion;

            // Write JSON and set filename
            await jsonWriter.WriteAsync(commandClone.DestinationPath, "output", result, (filename) => { result.JsonFilename = filename; });

            return(result);
        }
        /// <inheritdoc/>
        public async Task <ProcessResultModel> ProcessAsync(ProcessPathCommand command, CancellationToken ct)
        {
            Ensure.ArgumentNotNull(command, nameof(command));
            Ensure.ArgumentNotNull(ct, nameof(ct));

            if (string.IsNullOrWhiteSpace(command.SourcePath))
            {
                throw new UnexpectedNullException("Empty source path.");
            }

            if (string.IsNullOrWhiteSpace(command.DestinationPath))
            {
                throw new UnexpectedNullException("Empty destination path.");
            }

            var sourceFs    = fileSystemStrategy.Create(command.SourcePath);
            var destFs      = fileSystemStrategy.Create(command.DestinationPath);
            var watermarkFs = fileSystemStrategy.Create(command.WatermarkSourcePath);

            var commandClone = command.DeepClone();

            commandClone.SourcePath          = sourceFs.BuildAbsolutePath(command.SourcePath);
            commandClone.DestinationPath     = destFs.BuildAbsolutePath(command.DestinationPath);
            commandClone.WatermarkSourcePath = watermarkFs.BuildAbsolutePath(command.WatermarkSourcePath);

            // Creates all directories and subdirectories in the specified path unless they already exist.
            destFs.Directory.CreateDirectory(commandClone.DestinationPath);

            // SourcePath can be a directory, archive or file
            if (archiveReader.IsArchive(commandClone.SourcePath))
            {
                var extractedPath = destFs.Path.Combine(commandClone.DestinationPath, "Extracted");
                destFs.Directory.CreateDirectory(extractedPath);
                await archiveExtractor.ExtractAsync(commandClone.SourcePath, extractedPath, ct);

                // Use the extracted directory as source path
                commandClone.SourcePath = extractedPath;
            }

            var result = await imageExtractor.ProcessAsync(commandClone, ct);

            if (result == null)
            {
                throw new UnexpectedNullException("The images could not be processed.");
            }

            // Set GIFs
            result.Gifs = await gifImageWriter.WriteAsync(
                commandClone.DestinationPath, result.Images, commandClone.Delay, commandClone.BezierEasingTypePerAxis, ct);

            result.CombinedGif = await gifImageWriter.WriteAsync(
                commandClone.DestinationPath, result.Images, "combined", commandClone.Delay, commandClone.BezierEasingTypeCombined, ct);

            // Set application version
            var appInfo = appInfoFactory.Create();

            result.Version = appInfo.AppVersion;

            // Write JSON and set filename
            await jsonWriter.WriteAsync(commandClone.DestinationPath, "output", result, (filename) => { result.JsonFilename = filename; });

            return(result);
        }