Пример #1
0
        private void FileProcessing_Load(object sender, EventArgs e)
        {
            // Load the FileManagers
            smgr.ImportFileReaders();
            if (smgr.FileReaders.Count() == 0)
            {
                MessageBox.Show("No file readers found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Load the Scan engine and the patterns
            if (scanEngine.LoadPatterns() == 0)
            {
                MessageBox.Show("No patterns found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Пример #2
0
        private async void BtnStart_Click(object sender, EventArgs e)
        {
            // Load the FileManagers
            var smgr = new SearchManager();

            smgr.ImportFileReaders();
            if (smgr.FileReaders.Count() == 0)
            {
                MessageBox.Show("No file readers found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Load the Scan engine and the patterns
            var s = new Scanner.ScanEngine();

            if (s.LoadPatterns() == 0)
            {
                MessageBox.Show("No patterns found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            btnStart.Enabled = false;
            btnClear.Enabled = false;
            foreach (ListViewItem i in lstBatch.Items)
            {
                if (i.SubItems[ListItemIdxStatus].Text == Waiting)
                {
                    var dir = i.SubItems[ListItemIdxDirectory].Text;

                    var outFile = dir + ".csv";
                    try
                    {
                        if (File.Exists(outFile))
                        {
                            File.Delete(outFile);
                        }
                    }
                    catch (Exception)
                    {
                        outFile = string.Format($"{dir} {DateTime.Now.Ticks}.csv");
                    }
                    string errFile = dir + ".err";
                    try
                    {
                        if (File.Exists(errFile))
                        {
                            File.Delete(errFile);
                        }
                    }
                    catch (Exception)
                    {
                        errFile = string.Format($"{dir} {DateTime.Now.Ticks}.err");
                    }

                    bool imageScan = (bool)i.SubItems[ListItemIdxImageScan].Tag;

                    // Load the files to be processed
                    var files = Directory.GetFiles(dir);
                    if (files.Length == 0)
                    {
                        File.AppendAllText(errFile, "No files found\n");
                    }

                    i.SubItems[ListItemIdxStatus].Text = "Processing";
                    await Task.Run(() => { ProcessDirectories(smgr, s, outFile, errFile, imageScan, files); });

                    i.SubItems[ListItemIdxStatus].Text = Processed;
                    i.Tag = outFile;
                }
            }
            btnClear.Enabled = true;
        }