Ejemplo n.º 1
0
        public static async Task CompactFolder(this AbsolutePath folder, WorkQueue queue, Algorithm algorithm)
        {
            var driveInfo   = folder.DriveInfo().DiskSpaceInfo;
            var clusterSize = driveInfo.SectorsPerCluster * driveInfo.BytesPerSector;

            await folder
            .EnumerateFiles(true)
            .Where(f => f.Size > clusterSize)
            .PMap(queue, async path =>
            {
                Utils.Status($"Compacting {path.FileName}");
                await path.Compact(algorithm);
            });
        }
Ejemplo n.º 2
0
        public static List <TR> PMap <TI, TR>(this IEnumerable <TI> coll, Func <TI, TR> f)
        {
            var colllst = coll.ToList();

            WorkQueue.MaxQueueSize     = colllst.Count;
            WorkQueue.CurrentQueueSize = 0;

            var tasks = coll.Select(i =>
            {
                TaskCompletionSource <TR> tc = new TaskCompletionSource <TR>();
                WorkQueue.QueueTask(() =>
                {
                    try
                    {
                        tc.SetResult(f(i));
                    }
                    catch (Exception ex)
                    {
                        tc.SetException(ex);
                    }
                    Interlocked.Increment(ref WorkQueue.CurrentQueueSize);
                    WorkQueue.ReportNow();
                });
                return(tc.Task);
            }).ToList();

            return(tasks.Select(t =>
            {
                t.Wait();
                if (t.IsFaulted)
                {
                    throw t.Exception;
                }
                return t.Result;
            }).ToList());
        }
Ejemplo n.º 3
0
 public static Task PDoIndexed <T>(this IEnumerable <T> coll, WorkQueue queue, Action <int, T> f)
 {
     return(coll.Zip(Enumerable.Range(0, int.MaxValue), (v, idx) => (v, idx))
            .PMap(queue, vs => f(vs.idx, vs.v)));
 }
Ejemplo n.º 4
0
 public StatusFileStream(Stream fs, string message, WorkQueue queue = null)
 {
     _queue   = queue;
     _inner   = fs;
     _message = message;
 }