Ejemplo n.º 1
0
        async void RunCommand(FolderIconCommand command)
        {
            if (!MayRunCommand)
            {
                ReportError("Cannot start new job - one is already in progress");
                return;
            }
            Updates = 0;
            Roots.RefreshLabelsRegex();
            Elapsed = System.Diagnostics.Stopwatch.StartNew();
            ClearStatus();
            var arguments = new FolderIconCommandArguments(command,
                                                           SelectedDirectory?.FullPath, Settings);

            ReportStart(0, $"Loading Subdirectories of {arguments.Directory.FullName}", true);
            if (arguments.Recursive)
            {
                arguments.Directories = await Task.Run(() => arguments.Directories
                                                       .Concat(
                                                           arguments
                                                           .Directory
                                                           .EnumerateDirectories(EnumerationOptions.Recursive.Directories)
                                                           )
                                                       .OrderBy(x => x.FullName.ToLowerInvariant())
                                                       .ToArray()).ConfigureAwait(true);

                InfoReporter.ReportTiming($"Loaded {arguments.Directories.Length} Subdirectories of {arguments.Directory.FullName} in {Stopwatch.Elapsed.FormatFriendly()}");
                ReportStart(arguments.Directories.Length, "Loaded All Directories", true);
            }

            if (Toggles.Async)
            {
                bgwCommand.RunWorkerAsync(arguments);
                OnPropertyChanged(nameof(MayRunCommand));
            }
            else
            {
                MayRunCommand = false;
                bgwCommand_DoWork(arguments);
                bgwCommand_RunWorkerCompleted();
                MayRunCommand = true;
            }
        }