Exemplo n.º 1
0
        private void ProcessResxFile(string inputFileName)
        {
            try
            {
                var outputFileName = Path.Combine(Path.GetDirectoryName(inputFileName), Path.GetFileNameWithoutExtension(inputFileName) + ".qps-ploc" + Path.GetExtension(inputFileName));

                using (var inputStream = new FileStream(inputFileName, FileMode.Open, FileAccess.Read))
                    using (var outputStream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write))
                    {
                        var processor = new ResxProcessor();
                        if (EnableExtraLength || UseDefaultOptions)
                        {
                            processor.TransformString += (s, e) => { e.Value = ExtraLength.Transform(e.Value); };
                        }

                        if (EnableAccents || UseDefaultOptions)
                        {
                            processor.TransformString += (s, e) => { e.Value = Accents.Transform(e.Value); };
                        }

                        if (EnableBrackets || UseDefaultOptions)
                        {
                            processor.TransformString += (s, e) => { e.Value = Brackets.Transform(e.Value); };
                        }

                        if (EnableMirror)
                        {
                            processor.TransformString += (s, e) => { e.Value = Mirror.Transform(e.Value); };
                        }

                        if (EnableUnderscores)
                        {
                            processor.TransformString += (s, e) => { e.Value = Underscores.Transform(e.Value); };
                        }

                        processor.Transform(inputStream, outputStream);
                    }

                Console.WriteLine("The file {0} was written successfully.", outputFileName);
            }
            catch (Exception ex)
            {
                if (ex is PathTooLongException ||
                    ex is FileNotFoundException ||
                    ex is DirectoryNotFoundException ||
                    ex is IOException ||
                    ex is SecurityException)
                {
                    Console.WriteLine(ex.Message);
                }
                else
                {
                    throw;
                }
            }
        }
        public void ShouldAddFunnyAccentsWhenTransformingWithTheAccenterTransformation()
        {
            using (var inputStream = new FileStream(Test1FileName, FileMode.Open, FileAccess.Read))
                using (var outputStream = new FileStream(OutputFileName, FileMode.Create, FileAccess.Write))
                {
                    var processor = new ResxProcessor();
                    processor.TransformString += (s, e) => { e.Value = Accents.Transform(e.Value); };
                    processor.Transform(inputStream, outputStream);
                }

            var transformed = File.ReadAllText(OutputFileName);

            Assert.That(transformed.Contains("<value>\u00d0\u00fb\u00f0\u00e9</value>"));
            Assert.That(!transformed.Contains("<value>Dude</value>"));
            Assert.That(transformed.Contains("<comment>Foo</comment>"));
        }