public static Task <List <T> > GetAll <T>( string fileName, Func <T, bool> match) { using (var stream = FileUtils.GetReadStream(fileName)) { var list = stream.ReadList <T>(); return(Task.FromResult(list.Where(t => match(t)).ToList())); } }
public static Task <bool> Exists <T>( string fileName, T itemToFind, MatchForUpdate <T> matcher) { var found = false; using (var stream = FileUtils.GetReadStream(fileName)) { var list = stream.ReadList <T>(); for (int idx = 0; idx < list.Count && !found; idx++) { var item = list[idx]; bool shouldUpdate = false; (found, shouldUpdate) = matcher(item, itemToFind); } } return(Task.FromResult(found)); }
public static Task <T?> Get <T>( string fileName, Func <T, bool> match) where T : struct { var found = false; using (var stream = FileUtils.GetReadStream(fileName)) { var list = stream.ReadList <T>(); for (int idx = 0; idx < list.Count && !found; idx++) { if (match(list[idx])) { return(Task.FromResult <T?>(list[idx])); } } } return(Task.FromResult <T?>(null)); }
public Task <Stream> GetReadStream(string pathKey) => Task.FromResult <Stream>( FileUtils.GetReadStream( Path.Combine( _blobDirectory, pathKey)));
public static Task <int> CountAll <T>( string fileName) { using (var stream = FileUtils.GetReadStream(fileName)) { return(Task.FromResult(stream.ReadList <T>().Count)); } }