Example #1
0
        private static Stream GenerateHtmlFile(SetCollection data, string rootName, string xsltFilePath, Dictionary <string, string> xsltArgumentsDictionary)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            using (DataSet ds = new DataSet(rootName))
            {
                ds.Locale = System.Globalization.CultureInfo.InvariantCulture;

                foreach (DictionaryEntry set in data)
                {
                    var table = ds.Tables.Add(set.Key.ToString());

                    foreach (IDictionary <string, object> item in (IList <dynamic>)set.Value)
                    {
                        if (table.Columns.Count == 0)
                        {
                            foreach (var prop in item)
                            {
                                table.Columns.Add(prop.Key, prop.Value.GetType() == typeof(DBNull) ? typeof(object) : prop.Value.GetType());
                            }
                        }

                        DataRow row = table.NewRow();

                        foreach (var prop in item)
                        {
                            row[prop.Key] = HtmlGenerator.CleanInvalidXmlChars(prop.Value.ToString());
                        }

                        table.Rows.Add(row);
                    }
                }

                return(HtmlGenerator.GenerateHtmlFile(ds, xsltFilePath, xsltArgumentsDictionary));
            }
        }