public HttpResponseMessage GetNew(string path)
 {
     var viewModel = new FileSystemViewModel();
     var methods = new List<Func<FileInfo, bool>>()
     {
         entry => entry.Length < 10485760,
         entry => entry.Length > 10485760 && entry.Length < 52428800,
         entry => entry.Length > 104857600
     };
     viewModel = _fsManager.TraverseAvailableDirInfo(path, methods);
     if (viewModel == null)
     {
         return Request.CreateResponse(HttpStatusCode.NotFound, "Failed to find requested file/category");
     }
     else return Request.CreateResponse(HttpStatusCode.OK, viewModel);
 }
 public HttpResponseMessage GetAll()
 {
     var viewModel = new FileSystemViewModel();
     var defaultPath = _fsManager.ReturnDesktopPath();
     var methods = new List<Func<FileInfo, bool>>()
     {
         entry => entry.Length < 10485760,
         entry => entry.Length > 10485760 && entry.Length < 52428800,
         entry => entry.Length > 104857600
     };
     viewModel = _fsManager.TraverseAvailableDirInfo(defaultPath, methods);
     if (viewModel == null)
     {
         return Request.CreateResponse(HttpStatusCode.NotFound, "Failed to find requested file/category");
     }
     viewModel.Drives = _fsManager.ReturnDrives();
     return Request.CreateResponse(HttpStatusCode.OK, viewModel);
 }
 public void ReturnAvailableDirInfoTest()
 {
     FileSystemManager fs = new FileSystemManager();
     var path = @"L:\";
     FileSystemViewModel vm = new FileSystemViewModel();
     vm = fs.ReturnAvailableDirInfo(path);
     foreach (var item in vm.Folders)
     {
         Console.WriteLine(item);
     }
     foreach (var item in vm.Files)
     {
         Console.WriteLine(item);
     }
     Console.WriteLine(vm.Count10mb);
     Console.WriteLine(vm.Count50mb);
     Console.WriteLine(vm.Count100mb);
     Assert.IsNotNull(vm.Files);
     Assert.IsNotNull(vm.Folders);
 }
 /// <summary>
 /// Exception-safe method wrapper for ReturnAvailableFiles and ReturnAvailableDirectories.
 /// </summary>
 /// <param name="path">path to root directory</param>
 /// <returns></returns>
 public FileSystemViewModel ReturnAvailableDirInfo(string path)
 {
     switch (ExistsOrAvialable(path))
     {
         case false:
             return null;
         case true:
             var model = new FileSystemViewModel();
             model.Folders = ReturnAvailableDirectories(path);
             model.Files = ReturnAvailableFiles(path);
             model.Count10mb = CountAvailableFiles(path, entry => entry.Length < 10485760);
             model.Count50mb = CountAvailableFiles(path, entry => entry.Length > 10485760 && entry.Length < 52428800);
             model.Count100mb = CountAvailableFiles(path, entry => entry.Length > 104857600);
             return model;
     }
     return null;
 }
 /// <summary>
 /// Exception-safe method wrapper which includes path checking and decoding logic and files/folders deep processing.
 /// </summary>
 /// <param name="path">path that needs to be accessed</param>
 /// <param name="delegates">A delegate list of methods - part of processing logic.</param>
 /// <returns></returns>
 public FileSystemViewModel TraverseAvailableDirInfo(string path, List<Func<FileInfo, bool>> delegates)
 {
     switch (ExistsOrAvialable(path))
     {
         case false:
             var parsedPath = TryParse(path);
             if (parsedPath == null) { return null; }
             else
             {
                 var vmodel = new FileSystemViewModel();
                 vmodel.Folders = ReturnAvailableDirectories(parsedPath);
                 vmodel.Files = ReturnAvailableFiles(parsedPath);
                 if (vmodel.Folders == null || vmodel.Files == null) { return null; }
                 var filesCount1 = TraverseAvailableFiles(parsedPath, delegates);
                 vmodel.Count10mb = filesCount1[delegates[0]];
                 vmodel.Count50mb = filesCount1[delegates[1]];
                 vmodel.Count100mb = filesCount1[delegates[2]];
                 vmodel.DirectoryPath = parsedPath;
                 return vmodel;
             }
         case true:
             var model = new FileSystemViewModel();
             model.Folders = ReturnAvailableDirectories(path);
             model.Files = ReturnAvailableFiles(path);
             if (model.Folders == null || model.Files == null) { return null; }
             var filesCount2 = TraverseAvailableFiles(path, delegates);
             model.Count10mb = filesCount2[delegates[0]];
             model.Count50mb = filesCount2[delegates[1]];
             model.Count100mb = filesCount2[delegates[2]];
             model.DirectoryPath = path;
             return model;
     }
     return null;
 }