AddRecord() public method

public AddRecord ( string volume, List r, MyEverythingRecordType type ) : void
volume string
r List
type MyEverythingRecordType
return void
示例#1
0
 private void ProcessFileCreate(PInvokeWin32.USN_RECORD usn, string volume, MyEverythingDB db)
 {
     MyEverythingRecord record = MyEverythingRecord.ParseUSN(usn);
     string fullpath = record.Name;
     db.FindRecordPath(record, ref fullpath, db.GetFolderSource(volume));
     record.FullPath = fullpath;
     db.AddRecord(volume, record, usn.IsFolder ? MyEverythingRecordType.Folder : MyEverythingRecordType.File);
     Debug.WriteLine(string.Format(">>>> NewFile: {0}", record.FullPath));
     if (RecordAddedEvent != null)
         RecordAddedEvent(record);
 }
示例#2
0
        private void ProcessFileCreate(PInvokeWin32.USN_RECORD usn, string volume, MyEverythingDB db)
        {
            MyEverythingRecord record   = MyEverythingRecord.ParseUSN(usn);
            string             fullpath = record.Name;

            db.FindRecordPath(record, ref fullpath, db.GetFolderSource(volume));
            record.FullPath = fullpath;
            db.AddRecord(volume, record, usn.IsFolder ? MyEverythingRecordType.Folder : MyEverythingRecordType.File);
            Debug.WriteLine(string.Format(">>>> NewFile: {0}", record.FullPath));
            if (RecordAddedEvent != null)
            {
                RecordAddedEvent(record);
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.Write("Volumes for Scan (eg: C: D: E:): ");
            List <string> volumes = Console.ReadLine().ToUpper().Split(new char[] { ' ' }).ToList();

            MyEverythingDB db = new MyEverythingDB();

            // ----------------遍历 mft,找到指定 volume 上的所有文件和文件夹----------------
            Console.WriteLine("Note: If this is your first time run, it will take some time to open the NTFS Journal System.");
            var enumFilesTimeStart = DateTime.Now;

            foreach (string volume in volumes)
            {
                List <MyEverythingRecord> files;
                List <MyEverythingRecord> folders;
                Console.WriteLine("Scanning {0}...", volume);
                EnumerateVolume(volume, out files, out folders);

                db.AddRecord(volume, files, MyEverythingRecordType.File);
                db.AddRecord(volume, folders, MyEverythingRecordType.Folder);
            }
            Console.WriteLine("{0}s file and {1} folder indexed, {2}ms has spent.",
                              db.FileCount, db.FolderCount, DateTime.Now.Subtract(enumFilesTimeStart).TotalMilliseconds);
            // -----------------------------------------------------------------------------



            // ---------------------------命令模式------------------------------
            Console.WriteLine("\nMyEverything version 0.0.1");
            Console.WriteLine("Type ? for help.");
            while (true)
            {
                Console.Write("MyEverything> ");
                string[] cmd = Console.ReadLine().Split(' ');
                long     fileFoundCnt;
                long     folderFoundCnt;
                List <MyEverythingRecord> found;

                switch (cmd[0].ToLower())
                {
                case "s":
                    if (!string.IsNullOrEmpty(cmd[1]))
                    {
                        var searchtimestart = DateTime.Now;
                        found = db.FindByName(cmd[1], out fileFoundCnt, out folderFoundCnt);
                        found.ForEach(x => FillPath(x.VolumeName, x, db));
                        var searchtimeend = DateTime.Now;
                        if (cmd.Length == 3 && !string.IsNullOrEmpty(cmd[2]))
                        {
                            using (StreamWriter sw = new StreamWriter(cmd[2], false)) {
                                found.ForEach(x => sw.WriteLine(string.IsNullOrEmpty(x.FullPath) ? x.Name : x.FullPath));
                            }
                            Console.WriteLine("{0} has written.", cmd[2]);
                        }
                        else
                        {
                            found.ForEach(x => Console.WriteLine(string.IsNullOrEmpty(x.FullPath) ? x.Name : x.FullPath));
                        }
                        Console.WriteLine("{0}s file and {1}s folder matched, {2}ms has spent.",
                                          fileFoundCnt, folderFoundCnt, searchtimeend.Subtract(searchtimestart).TotalMilliseconds);
                    }
                    break;

                case "?":
                    Console.WriteLine("s filename [logfile]\tSearch files and folders, \n\t\t\tif logfile specified, the result \n\t\t\twill be written to the logfile, \n\t\t\teg: s .txt");
                    Console.WriteLine("mo volume [debug]\tMonitor the volume, eg: mo E: debug\n\t\t\tIf debug param is specified, some debug msg\n\t\t\twill be print to screen.\n\t\t\tNote: multiple volume monitor is not stable now.");
                    Console.WriteLine("x\t\t\tExit this app.");
                    break;

                case "x":
                    Environment.Exit(0);
                    break;

                case "mo":
                    bool          pridebug = (cmd.Length == 3) && (cmd[2] == "debug");
                    VolumeMonitor monitor  = new VolumeMonitor();
                    monitor.RecordAddedEvent += delegate(MyEverythingRecord record) {
                        if (pridebug)
                        {
                            Console.WriteLine(">>>> New file {0} added.", record.FullPath);
                        }
                    };
                    monitor.RecordDeletedEvent += delegate(MyEverythingRecord record) {
                        if (pridebug)
                        {
                            Console.WriteLine(">>>> File {0} deleted.", record.FullPath);
                        }
                    };
                    monitor.RecordRenameEvent += delegate(MyEverythingRecord oldRecord, MyEverythingRecord newRecord) {
                        if (pridebug)
                        {
                            Console.WriteLine(">>>> File {0} renamed to {1}.", oldRecord.FullPath, newRecord.FullPath);
                        }
                    };
                    monitor.Monitor(cmd[1].ToUpper().Split(' ').ToList(), db);
                    Console.WriteLine("Moniting on {0}......", cmd[1].ToUpper());
                    break;
                }
            }
        }
        static void Main(string[] args)
        {
            Console.Write("Volumes for Scan (eg: C: D: E:): ");
            List<string> volumes = Console.ReadLine().ToUpper().Split(new char[] {' '}).ToList();

            MyEverythingDB db = new MyEverythingDB();

            // ----------------遍历 mft,找到指定 volume 上的所有文件和文件夹----------------
            Console.WriteLine("Note: If this is your first time run, it will take some time to open the NTFS Journal System.");
            var enumFilesTimeStart = DateTime.Now;
            foreach (string volume in volumes) {
                List<MyEverythingRecord> files;
                List<MyEverythingRecord> folders;
                Console.WriteLine("Scanning {0}...", volume);
                EnumerateVolume(volume, out files, out folders);

                db.AddRecord(volume, files, MyEverythingRecordType.File);
                db.AddRecord(volume, folders, MyEverythingRecordType.Folder);

            }
            Console.WriteLine("{0}s file and {1} folder indexed, {2}ms has spent.",
                db.FileCount, db.FolderCount, DateTime.Now.Subtract(enumFilesTimeStart).TotalMilliseconds);
            // -----------------------------------------------------------------------------

            // ---------------------------命令模式------------------------------
            Console.WriteLine("\nMyEverything version 0.0.1");
            Console.WriteLine("Type ? for help.");
            while (true) {
                Console.Write("MyEverything> ");
                string[] cmd = Console.ReadLine().Split(' ');
                long fileFoundCnt;
                long folderFoundCnt;
                List<MyEverythingRecord> found;

                switch (cmd[0].ToLower()) {
                    case "s":
                        if (!string.IsNullOrEmpty(cmd[1])) {
                            var searchtimestart = DateTime.Now;
                            found = db.FindByName(cmd[1], out fileFoundCnt, out folderFoundCnt);
                            found.ForEach(x => FillPath(x.VolumeName, x, db));
                            var searchtimeend = DateTime.Now;
                            if (cmd.Length == 3 && !string.IsNullOrEmpty(cmd[2])) {
                                using (StreamWriter sw = new StreamWriter(cmd[2], false)) {
                                    found.ForEach(x => sw.WriteLine(string.IsNullOrEmpty(x.FullPath) ? x.Name : x.FullPath));
                                }
                                Console.WriteLine("{0} has written.", cmd[2]);
                            } else {
                                found.ForEach(x => Console.WriteLine(string.IsNullOrEmpty(x.FullPath) ? x.Name : x.FullPath));
                            }
                            Console.WriteLine("{0}s file and {1}s folder matched, {2}ms has spent.",
                                fileFoundCnt, folderFoundCnt, searchtimeend.Subtract(searchtimestart).TotalMilliseconds);
                        }
                        break;
                    case "?":
                        Console.WriteLine("s filename [logfile]\tSearch files and folders, \n\t\t\tif logfile specified, the result \n\t\t\twill be written to the logfile, \n\t\t\teg: s .txt");
                        Console.WriteLine("mo volume [debug]\tMonitor the volume, eg: mo E: debug\n\t\t\tIf debug param is specified, some debug msg\n\t\t\twill be print to screen.\n\t\t\tNote: multiple volume monitor is not stable now.");
                        Console.WriteLine("x\t\t\tExit this app.");
                        break;
                    case "x":
                        Environment.Exit(0);
                        break;
                    case "mo":
                        bool pridebug = (cmd.Length == 3) && (cmd[2] == "debug");
                        VolumeMonitor monitor = new VolumeMonitor();
                        monitor.RecordAddedEvent += delegate(MyEverythingRecord record) {
                            if (pridebug) Console.WriteLine(">>>> New file {0} added.", record.FullPath);
                        };
                        monitor.RecordDeletedEvent += delegate(MyEverythingRecord record) {
                            if (pridebug) Console.WriteLine(">>>> File {0} deleted.", record.FullPath);
                        };
                        monitor.RecordRenameEvent += delegate(MyEverythingRecord oldRecord, MyEverythingRecord newRecord) {
                            if (pridebug) Console.WriteLine(">>>> File {0} renamed to {1}.", oldRecord.FullPath, newRecord.FullPath);
                        };
                        monitor.Monitor(cmd[1].ToUpper().Split(' ').ToList(), db);
                        Console.WriteLine("Moniting on {0}......", cmd[1].ToUpper());
                        break;
                }
            }
        }