示例#1
0
        private static ScanFolderResult ScanFolder(string folder, bool log = true)
        {
            var res = new ScanFolderResult(folder);

            try
            {
                IEnumerable <string> subFolders = Directory.GetDirectories(folder);
                Parallel.ForEach(subFolders, subFolder =>
                {
                    if (log)
                    {
                        Console.WriteLine(subFolder);
                    }
                    var subFolderResult = ScanFolder(subFolder, false);
                    lock (res)
                    {
                        res.AddSubFolder(subFolderResult);
                    }
                });
                res.FolderSize = GetFolderSize(folder);
            }
            catch (UnauthorizedAccessException e)
            {
            }
            return(res);
        }
示例#2
0
 private static ScanFolderResult ScanFolder(string folder, bool log = true)
 {
     var res = new ScanFolderResult(folder);
     try
     {
         IEnumerable<string> subFolders = Directory.GetDirectories(folder);
         Parallel.ForEach(subFolders, subFolder =>
         {
             if (log)
             {
                 Console.WriteLine(subFolder);
             }
             var subFolderResult = ScanFolder(subFolder, false);
             lock (res)
             {
                 res.AddSubFolder(subFolderResult);
             }
         });
         res.FolderSize = GetFolderSize(folder);
     }
     catch (UnauthorizedAccessException e)
     {
         
     }
     return res;
 }
示例#3
0
 private static IEnumerable<ScanFolderResult> GetAllFolders(ScanFolderResult scanFolderResult)
 {
     yield return scanFolderResult;
     foreach (var subFolder in scanFolderResult.SubFolders.SelectMany(GetAllFolders))
     {
         yield return subFolder;
     }
 }
示例#4
0
        private static IEnumerable <ScanFolderResult> GetAllFolders(ScanFolderResult scanFolderResult)
        {
            yield return(scanFolderResult);

            foreach (var subFolder in scanFolderResult.SubFolders.SelectMany(GetAllFolders))
            {
                yield return(subFolder);
            }
        }
示例#5
0
 private static IEnumerable<FolderDiff> CompareFolders(ScanFolderResult scanFolderResult, ScanFolderResult previousFolderScan)
 {
     var previousFolders = GetAllFolders(previousFolderScan).ToDictionary(f => f.Folder, f => f.FolderSize);
     foreach (var folder in GetAllFolders(scanFolderResult))
     {
         var diff = folder.FolderSize;
         if (previousFolders.ContainsKey(folder.Folder))
         {
             diff = folder.FolderSize - previousFolders[folder.Folder];
         }
         yield return new FolderDiff{ Folder = folder.Folder, Diff = diff };
     }
 }
示例#6
0
        private static IEnumerable <FolderDiff> CompareFolders(ScanFolderResult scanFolderResult, ScanFolderResult previousFolderScan)
        {
            var previousFolders = GetAllFolders(previousFolderScan).ToDictionary(f => f.Folder, f => f.FolderSize);

            foreach (var folder in GetAllFolders(scanFolderResult))
            {
                var diff = folder.FolderSize;
                if (previousFolders.ContainsKey(folder.Folder))
                {
                    diff = folder.FolderSize - previousFolders[folder.Folder];
                }
                yield return(new FolderDiff {
                    Folder = folder.Folder, Diff = diff
                });
            }
        }
示例#7
0
        private static void WritePreviousFolderScan(ScanFolderResult scanFolderResult)
        {
            var path = Path.Combine(scanFolderResult.Folder, ScanResultFilename);

            new XmlSerializer(typeof(ScanFolderResult)).Serialize(File.Create(path), scanFolderResult);
        }
示例#8
0
 public void AddSubFolder(ScanFolderResult subFolderResult)
 {
     SubFolders.Add(subFolderResult);
 }
示例#9
0
 private static void WritePreviousFolderScan(ScanFolderResult scanFolderResult)
 {
     var path = Path.Combine(scanFolderResult.Folder, ScanResultFilename);
     new XmlSerializer(typeof(ScanFolderResult)).Serialize(File.Create(path), scanFolderResult);
 }
示例#10
0
 public void AddSubFolder(ScanFolderResult subFolderResult)
 {
     SubFolders.Add(subFolderResult);
 }