示例#1
0
        public override void Open()
        {
            object dataSource = base.DataSource;

            this.fileSource = dataSource as CsvFileSource;
            if ((this.fileSource != null) && (this.fileSource.FileStream != null))
            {
                try
                {
                    Encoding encoding = this.fileSource.Encoding;
                    if (encoding == null)
                    {
                        encoding = Encoding.UTF8;
                    }
                    string data = new StreamReader(this.fileSource.FileStream, encoding, true).ReadToEnd();
                    this.cachedFileText  = CsvImp.ParseText(data, this.fileSource.RowDelimiter, this.fileSource.ColumnDelimiter, this.fileSource.CellDelimiter);
                    this.hasRowHeader    = (this.fileSource.OpenFlags & TextFileOpenFlags.IncludeRowHeader) == TextFileOpenFlags.IncludeRowHeader;
                    this.hasColumnHeader = (this.fileSource.OpenFlags & TextFileOpenFlags.IncludeColumnHeader) == TextFileOpenFlags.IncludeColumnHeader;
                    base.Open();
                    if ((this.cachedFileText != null) && (this.cachedFileText.Count > 0))
                    {
                        this.CreateDataFields();
                    }
                }
                catch
                {
                }
            }
        }
示例#2
0
 void CreateDataFields()
 {
     if ((this.cachedFileText != null) || (this.cachedFileText.Count > 0))
     {
         int maxLength = CsvImp.GetMaxLength(this.cachedFileText);
         if (this.hasColumnHeader)
         {
             this.cachedHeaders = this.cachedFileText[0];
         }
         else
         {
             this.cachedHeaders = new List <string>();
             int num2 = 0;
             if (!this.hasRowHeader)
             {
                 num2 = 1;
             }
             for (int i = num2; i <= maxLength; i++)
             {
                 this.cachedHeaders.Add("Column" + ((int)i).ToString());
             }
         }
     }
 }