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);
            }
        }
 public int GetProcessedFilesCountMarked()
 {
     int fileCount = 0;
     CaptureFileData cfd = new CaptureFileData();
     fileCount = cfd.GetProcessedFilesCountMarked();
     return fileCount;
 }
 public int GetMeanCount()
 {
     CaptureFileData cfd = new CaptureFileData();
     return cfd.GetMeanCount();
 }
 public decimal GetMean(CaptureState captureState, bool trimmed)
 {
     CaptureFileData cfd = new CaptureFileData();
     return cfd.GetMean(captureState, trimmed);
 }
        public BindingList<CurrentCaptureFile> GetLastCaptureBatchIds()
        {
            BindingList<CurrentCaptureFile> lastBatchIds = new BindingList<CurrentCaptureFile>();

            CaptureFileData cfd = new CaptureFileData();
            var batch = cfd.GetBatchIds();

            var lastMarkedBatchId = (from m in batch
                                     where m.CaptureState == CaptureState.Marked
                                     orderby m.CaptureBatchId descending
                                     select m).FirstOrDefault();

            var lastUnmarkedBatchId = (from m in batch
                                     where m.CaptureState == CaptureState.Unmarked
                                     orderby m.CaptureBatchId descending
                                       select m).FirstOrDefault();

            lastBatchIds.Add(lastMarkedBatchId);
            lastBatchIds.Add(lastUnmarkedBatchId);

            return lastBatchIds;
        }
 private int GetLastCaptureBatchId()
 {
     BindingList<CurrentCaptureFile> currentCaptureFiles = new BindingList<CurrentCaptureFile>();
     CaptureFileData cfd = new CaptureFileData();
     currentCaptureFiles = cfd.GetBatchIds();
     int lastBatchId = 0;
     foreach (var item in currentCaptureFiles)
     {
         if (item.CaptureBatchId > lastBatchId)
         {
             lastBatchId = item.CaptureBatchId;
         }
     }
     return lastBatchId;
 }
 public void TruncateAllTables()
 {
     CaptureFileData cfd = new CaptureFileData();
     cfd.TruncateAllTables();
 }
        public BindingList<CurrentCaptureFile> GetAllCaptureFiles()
        {
            BindingList<CurrentCaptureFile> files = new BindingList<CurrentCaptureFile>();

            CaptureFileData cfd = new CaptureFileData();
            files = cfd.GetAllFiles();
            return files;
        }
 public decimal CalculateStdDevForMeanOfMeans(CaptureState captureState, bool trimmed)
 {
     CaptureFileData cfd = new CaptureFileData();
     return cfd.CalculateStdDevForMeanOfMeans(captureState, trimmed);
 }
示例#11
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();
        }
示例#12
0
 private void UpdateCaptureBatchParseStatusForRecalculation(int captureBatchId)
 {
     CaptureFileData cfd = new CaptureFileData();
     cfd.UpdateCaptureBatchParseStatus(captureBatchId);
 }
示例#13
0
 private void UpdateCaptureBatchParseStatus()
 {
     CaptureFileData cfd = new CaptureFileData();
     cfd.UpdateCaptureBatchParseStatus(_CurrentCaptureBatchId);
 }
 public int GetRawFileCountUnmarked()
 {
     int fileCount = 0;
     CaptureFileData cfd = new CaptureFileData();
     fileCount = cfd.GetRawFileCountUnmarked();
     return fileCount;
 }
 public int GetCaptureBatchId(string fileName)
 {
     CaptureFileData cfd = new CaptureFileData();
     return cfd.GetBatchId(fileName);
 }
        public void ProcessPacketFile(string fileName)
        {
            BindingList<RawPacket> rawPackets = new BindingList<RawPacket>();
            BindingList<CapturePacket> capturePackets = new BindingList<CapturePacket>();

            try
            {
                ////using (var context = new PacketCaptureContext())
                //using (var context = new PacketAnalysisEntity())
                //{
                //var capturePackets = context.CapturePackets.ToList();
                //var batch = context.BatchIntervals.ToList();

                CaptureFileData cfd = new CaptureFileData();
                capturePackets = cfd.GetRawPacketData();

                //foreach (var pkt in capturePackets)
                //foreach (var pkt in context.CapturePackets)
                foreach (var pkt in capturePackets)
                {
                    RawPacket packet = new RawPacket();
                    packet.CapturePacketId = pkt.CapturePacketId;
                    //packet.FileName = pkt.FileName;
                    packet.PacketNumber = pkt.PacketNumber;
                    packet.TimeStamp = pkt.TimeStamp;
                    packet.Marked = pkt.Marked == true? CaptureState.Marked : CaptureState.Unmarked;
                    rawPackets.Add(packet);

                    _PacketCount = rawPackets.Count;
                }
                //}
                //_PacketCount = rawPackets.Count;
            }
            catch (Exception ex)
            {
                throw new Exception("Error processing packet file: " + ex.Message);
            }
        }
        public CurrentCaptureFile GetCurrentCaptureFile(string fileName)
        {
            CurrentCaptureFile ccf = null;

            try
            {
                CaptureFileData cfd = new CaptureFileData();
                ccf = cfd.GetCurrentCaptureFile(fileName);

                return ccf;
            }
            catch (Exception ex)
            {
                throw new Exception("Error retrieving current capture file information: " + ex.Message);
            }
        }
        public bool UpdateBatchMean(int captureBatchId, decimal mean, decimal trimmedMean)
        {
            bool result = false;

            CaptureFileData cfd = new CaptureFileData();
            result = cfd.UpdateBatchMean(captureBatchId, mean, trimmedMean);
            return result;
        }
 public int GetLastCaptureBatchId()
 {
     CaptureFileData cfd = new CaptureFileData();
     return cfd.GetLastBatchId();
 }
示例#20
0
        public bool CalculateSingleBatchStatistics()
        {
            bool result = false;

            // Calculate single batch statistics
            //// Get the last marked and unmarked batches and add them to the graph
            //int lastBatchId = 0;
            ProcessCapturePackets pcp = new ProcessCapturePackets();
            //lastBatchId = pcp.GetLastCaptureBatchId();
            CurrentCaptureFile captureFile = new CurrentCaptureFile();
            CaptureFileData cfd = new CaptureFileData();
            //captureFile = cfd.GetLastCaptureBatchRecord();
            captureFile = cfd.GetCurrentCaptureFile(_CaptureFileName);

            // Set the global variable
            _CaptureState = captureFile.CaptureState;

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

            // Calculate probabilities
            batchIntervals = pcp.GetMarkedBatchIntervals(captureFile.CaptureBatchId);
            int histogramBinSize = Convert.ToInt32(_HistogramBinSize);
            SortedDictionary<int, decimal> probabilities = new CalculateProbability(batchIntervals).GetProbabilityByPacketRange(_TrimZeroPacketIntervals, histogramBinSize);

            BatchStatistics markedSingleStats = new BatchStatistics();
            BatchStatistics unmarkedSingleStats = new BatchStatistics();

            // Add the results to the DisplayStatistics table
            DisplayStatisticsData dsd = new DisplayStatisticsData();
            if(captureFile.CaptureState == CaptureState.Marked)
            {
                markedSingleStats = CalculateBatchStatistics(batchIntervals, CaptureState.Marked, BatchType.Single);
            }
            else
            {
                unmarkedSingleStats = CalculateBatchStatistics(batchIntervals, CaptureState.Unmarked, BatchType.Single);
            }
            return result;
        }
示例#21
0
        public void RecalculateBatchIntervals()
        {
            // Recalculate intervals for all existing batch data using a new interval size

            // First delete all existing batch intervals and cumulative intervals
            BatchIntervalData bid = new BatchIntervalData();
            //bid.RemoveAllBatchIntervals();
            bid.TruncateAllIntervalStatisticAndTestTables();

            // Get a list of all capture files
            CaptureFileData cfd = new CaptureFileData();

            BindingList<CurrentCaptureFile> captureFiles = new BindingList<CurrentCaptureFile>();
            captureFiles = cfd.GetBatchIds();

            // Create new intervals for each capture file and update the cumulative intervals
            foreach (CurrentCaptureFile file in captureFiles)
            {
                BindingList<PacketInterval> intervals = new BindingList<PacketInterval>();
                intervals = CreateBatchIntervals(file.FileName);
                UpdateCumulativeIntervals(intervals);
                UpdateCaptureBatchParseStatusForRecalculation(file.CaptureBatchId);
            }
        }