public IColumnReader GetOrBuild(string key, CachingOption option, Func <IColumnReader> build) { if (option == CachingOption.Always || (ColumnCache.IsEnabled && option == CachingOption.AsConfigured)) { return(_cache.GetOrBuild(key, null, () => { IColumnReader inner = build(); if (inner == null) { return null; } if (inner is CachedColumnReader) { return inner; } return new CachedColumnReader(inner); })); } else { IColumnReader result; if (_cache.TryGet(key, out result)) { return(result); } return(build()); } }
public CachedColumnReader(IColumnReader inner) { using (inner) { _column = inner.Read(ArraySelector.All(inner.Count)); } }
/// <summary> /// Call this function on a data reader to get that rows return status info. /// </summary> private static ReturnStatus ParseInternal(IColumnReader reader) { // check if the reader has return status info if (!Exists(reader)) { return(null); } // first get the status string status = reader.GetString("status"); ReturnStatus returnStatus = new ReturnStatus(status); // get the reason if it exists if (reader.HasValue("reason")) { returnStatus._reason = reader.GetString("reason"); } // get i18n info if (reader.HasValue("context")) { returnStatus._context = reader.GetString("context"); } if (reader.HasValue("appkey")) { returnStatus._appKey = reader.GetString("appkey"); } return(returnStatus); }
public VariableIntegerReader(IStreamProvider streamProvider, string columnPathPrefix, CachingOption option) { // Look for each potential size in descending order and build the right reader and converter Type type = typeof(int); string path = VariableIntegerWriter.PathForType(columnPathPrefix, typeof(int)); if (streamProvider.Attributes(path).Exists) { _reader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(int), path, option, typeof(VariableIntegerReader)); _converter = null; return; } path = VariableIntegerWriter.PathForType(columnPathPrefix, typeof(ushort)); if (streamProvider.Attributes(path).Exists) { _reader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(ushort), path, option, typeof(VariableIntegerReader)); _converter = TypeConverterFactory.GetConverter(typeof(ushort), typeof(int)); return; } path = VariableIntegerWriter.PathForType(columnPathPrefix, typeof(byte)); _reader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(byte), path, option, typeof(VariableIntegerReader)); _converter = TypeConverterFactory.GetConverter(typeof(byte), typeof(int)); }
public void Dispose() { if (_columnReader != null) { _columnReader.Dispose(); _columnReader = null; } }
public String8ColumnReader(IStreamProvider streamProvider, string columnPath, CachingOption option) { _columnPath = columnPath; _streamProvider = streamProvider; _bytesReader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(byte), Path.Combine(columnPath, "V.s.bin"), option, typeof(String8ColumnReader)); _positionsReader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(int), Path.Combine(columnPath, "Vp.i32.bin"), option, typeof(String8ColumnReader)); }
public void Dispose() { if (_reader != null) { _reader.Dispose(); _reader = null; } }
public void Dispose() { if (_innerReader != null) { _innerReader.Dispose(); _innerReader = null; } }
public static IColumnReader Build(IColumnReader innerReader, Func <XArray, XArray> converter) { // If the inner column is null, return null (so the column cache can track columns which aren't present) if (innerReader == null) { return(null); } return(new ConvertingReader(innerReader, converter)); }
public static IColumnReader GetColumnReader(IStreamProvider streamProvider, Type columnType, string columnPath, CachingOption option = CachingOption.AsConfigured, Type callingType = null) { IColumnReader reader = TryGetColumnReader(streamProvider, columnType, columnPath, option, callingType); if (reader == null) { throw new ColumnDataNotFoundException($"Column data not found at '{columnPath}'.", columnPath); } return(reader); }
public Bits Deserialize( IColumnReader reader, ISerializationContext context) { using (var w = new System.IO.StreamReader(reader.BaseStream)) { string bitstring = w.ReadToEnd(); var bits = new Bits(bitstring); return(bits); } }
/// <summary> /// Advance the reader if there is return status data and parse. /// </summary> public static ReturnStatus ReadAndParse(IColumnReader reader) { // check if the reader has return status info if (!Exists(reader)) { return(null); } // read first record reader.Read(); return(ParseInternal(reader)); }
public void Dispose() { if (_valueReader != null) { _valueReader.Dispose(); _valueReader = null; } if (_nullReader != null) { _nullReader.Dispose(); _nullReader = null; } }
public void Dispose() { if (_valueReader != null) { _valueReader.Dispose(); _valueReader = null; } if (_rowIndexReader != null) { _rowIndexReader.Dispose(); _rowIndexReader = null; } }
public void Dispose() { if (_bytesReader != null) { _bytesReader.Dispose(); _bytesReader = null; } if (_positionsReader != null) { _positionsReader.Dispose(); _positionsReader = null; } }
public static IColumnReader Wrap(IStreamProvider streamProvider, Type columnType, string columnPath, CachingOption option) { // Build an (optional) reader for the row indices (will be null if the 'VR.u8.bin' file isn't there) IColumnReader rowIndexReader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(byte), Path.Combine(columnPath, EnumWriter.RowIndexFileName), option, typeof(EnumReader)); // Build a reader for the values (require caching if we we have row indices) IColumnReader valueReader = TypeProviderFactory.GetColumnReader(streamProvider, columnType, columnPath, (rowIndexReader != null ? CachingOption.Always : option), typeof(EnumReader)); // If there were row indices, wrap the column. Otherwise, return as-is. if (rowIndexReader != null) { return(new EnumReader(valueReader, rowIndexReader)); } return(valueReader); }
/// <summary> /// Check if the DB has the SP /// </summary> /// <remarks> /// Avoid usage of this function as it has to query to figure out info. /// Currently this is NOT used in any code. /// </remarks> protected bool HasSP(string name) { string sql = string.Format("select OBJECT_ID('[dbo].{0}') AS ID", name); SqlCommand cmd = CreateCommand(CommandType.Text, sql); using (IColumnReader reader = ExecuteTableReader(cmd)) { if (reader.Read()) { return(!reader.IsDBNull("ID")); } } return(false); }
private void Upconvert(Type toType) { // Close the current writer _writer.Dispose(); _writer = null; // Determine previous and new file paths string columnValuesFullPath = PathForType(_columnPathPrefix, WritingAsType); string columnConvertedFullPath = PathForType(_columnPathPrefix, toType); // Build a writer for the larger type IColumnWriter writer = BuildDirectWriter(_streamProvider, toType, columnConvertedFullPath); // Convert already written values (if any) if (_rowCountWritten > 0) { // Build a converter to convert the values Func <XArray, XArray> converter = TypeConverterFactory.GetConverter(WritingAsType, toType); // Stream them in, convert them, and write them out using (IColumnReader reader = TypeProviderFactory.TryGetColumnReader(_streamProvider, WritingAsType, columnValuesFullPath)) { int rowCount = reader.Count; ArraySelector page = ArraySelector.All(0).NextPage(rowCount, 10240); while (page.Count > 0) { XArray original = reader.Read(page); XArray converted = converter(original); writer.Append(converted); page = page.NextPage(rowCount, 10240); } } } // Delete the original file _streamProvider.Delete(columnValuesFullPath); // Re-initialize for the new writer WritingAsType = toType; _writer = writer; _converter = (toType == typeof(int) ? null : TypeConverterFactory.GetConverter(typeof(int), toType)); }
private void GetReader(CachingOption option = CachingOption.AsConfigured) { // If we already have a reader with appropriate caching, keep using it if (_columnReader != null && (option != CachingOption.Always || _isCached == true)) { return; } // If we had a reader but need a cached one, Dispose the previous one if (_columnReader != null) { _columnReader.Dispose(); } // Build the new reader and store a typed EnumReader copy. _columnReader = TypeProviderFactory.TryGetColumnReader(_streamProvider, ColumnDetails.Type, Path.Combine(_table.TablePath, ColumnDetails.Name), option); _enumReader = _columnReader as EnumReader; _isCached = (option == CachingOption.Always || (option == CachingOption.AsConfigured && ColumnCache.IsEnabled)); }
//save a table to a file public static bool SaveCSV(string file, IColumnReader reader) { try { if (reader == null) { return(false); } bool bHasRow = false; //generate the file using (TextWriter csvFile = new StreamWriter(file, false)) { if (reader.Columns != null) { bHasRow = true; foreach (string colname in reader.Columns) { csvFile.Write(colname); csvFile.Write(','); } csvFile.WriteLine(); } reader.FixNulls = true; int colCount = reader.Columns.Count; while (reader.Read()) { for (int i = 0; i < colCount; i++) { csvFile.Write(reader[i].ToString()); csvFile.Write(','); } csvFile.WriteLine(); } } return(bHasRow); } catch { throw; } }
public static IColumnReader Wrap(IStreamProvider streamProvider, Type columnType, string columnPath, CachingOption option) { // Get the underlying value column IColumnReader valueReader = TypeProviderFactory.TryGetColumnReader(streamProvider, columnType, columnPath, option, typeof(NullableReader)); if (valueReader == null) { return(null); } // Get a null reader (or null if there's no nulls file) string nullsPath = Path.Combine(columnPath, "Vn.b8.bin"); IColumnReader nullReader = TypeProviderFactory.TryGetColumnReader(streamProvider, typeof(bool), nullsPath, option, typeof(NullableReader)); // If there are nulls, wrap in a NullableReader if (nullReader != null) { return(new NullableReader(valueReader, nullReader)); } // If not, return the underlying reader unwrapped return(valueReader); }
private ConvertingReader(IColumnReader innerReader, Func <XArray, XArray> converter) { _innerReader = innerReader; _converter = converter; }
/// <summary> /// Does this reader have a return status /// </summary> public static bool Exists(IColumnReader reader) { return(reader.HasColumn("status") && reader.HasColumn("reason")); }
/// <summary> /// Parse any current return status data. /// </summary> public static ReturnStatus Parse(IColumnReader reader) { return(ParseInternal(reader)); }
private NullableReader(IColumnReader valueReader, IColumnReader nullReader) { _valueReader = valueReader; _nullReader = nullReader; }
private EnumReader(IColumnReader valueReader, IColumnReader rowIndexReader) { _valueReader = valueReader; _rowIndexReader = rowIndexReader; _rowIndexToIntConverter = TypeConverterFactory.GetConverter(typeof(byte), typeof(int)); }