public void Start(ChoConsoleProgressorStart consoleProgressorStart, ChoAsyncCallback callback, object state, int timeout)
        {
            ChoGuard.NotDisposed(this);

            int isStarted = Interlocked.CompareExchange(ref _isStarted, 1, 0);

            if (isStarted == 1)
            {
                return;
            }

            Interlocked.CompareExchange(ref _stopRequested, 0, 1);

            lock (ChoConsole.SyncRoot)
            {
                ChoConsole.Clear();
                ChoConsole.ClearKeys();

                IChoAsyncResult result = ChoConsole.OutputQueuedExecutionService.Enqueue(() =>
                {
                    _location          = WriteNSavePosition(_msg + " ");
                    _statusMsgLocation = new ChoPoint(_consolePercentageProgressorSettings.ProgressBarMarginX, _location.Y + 1);
                    WriteSpinner("/");
                });
                result.AsyncWaitHandle.WaitOne();
            }

            Action <ChoConsoleSpinProgressor> wrappedFunc = delegate
            {
                _threadToKill = Thread.CurrentThread;

                try
                {
                    while (true)
                    {
                        if (_stopRequested == 1)
                        {
                            break;
                        }

                        ChoConsole.WriteLine(GetNextSpinChar().ToString(), _location, _foregroundColor, _backgroundColor);
                        bool retValue = consoleProgressorStart(this, state);
                        if (!retValue)
                        {
                            break;
                        }
                    }
                }
                catch (ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
            };

            _result = ChoAbortableQueuedExecutionService.Global.Enqueue <ChoConsoleSpinProgressor>(wrappedFunc, this);
        }
        private bool SetPercentageComplete(int percentage)
        {
            if (percentage < MinPercentage)
            {
                throw new ChoConsoleException(String.Format("Percentage must be >= {0}", MinPercentage));
            }
            if (percentage > MaxPercentage)
            {
                throw new ChoConsoleException(String.Format("Percentage must be <= {0}", MaxPercentage));
            }

            ChoConsole.WriteLine(String.Format("[{0}%]", percentage).PadRight(_padLength + 3), _location, _foregroundColor, _backgroundColor);

            return(percentage < MaxPercentage);
        }
        private void PrintHeader()
        {
            string applicationName = ApplicationName;

            if (applicationName.IsNullOrWhiteSpace())
            {
                applicationName = ChoGlobalApplicationSettings.Me.ApplicationName;
            }

            string version = ChoAssembly.GetEntryAssembly().GetName().Version.ToString();

            ChoConsole.WriteLine("{0} [Version {1}]".FormatString(applicationName, version));

            if (!Copyright.IsNullOrWhiteSpace())
            {
                ChoConsole.WriteLine(Copyright);
            }

            ChoConsole.WriteLine();
        }
        public void StartFileCopy(string sourceDirectory = null, string destDirectory = null)
        {
            try
            {
                ChoAppSettings appSettings = new ChoAppSettings();
                if (!SettingsFilePath.IsNullOrWhiteSpace())
                {
                    if (!File.Exists(SettingsFilePath))
                    {
                        throw new ArgumentException("Can't find '{0}' settings file.".FormatString(SettingsFilePath));
                    }

                    appSettings.LoadXml(File.ReadAllText(SettingsFilePath));
                }

                ChoConsole.WriteLine();

                ChoRoboCopyManager _roboCopyManager = new ChoRoboCopyManager(SettingsFilePath);
                _roboCopyManager.Status += (sender, e) =>
                {
                    ChoTrace.Write(e.Message);
                    ChoConsole.Write(e.Message, ConsoleColor.Yellow);
                };
                _roboCopyManager.AppStatus += (sender, e) =>
                {
                    ChoTrace.Write(e.Message);
                    ChoConsole.Write(e.Message, ConsoleColor.Yellow);
                };

                _roboCopyManager.Process(appSettings.RoboCopyFilePath, appSettings.GetCmdLineParams(),
                                         appSettings, true);
            }
            catch (ThreadAbortException)
            {
                Console.WriteLine("RoboCopy operation cancelled by user.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("RoboCopy operation failed." + Environment.NewLine + ChoApplicationException.ToString(ex));
            }
        }