Beispiel #1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("*** Please specify the source XML file.");
            }

            string fin = args[0];

            string fout;

            if (args.Length > 1)
            {
                fout = args[1];
            }
            else
            {
                fout = Path.ChangeExtension(fin, ".json");
            }

            var     xin  = XDocument.Load(fin);
            JObject jout = AuFormsHelpers.ConvertRoot(xin);

            using (StreamWriter file = File.CreateText(fout))
                using (JsonTextWriter writer = new JsonTextWriter(file))
                {
                    jout.WriteTo(writer);
                }

            Console.WriteLine("Conversione complete.");
        }
Beispiel #2
0
        private void OpenSourceFile(string fileIn)
        {
            this._minifiedOutput      = null;
            this.TxtSource.Text       = string.Empty;
            this.TxtTarget.Text       = string.Empty;
            this.TxtSource.Background = this.Background;
            this.TxtTarget.Background = this.Background;
            if (string.IsNullOrEmpty(fileIn))
            {
                return;
            }

            XDocument xin;

            try
            {
                xin = XDocument.Load(fileIn);
            }
            catch (Exception ex)
            {
                this.TxtSource.Text       = ex.Message;
                this.TxtSource.Background = Brushes.LightPink;
                return;
            }

            if (xin.Root?.Name.LocalName != "auForm")
            {
                this.TxtSource.Text       = "Not a valid 'auForm' template.";
                this.TxtSource.Background = Brushes.LightPink;
                return;
            }

            this.TxtSource.Text       = xin.ToString();
            this.TxtSource.Background = Brushes.PaleGreen;

            JObject jout;

            try
            {
                jout = AuFormsHelpers.ConvertRoot(xin);
            }
            catch (Exception ex)
            {
                this.TxtTarget.Text       = ex.Message;
                this.TxtTarget.Background = Brushes.LightPink;
                return;
            }

            try
            {
                string fileOut = System.IO.Path.ChangeExtension(fileIn, ".json");
                using (System.IO.StreamWriter file = System.IO.File.CreateText(fileOut))
                    using (var writer = new Newtonsoft.Json.JsonTextWriter(file))
                    {
                        jout.WriteTo(writer);
                    }
            }
            catch (Exception ex)
            {
                this.TxtTarget.Text       = ex.Message;
                this.TxtTarget.Background = Brushes.LightPink;
            }

            var sb = new StringBuilder();

            using (var sw = new System.IO.StringWriter(sb))
                using (var writer = new Newtonsoft.Json.JsonTextWriter(sw))
                {
                    jout.WriteTo(writer);
                }
            this._minifiedOutput = sb.ToString();

            this.TxtTarget.Text = jout.ToString(Newtonsoft.Json.Formatting.Indented);

            this.TxtTarget.Background = Brushes.PaleGreen;
        }