Exemplo n.º 1
0
        /// <summary>
        /// Get table content from table settings.
        /// </summary>
        /// <param name="settings">Table settings.</param>
        /// <param name="pageContext">Page context.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Element content.</returns>
        public IElementContent GetContent(IElementSettings settings, IPageContext pageContext, IUnitOfWork unitOfWork = null)
        {
            TableSettings tableSettings = (TableSettings)settings;
            TableContent  content       = new TableContent {
                PartialViewName = "Table", Rows = new List <List <string> >()
            };

            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(tableSettings.Rows)))
            {
                using (StreamReader sr = new StreamReader(ms))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        List <string> values = _stringService.GetCsvValues(line);
                        if (tableSettings.ShowHeaders && content.Headers == null)
                        {
                            content.Headers = values;
                        }
                        else
                        {
                            content.Rows.Add(values);
                        }
                    }
                }
            }
            return(content);
        }