Exemplo n.º 1
0
        /// <summary>
        /// Adds selected row to good csv collection
        /// </summary>
        /// <param name="row"></param>
        /// <param name="dao"></param>
        /// <param name="optionalColumnData"></param>
        /// <param name="csvDaoFunc"></param>
        /// <returns></returns>
        public static bool MarkSelectedRowRecordAsGood(List <string> row, CsvDao dao = null, string optionalColumnData = null, Action <CsvDao> csvDaoFunc = null)
        {
            try
            {
                if (csvDaoFunc != null && dao != null)
                {
                    csvDaoFunc(dao);
                }

                var rowData = row;
                if (rowData == null)
                {
                    return(false);
                }

                var cloneRow = new List <string>();
                rowData.ForEach(cloneRow.Add);

                if (!string.IsNullOrWhiteSpace(optionalColumnData))
                {
                    AppendColumnData(optionalColumnData, cloneRow);
                }

                if (dao != null)
                {
                    dao._goodCsvRowData.Add(cloneRow);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="skipFirstRow"></param>
        /// <returns></returns>
        public static CsvDao ParseFromString(string data, bool skipFirstRow = false)
        {
            if (string.IsNullOrWhiteSpace(data))
            {
                return(null);
            }

            var reader     = new CsvDao();
            var csvRows    = data.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            var rowsToSkip = skipFirstRow ? 1 : 0;

            foreach (var csvRow in csvRows.Skip(rowsToSkip))
            {
                var columns    = SplitColumns(csvRow);
                var columnList = columns.Select(column => column.Trim()).ToList();
                reader._csvRowData.Add(columnList);
            }

            return(reader);
        }