public BindingList<CurrentCaptureFile> CheckForNewFiles(string inputFilePath, string outputFilePath) { BindingList<CurrentCaptureFile> currentCaptureFiles = new BindingList<CurrentCaptureFile>(); FileInfo[] fi = null; string currentCaptureFileName = string.Empty; // Process the file ProcessCapturePackets pcp = new ProcessCapturePackets(); try { if (inputFilePath != "") { DirectoryInfo di = new DirectoryInfo(inputFilePath); fi = di.GetFiles(); foreach (var file in fi) { if (file.Name != "TestFile.txt") { pcp.ProcessPacketFile(file.Name); if (currentCaptureFileName != file.Name) { CurrentCaptureFile ccf = new CurrentCaptureFile(); ccf = pcp.GetCurrentCaptureFile(file.Name); currentCaptureFiles.Add(ccf); } } // Move the file to the done folder File.Move(inputFilePath + "\\" + file.Name, outputFilePath + "\\" + file.Name); } } } catch (Exception ex) { // Possible conflict with parse files service - ignore this error for now - we'll try // again in a few seconds } return currentCaptureFiles; }
public BatchStatistics CalculateBatchStatistics(BindingList<BatchIntervalMarked> batchIntervals, CaptureState captureState, BatchType batchType) { decimal batchIntervalsMean = 0; decimal batchIntervalsTrimmedMean = 0; // Trim zero packets from the batch interval BindingList<BatchIntervalMarked> batchIntervalsTrimmed = new BindingList<BatchIntervalMarked>(); foreach (BatchIntervalMarked bim in batchIntervals) { if (bim.PacketCount > AnalysisConfiguration.HistogramBinSize) { batchIntervalsTrimmed.Add(bim); } } // Calculate statistics for the batch BatchStatistics bs = new BatchStatistics(); if (AnalysisConfiguration.TrimSmallPackets) { BaseStatistics stats = new BaseStatistics(batchIntervalsTrimmed); bs.IntervalCountTrimmed = stats.Count; bs.PacketCountMaximum = stats.Maximum; bs.PacketCountMinimum = stats.Minimum; bs.PacketCountMean = stats.Mean; bs.PacketCountStandardDeviation = stats.StdDev; // Calculate both means for updating the capture batch intervals batchIntervalsTrimmedMean = stats.Mean; batchIntervalsMean = Convert.ToDecimal((from t in batchIntervals select t.PacketCount).Average()); // Get both counts for the batch bs.IntervalCountTrimmed = stats.Count < 0 ? 0 : stats.Count; bs.IntervalCount = batchIntervals.Count < 0 ? 0 : batchIntervals.Count; } else { BaseStatistics stats = new BaseStatistics(batchIntervals); bs.IntervalCount = stats.Count; bs.PacketCountMaximum = stats.Maximum; bs.PacketCountMinimum = stats.Minimum; bs.PacketCountMean = stats.Mean; bs.PacketCountStandardDeviation = stats.StdDev; // Calculate both means for updating the capture batch intervals batchIntervalsMean = bs.PacketCountMean; batchIntervalsTrimmedMean = Convert.ToDecimal((from t in batchIntervalsTrimmed select t.PacketCount).Average()); // Get both counts for the batch bs.IntervalCount = stats.Count < 0 ? 0 : stats.Count; bs.IntervalCountTrimmed = batchIntervalsTrimmed.Count < 0 ? 0 : batchIntervalsTrimmed.Count; } // Update the batch mean - only for single batches, not cumulative batches CurrentCaptureFile captureFile = new CurrentCaptureFile(); ProcessCapturePackets pcp = new ProcessCapturePackets(); captureFile = pcp.GetCurrentCaptureFile(_CaptureFileName); int captureBatchId = captureFile.CaptureBatchId; if (batchType == BatchType.Single && captureBatchId != 0) { try { //ProcessCapturePackets pcp = new ProcessCapturePackets(); //if (!pcp.UpdateBatchMean(Convert.ToInt32(captureBatchId), bs.PacketCountMean)) if (!pcp.UpdateBatchMean(Convert.ToInt32(captureBatchId), batchIntervalsMean, batchIntervalsTrimmedMean)) { throw new Exception("Error updating batch mean for CaptureBatchId " + captureBatchId); } } catch (Exception ex) { throw new Exception("Error updating batch mean for CaptureBatchId " + captureBatchId + ": " + ex.Message); } } // Save the statistics to the database for display on the Analysis tab (save to DisplayStatistics table) SaveDisplayStatistics(bs, captureBatchId, captureState, batchType, true); return bs; }
public void CalculateSingleHistogramData() { ProcessCapturePackets pcp = new ProcessCapturePackets(); BindingList<BatchIntervalMarked> batchIntervals = new BindingList<BatchIntervalMarked>(); // Get the batch intervals CurrentCaptureFile captureFile = new CurrentCaptureFile(); captureFile = pcp.GetCurrentCaptureFile(_CaptureFileName); batchIntervals = pcp.GetMarkedBatchIntervals(captureFile.CaptureBatchId); CalculateSingleHistogramProbability(batchIntervals, BatchType.Single, captureFile); //switch (_CaptureState) //{ // case CaptureState.Marked: // CalculateHistogramDataByType(batchIntervals, BatchType.Single, CaptureState.Marked); // break; // case CaptureState.Unmarked: // CalculateHistogramDataByType(batchIntervals, BatchType.Single, CaptureState.Unmarked); // break; //} }