Ejemplo n.º 1
0
        private void ConvertFiles(DirectoryInfo source, DirectoryInfo target)
        {
            _errorFile = null;

            FileSvgConverter fileConverter = new FileSvgConverter(this.SaveXaml,
                                                                  this.SaveZaml, this.DrawingSettings);

            fileConverter.FallbackOnWriterError = _fallbackOnWriterError;

            string targetDirName = target.ToString();
            string xamlFilePath;

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

            foreach (string svgFileName in fileIterator)
            {
                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;
                            }
                        }

                        xamlFilePath = Path.Combine(targetDirName,
                                                    Path.GetFileNameWithoutExtension(svgFileName) + ".xaml");

                        fileConverter.Convert(svgFileName, xamlFilePath);

                        File.SetAttributes(xamlFilePath, fileAttr);
                        // if required to set the security or access control
                        if (_includeSecurity)
                        {
                            File.SetAccessControl(xamlFilePath, File.GetAccessControl(svgFileName));
                        }

                        _convertedCount++;

                        if (fileConverter.WriterErrorOccurred)
                        {
                            _writerErrorOccurred = true;
                        }
                    }
                    catch
                    {
                        _errorFile = svgFileName;

                        throw;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // 1. Create conversion options
            WpfDrawingSettings settings = new WpfDrawingSettings();
            settings.IncludeRuntime = false;
            settings.TextAsGeometry = true;

            // 2. Select a file to be converted
            string svgTestFile = "Test.svg";

            // 3. Create a file converter
            FileSvgConverter converter = new FileSvgConverter(settings);
            // 4. Perform the conversion to XAML
            converter.Convert(svgTestFile);
        }
        private void ConvertFiles(DirectoryInfo source, DirectoryInfo target)
        {
            _errorFile = null;

            FileSvgConverter fileConverter = new FileSvgConverter(this.SaveXaml,
                this.SaveZaml, this.DrawingSettings);
            fileConverter.FallbackOnWriterError = _fallbackOnWriterError;

            string targetDirName = target.ToString();
            string xamlFilePath;

            IEnumerable<string> fileIterator = DirectoryUtils.FindFiles(
              source, "*.*", SearchOption.TopDirectoryOnly);
            foreach (string svgFileName in fileIterator)
            {
                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;
                            }
                        }

                        xamlFilePath = Path.Combine(targetDirName,
                            Path.GetFileNameWithoutExtension(svgFileName) + ".xaml");

                        fileConverter.Convert(svgFileName, xamlFilePath);

                        File.SetAttributes(xamlFilePath, fileAttr);
                        // if required to set the security or access control
                        if (_includeSecurity)
                        {
                            File.SetAccessControl(xamlFilePath, File.GetAccessControl(svgFileName));
                        }

                        _convertedCount++;

                        if (fileConverter.WriterErrorOccurred)
                        {
                            _writerErrorOccurred = true;
                        }
                    }
                    catch
                    {
                        _errorFile = svgFileName;

                        throw;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void ConvertFiles(DirectoryInfo source, DirectoryInfo target)
        {
            _errorFile = null;

            var fileConverter = new FileSvgConverter(this.SaveXaml, this.SaveZaml, this.DrawingSettings);

            fileConverter.Background            = this.Background;
            fileConverter.FallbackOnWriterError = _fallbackOnWriterError;

            fileConverter.DpiX = _dpiX;
            fileConverter.DpiY = _dpiY;

            string targetDirName = target.ToString();
            string xamlFilePath;

            var fileIterator = Directory.EnumerateFiles(source.FullName, "*.svg*", SearchOption.TopDirectoryOnly);

            foreach (string svgFileName in fileIterator)
            {
                string fileExt = Path.GetExtension(svgFileName);
                if (string.Equals(fileExt, SvgExt, StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(fileExt, CompressedSvgExt, StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        FileAttributes fileAttr = File.GetAttributes(svgFileName);
                        if (!_includeHidden)
                        {
                            if ((fileAttr & FileAttributes.Hidden) == FileAttributes.Hidden)
                            {
                                continue;
                            }
                        }

                        xamlFilePath = Path.Combine(targetDirName, Path.GetFileNameWithoutExtension(svgFileName) + XamlExt);

                        fileConverter.Convert(svgFileName, xamlFilePath);

                        File.SetAttributes(xamlFilePath, fileAttr);
#if NET40
                        // if required to set the security or access control
                        if (_includeSecurity)
                        {
                            File.SetAccessControl(xamlFilePath, File.GetAccessControl(svgFileName));
                        }
#endif
                        _convertedCount++;

                        if (fileConverter.WriterErrorOccurred)
                        {
                            _writerErrorOccurred = true;
                        }
                    }
                    catch
                    {
                        _errorFile = svgFileName;

                        throw;
                    }
                }
            }
        }