コード例 #1
0
        private void GenerateWithXmlWriter(IDbExtractor reader, DbConnection connection, string tableName, string path)
        {
            string filePath    = Path.Combine(path, $"{tableName}.xml");
            var    columns     = reader.GetColumns(connection, tableName);
            var    columnNames = columns.Select(x => x.ColumnName).ToArray();

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent  = true;
            using var writer = XmlWriter.Create(filePath, settings);

            writer.WriteStartElement(tableName);
            using var dataReader = reader.ReadData(connection, tableName, columnNames);
            while (dataReader.Read())
            {
                writer.WriteStartElement("Entity");
                for (int i = 0; i < dataReader.FieldCount; i++)
                {
                    writer.WriteElementString(dataReader.GetName(i), dataReader.GetValue(i).ToString());
                }

                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
コード例 #2
0
        private void GenerateWithXmlDocument(IDbExtractor reader, DbConnection connection, string tableName,
                                             string path)
        {
            string filePath    = Path.Combine(path, $"{tableName}.xml");
            var    columns     = reader.GetColumns(connection, tableName);
            var    columnNames = columns.Select(x => x.ColumnName).ToArray();

            XDocument document = new XDocument();
            XElement  root     = new XElement($"{tableName}");

            document.Add(root);

            using var dataReader = reader.ReadData(connection, tableName, columnNames);
            while (dataReader.Read())
            {
                XElement entity = new XElement("entity");
                root.Add(entity);
                for (int i = 0; i < dataReader.FieldCount; i++)
                {
                    entity.Add(new XAttribute(dataReader.GetName(i), dataReader.GetValue(i)));
                }
            }

            document.Save(filePath);
        }
コード例 #3
0
        public void Generate(IDbExtractor reader, DbConnection connection, string tableName, string path)
        {
            string filePath = Path.Combine(path, $"{tableName}.csv");

            using var fileStream = File.Create(filePath);
            using var fileWriter = new StreamWriter(fileStream);
            var columns     = reader.GetColumns(connection, tableName);
            var columnNames = columns.Select(x => x.ColumnName).ToArray();

            fileWriter.WriteLine(String.Join(",", columnNames));

            using var dataReader = reader.ReadData(connection, tableName, columnNames);
            while (dataReader.Read())
            {
                for (int i = 0; i < dataReader.FieldCount; i++)
                {
                    fileWriter.Write(dataReader.GetValue(i));
                    if (i < dataReader.FieldCount - 1)
                    {
                        fileWriter.Write(",");
                    }
                }

                fileWriter.WriteLine();
            }
        }
コード例 #4
0
        public void Generate(IDbExtractor reader, DbConnection connection, string tableName, string path)
        {
            string filePath = Path.Combine(path, $"{tableName}.html");

            using var fileStream = File.Create(filePath);
            using var fileWriter = new StreamWriter(fileStream);

            var columns     = reader.GetColumns(connection, tableName);
            var columnNames = columns.Select(x => x.ColumnName).ToArray();

            fileWriter.WriteLine("<!DOCTYPE html>");
            fileWriter.WriteLine("<html>");
            fileWriter.WriteLine("<head>");
            fileWriter.WriteLine(1, "<style>");
            fileWriter.WriteLine(2, "table {");
            fileWriter.WriteLine(3, "font-family: arial, sans-serif; border-collapse: collapse; width: 100%; }");
            fileWriter.WriteLine(2, "td, th {");
            fileWriter.WriteLine(3, "border: 1px solid #dddddd;text-align: left; padding: 8px; }");
            fileWriter.WriteLine(2, "tr:nth-child(even) {");
            fileWriter.WriteLine(3, "background-color: #dddddd;}");
            fileWriter.WriteLine(1, "</style>");
            fileWriter.WriteLine("</head>");
            fileWriter.WriteLine("<body>");
            fileWriter.WriteLine(1, "<table style='width:100%'>");
            fileWriter.WriteLine(1, "<h2>Table ", tableName, "</h2>");

            fileWriter.WriteLine(2, "<tr>");
            foreach (var column in columns)
            {
                fileWriter.WriteLine(3, "<th>", column.ColumnName, "</th>");
            }

            fileWriter.WriteLine(2, "</tr>");

            using var readData = reader.ReadData(connection, tableName, columnNames);
            while (readData.Read())
            {
                fileWriter.WriteLine(2, "<tr>");
                for (int i = 0; i < readData.FieldCount; i++)
                {
                    fileWriter.WriteLine(3, "<td>", readData.GetValue(i).ToString(), "</td>");
                }

                fileWriter.WriteLine(2, "</tr>");
            }

            fileWriter.WriteLine(2, "</table>");
            fileWriter.WriteLine("</body>");
            fileWriter.WriteLine("</html>");
        }