Пример #1
0
        public void Start()
        {
            IsRunning = true;

            FileInfo[] fi = null;

            while (IsRunning)
            {
                try
                {
                    if (_processedFilesPath != "")
                    {
                        CaptureFileData cfd = new CaptureFileData();

                        DirectoryInfo di = new DirectoryInfo(_processedFilesPath);
                        fi = di.GetFiles("*.pcap");
                        if (fi.Length > 0)
                        {
                            foreach (var file in fi)
                            {
                                if (!updatedFiles.ContainsKey(file.Name))
                                {
                                    int batchId = cfd.GetBatchId(file.Name);
                                    if (batchId > 0)
                                    {
                                        cfd.UpdateCaptureBatchParseStatus(batchId);
                                        updatedFiles.Add(file.Name, batchId);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Thread.Sleep(3000);
                    }
                }
                catch (Exception ex)
                {
                    // Ignore file not found errors
                    //throw new Exception("ParsedFileNotifier unable to find parsed pcap files: " + ex.Message);
                }
            }
        }
        public void ProcessFiles()
        {
            IsRunning = true;

            while (IsRunning)
            {
                List<CurrentCaptureFile> files = new List<CurrentCaptureFile>();

                while (FileQueue.Count > 0)
                {
                    CurrentCaptureFile file = FileQueue.Dequeue();
                    files.Add(file);
                }

                CaptureFileData cfd = new CaptureFileData();

                foreach(CurrentCaptureFile file in files)
                {
                    file.CaptureBatchId = cfd.GetBatchId(file.FileName);
                    if (cfd.GetParsedFileStatus(file.CaptureBatchId))
                    {
                        BatchIntervalEngine intervalEngine = new BatchIntervalEngine(DatabaseConnections.SqlConnection, AnalysisConfiguration.ProcessedCaptureFilesPath, file.FileName, 5, AnalysisConfiguration.IntervalSize);
                        intervalEngine.ProcessNewBatchIntervals();
                        CreateAnalysisData(file);
                        intervalEngine = null;
                    }
                    else
                    {
                        FileQueue.Enqueue(file);
                    }
                }

                if(files.Count > 0)
                {
                    files.Clear();
                }
                Thread.Sleep(3000);
            }
        }
Пример #3
0
 public int GetCaptureBatchId(string fileName)
 {
     CaptureFileData cfd = new CaptureFileData();
     return cfd.GetBatchId(fileName);
 }
Пример #4
0
        public void ProcessNewBatchIntervals()
        {
            // Create new batch intervals from parsed capture data and add new intervals to cumulative intervals

            //// Wait for capture file to be parsed by ParseCaptureFilesService service
            //int waitSeconds = 0;

            CaptureFileData cfd = new CaptureFileData();
            _CurrentCaptureBatchId = cfd.GetBatchId(_CaptureFileName);

            //while (waitSeconds < _WaitSecondsLimit)
            //{
            //    if (File.Exists(_ProcessedCaptureFilesPath + "\\" + _CaptureFileName))
            //    {
                    //ClientStatusToolStripStatusLabel.Visible = true;
                    //ClientStatusToolStripProgressBar.Visible = true;
                    //ClientStatusToolStripStatusLabel.Text = "Loading capture packets into data store for file [" + file.FileName + "]...";

                    //FileQueue.Dequeue();

                    BindingList<PacketInterval> batchIntervals = new BindingList<PacketInterval>();

                    batchIntervals = CreateBatchIntervals(_CaptureFileName);
                    UpdateCumulativeIntervals(batchIntervals);
                    //UpdateCaptureBatchParseStatus();
            //        break;
            //    }
            //    else
            //    {
            //        Thread.Sleep(1000);
            //        waitSeconds++;
            //    }
            //}

            //bool parsedStatus = cfd.GetParsedFileStatus(_CurrentCaptureBatchId);

            //while (!parsedStatus)
            //{
            //    Thread.Sleep(2000);
            //    parsedStatus = cfd.GetParsedFileStatus(_CurrentCaptureBatchId);

            //    if (waitSeconds == _WaitSecondsLimit)
            //    {
            //        throw new Exception("BatchIntervalEngine error: time expired - cannot find parsed capture file!");
            //    }
            //}
            //BindingList<PacketInterval> batchIntervals = new BindingList<PacketInterval>();

            //batchIntervals = CreateBatchIntervals(_CaptureFileName);
            //UpdateCumulativeIntervals(batchIntervals);
            ////UpdateCaptureBatchParseStatus();
            //FileQueue.Dequeue();
        }