示例#1
0
 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()));
     }
 }
示例#2
0
        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));
        }
示例#3
0
        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));
        }
示例#4
0
 public Task <Stream> GetReadStream(string pathKey)
 => Task.FromResult <Stream>(
     FileUtils.GetReadStream(
         Path.Combine(
             _blobDirectory, pathKey)));
示例#5
0
 public static Task <int> CountAll <T>(
     string fileName)
 {
     using (var stream = FileUtils.GetReadStream(fileName))
     { return(Task.FromResult(stream.ReadList <T>().Count)); }
 }