Пример #1
0
        public override bool Convert(ConsoleWriter writer)
        {
            if (string.IsNullOrWhiteSpace(_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.IsNullOrWhiteSpace(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);
            }
        }
        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);
            }
        }
Пример #3
0
        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.IsNullOrWhiteSpace(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);
            }
        }