Beispiel #1
0
        private void OfflineDetectionThread()
        {
            string traceFile = null;

            try
            {
                traceFile = _openOfflineDetectionDlg.FileName;
                if (File.Exists(traceFile) == false)
                {
                    throw new FileNotFoundException("Trace file " + traceFile + " doesn't exist.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            _flowFeatureProducerConsumer = new ProducerConsumer <FlowFeature>(consumeFeature, false, true, true);
            _parser = new NMParser(traceFile, _malFlowDetector.TimeWindow, _flowFeatureProducerConsumer);
            System.Diagnostics.Debug.WriteLine("Created new parser");

            //Get all the flows from the trace file
            System.Diagnostics.Debug.WriteLine("Extracting features from tracefile");
            _featureProducer = new Thread(new ThreadStart(_parser.EnqueueNetworkFlowFeatures));

            ///// inja print konnnnnnnnnnnnnnnnnnnnnnnnnn

            _featureProducer.Start();
            _featureProducer.Join();

            menuOfflineDetection.Text = "Start Offline Detection";
            _parser = null;
            _flowFeatureProducerConsumer.Stop();
            _featureProducer.Abort();
            _featureProducer             = null;
            _flowFeatureProducerConsumer = null;

            if (traceFile != null)
            {
                MessageBox.Show("Finished Processing " + traceFile + " trace file...");
            }
        }
Beispiel #2
0
        private ContextMenu CreateContextMenu()
        {
            List <MenuItem> items = new List <MenuItem>();

            //add context menu items here.
            MenuItem miLastError = new MenuItem("Display Last Error");

            miLastError.Click += new EventHandler(
                (o, e) =>
            {
                MessageBox.Show(
                    string.IsNullOrEmpty(_lastErrorMsg) ? "There is no error message."
                        : _lastErrorMsg
                    , "Last Error Message", MessageBoxButtons.OK);
            }
                );
            items.Add(miLastError);

            // Change Decision Tree Signature menu item
            // this can be done through the xml configuration file

            /*
             * MenuItem miChangeSignature = new MenuItem("Change Detection Signature");
             * miChangeSignature.Click += new EventHandler(OnChangeSignatureFile);
             * items.Add(miChangeSignature);
             */

            // Training Signature menu item
            menuTraining        = new MenuItem();
            menuTraining.Text   = Properties.Resources.StartTrainingText;
            menuTraining.Click += new EventHandler(
                (o, e) =>
            {
                if (menuTraining.Text.Equals(Properties.Resources.CancelTrainingText) &&
                    _trainingThread.ThreadState == System.Threading.ThreadState.Running)
                {
                    _trainingThread.Abort();
                    menuTraining.Text = Properties.Resources.StartTrainingText;
                    _trainingThread   = null;
                    return;
                }

                if (_openTrainingSetDlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                if (_trainingThread == null ||
                    _trainingThread.ThreadState == System.Threading.ThreadState.Stopped)
                {
                    _trainingThread = new Thread(new ThreadStart(this.TrainingThread));
                    _trainingThread.SetApartmentState(ApartmentState.STA);
                    _trainingThread.Name = "Training Thread";
                    _trainingThread.Start();

                    menuTraining.Text = Properties.Resources.CancelTrainingText;
                }

                /*
                 * else if (_trainingThread.ThreadState == System.Threading.ThreadState.Running)
                 * {
                 *  _trainingThread.Abort();
                 *  menuTraining.Text = Properties.Resources.StartTrainingText;
                 * }
                 * */
            });
            items.Add(menuTraining);

            // Display CPU usage menu item
            MenuItem menuCpuUsage = new MenuItem("CPU Usage");

            menuCpuUsage.Click += new EventHandler(
                (o, e) =>
            {
                if (_notifyIcon != null)
                {
                    _notifyIcon.BalloonTipText = "CPU: " + CpuUsage().ToString("P1");
                    _notifyIcon.ShowBalloonTip(1000);
                }
            });
            items.Add(menuCpuUsage);

            /*
             * // System setting menu item
             * MenuItem miServerSetting = new MenuItem();
             * miServerSetting.Text = Properties.Resources.ServerSettingText;
             * miServerSetting.Click += new EventHandler(
             *  (o, e) =>
             *  {
             *      // TODO: Implement the Server menu setting
             *
             *  }
             *  );
             * items.Add(miServerSetting);
             */

            // Offline Detection Menu Item
            menuOfflineDetection        = new MenuItem("Start Offline Detection");
            menuOfflineDetection.Click += new EventHandler(
                (o, e) =>
            {
                if (menuOfflineDetection.Text.Equals("Stop Offline Detection") &&
                    _offlineDetectionThread.ThreadState == System.Threading.ThreadState.WaitSleepJoin)
                {
                    _offlineDetectionThread.Abort();
                    _offlineDetectionThread   = null;
                    menuOfflineDetection.Text = "Start Offline Detectiont";

                    _featureProducer.Abort();
                    _featureProducer = null;
                    _flowFeatureProducerConsumer.Stop();
                    _flowFeatureProducerConsumer = null;
                    _parser = null;

                    return;
                }

                if (_openOfflineDetectionDlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                if (_offlineDetectionThread == null ||
                    _offlineDetectionThread.ThreadState == System.Threading.ThreadState.Stopped)
                {
                    _offlineDetectionThread = new Thread(new ThreadStart(this.OfflineDetectionThread));
                    _offlineDetectionThread.SetApartmentState(ApartmentState.STA);
                    _offlineDetectionThread.Name = "Offline Detection Thread";
                    _offlineDetectionThread.Start();

                    menuOfflineDetection.Text = "Stop Offline Detection";
                }

                /*
                 * else if (_offlineDetectionThread.ThreadState == System.Threading.ThreadState.Running)
                 * {
                 *  _offlineDetectionThread.Interrupt();
                 *
                 *  menuOfflineDetection.Text = "Start Offline Detectiont";
                 * }
                 */
            });
            items.Add(menuOfflineDetection);

            // About dialog menu
            MenuItem menuAbout = new MenuItem("About");

            menuAbout.Click += new EventHandler(
                (o, e) =>
            {
                MessageBox.Show("Network Flow Detector Server application. Version: "
                                + Properties.Settings.Default.Version,
                                "About",
                                MessageBoxButtons.OK);
            }
                );
            items.Add(menuAbout);

            // Exit menu item
            MenuItem menuExit = new MenuItem("E&xit");

            menuExit.Click += new EventHandler(MenuExit_Click);
            items.Add(menuExit);

            return(new ContextMenu(items.ToArray()));
        }