Exemple #1
0
        public void LoadFromString(string data, bool isUpdate, bool purge, bool hasHeader)
        {
            StringReader sr = new StringReader(data);

            if (!isUpdate || hasHeader)
            {
                if (sr.Peek() >= 0)
                {
                    string headerLine = sr.ReadLine();

                    if (!headerLine.Contains("\t") && headerLine.Contains(","))
                    {
                        Delimiter = ',';
                    }

                    if (!isUpdate)
                    {
                        Rows.Clear();
                    }
                    Header = UiTools.SplitString(headerLine, Delimiter);
                }
                else
                {
                    Header = new string[0];
                }
            }
            List <string[]> temp = new List <string[]>();

            if (!purge)
            {
                temp = Rows;
            }

            int count = 0;

            while (sr.Peek() >= 0)
            {
                string   line    = sr.ReadLine();
                string[] rowData = UiTools.SplitString(line, Delimiter);
                if (rowData.Length < 1)
                {
                    break;
                }
                temp.Add(rowData);
                count++;
            }
            if (purge)
            {
                Rows = temp;
            }
        }
Exemple #2
0
        public void Append(string data)
        {
            StringReader sr    = new StringReader(data);
            int          count = 0;

            while (sr.Peek() >= 0)
            {
                string   line    = sr.ReadLine();
                string[] rowData = UiTools.SplitString(line, Delimiter);
                if (rowData.Length < 2)
                {
                    break;
                }
                Rows.Add(rowData);
                count++;
            }
        }
Exemple #3
0
        public static Table Load(Stream stream, char delimiter)
        {
            bool gZip = IsGzip(stream);

            stream.Seek(0, SeekOrigin.Begin);
            if (gZip)
            {
                stream = new GZipStream(stream, CompressionMode.Decompress);
            }

            Table table = new Table();

            table.Delimiter = delimiter;

            StreamReader sr = new StreamReader(stream);

            if (sr.Peek() >= 0)
            {
                string headerLine = sr.ReadLine();
                table.Rows.Clear();
                table.Header = UiTools.SplitString(headerLine, delimiter);
            }
            else
            {
                table.Header = new string[0];
            }

            int count = 0;

            while (sr.Peek() >= 0)
            {
                string   line    = sr.ReadLine();
                string[] rowData = UiTools.SplitString(line, delimiter);
                if (rowData.Length < 2)
                {
                    break;
                }
                table.Rows.Add(rowData);
                count++;
            }
            return(table);
        }