Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            SetScanProperties();

            int numberOfFiles = DirectoryParser.GetAllFiles(Folder, Recursive).Count;

            backgroundWorker1.RunWorkerAsync(numberOfFiles);
        }
Exemplo n.º 2
0
        private void StartScanForms(DoWorkEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(Folder))
            {
                return;
            }

            Scan scan = new Scan
            {
                FilePath      = Folder,
                HashAlgorithm = Algorithm,
                Time          = DateTime.Now
            };

            try
            {
                scan.Insert();
            }
            catch (Exception ex)
            {
            }

            List <string> allFiles = DirectoryParser.GetAllFiles(Folder, Recursive);

            int nFiles = allFiles.Count;
            int i      = 0;

            foreach (string file in allFiles)
            {
                if (backgroundWorker1.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                else
                {
                    try
                    {
                        FileScan.ScanFile(file, scan);
                        int progress = (int)Math.Ceiling((double)i / nFiles) * 100;

                        backgroundWorker1.ReportProgress(progress, (object)file);
                        i++;
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static void StartScanConsole(string filePath, bool recursive, AvailableHashAlgorithms hashAlgorithm)
        {
            Scan scan = new Scan
            {
                FilePath      = filePath,
                HashAlgorithm = new FIMHashAlgorithm {
                    Id = (int)hashAlgorithm
                },
                Time = DateTime.Now
            };

            scan.Insert();

            //insert scan in database

            List <string> allFiles = DirectoryParser.GetAllFiles(filePath, recursive);

            int nFiles = allFiles.Count;
            int i      = 0;

            Console.WriteLine("Scanning ...");
            foreach (string file in allFiles)
            {
                try
                {
                    FileScan.ScanFile(file, scan);

                    Console.WriteLine(Math.Ceiling(((double)i / nFiles) * 100).ToString() + "%");
                    Console.SetCursorPosition(0, Console.CursorTop - 1);
                    System.Threading.Thread.Sleep(50);
                    i++;
                }
                catch (Exception ex)
                {
                    Logger.Log(ex.Message, LogType.Error);

                    continue;
                }
            }
        }
Exemplo n.º 4
0
        private void StartBackgroundScan()
        {
            int numberOfFiles = DirectoryParser.GetAllFiles(Folder, Recursive).Count;

            backgroundWorker1.RunWorkerAsync(numberOfFiles);
        }