コード例 #1
0
ファイル: DeviceSorter.cs プロジェクト: tzAcee/photonized
        public void sort()
        {
            DeviceUserEntry entry = UserInputService.get_user_entry(_Console);

            if (entry.Equals(default(DeviceUserEntry)))
            {
                return;
            }

            //TODO check for parser for all modules
            var files = Directory.EnumerateFiles(_parser.DirPath, "*.*") // Remove/Add SearchOption if dont need to resort
                        .Where(s => s.EndsWith(".png") || s.EndsWith(".jpg") || s.EndsWith(".tif"));

            if (files.Count() == 0)
            {
                return;
            }
            var sortPath = Directory.CreateDirectory(Path.Combine(_parser.DirPath, entry.SortWord));

            int index = 0;

            foreach (var file in files)
            {
                FileInfo curFile = DevicePathService.get_file(file);
                if (!(entry.SortTime.Year == curFile.CreationTime.Year &&
                      entry.SortTime.Day == curFile.CreationTime.Day &&
                      entry.SortTime.Month == curFile.CreationTime.Month))
                {
                    continue;
                }
                try
                {
                    System.IO.File.Move(curFile.FullName, Path.Combine(sortPath.FullName, curFile.Name));
                    index++;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            if (index == 0)
            {
                Directory.Delete(sortPath.FullName);
                _Console.WriteLine("No entries with this creation date found.");
                _Console.ReadLine();
            }
            else
            {
                DeviceNoteService.add_entry(_parser.DirPath, entry);
                var tree = new Node(_parser.DirPath);

                _Console.Clear();
                _Console.WriteLine("Your new Structure! Press Any Key to proceed.");
                _Console.WriteLine("");
                NodePrinter.print_tree(tree, "", true);
                _Console.ReadLine();
            }
        }
コード例 #2
0
        public void get_user_entry_name_test()
        {
            var console = new Mock <IConsole>();

            console.Setup(item => item.WriteLine("For which day you want to sort the pictures ? (DD / MM / YYYY)"));
            console.Setup(func => func.ReadLine()).Returns("12/03/2222");
            console.Setup(item => item.WriteLine("What did you do @ this day?"));

            UserInputService.get_user_entry(console.Object);

            console.VerifyAll();
        }