コード例 #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_file_path_create_test()
        {
            var file = DeviceNoteService.get_file_path("./", true);

            if (File.Exists(file))
            {
                File.Delete(file);
                return;
            }
            Assert.Fail();
        }
コード例 #3
0
ファイル: DeviceReader.cs プロジェクト: tzAcee/photonized
        public void delete()
        {
            var entries = _repo.read_entries(_parser.DirPath);

            if (entries == null)
            {
                _Console.WriteLine("No Entries found.");
                _Console.ReadLine();
                return;
            }
            if (entries.Count == 0)
            {
                _Console.Clear();
                _Console.WriteLine("No Entries... (Any Key to continue)");
                _Console.ReadLine();
                return;
            }
            compare(entries);
            _Console.Write("What is the name of the entry you want to delete? ");
            var name = _Console.ReadLine();
            var item = entries.Find(x => x.SortWord == name);

            if (item.SortWord == null)
            {
                _Console.WriteLine("No entry found.");
                _Console.ReadLine();
                return;
            }

            _Console.Write("Entry " + item.SortWord + " found, wish to delete it? y/N: ");
            var inp = _Console.ReadLine();

            if (inp.ToUpper() == "Y")
            {
                DeviceNoteService.delete_entry(_parser.DirPath, item);
                _Console.WriteLine("Want also to exclude the sorted data & delete the created directory for the entry? Y/n: ");
                inp = _Console.ReadLine();
                if (inp.ToUpper() == "N")
                {
                    return;
                }
                else
                {
                    DeviceNoteService.exclude_directory_delete(_parser.DirPath, item.SortWord);
                }
            }
            else
            {
                return;
            }
        }
コード例 #4
0
ファイル: DeviceReader.cs プロジェクト: tzAcee/photonized
        public void compare(List <DeviceUserEntry> entries)
        {
            string[] paths = Directory.GetDirectories(_parser.DirPath);

            foreach (var entry in entries)
            {
                bool found = false;
                foreach (var p in paths)
                {
                    var info = new DirectoryInfo(p).Name;
                    if (entry.SortWord == info)
                    {
                        found = true;
                    }
                }
                if (found == false)
                {
                    DeviceNoteService.delete_entry(_parser.DirPath, entry);
                }
            }
        }
コード例 #5
0
        public List <DeviceUserEntry> read_entries(string path)
        {
            string filePath = DeviceNoteService.get_file_path(path, false);

            if (filePath == null)
            {
                return(null);
            }

            String data;

            try
            {
                data = File.ReadAllText(filePath);
            }
            catch (Exception e)
            {
                if (e.GetType().IsAssignableFrom(typeof(System.IO.FileNotFoundException)))
                {
                    Console.WriteLine("No Entries found.");
                }
                else
                {
                    Console.WriteLine(e.ToString());
                }
                return(null);
            }

            var jsonListFile = JsonConvert.DeserializeObject <List <DeviceUserEntry> >(data);

            if (jsonListFile == null)
            {
                jsonListFile = new List <DeviceUserEntry>();
            }

            return(jsonListFile);
        }
コード例 #6
0
        public void get_file_path_test()
        {
            const string path = "./";

            Assert.AreEqual(DevicePathService.get_file(path).FullName + ".photon.json", DeviceNoteService.get_file_path(path, false));
        }
コード例 #7
0
 public void get_file_path_null_test()
 {
     Assert.AreEqual(null, DeviceNoteService.get_file_path(null, false));
 }