Ejemplo n.º 1
0
        public void StructuredFileWriterXMLEncodeTest()
        {
            var writeFile = new StructuredFile
            {
                ID       = "Write",
                FileName = Path.Combine(m_ApplicationDirectory, "StructuredFileOutputXML.txt"),

                SqlStatement = "Read",
                InOverview   = true,
                JSONEncode   = false
            };
            var cols = DetermineColumnFormat.GetWriterSourceColumns(writeFile, CancellationToken.None);

            var sb = new StringBuilder();

            sb.AppendLine("<?xml version=\"1.0\"?>\n");
            sb.AppendLine("<rowset>");
            writeFile.Header = sb.ToString();
            sb.Clear();
            sb.AppendLine("  <row>");
            foreach (var col in cols)
            {
                sb.AppendFormat("    <{0}>{1}</{0}>\n", HTMLStyle.XmlElementName(col.Header),
                                string.Format(System.Globalization.CultureInfo.InvariantCulture, StructuredFileWriter.cFieldPlaceholderByName, col.Header));
            }

            sb.AppendLine("  </row>");
            writeFile.Row    = sb.ToString();
            writeFile.Footer = "</rowset>";

            var writer = new StructuredFileWriter(writeFile, CancellationToken.None);

            _ = writer.Write();
        }
Ejemplo n.º 2
0
        public void StructuredFileWriterJSONEncodeTest()
        {
            var writeFile = new StructuredFile
            {
                ID           = "Write",
                FileName     = Path.Combine(m_ApplicationDirectory, "StructuredFileOutputJSON.txt"),
                SqlStatement = "Read",
                InOverview   = true,
                JSONEncode   = true
            };
            var cols = DetermineColumnFormat.GetWriterSourceColumns(writeFile, CancellationToken.None);

            writeFile.Header = "{\"rowset\":[\n";
            var sb = new StringBuilder("{");

            // { "firstName":"John", "lastName":"Doe"},
            foreach (var col in cols)
            {
                sb.AppendFormat("\"{0}\":\"{1}\", ", HTMLStyle.JsonElementName(col.Header),
                                string.Format(System.Globalization.CultureInfo.InvariantCulture, StructuredFileWriter.cFieldPlaceholderByName, col.Header));
            }

            if (sb.Length > 1)
            {
                sb.Length -= 2;
            }
            sb.AppendLine("},");
            writeFile.Row = sb.ToString();
            var writer = new StructuredFileWriter(writeFile, CancellationToken.None);

            _ = writer.Write();
        }