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); } }
private void ProcessCaptureDataButton_Click(object sender, EventArgs e) { // For testing - code to be moved to background worker thread // For production: use the OnFileReceived event handler to notify the BatchIntervalEngine that a new file has been received // For testing: BindingList<CurrentCaptureFile> _CurrentCaptureFiles = new BindingList<CurrentCaptureFile>(); CurrentCaptureFile ccf = new CurrentCaptureFile("CaptureFile635674934252530702u.pcap", CaptureState.Unmarked); CurrentCaptureFile ccf1 = new CurrentCaptureFile("CaptureFile635674934452612146d.pcap", CaptureState.Marked); CurrentCaptureFile ccf2 = new CurrentCaptureFile("CaptureFile635674934652743658u.pcap", CaptureState.Unmarked); CurrentCaptureFile ccf3 = new CurrentCaptureFile("CaptureFile635674934852905142d.pcap", CaptureState.Marked); _CurrentCaptureFiles.Add(ccf); _CurrentCaptureFiles.Add(ccf1); _CurrentCaptureFiles.Add(ccf2); _CurrentCaptureFiles.Add(ccf3); if (_CurrentCaptureFiles.Count > 0) { foreach (CurrentCaptureFile file in _CurrentCaptureFiles) { string captureFileName = file.FileName; //BatchIntervalEngine biEngine = new BatchIntervalEngine(DbConnectionString, _ParsedFilesPath, _CurrentCaptureFileName, 5, InterarrivalInterval.GetIntervalMilliSeconds()); //string captureFileName = "CaptureFile635674934252530702u.pcap"; BatchIntervalEngine biEngine = new BatchIntervalEngine(DbConnectionString, _ParsedFilesPath, captureFileName, 5, InterarrivalInterval.GetIntervalMilliSeconds()); biEngine.ProcessNewBatchIntervals(); //AnalysisEngine analysisEngine = new AnalysisEngine(AnalysisConfiguration.TrimSmallPackets, AnalysisConfiguration.HistogramBinSize, AnalysisConfiguration.HypothesisTest, captureFileName, file.CaptureState); AnalysisEngine analysisEngine = new AnalysisEngine(AnalysisConfiguration.TrimSmallPackets, AnalysisConfiguration.HistogramBinSize, AnalysisConfiguration.HypothesisTestType, file); analysisEngine.CalculateSingleBatchStatistics(); analysisEngine.CalculateCumulativeBatchStatistics(); analysisEngine.CalculateSingleHistogramData(); analysisEngine.CalculateCumulativeHistogramData(); analysisEngine.CalculateCumulativeProbabilityDistribution(file.CaptureState); analysisEngine.CalculateHypothesisTestResults(); biEngine = null; analysisEngine = null; } } /******************************** Old code ********************************************/ //DisplayStatisticsData bsd = new DisplayStatisticsData(); //BindingList<DisplayStatistic> ds = new BindingList<DisplayStatistic>(); //ds = bsd.GetSingleMarkedDisplayStatistics(); //bool success = false; ////int intervalSizeMs = 30 ; //int intervalSizeMs = InterarrivalInterval.GetIntervalMilliSeconds(); //// For testing: //BindingList<CurrentCaptureFile> _CurrentCaptureFiles = new BindingList<CurrentCaptureFile>(); //CurrentCaptureFile ccf = new CurrentCaptureFile("CaptureFile635674934252530702u.pcap", CaptureState.Unmarked); //CurrentCaptureFile ccf1 = new CurrentCaptureFile("CaptureFile635674934452612146d.pcap", CaptureState.Marked); //CurrentCaptureFile ccf2 = new CurrentCaptureFile("CaptureFile635674934652743658u.pcap", CaptureState.Unmarked); //CurrentCaptureFile ccf3 = new CurrentCaptureFile("CaptureFile635674934852905142d.pcap", CaptureState.Marked); //_CurrentCaptureFiles.Add(ccf); //_CurrentCaptureFiles.Add(ccf1); //_CurrentCaptureFiles.Add(ccf2); //_CurrentCaptureFiles.Add(ccf3); //if (_CurrentCaptureFiles.Count > 0) //{ // foreach (CurrentCaptureFile file in _CurrentCaptureFiles) // { // BindingList<RawPacket> rawPackets = new BindingList<RawPacket>(); // BindingList<PacketInterval> intervalCounts = new BindingList<PacketInterval>(); // //int captureBatchId = 0; // ProcessCapturePackets pcp = new ProcessCapturePackets(); // ClientStatusToolStripStatusLabel.Visible = true; // ClientStatusToolStripProgressBar.Visible = true; // ClientStatusToolStripStatusLabel.Text = "Loading capture packets into data store for file [" + file.FileName + "]..."; // try // { // rawPackets = pcp.LoadPackets(file.FileName); // if (rawPackets.Count > 0) { success = true; } // } // catch (Exception ex) // { // MessageBox.Show("Error loading raw packet data for file [" + file.FileName + "]: " + ex.Message, "Process Capture Packets - Load Packets"); // } // try // { // if (success) // { // intervalCounts = pcp.CalculateIntervalCounts(rawPackets, intervalSizeMs); // } // } // catch (Exception ex) // { // success = false; // MessageBox.Show("Error calculating interval counts for file [" + file.FileName + "]: " + ex.Message, "Process Capture Packets - Calculate Interval Counts"); // } // // Load the batch intervals into the database // if (success) // { // try // { // //success = pcp.SaveBatchIntervals(DbConnectionString, intervalCounts, file.FileName, captureBatchId, file.Marked); // success = pcp.SaveBatchIntervals(DbConnectionString, intervalCounts); // } // catch (Exception ex) // { // success = false; // MessageBox.Show("Error saving batch interval counts: " + ex.Message, "Save Batch Intervals"); // } // } // // Add batch to cumulative totals // if(success) // { // try // { // //success = pcp.UpdateCumulativeIntervals(DbConnectionString, intervalCounts, file.Marked); // success = pcp.UpdateCumulativeIntervals(DbConnectionString, intervalCounts); // } // catch (Exception ex) // { // success = false; // MessageBox.Show("Error updating cumulative intervals for this file [" + file.FileName + "]: " + ex.Message); // } // } // BindingList<BatchIntervalMarked> markedIntervals = new BindingList<BatchIntervalMarked>(); // var captureBatchId = (from i in intervalCounts // select i.CaptureBatchId).FirstOrDefault(); // markedIntervals = pcp.GetMarkedBatchIntervals(captureBatchId); // //AnalyzeData ad = new AnalyzeData(markedIntervals); // CalculateHistogram h = new CalculateHistogram(); // Dictionary<int, int> histValues = new Dictionary<int, int>(); // //histValues = h.CalculateHistogramValues(markedIntervals); // BindingList<CapturePacket> capturePackets = new BindingList<CapturePacket>(); // capturePackets = pcp.GetCapturePackets(file.FileName); // histValues = h.CalculateHistogramValues(capturePackets); // //Dictionary<int, decimal> probabilities = new CalculateProbability(histValues).GetProbabilityValues(); // //SortedDictionary<int, decimal> probabilities = new CalculateProbability(markedIntervals).GetProbabilityByPacketRange(); // // Display the batch in the graph: // // - One batch each of marked and unmarked - alternate as a new batch becomes available // // - One batch each of cumulative marked and unmarked - alternate as a new batch becomes available // // - Add to cumulative distribution and display // } //} //else //{ // MessageBox.Show("No capture files found to process!", "Process Capture Files"); //} }