示例#1
0
 private static void SetHandlersIfNecessary(ProcessRunner ufrawRunner, UfrawOutputHandlers handlers)
 {
     if (handlers != null && handlers.AnyHandlerSet)
     {
         ufrawRunner.OutputChanged         += handlers.OutputChangedHandler;
         ufrawRunner.ErrorChanged          += handlers.ErrorChangedHandler;
         ufrawRunner.CombinedOutputChanged += handlers.CombinedOutputChangedHandler;
     }
 }
示例#2
0
        private async Task <RunResults> StartConversion(string[] outputArguments, UfrawOutputHandlers handlers)
        {
            var messageFormatter = GetMessageFormatter(handlers);

            using (var ufrawRunner = new ProcessRunner(ufrawBatchExeLocation.Value, outputArguments, false, messageFormatter))
            {
                SetHandlersIfNecessary(ufrawRunner, handlers);
                ufrawProcessRunner = ufrawRunner;
                var runResults = await ufrawRunner.StartAsync();

                return(runResults);
            }
        }
示例#3
0
        /// <summary>
        /// Converts all non-converted files in directory to the selected format asynchronously.
        /// </summary>
        /// <param name="directory">Directory to be processed.</param>
        /// <param name="imageFormat">Chosen image format.</param>
        /// <param name="maxThreads">Max amount of running parallel instances, <see cref="Environment.ProcessorCount"/> will be selected if null.</param>
        /// <param name="handlers">Handlers of the ufraw-batch console output.</param>
        /// <returns>Output of all ufraw-batch instances.</returns>
        /// <exception cref="ArgumentException">Wrong image format or directory does not exist.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Max threads is negative or zero.</exception>
        /// <exception cref="InvalidOperationException">Conversion is already in progress.</exception>
        public async Task <string> ConvertAsync(string directory, ImageFormat imageFormat, int?maxThreads = null, UfrawOutputHandlers handlers = null)
        {
            CheckCommonPrerequisites(imageFormat, ref maxThreads);

            if (!Directory.Exists(directory))
            {
                throw new ArgumentException(nameof(directory));
            }

            string outTypeParameter = imageFormatExtensions[imageFormat];

            string[] filteredFilenames = FileFilter.GetFilenamesToConvert(directory, outTypeParameter);

            var runResults = await ConvertInner(filteredFilenames, outTypeParameter, maxThreads.Value, handlers);

            return(runResults.CombinedOutput);
        }
示例#4
0
 /// <summary>
 /// Converts all non-converted files in directory to the selected format.
 /// </summary>
 /// <param name="filenamesToConvert">Filenames of files to be converted.</param>
 /// <param name="imageFormat">Chosen image format.</param>
 /// <param name="maxThreads">Max amount of running parallel instances, <see cref="Environment.ProcessorCount"/> will be selected if null.</param>
 /// <param name="handlers">Handlers of the ufraw-batch console output.</param>
 /// <returns>Output of all ufraw-batch instances.</returns>
 /// <exception cref="ArgumentException">Wrong image format.</exception>
 /// <exception cref="ArgumentNullException">Filenames array is null.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Max threads is negative or zero.</exception>
 /// <exception cref="InvalidOperationException">Conversion is already in progress.</exception>
 public string Convert(string[] filenamesToConvert, ImageFormat imageFormat, int?maxThreads = null, UfrawOutputHandlers handlers = null) =>
 Convert(filenamesToConvert, imageFormat, maxThreads, handlers);
示例#5
0
 /// <summary>
 /// Converts all non-converted files in directory to the selected format.
 /// </summary>
 /// <param name="directory">Directory to be processed.</param>
 /// <param name="imageFormat">Chosen image format.</param>
 /// <param name="maxThreads">Max amount of running parallel instances, <see cref="Environment.ProcessorCount"/> will be selected if null.</param>
 /// <param name="handlers">Handlers of the ufraw-batch console output.</param>
 /// <returns>Output of all ufraw-batch instances.</returns>
 /// <exception cref="ArgumentException">Wrong image format or directory does not exist.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Max threads is negative or zero.</exception>
 /// <exception cref="InvalidOperationException">Conversion is already in progress.</exception>
 public string Convert(string directory, ImageFormat imageFormat, int?maxThreads = null, UfrawOutputHandlers handlers = null) =>
 ConvertAsync(directory, imageFormat, maxThreads, handlers).Result;
示例#6
0
 private static IMessageFormatter GetMessageFormatter(UfrawOutputHandlers handlers) =>
 handlers != null && handlers.AnyHandlerSet ? MessageFormatter.LastLine : MessageFormatter.NoMessages;
示例#7
0
 private Task <RunResults> ConvertInner(string[] filteredFilenames, string outTypeParameter, int maxThreads, UfrawOutputHandlers handlers)
 {
     string[] arguments = PrepareArguments(filteredFilenames, outTypeParameter, maxThreads);
     return(StartConversion(arguments, handlers));
 }