Exemplo n.º 1
0
 /// <summary>
 /// Gets the next results and add the rows to the current RowSet queue
 /// </summary>
 protected virtual void PageNext()
 {
     if (IsFullyFetched)
     {
         return;
     }
     if (FetchNextPage == null)
     {
         //There is no handler, clear the paging state
         this.PagingState = null;
         return;
     }
     lock (_pageLock)
     {
         var pageState = this.PagingState;
         if (pageState == null)
         {
             return;
         }
         bool value;
         bool alreadyPresent = _pagers.TryGetValue(pageState, out value);
         if (alreadyPresent)
         {
             return;
         }
         var rs = FetchNextPage(pageState);
         foreach (var newRow in rs.RowQueue)
         {
             RowQueue.Enqueue(newRow);
         }
         PagingState = rs.PagingState;
         _pagers.AddOrUpdate(pageState, true, (k, v) => v);
     }
 }
Exemplo n.º 2
0
        public void Close()
        {
            if (IsFileOpen)
            {
                try
                {
                    File.Close();
                }
                catch (Exception)
                {
                }
            }

            if (Queued)
            {
                RowQueue.Quit();
            }

            IsFileOpen = false;
            m_Filesize = 0;

            ResetError();
            ResetColumnProperties();
            ResetColumnWidths();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Adds a row to the inner row list
 /// </summary>
 internal virtual void AddRow(Row row)
 {
     if (RowQueue == null)
     {
         throw new InvalidOperationException("Can not append a Row to a RowSet instance created for VOID results");
     }
     RowQueue.Enqueue(row);
 }
Exemplo n.º 4
0
 public IEnumerator <Row> GetEnumerator()
 {
     while (!IsExhausted())
     {
         Row row = null;
         while (RowQueue.TryDequeue(out row))
         {
             yield return(row);
         }
     }
 }
Exemplo n.º 5
0
 public virtual IEnumerator <Row> GetEnumerator()
 {
     if (RowQueue == null)
     {
         yield break;
     }
     while (!IsExhausted())
     {
         Row row;
         while (RowQueue.TryDequeue(out row))
         {
             yield return(row);
         }
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Adds a row to the inner row list
 /// </summary>
 internal virtual void AddRow(Row row)
 {
     RowQueue.Enqueue(row);
 }
Exemplo n.º 7
0
        // --- Higer Level Functions ---

        public DataSet GetDataset(int MaxRows)
        {
            bool OldColumnHeaders = ColumnHeaders;

            ColumnHeaders = false;
            if (!InitRead())
            {
                return(null);
            }
            ColumnHeaders = OldColumnHeaders;

            m_MaxRows = MaxRows;

            int       i;
            DataSet   DS = new DataSet();
            DataTable DT = new DataTable();

            bCancel = false;

            string strColumnName;

            if (ColumnHeaders)
            {
                for (i = 0; i <= m_ColumnCount - 1; i++)
                {
                    strColumnName = ColumnValues[i].Trim();
                    if (strColumnName == "")
                    {
                        strColumnName = "Column" + i.ToString();
                    }

                    try
                    {
                        DT.Columns.Add(strColumnName, Type.GetType("System.String"));
                    }
                    catch
                    {
                        strColumnName = "Column" + i.ToString();
                        DT.Columns.Add(strColumnName, Type.GetType("System.String"));
                    }
                }
                if (!EOF)
                {
                    if (!MoveNext())
                    {
                        return(null);
                    }
                }
                m_RecordCount = 1;
            }
            else
            {
                for (i = 0; i <= m_ColumnCount - 1; i++)
                {
                    DT.Columns.Add("Column" + i.ToString(), Type.GetType("System.String"));
                }
            }

            DataRow Row;
            int     Percent;

            if (!EOF)
            {
                if (ProgressChangeEvent != null)
                {
                    ProgressChangeEvent(0);
                }

                while (!EOF && !bCancel)
                {
                    Row = DT.NewRow();
                    for (i = 0; i <= m_ColumnCount - 1; i++)
                    {
                        try
                        {
                            Row[i] = Strings.ConvertNull(ColumnValues[i]);
                        }
                        catch (Exception)
                        {
                        }
                    }

                    if (Queued)
                    {
                        RowQueue.Enqueue(Row);
                    }
                    else
                    {
                        DT.Rows.Add(Row);
                    }

                    if (!MoveNext())
                    {
                        return(null);
                    }

                    Percent = PercentDone;
                    if (ProgressChangeEvent != null)
                    {
                        ProgressChangeEvent(Percent);
                    }

                    if (MaxRows > 0 && m_RecordCount > MaxRows)
                    {
                        break;
                    }
                }

                if (ProgressChangeEvent != null)
                {
                    ProgressChangeEvent(100);
                }
            }


            //if (Queued)
            //    RowQueue.Quit();

            DS.Tables.Add(DT);
            return(DS);
        }
Exemplo n.º 8
0
        // --- File
        public bool Open(string FName, bool AutoDetectDelimiters, System.Text.Encoding Encoding)
        {
            if (Queued)
            {
                RowQueue.Start();
            }

            if (IsFileOpen)
            {
                Close();
            }

            if (Encoding == null)
            {
                Encoding = System.Text.Encoding.Default;
            }

            if (FName != "")
            {
                Filename = FName;
            }

            if (!Strings.FileExists(Filename))
            {
                m_LastError            = -1;
                m_LastErrorDescription = "File not found";
                return(false);
            }

            try
            {
                FileInfo info = new FileInfo(Filename);
                m_Filesize = (int)(info.Length);
            }
            catch (Exception ex)
            {
                m_LastError            = -1;
                m_LastErrorDescription = ex.Message;
                return(false);
            }

            try
            {
                File = new StreamReader(Filename, Encoding, true);
            }
            catch (Exception ex)
            {
                m_LastError            = -1;
                m_LastErrorDescription = ex.Message;
                return(false);
            }

            IsFileOpen = true;

            ResetError();
            ResetColumnProperties();
            ResetColumnWidths();

            if (AutoDetectDelimiters)
            {
                Delimiter = AutoDetectDelimiter();
                if (Delimiter != null)
                {
                    TextMarker = AutoDetectTextmarker(Delimiter);
                    if (TextMarker != null)
                    {
                        ColumnHeaders = AutoDetectColumnHeaders(Delimiter, TextMarker);
                    }
                }

                if (Delimiter == null)
                {
                    Delimiter = ";";
                }
                if (TextMarker == null)
                {
                    TextMarker = "";
                }
                if (Encoding == System.Text.Encoding.ASCII)
                {
                    ConvertFromAscii = AutoDetectAscii();
                }
                if (!MoveFirst())
                {
                    return(false);
                }
            }

            return(true);
        }