Пример #1
0
        private void OnWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            ConsoleWorker worker = (ConsoleWorker)sender;

            ConverterOptions options = this.Options;

            _wpfSettings.IncludeRuntime = options.IncludeRuntime;
            _wpfSettings.TextAsGeometry = options.TextAsGeometry;

            _fileReader.UseFrameXamlWriter = !options.UseCustomXamlWriter;

            if (options.GeneralWpf)
            {
                _fileReader.SaveXaml = options.SaveXaml;
                _fileReader.SaveZaml = options.SaveZaml;
            }
            else
            {
                _fileReader.SaveXaml = false;
                _fileReader.SaveZaml = false;
            }

            this.ProcessConversion(e, _sourceInfoDir, _outputInfoDir);

            if (!e.Cancel)
            {
                e.Result = "Successful";
            }
        }
        private void OnOptionsPageLoaded(object sender, RoutedEventArgs e)
        {
            Debug.Assert(_options != null);
            if (_options == null)
            {
                _options = new ConverterOptions();
            }

            _isInitialising = true;

            chkTextAsGeometry.IsChecked = _options.TextAsGeometry;
            chkIncludeRuntime.IsChecked = _options.IncludeRuntime;

            chkXaml.IsChecked       = _options.GeneralWpf;
            panelXaml.IsEnabled     = _options.GeneralWpf;
            chkSameXaml.IsChecked   = _options.SaveXaml;
            chkSameZaml.IsChecked   = _options.SaveZaml;
            chkXamlWriter.IsChecked = _options.UseCustomXamlWriter;

            chkImage.IsChecked      = _options.GenerateImage;
            panelImage.IsEnabled    = _options.GenerateImage;
            cboImages.SelectedIndex = (int)_options.EncoderType;

            _isInitialising = false;
        }
        public ConverterOptions Clone()
        {
            ConverterOptions options = new ConverterOptions(this);

            if (_errorMessage != null)
            {
                options._errorMessage = String.Copy(_errorMessage);
            }

            return(options);
        }
Пример #4
0
        public ConverterOptions Clone()
        {
            ConverterOptions options = new ConverterOptions(this);

            if (_errorMessage != null)
            {
                options._errorMessage = new string(_errorMessage.ToCharArray());
            }

            return(options);
        }
Пример #5
0
        private void OnWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            ConsoleWorker worker = (ConsoleWorker)sender;

            ConverterOptions options = this.Options;

            _wpfSettings.IncludeRuntime = options.IncludeRuntime;
            _wpfSettings.TextAsGeometry = options.TextAsGeometry;

            _fileReader.UseFrameXamlWriter = !options.UseCustomXamlWriter;

            if (options.GeneralWpf)
            {
                _fileReader.SaveXaml = options.SaveXaml;
                _fileReader.SaveZaml = options.SaveZaml;
            }
            else
            {
                _fileReader.SaveXaml = false;
                _fileReader.SaveZaml = false;
            }

            _drawing = _fileReader.Read(_sourceFile, _outputInfoDir);

            if (_drawing == null)
            {
                e.Result = "Failed";
                return;
            }

            if (options.GenerateImage)
            {
                _fileReader.SaveImage(_sourceFile, _outputInfoDir,
                                      options.EncoderType);

                _imageFile = _fileReader.ImageFile;
            }
            _xamlFile = _fileReader.XamlFile;
            _zamlFile = _fileReader.ZamlFile;

            if (_drawing.CanFreeze)
            {
                _drawing.Freeze();
            }

            e.Result = "Successful";
        }
        public ConverterOptions(ConverterOptions source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            _textAsGeometry   = source._textAsGeometry;
            _includeRuntime   = source._includeRuntime;
            _generateImage    = source._generateImage;
            _generalWpf       = source._generalWpf;
            _saveXaml         = source._saveXaml;
            _saveZaml         = source._saveZaml;
            _customXamlWriter = source._customXamlWriter;
            _encoderType      = source._encoderType;
            _errorMessage     = source._errorMessage;
        }
Пример #7
0
        public ConverterOptions(ConverterOptions source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            _textAsGeometry   = source._textAsGeometry;
            _includeRuntime   = source._includeRuntime;
            _generateImage    = source._generateImage;
            _generalWpf       = source._generalWpf;
            _saveXaml         = source._saveXaml;
            _saveZaml         = source._saveZaml;
            _customXamlWriter = source._customXamlWriter;
            _encoderType      = source._encoderType;
            _errorMessage     = source._errorMessage;
        }
        public ConverterWindow()
        {
            InitializeComponent();

            this.MinWidth  = 640;
            this.MinHeight = 340;

            this.Width  = 640;
            this.Height = 340;

            _options = new ConverterOptions();

            this.Loaded   += new RoutedEventHandler(OnWindowLoaded);
            this.Unloaded += new RoutedEventHandler(OnWindowUnloaded);

            this.Closing         += new CancelEventHandler(OnWindowClosing);
            this.ContentRendered += new EventHandler(OnWindowContentRendered);
        }
Пример #9
0
        public ConverterWindow()
        {
            InitializeComponent();

            this.MinWidth  = 640;
            this.MinHeight = 340;

            this.Width     = 640;
            this.Height    = 340;

            _options = new ConverterOptions();

            this.Loaded   += new RoutedEventHandler(OnWindowLoaded);
            this.Unloaded += new RoutedEventHandler(OnWindowUnloaded);

            this.Closing  += new CancelEventHandler(OnWindowClosing);
            this.ContentRendered += new EventHandler(OnWindowContentRendered);
        }
Пример #10
0
 public ConsoleApplication(Process process)
 {
     _process = process;
     _options = new ConverterOptions();
 }
Пример #11
0
        private void OnOptionsPageLoaded(object sender, RoutedEventArgs e)
        {
            Debug.Assert(_options != null);
            if (_options == null)
            {
                _options = new ConverterOptions();
            }

            _isInitialising = true;

            chkTextAsGeometry.IsChecked = _options.TextAsGeometry;
            chkIncludeRuntime.IsChecked = _options.IncludeRuntime;

            chkXaml.IsChecked       = _options.GeneralWpf;
            panelXaml.IsEnabled     = _options.GeneralWpf;
            chkSameXaml.IsChecked   = _options.SaveXaml;
            chkSameZaml.IsChecked   = _options.SaveZaml;
            chkXamlWriter.IsChecked = _options.UseCustomXamlWriter;

            chkImage.IsChecked      = _options.GenerateImage;
            panelImage.IsEnabled    = _options.GenerateImage;
            cboImages.SelectedIndex = (int)_options.EncoderType;

            _isInitialising = false;
        }
Пример #12
0
        public MainWindow()
        {
            InitializeComponent();

            this.MinWidth  = 640;
            this.MinHeight = 700;

            this.Width  = 720;
            this.Height = 700;

            _startTabIndex = 0;

            _options = new ConverterOptions();
            MainApplication theApp = (MainApplication)Application.Current;

            Debug.Assert(theApp != null);
            if (theApp != null)
            {
                ConverterCommandLines commandLines = theApp.CommandLines;
                if (commandLines != null)
                {
                    if (commandLines.IsEmpty)
                    {
                        IList <string> sources = commandLines.Arguments;
                        _displayHelp = commandLines.ShowHelp ||
                                       (sources != null && sources.Count != 0);
                    }
                    else
                    {
                        _options.Update(commandLines);
                    }
                }
                else
                {
                    _displayHelp = true;
                }

                if (!_displayHelp)
                {
                    string sourceFile = commandLines.SourceFile;
                    if (!String.IsNullOrEmpty(sourceFile) && File.Exists(sourceFile))
                    {
                        _startTabIndex = 1;
                    }
                    else
                    {
                        string sourceDir = commandLines.SourceDir;
                        if (!String.IsNullOrEmpty(sourceDir) && Directory.Exists(sourceDir))
                        {
                            _startTabIndex = 3;
                        }
                        else
                        {
                            IList <string> sourceFiles = commandLines.SourceFiles;
                            if (sourceFiles != null && sourceFiles.Count != 0)
                            {
                                _startTabIndex = 2;
                            }
                        }
                    }
                }
            }

            _filesPage             = new FileConverterPage();
            _filesPage.Options     = _options;
            _filesPage.ParentFrame = filesFrame;
            _filesPage.Subscribe(this);

            filesFrame.Content = _filesPage;

            _filesListPage             = new FileListConverterPage();
            _filesListPage.Options     = _options;
            _filesListPage.ParentFrame = filesListFrame;
            _filesListPage.Subscribe(this);

            filesListFrame.Content = _filesListPage;

            _directoriesPage             = new DirectoryConverterPage();
            _directoriesPage.Options     = _options;
            _directoriesPage.ParentFrame = directoriesFrame;
            _directoriesPage.Subscribe(this);

            directoriesFrame.Content = _directoriesPage;

            _optionsPage         = new OptionsPage();
            _optionsPage.Options = _options;

            optionsFrame.Content = _optionsPage;

            this.Loaded   += new RoutedEventHandler(OnWindowLoaded);
            this.Unloaded += new RoutedEventHandler(OnWindowUnloaded);

            this.Closing += new CancelEventHandler(OnWindowClosing);
        }
Пример #13
0
        private void ConvertFiles(DoWorkEventArgs e, DirectoryInfo source,
                                  DirectoryInfo target)
        {
            _fileReader.FallbackOnWriterError = _fallbackOnWriterError;

            if (e.Cancel)
            {
                return;
            }

            if (_worker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            ConverterOptions options = this.Options;

            IEnumerable <string> fileIterator = DirectoryUtils.FindFiles(
                source, "*.*", SearchOption.TopDirectoryOnly);

            foreach (string svgFileName in fileIterator)
            {
                if (_worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }

                string fileExt = Path.GetExtension(svgFileName);
                if (string.Equals(fileExt, ".svg", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        FileAttributes fileAttr = File.GetAttributes(svgFileName);
                        if (!_includeHidden)
                        {
                            if ((fileAttr & FileAttributes.Hidden) == FileAttributes.Hidden)
                            {
                                continue;
                            }
                        }

                        FileSecurity security = null;

                        if (_includeSecurity)
                        {
                            security = File.GetAccessControl(svgFileName);
                        }

                        if (_worker.CancellationPending)
                        {
                            e.Cancel = true;
                            break;
                        }

                        DrawingGroup drawing = _fileReader.Read(svgFileName,
                                                                target);

                        if (drawing == null)
                        {
                            if (_continueOnError)
                            {
                                throw new InvalidOperationException(
                                          "The conversion failed due to unknown error.");
                            }
                        }

                        if (options.SaveXaml)
                        {
                            string xamlFile = _fileReader.XamlFile;
                            if (!string.IsNullOrWhiteSpace(xamlFile) &&
                                File.Exists(xamlFile))
                            {
                                File.SetAttributes(xamlFile, fileAttr);

                                // if required to set the security or access control
                                if (_includeSecurity)
                                {
                                    File.SetAccessControl(xamlFile, security);
                                }
                            }
                        }
                        if (options.SaveZaml)
                        {
                            string zamlFile = _fileReader.ZamlFile;
                            if (!string.IsNullOrWhiteSpace(zamlFile) &&
                                File.Exists(zamlFile))
                            {
                                File.SetAttributes(zamlFile, fileAttr);

                                // if required to set the security or access control
                                if (_includeSecurity)
                                {
                                    File.SetAccessControl(zamlFile, security);
                                }
                            }
                        }

                        if (drawing != null && options.GenerateImage)
                        {
                            _fileReader.SaveImage(svgFileName, target,
                                                  options.EncoderType);
                            string imageFile = _fileReader.ImageFile;
                            if (!string.IsNullOrWhiteSpace(imageFile) &&
                                File.Exists(imageFile))
                            {
                                File.SetAttributes(imageFile, fileAttr);

                                // if required to set the security or access control
                                if (_includeSecurity)
                                {
                                    File.SetAccessControl(imageFile, security);
                                }
                            }
                        }

                        if (drawing != null)
                        {
                            _convertedCount++;
                        }

                        if (_fileReader.WriterErrorOccurred)
                        {
                            _writerErrorOccurred = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        _errorFiles.Add(svgFileName);

                        if (_continueOnError)
                        {
                            StringBuilder builder = new StringBuilder();
                            builder.AppendLine("Error converting: " + svgFileName);
                            builder.AppendFormat("Error: Exception ({0})", ex.GetType());
                            builder.AppendLine();
                            builder.AppendLine(ex.Message);
                            builder.AppendLine(ex.ToString());

                            _worker.ReportProgress(0, builder.ToString());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }
Пример #14
0
        private void OnSyncConvert()
        {
            StringBuilder builder = new StringBuilder();

            try
            {
                ConverterOptions options = this.Options;

                _wpfSettings.IncludeRuntime = options.IncludeRuntime;
                _wpfSettings.TextAsGeometry = options.TextAsGeometry;

                _fileReader.UseFrameXamlWriter = !options.UseCustomXamlWriter;

                if (options.GeneralWpf)
                {
                    _fileReader.SaveXaml = options.SaveXaml;
                    _fileReader.SaveZaml = options.SaveZaml;
                }
                else
                {
                    _fileReader.SaveXaml = false;
                    _fileReader.SaveZaml = false;
                }

                Drawing drawing = _fileReader.Read(_sourceFile, _outputInfoDir);

                if (drawing == null)
                {
                    this.AppendLine("Result: Conversion Failed.");
                }
                else
                {
                    string _imageFile = null;
                    if (options.GenerateImage)
                    {
                        _fileReader.SaveImage(_sourceFile, _outputInfoDir,
                                              options.EncoderType);

                        _imageFile = _fileReader.ImageFile;
                    }
                    string _xamlFile = _fileReader.XamlFile;
                    string _zamlFile = _fileReader.ZamlFile;

                    builder.AppendLine("Result: Conversion is Successful.");

                    builder.AppendLine("Output Files:");
                    if (_xamlFile != null)
                    {
                        builder.AppendLine(_xamlFile);
                    }
                    if (_zamlFile != null)
                    {
                        builder.AppendLine(_zamlFile);
                    }
                    if (_imageFile != null)
                    {
                        builder.AppendLine(_imageFile);
                    }
                }
            }
            catch (Exception ex)
            {
                builder.AppendFormat("Error: Exception ({0})", ex.GetType());
                builder.AppendLine();
                builder.AppendLine(ex.Message);
                builder.AppendLine(ex.ToString());
            }

            this.AppendLine(builder.ToString());
        }
Пример #15
0
        public ConverterOptions Clone()
        {
            ConverterOptions options = new ConverterOptions(this);
            if (_errorMessage != null)
            {
                options._errorMessage = String.Copy(_errorMessage);
            }

            return options;
        }
Пример #16
0
 public ConsoleApplication(Process process)
 {
     _process = process;
     _options = new ConverterOptions();
 }
Пример #17
0
        private void ConvertFiles(DoWorkEventArgs e, DirectoryInfo target)
        {
            _fileReader.FallbackOnWriterError = _fallbackOnWriterError;

            if (e.Cancel)
            {
                return;
            }

            if (_worker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            DirectoryInfo outputDir = target;

            foreach (string svgFileName in _sourceFiles)
            {
                if (_worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }

                ConverterOptions options = this.Options;

                string fileExt = Path.GetExtension(svgFileName);
                if (string.Equals(fileExt, ".svg", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        if (_worker.CancellationPending)
                        {
                            e.Cancel = true;
                            break;
                        }

                        if (target == null)
                        {
                            outputDir = new DirectoryInfo(
                                Path.GetDirectoryName(svgFileName));
                        }

                        DrawingGroup drawing = _fileReader.Read(svgFileName,
                                                                outputDir);

                        if (drawing == null)
                        {
                            if (_continueOnError)
                            {
                                throw new InvalidOperationException(
                                          "The conversion failed due to unknown error.");
                            }
                        }

                        if (drawing != null && options.GenerateImage)
                        {
                            _fileReader.SaveImage(svgFileName, target,
                                                  options.EncoderType);
                        }

                        if (drawing != null)
                        {
                            _convertedCount++;
                        }

                        if (_fileReader.WriterErrorOccurred)
                        {
                            _writerErrorOccurred = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        _errorFiles.Add(svgFileName);

                        if (_continueOnError)
                        {
                            StringBuilder builder = new StringBuilder();
                            builder.AppendLine("Error converting: " + svgFileName);
                            builder.AppendFormat("Error: Exception ({0})", ex.GetType());
                            builder.AppendLine();
                            builder.AppendLine(ex.Message);
                            builder.AppendLine(ex.ToString());

                            _worker.ReportProgress(0, builder.ToString());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }
Пример #18
0
        public MainWindow()
        {
            InitializeComponent();

            this.MinWidth  = 640;
            this.MinHeight = 700;

            this.Width     = 720;
            this.Height    = 700;

            _startTabIndex = 0;

            _options = new ConverterOptions();
            MainApplication theApp = (MainApplication)Application.Current;
            Debug.Assert(theApp != null);
            if (theApp != null)
            {
                ConverterCommandLines commandLines = theApp.CommandLines;
                if (commandLines != null)
                {
                    if (commandLines.IsEmpty)
                    {
                        IList<string> sources = commandLines.Arguments;
                        _displayHelp = commandLines.ShowHelp ||
                            (sources != null && sources.Count != 0);
                    }
                    else
                    {
                        _options.Update(commandLines);
                    }
                }
                else
                {
                    _displayHelp = true;
                }

                if (!_displayHelp)
                {
                    string sourceFile = commandLines.SourceFile;
                    if (!String.IsNullOrEmpty(sourceFile) && File.Exists(sourceFile))
                    {
                        _startTabIndex = 1;
                    }
                    else
                    {
                        string sourceDir = commandLines.SourceDir;
                        if (!String.IsNullOrEmpty(sourceDir) && Directory.Exists(sourceDir))
                        {
                            _startTabIndex = 3;
                        }
                        else
                        {
                            IList<string> sourceFiles = commandLines.SourceFiles;
                            if (sourceFiles != null && sourceFiles.Count != 0)
                            {
                                _startTabIndex = 2;
                            }
                        }
                    }

                }
            }

            _filesPage = new FileConverterPage();
            _filesPage.Options     = _options;
            _filesPage.ParentFrame = filesFrame;
            _filesPage.Subscribe(this);

            filesFrame.Content = _filesPage;

            _filesListPage = new FileListConverterPage();
            _filesListPage.Options     = _options;
            _filesListPage.ParentFrame = filesListFrame;
            _filesListPage.Subscribe(this);

            filesListFrame.Content = _filesListPage;

            _directoriesPage = new DirectoryConverterPage();
            _directoriesPage.Options     = _options;
            _directoriesPage.ParentFrame = directoriesFrame;
            _directoriesPage.Subscribe(this);

            directoriesFrame.Content = _directoriesPage;

            _optionsPage = new OptionsPage();
            _optionsPage.Options = _options;

            optionsFrame.Content = _optionsPage;

            this.Loaded   += new RoutedEventHandler(OnWindowLoaded);
            this.Unloaded += new RoutedEventHandler(OnWindowUnloaded);

            this.Closing += new CancelEventHandler(OnWindowClosing);
        }