Example #1
0
        public int Run()
        {
            Debug.Assert(_writer != null);
            Debug.Assert(_process != null);
            Debug.Assert(_commandLines != null);

            _isConverting = false;
            _isConversionError = false;

            bool? isControlling = null;
            try
            {
                if (!_writer.IsQuiet)
                {
                    // If not quiet, we will display the progress information
                    // to the console window, so try creating or attaching to
                    // existing one...
                    _consoleSuccess = this.CreateConsole();
                    if (!_consoleSuccess)
                    {
                        return 1;
                    }

                    // Turn off the default system behavior when CTRL+C is pressed. When
                    // Console.TreatControlCAsInput is false, CTRL+C is treated as an
                    // interrupt instead of as input.
                    isControlling = Console.TreatControlCAsInput;

                    Console.TreatControlCAsInput = false;

                    Console.CancelKeyPress += new ConsoleCancelEventHandler(OnConsoleCancelKeyPress);
                }

                _options.Update(_commandLines);

                _converterOutput = this.CreateConverter();
                if (_converterOutput == null)
                {
                    return 1;
                }

                // The convert method will simply start the background
                // conversion thread and start processing. It will return
                // immediately...
                bool startedConversion = _converterOutput.Convert(_writer);
                if (!startedConversion)
                {
                    return 1;
                }

                _writer.WriteLine("Press Control + C keys to cancel the conversion.");
                while (_isConverting)
                {
                    // just wait...
                }

                return 0;
            }
            catch (Exception ex)
            {
             	if (_writer != null)
                {
                    string message = ex.Message;
                    if (String.IsNullOrEmpty(message))
                    {
                        _writer.WriteErrorLine(ex.ToString());
                    }
                    else
                    {
                        _writer.WriteErrorLine(message);
                    }
                }

                return 1;
            }
            finally
            {
                if (isControlling != null && isControlling.HasValue)
                {
                    Console.TreatControlCAsInput = isControlling.Value;

                    Console.CancelKeyPress -= new ConsoleCancelEventHandler(OnConsoleCancelKeyPress);
                }

                if (_consoleSuccess)
                {
                    this.DestroyConsole();

                    _consoleSuccess = false;
                }
            }
        }
        public int Run()
        {
            Debug.Assert(_writer != null);
            Debug.Assert(_process != null);
            Debug.Assert(_commandLines != null);

            _isConverting      = false;
            _isConversionError = false;

            bool?isControlling = null;

            try
            {
                if (!_writer.IsQuiet)
                {
                    // If not quiet, we will display the progress information
                    // to the console window, so try creating or attaching to
                    // existing one...
                    _consoleSuccess = this.CreateConsole();
                    if (!_consoleSuccess)
                    {
                        return(1);
                    }

                    // Turn off the default system behavior when CTRL+C is pressed. When
                    // Console.TreatControlCAsInput is false, CTRL+C is treated as an
                    // interrupt instead of as input.
                    isControlling = Console.TreatControlCAsInput;

                    Console.TreatControlCAsInput = false;

                    Console.CancelKeyPress += new ConsoleCancelEventHandler(OnConsoleCancelKeyPress);
                }

                _options.Update(_commandLines);

                _converterOutput = this.CreateConverter();
                if (_converterOutput == null)
                {
                    return(1);
                }

                // The convert method will simply start the background
                // conversion thread and start processing. It will return
                // immediately...
                bool startedConversion = _converterOutput.Convert(_writer);
                if (!startedConversion)
                {
                    return(1);
                }

                _writer.WriteLine("Press Control + C keys to cancel the conversion.");
                while (_isConverting)
                {
                    // just wait...
                }

                return(0);
            }
            catch (Exception ex)
            {
                if (_writer != null)
                {
                    string message = ex.Message;
                    if (String.IsNullOrEmpty(message))
                    {
                        _writer.WriteErrorLine(ex.ToString());
                    }
                    else
                    {
                        _writer.WriteErrorLine(message);
                    }
                }

                return(1);
            }
            finally
            {
                if (isControlling != null && isControlling.HasValue)
                {
                    Console.TreatControlCAsInput = isControlling.Value;

                    Console.CancelKeyPress -= new ConsoleCancelEventHandler(OnConsoleCancelKeyPress);
                }

                if (_consoleSuccess)
                {
                    this.DestroyConsole();

                    _consoleSuccess = false;
                }
            }
        }