private static async ValueTask WriteImplAsync <T>(IBoundConfiguration <T> c, IAsyncEnumerable <T> rows, TextWriter writer, object?context, CancellationToken cancellationToken) { await using (var csv = c.CreateAsyncWriter(writer, context)) { await ConfigureCancellableAwait(csv, csv.WriteAllAsync(rows, cancellationToken), cancellationToken); } }
private static void WriteImpl <T>(IBoundConfiguration <T> c, IEnumerable <T> rows, TextWriter writer, object?context) { using (var csv = c.CreateWriter(writer, context)) { csv.WriteAll(rows); } }
internal static T ImpossibleException_Returns <T, V>( string message, IBoundConfiguration <V> config, [CallerFilePath] string?file = null, [CallerMemberName] string?member = null, [CallerLineNumber] int line = -1) => throw Cesil.ImpossibleException.Create(message, file ?? UNKNOWN_FILE, member ?? UNKNOWN_MEMBER, line, config);
private static IEnumerable <T> EnumerateFromStreamImpl <T>(IBoundConfiguration <T> c, TextReader reader, object?context) { using (var csv = c.CreateReader(reader, context)) { foreach (var row in csv.EnumerateAll()) { yield return(row); } } }
private static async IAsyncEnumerable <T> EnumerateFromStreamImplAsync <T>(IBoundConfiguration <T> c, TextReader reader, object?context, [EnumeratorCancellation] CancellationToken cancellationToken) { await using (var csv = c.CreateAsyncReader(reader, context)) { await using (var e = csv.EnumerateAllAsync().GetAsyncEnumerator(cancellationToken)) { while (await ConfigureCancellableAwait(csv, e.MoveNextAsync(), cancellationToken)) { yield return(e.Current); } } } }
public void Initialize() { WideRow.Initialize(); StaticConfig = Configuration.For <WideRow>(); DynamicConfig = Configuration.ForDynamic(); StaticRows = GetStaticRows(RowSet); DynamicRows_Static = GetRows(RowSet, "Static"); DynamicRows_Cesil = GetRows(RowSet, "Cesil"); DynamicRows_ExpandoObject = GetRows(RowSet, nameof(ExpandoObject)); DynamicRows_Custom = GetRows(RowSet, "Custom"); }
public void Initialize() { WideRow.Initialize(); if (StaticConfig != null && DynamicConfig != null) { return; } DynamicConfig = Configuration.ForDynamic(); StaticConfig = Configuration.For <WideRow>(); CSV = MakeCSV(); }
private static DataSourceTuple CreateFolderDataSource() { MockDirectoryInteractorFactory mockDirectoryInteractorFactory = new MockDirectoryInteractorFactory( FolderDataSourceTests.SuppliedFiles, FolderDataSourceTests.SuppliedDirectories); Action <object, IFolderDataChangeEventArgs> added = null; Action <object, IFolderDataChangeEventArgs> changed = null; Action <object, IFolderDataChangeEventArgs> moved = null; Action <object, IFolderDataChangeEventArgs> removed = null; MockFolderDataWatcherFactory mockFolderDataWatcherFactory = new MockFolderDataWatcherFactory( _ => { MockFolderDataWatcher result = new MockFolderDataWatcher( out Action <object, IFolderDataChangeEventArgs> invokeAdded, out Action <object, IFolderDataChangeEventArgs> invokeChanged, out Action <object, IFolderDataChangeEventArgs> invokeMoved, out Action <object, IFolderDataChangeEventArgs> invokeRemoved); added = invokeAdded; changed = invokeChanged; moved = invokeMoved; removed = invokeRemoved; return(result); }); FolderDataSourceFactory factory = new FolderDataSourceFactory(); IReadOnlyDictionary <IConfigurationRequirement, object> bindings = new Dictionary <IConfigurationRequirement, object>() { [factory.Requirements[0]] = new FilePath( FolderDataSourceTests.RootPath, FolderDataSourceTests.pathInteractor), [factory.Requirements[3]] = mockFolderDataWatcherFactory, [factory.Requirements[4]] = mockDirectoryInteractorFactory }; IBoundConfiguration configuration = factory.Configure(bindings); return(new DataSourceTuple( factory.MakeDataSource(configuration), added, changed, moved, removed)); }
public void InitializeAndTest() { foreach (var rows in KnownRowSet) { StaticConfig = null; DynamicConfig = null; CSV = null; RowSet = rows; Initialize(); var staticHashes = new List <int>(); using (var str = new StringReader(CSV)) using (var csv = StaticConfig.CreateReader(str)) { foreach (var row in csv.EnumerateAll()) { var h = HashAllMembers(row); staticHashes.Add(h); } } var dynamicHashes = new List <int>(); using (var str = new StringReader(CSV)) using (var csv = DynamicConfig.CreateReader(str)) { foreach (var row in csv.EnumerateAll()) { var h = HashAllMembers(row); dynamicHashes.Add(h); } } if (staticHashes.Count != dynamicHashes.Count) { throw new Exception(); } for (var i = 0; i < staticHashes.Count; i++) { if (staticHashes[i] != dynamicHashes[i]) { throw new Exception(); } } } }
/// <inheritdoc /> public IDataSource <IFileInformation> MakeDataSource(IBoundConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } IFolderDataWatcherFactory factory = (IFolderDataWatcherFactory)(configuration.GetOrDefault( FolderDataSourceFactory.watcherFactory, () => new FolderDataWatcherFactory( (string)configuration.GetOrDefault(FolderDataSourceFactory.factoryFilter, () => null), (long)configuration.GetOrDefault(FolderDataSourceFactory.factoryChangeFilterTicks, () => 0L)))); return(new FolderDataSource( (FilePath)configuration[FolderDataSourceFactory.path], factory, (IDirectoryInteractorFactory)configuration[FolderDataSourceFactory.interactorFactory])); }
internal void AssertNotPoisoned <T>(IBoundConfiguration <T> self) { if (Poison != null) { switch (Poison.Value) { case PoisonType.Cancelled: Throw.InvalidOperationException("Object is in an invalid state, a previous operation was canceled"); return; case PoisonType.Exception: Throw.InvalidOperationException("Object is in an invalid state, a previous operation raised an exception"); return; default: Throw.ImpossibleException($"Unexpected {nameof(PoisonType)}: {Poison}", self); return; } } }
public void Initialize() { WideRow.Initialize(); // Configure Cesil { var opts = Options.CreateBuilder(Options.Default).WithWriteTrailingRowEnding(WriteTrailingRowEnding.Always).ToOptions(); CesilConfig = Configuration.For <WideRow>(opts); } // Configure CsvHelper { CsvHelperConfig = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture); CsvHelperConfig.RegisterClassMap <WideRowMapping>(); } CSV = MakeCSV(); DoCsvHelper = GetReadFunc(nameof(CsvHelper)); DoCesil = GetReadFunc(nameof(Cesil)); }
internal static ImpossibleException Create <T>(string reason, string fileName, string memberName, int lineNumber, IBoundConfiguration <T> config) => new ImpossibleException( DefaultMessage(reason, fileName, memberName, lineNumber) + "\r\n" + $"Bound to {typeof(T).FullName}\r\n" + (config is ConcreteBoundConfiguration <T>? "Concrete binding" : "Dynamic binding") + "\r\n" + OptionsMessage(config.Options) );
static Action <IEnumerable <NarrowRow <T> >, TextWriter> MakeWriteWithCesilDel(IBoundConfiguration <NarrowRow <T> > config) { return ((IEnumerable <NarrowRow <T> > rows, TextWriter into) => { using (var writer = config.CreateWriter(into)) { writer.WriteAll(rows); } }); }