Пример #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);
 }