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 ShouldLeaveTheXmlUntouchedWhenUsingAnIdentityTransformation() { 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.Transform(inputStream, outputStream); } Assert.That(File.ReadAllBytes(Test1FileName), Is.EqualTo(File.ReadAllBytes(OutputFileName)), "the output file is identical to the input file."); }
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>")); }
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 += (_, e) => e.Value = Accents.Instance.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>")); }
public void ShouldApplyMultipleTransformations() { 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 = e.Value + "1"; }; processor.TransformString += (s, e) => { e.Value = Brackets.Transform(e.Value); }; processor.TransformString += (s, e) => { e.Value = e.Value + "2"; }; processor.Transform(inputStream, outputStream); } var original = File.ReadAllText(Test1FileName); var transformed = File.ReadAllText(OutputFileName); Assert.That(original.Contains("<value>Dude</value>")); Assert.That(transformed.Contains("<value>[Dude1]2</value>")); }
public void ShouldApplyMultipleTransformations() { 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 += (_, e) => e.Value += "1"; processor.TransformString += (_, e) => e.Value = Brackets.Instance.Transform(e.Value); processor.TransformString += (_, e) => e.Value += "2"; processor.Transform(inputStream, outputStream); } var original = File.ReadAllText(Test1FileName); var transformed = File.ReadAllText(OutputFileName); Assert.That(original.Contains("<value>Dude</value>")); Assert.That(transformed.Contains("<value>[Dude1]2</value>")); }
public void ShouldReverseStringsButLeaveTheCommentsUntouchedWhenTransformingWithAStringReverseTransformation() { 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 = Mirror.Transform(e.Value); }; processor.Transform(inputStream, outputStream); } var original = File.ReadAllText(Test1FileName); var transformed = File.ReadAllText(OutputFileName); Assert.That(original.Contains("<value>Dude</value>")); Assert.That(!original.Contains("<value>eduD</value>")); Assert.That(transformed.Contains("<value>eduD</value>")); Assert.That(!transformed.Contains("<value>Dude</value>")); Assert.That(original.Contains("<comment>Foo</comment>")); Assert.That(transformed.Contains("<comment>Foo</comment>")); }
public void ShouldReverseStringsButLeaveTheCommentsUntouchedWhenTransformingWithAStringReverseTransformation() { 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 = Mirror.Instance.Transform(e.Value); }; processor.Transform(inputStream, outputStream); } var original = File.ReadAllText(Test1FileName); var transformed = File.ReadAllText(OutputFileName); Assert.That(original.Contains("<value>Dude</value>")); Assert.That(!original.Contains("<value>eduD</value>")); Assert.That(transformed.Contains("<value>eduD</value>")); Assert.That(!transformed.Contains("<value>Dude</value>")); Assert.That(original.Contains("<comment>Foo</comment>")); Assert.That(transformed.Contains("<comment>Foo</comment>")); }