private async void Preview_Clicked(object?sender, RoutedEventArgs e)
        {
            // Load resources
            var sourceXml = await File.ReadAllTextAsync(ViewModel.SourceFileUrl);

            var transformXml = await File.ReadAllTextAsync(ViewModel.TransformFileUrl);

            var transformXml2 = string.IsNullOrEmpty(ViewModel.TransformFileUrl2)
                ? string.Empty
                : await File.ReadAllTextAsync(ViewModel.TransformFileUrl2);

            // Transform the XML
            var transformedXml = new XmlTransformService().Transform(sourceXml, transformXml);

            if (!string.IsNullOrWhiteSpace(transformXml2))
            {
                transformedXml = new XmlTransformService().Transform(transformedXml, transformXml2);
            }

            // Write to file
            var tempFileUrl = Path.GetTempPath() + Path.DirectorySeparatorChar + "temp.xml";
            await File.WriteAllTextAsync(tempFileUrl, transformedXml);

            ProcessStartInfo psi = new ProcessStartInfo
            {
                FileName        = tempFileUrl,
                UseShellExecute = true
            };

            Process.Start(psi);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            try
            {
                if (!args.Any())
                {
                    throw new ArgumentException("Arguments not specified. --help for supported arguments.");
                }

                Parser.Default.ParseArguments <CommandLineArguments>(args)
                .WithParsed((args) =>
                {
                    if (string.IsNullOrWhiteSpace(args.InputFile))
                    {
                        throw new ArgumentException(nameof(args.InputFile) + " must not be empty.");
                    }

                    if (!args.TransformFiles.Any())
                    {
                        throw new ArgumentException("At least one transform file must be provided.");
                    }

                    var sourceXml = File.ReadAllText(args.InputFile);
                    foreach (var transformFile in args.TransformFiles)
                    {
                        var transformXml = File.ReadAllText(transformFile);
                        sourceXml        = new XmlTransformService().Transform(sourceXml, transformXml);
                    }

                    File.WriteAllText(args.InputFile, sourceXml);
                });
            }
            catch (Exception e)
            {
                System.Console.Error.WriteLine(e.ToString());
            }
        }
        private async void Transform_Clicked(object?sender, RoutedEventArgs e)
        {
            // Load resources
            var sourceXml = await File.ReadAllTextAsync(ViewModel.SourceFileUrl);

            var transformXml = await File.ReadAllTextAsync(ViewModel.TransformFileUrl);

            var transformXml2 = string.IsNullOrEmpty(ViewModel.TransformFileUrl2)
                ? string.Empty
                : await File.ReadAllTextAsync(ViewModel.TransformFileUrl2);

            // transform the XML
            var transformedXml = new XmlTransformService().Transform(sourceXml, transformXml);

            if (!string.IsNullOrWhiteSpace(transformXml2))
            {
                transformedXml = new XmlTransformService().Transform(transformedXml, transformXml2);
            }

            _sourceBackup = new string(sourceXml);

            // Write to file
            await File.WriteAllTextAsync(ViewModel.SourceFileUrl, transformedXml);
        }