コード例 #1
0
        public JsonResult Get([FromQuery] string path)
        {
            if (path == null)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(null);
            }

            try
            {
                // Get files and folders for path
                var currentFolderItems = FolderManager.GetAllItemsForFolder(path);

                FolderFilesVariations countFilesVariationsForFolder;

                // If path - drive check cache
                if (path.Length == 3)
                {
                    countFilesVariationsForFolder = SetGetCache(path);
                }
                else
                {
                    countFilesVariationsForFolder = GlobalFilesCalculation.GetFilesCount(path);
                }

                Response.StatusCode = (int)HttpStatusCode.OK;
                return(Json(new { files = currentFolderItems, countFiles = countFilesVariationsForFolder }));
            }
            catch
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(null);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            List <Drive> listAll = DriveManager.GetAllDrives();

            string path               = "C:\\";
            string pathRec            = "C:\\";
            var    currentFolderItems = FolderManager.GetAllItemsForFolder(path);

            foreach (var item in listAll)
            {
                Console.WriteLine(item.Name);
            }
            Console.WriteLine("----------------------------------------------------------");

            foreach (var item in currentFolderItems)
            {
                Console.WriteLine(item.Name);
            }
            Console.WriteLine("----------------------------------------------------------");

            var items = GlobalFilesCalculation.GetFilesCount(pathRec);

            Console.WriteLine($"{items.FilesThatLessThan10Mb} -- " +
                              $"{items.FilesBetween10ANd50Mb} --" +
                              $"errors - {items.Errors} --" +
                              $"{items.FilesMoreThan100Mb}");

            Console.ReadKey();
        }
コード例 #3
0
        public void GetItemsWhenNullPath()
        {
            List <Item> filesAndFolders = new List <Item>();

            filesAndFolders = FolderManager.GetAllItemsForFolder(null);

            Assert.That(filesAndFolders, Is.Null);
        }
コード例 #4
0
        public void GetItemsWhenWrongPath()
        {
            List <Item> filesAndFolders = new List <Item>();
            string      path            = "sdasdas/asa";

            filesAndFolders = FolderManager.GetAllItemsForFolder(path);

            Assert.That(filesAndFolders, Is.Null);
        }
コード例 #5
0
        public void GetItemsForFolderE()
        {
            List <Item> filesAndFolders = new List <Item>();
            string      path            = "E:\\";
            int         count           = 26;

            filesAndFolders = FolderManager.GetAllItemsForFolder(path);

            Assert.That(filesAndFolders.Count, Is.EqualTo(count));
        }
コード例 #6
0
        public void GetFoldersCount()
        {
            List <Item> filesAndFolders = new List <Item>();
            string      path            = "G:\\";
            int         count           = 11;

            filesAndFolders = FolderManager.GetAllItemsForFolder(path);
            int foldersCount = filesAndFolders.Where(c => c.Kind == ItemEnum.Folder).ToList().Count;

            Assert.That(filesAndFolders.Count, Is.EqualTo(count));
        }
コード例 #7
0
        public void GetItemsForEmptyFolder()
        {
            List <Item> filesAndFolders = new List <Item>();
            string      path            = "E:\\";
            int         count           = 0;

            DirectoryInfo di         = new DirectoryInfo(path);
            string        folderName = "EmptyTestFolder";

            di.CreateSubdirectory(folderName);
            string fullPath = "E:\\EmptyTestFolder";

            filesAndFolders = FolderManager.GetAllItemsForFolder(fullPath);

            Assert.That(filesAndFolders.Count, Is.EqualTo(count));
#warning !
            DirectoryInfo diToDel = new DirectoryInfo(fullPath);
            diToDel.Delete();
        }