Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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);
            }
        }
        public void IfPathIsWrong()
        {
            FolderFilesVariations filesCount = new FolderFilesVariations();
            string path = "Essad:\\";

            filesCount = GlobalFilesCalculation.GetFilesCount(path);

            Assert.That(filesCount, Is.Null);
        }
        public void GetFilesCount()
        {
            FolderFilesVariations filesCount = new FolderFilesVariations();
            string path = "E:\\";

            filesCount = GlobalFilesCalculation.GetFilesCount(path);

            Assert.That(filesCount.AllFilesCount, Is.GreaterThan(700));
        }
        public void CheckNumberOfFilesBetween50To100()
        {
            FolderFilesVariations filesCount = new FolderFilesVariations();
            string path = "E:\\";

            filesCount = GlobalFilesCalculation.GetFilesCount(path);
            var filesCountBetween50To100 = filesCount.AllFilesCount - (filesCount.FilesBetween10ANd50Mb + filesCount.FilesMoreThan100Mb + filesCount.FilesThatLessThan10Mb);

            Assert.That(filesCount.AllFilesCount, Is.GreaterThan(0));
        }
Ejemplo n.º 6
0
        public FolderFilesVariations SetGetCache(string path)
        {
            FolderFilesVariations responseCountFiles;
            const int             countMinutesForCache = 15;

            if (_memoryCache.TryGetValue(path, out responseCountFiles))
            {
                return(responseCountFiles);
            }
            else
            {
                responseCountFiles = GlobalFilesCalculation.GetFilesCount(path);
                _memoryCache.Set(path, responseCountFiles,
                                 new MemoryCacheEntryOptions()
                                 .SetAbsoluteExpiration(TimeSpan.FromMinutes(countMinutesForCache)));
            }

            return(responseCountFiles);
        }