Exemplo n.º 1
0
        public void InitializeComponent(bool startedInConsole, bool isQuiet)
        {
            _startedInConsole = startedInConsole;

            _writer = new ConsoleWriter(isQuiet, ConsoleWriterVerbosity.Normal);

            _progressBar = new ConsoleProgress(isQuiet, _writer);
            this.Subscribe(_progressBar);
        }
        public override bool Convert(ConsoleWriter writer)
        {
            if (String.IsNullOrEmpty(_sourceDir) || !Directory.Exists(_sourceDir))
            {
                return false;
            }

            _writer = writer;

            _errorFiles = new List<string>();

            string outputDir = this.OutputDir;

            try
            {
                this.AppendLine(String.Empty);
                this.AppendLine("Converting files, please wait...");
                this.AppendLine("Input Directory: " + _sourceDir);

                Debug.Assert(_sourceDir != null && _sourceDir.Length != 0);
                if (String.IsNullOrEmpty(outputDir))
                {
                    outputDir = String.Copy(_sourceDir);
                }
                _sourceInfoDir = new DirectoryInfo(_sourceDir);
                _outputInfoDir = new DirectoryInfo(outputDir);

                _worker.RunWorkerAsync();

                if (_observer != null)
                {
                    _observer.OnStarted(this);
                }

                return true;
            }
            catch (Exception ex)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendFormat("Error: Exception ({0})", ex.GetType());
                builder.AppendLine();
                builder.AppendLine(ex.Message);

                this.AppendText(builder.ToString());

                return false;
            }
        }
Exemplo n.º 3
0
 public ConsoleProgress(bool isQuiet, ConsoleWriter writer)
 {
     _isQuiet = isQuiet;
     _writer  = writer;
 }
        public override bool Convert(ConsoleWriter writer)
        {
            Debug.Assert(writer != null);

            Debug.Assert(_sourceFiles != null && _sourceFiles.Count != 0);
            if (_sourceFiles == null || _sourceFiles.Count == 0)
            {
                return false;
            }

            _writer = writer;

            _errorFiles = new List<string>();

            try
            {
                this.AppendLine(String.Empty);
                this.AppendLine("Converting files, please wait...");

                string outputDir = this.OutputDir;
                Debug.Assert(_sourceFiles != null && _sourceFiles.Count != 0);
                if (_sourceFiles == null || _sourceFiles.Count == 0)
                {
                    return false;
                }
                if (!String.IsNullOrEmpty(outputDir))
                {
                    _outputInfoDir = new DirectoryInfo(outputDir);
                    if (!_outputInfoDir.Exists)
                    {
                        _outputInfoDir.Create();
                    }
                }

                this.AppendLine("Input Files:");
                for (int i = 0; i < _sourceFiles.Count; i++)
                {
                    this.AppendLine(_sourceFiles[i]);
                }
                this.AppendLine(String.Empty);

                _worker.RunWorkerAsync();

                if (_observer != null)
                {
                    _observer.OnStarted(this);
                }

                return true;
            }
            catch (Exception ex)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendFormat("Error: Exception ({0})", ex.GetType());
                builder.AppendLine();
                builder.AppendLine(ex.Message);

                this.AppendText(builder.ToString());

                return false;
            }
        }
Exemplo n.º 5
0
 public abstract bool Convert(ConsoleWriter writer);
        public override bool Convert(ConsoleWriter writer)
        {
            Debug.Assert(writer != null);

            Debug.Assert(_sourceFile != null && _sourceFile.Length != 0);
            if (String.IsNullOrEmpty(_sourceFile) || !File.Exists(_sourceFile))
            {
                return false;
            }

            _writer = writer;

            try
            {
                this.AppendLine(String.Empty);
                this.AppendLine("Converting file, please wait...");
                this.AppendLine("Input File: " + _sourceFile);

                string _outputDir = this.OutputDir;
                if (String.IsNullOrEmpty(_outputDir))
                {
                    _outputDir = Path.GetDirectoryName(_sourceFile);
                }
                _outputInfoDir = new DirectoryInfo(_outputDir);

                //this.OnConvert();

                _worker.RunWorkerAsync();

                if (_observer != null)
                {
                    _observer.OnStarted(this);
                }

                return true;
            }
            catch (Exception ex)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendFormat("Error: Exception ({0})", ex.GetType());
                builder.AppendLine();
                builder.AppendLine(ex.Message);

                this.AppendText(builder.ToString());

                return false;
            }
        }