Beispiel #1
0
        //This event manage the change value of the DM_slider, to change the view of the DM_graph
        private void DM_slider_ValueChanged_Event(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (e.NewValue.Equals(e.OldValue))
            {
                return;
            }

            //Here I update the view of the DM_graph
            try
            {
                DateTime dateOfInterest = Statistic_Auxiliary.Translate_Slider_Value(DM_slider.Value, activity_timeline);

                //Update the labels of the time
                this.DM_date.Text = dateOfInterest.ToString();

                //Clear the 2 list of positions
                devices_position.Clear();
                DM_positions.Values.Clear();

                //Re-update the list of values  and the graph
                devices_position        = dataCaching.LastPosition_List(dateOfInterest);
                DM_numberOfDevices.Text = devices_position.Count.ToString();
                foreach (Position p in devices_position)
                {
                    DM_positions.Values.Add(new ObservablePoint(p.Coordinates.X, p.Coordinates.Y));
                }
            }
            catch (System.Data.Entity.Core.ProviderIncompatibleException dex)
            {
                Console.WriteLine(dex.StackTrace);
                Console.WriteLine(dex.Message);
                Handle_DB_Error();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);

                Synchronizer.StopEngine(configuration);
                if (Features.openedWindow.Equals(Features.Window_type.Statistic))
                {
                    this.BackToMain();
                }
            }

            //Here I update the real time variable to understand if I'm or not in real time mode
            if (DM_slider.Value == DM_slider.Maximum)
            {
                DM_realtime = true;
            }
            else
            {
                DM_realtime = false;
            }

            return;
        }
Beispiel #2
0
        //This event manage the change value of th lower and higher value of the FM_rangeSlider, to change the view of the FM_graph
        private void FM_rangeSlider_ValueChanged_Event(object sender, RoutedEventArgs e)
        {
            try
            {
                DateTime min = Statistic_Auxiliary.Translate_Slider_Value(FM_rangeSlider.LowerValue, activity_timeline);
                DateTime max = Statistic_Auxiliary.Translate_Slider_Value(FM_rangeSlider.HigherValue, activity_timeline);

                //Updated the date labels
                this.FM_date_start.Text = min.ToString();
                this.FM_date_end.Text   = max.ToString();

                //Set the mouse in a wait statud
                FM_rangeSlider.IsEnabled = false;
                Mouse.OverrideCursor     = Cursors.Wait;

                //Updating the number of continuative presence
                String display_value = Device.ContinuativeDevices_Count(configuration, min, max.Subtract(min)).ToString();
                FM_numberContinuativePresence.Text = display_value;

                //Retriving the new list of MACs to display
                frequentMACs = Statistic_Auxiliary.RetriveNewFrequentMACs(frequentMACs, configuration, min, max.Subtract(min));

                //Updating the FM_graph
                Statistic_Auxiliary.DisplayNewFrequentMACs(this, frequentMACs);

                //Updating the min and max values of the x axis of FM graph
                FM_Map.AxisX[0].MaxValue = max.Ticks + 30000;
                FM_Map.AxisX[0].MinValue = min.Ticks - 30000;

                //Turn back to the normal status of the mouse
                Mouse.OverrideCursor     = null;
                FM_rangeSlider.IsEnabled = true;
            }
            catch (System.Data.Entity.Core.ProviderIncompatibleException dex)
            {
                Console.WriteLine(dex.StackTrace);
                Console.WriteLine(dex.Message);

                Handle_DB_Error();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);

                Synchronizer.StopEngine(configuration);
                if (Features.openedWindow.Equals(Features.Window_type.Statistic))
                {
                    this.BackToMain();
                }
            }

            return;
        }
Beispiel #3
0
        //This method manage the event raised if the user move the higher thumb of the CoT range slider
        private void CoT_RangeSlider_ValueChanged_Event(object sender, RoutedEventArgs e)
        {
            //Here I update the axis max values
            try
            {
                Statistic_Auxiliary.UpdateCoTAxisConfiguration(this, activity_timeline);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);

                Synchronizer.StopEngine(configuration);
                if (Features.openedWindow.Equals(Features.Window_type.Statistic))
                {
                    this.BackToMain();
                }
            }

            //Here I compute the last activity range
            KeyValuePair <DateTime, TimeSpan> lastActivityRange = activity_timeline.OrderByDescending(t => t.Key).First();

            //Here I check the usability or not of the radio button
            if (CoT_rangeSlider.HigherValue == CoT_rangeSlider.Maximum)
            {
                double lowerValue_realTime;
                if (lastActivityRange.Value.TotalSeconds < Features.MaxMinDifferenceRange)
                {
                    lowerValue_realTime = activity_timeline.Values.Sum(cot => cot.TotalSeconds) - lastActivityRange.Value.TotalSeconds;
                }
                else
                {
                    lowerValue_realTime = activity_timeline.Values.Sum(cot => cot.TotalSeconds) - Features.MaxMinDifferenceRange;
                }

                if (CoT_rangeSlider.LowerValue >= lowerValue_realTime - 20)
                {
                    CoT_realtime = true;
                }
                else
                {
                    CoT_realtime = false;
                }
            }
            else
            {
                CoT_realtime = false;
            }

            return;
        }
Beispiel #4
0
        //This method handle the click event on the Restart Detection button
        private void Restart_Detection_Button_Click(object sender, RoutedEventArgs e)
        {
            //Critical Section that have to be executed atomically
            lock (_lockObject)
            {
                try
                {
                    //Stopping the timer needed to understand if we are in presence of timeout
                    timeout.Stop();
                    timeout.Tick -= Timeout_handler;

                    //Instantly re-starting the execution of the C++ code
                    Synchronizer.StartEngine(configuration, Handle_Cpp_Error);

                    //Change the button visibility in the window
                    this.restart_detection_button.Visibility = Visibility.Hidden;
                    this.stop_detection_button.Visibility    = Visibility.Visible;
                    no_detection                     = false;
                    detection_mode                   = Features.Detection_Status.Running;
                    this.detection_status.Text       = detection_mode.ToString();
                    this.detection_status.Foreground = Brushes.Green;

                    //Update the activity timeline dictionary
                    activity_timeline = Log.GetEngineActivityTimeline(configuration, true);

                    //Update the maximum of all the sliders
                    double max = activity_timeline.Sum(t => t.Value.TotalSeconds);
                    DM_slider.Maximum       = max;
                    CoT_rangeSlider.Maximum = max;
                    FM_rangeSlider.Maximum  = max;

                    //Updating the tick frequency of the sliders
                    DM_slider.TickFrequency       = Features.percentageUpgradeSteps * DM_slider.Maximum;
                    CoT_rangeSlider.TickFrequency = Features.percentageUpgradeSteps * CoT_rangeSlider.Maximum;
                    FM_rangeSlider.TickFrequency  = Features.percentageUpgradeSteps * FM_rangeSlider.Maximum;

                    //Here I update the splitters
                    Statistic_Auxiliary.SplittersDisplay(this, activity_timeline);

                    //Check if I have to update the graphs
                    if (DM_realtime)
                    {
                        DM_slider.Value = DM_slider.Maximum;
                    }

                    if (CoT_realtime)
                    {
                        //Here I compute the last activity range
                        KeyValuePair <DateTime, TimeSpan> lastActivityRange = activity_timeline.OrderByDescending(t => t.Key).First();

                        //Here I update the CoT slider values, without the raising of the event
                        CoT_rangeSlider.HigherValue = CoT_rangeSlider.Maximum;
                        CoT_rangeSlider.LowerValue  = activity_timeline.Values.Sum(cot => cot.TotalSeconds) - lastActivityRange.Value.TotalSeconds;
                    }

                    //Here I set the new last detection to the period of restart detection
                    last_detection = DateTime.Now;

                    //Re-starting the timer needed to update the graphs
                    this.ActiveUpdateTimers();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                    Console.WriteLine(ex.Message);
                    Handle_DB_Error();
                }
            }

            return;
        }
Beispiel #5
0
        //This method handle the event raised by the timer setted for the update of the grid views
        private void Update_Graph_handler(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;

            //Here I update all the sliders
            DM_slider.Maximum       += now.Subtract(last_detection).TotalSeconds;
            CoT_rangeSlider.Maximum += now.Subtract(last_detection).TotalSeconds;
            FM_rangeSlider.Maximum  += now.Subtract(last_detection).TotalSeconds;

            //Updating the tick frequency of the sliders
            DM_slider.TickFrequency       = Features.percentageUpgradeSteps * DM_slider.Maximum;
            CoT_rangeSlider.TickFrequency = Features.percentageUpgradeSteps * CoT_rangeSlider.Maximum;
            FM_rangeSlider.TickFrequency  = Features.percentageUpgradeSteps * FM_rangeSlider.Maximum;

            //Here I update the timespan of the last entry of the activity timeline dictionary
            KeyValuePair <DateTime, TimeSpan> lastActivityRange = activity_timeline.OrderByDescending(t => t.Key).First();
            DateTime lastActivityDate = lastActivityRange.Key;

            activity_timeline[lastActivityDate] = now.Subtract(lastActivityDate);

            //Here I update the splitters
            Statistic_Auxiliary.SplittersDisplay(this, activity_timeline);

            //Here I save the last detection of reference
            last_detection = DateTime.Now;

            //Here I update the slider of the DM representation
            if (DM_realtime)
            {
                DM_slider.Value = DM_slider.Maximum;
            }

            //Here I add some data to the counting over time graph
            try
            {
                devices_position = dataCaching.LastPosition_List(last_detection);
                CoT_devices.Values.Add(new DateTimePoint(last_detection, devices_position.Count));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);
                Handle_DB_Error();
            }

            //Here I update the slider of the CoT representation
            if (CoT_realtime)
            {
                CoT_rangeSlider.HigherValue = CoT_rangeSlider.Maximum;
                if (activity_timeline[lastActivityDate].TotalSeconds < Features.MaxMinDifferenceRange)
                {
                    CoT_rangeSlider.LowerValue = activity_timeline.Values.Sum(cot => cot.TotalSeconds) - activity_timeline[lastActivityDate].TotalSeconds;
                }
                else
                {
                    CoT_rangeSlider.LowerValue = activity_timeline.Values.Sum(cot => cot.TotalSeconds) - Features.MaxMinDifferenceRange;
                }
            }

            //At the end of all operations this handler set again the timer after what to retrive the new data
            update_Graph.Interval = new TimeSpan(0, 0, Features.delayUpdateGraphs);
            update_Graph.Start();
        }
Beispiel #6
0
 //Managing the resize of the window
 private void ResizedWindow_Event(object sender, EventArgs e)
 {
     Statistic_Auxiliary.SplittersDisplay(this, activity_timeline);
 }
Beispiel #7
0
        //This method initialize the entire statistic window
        private void OnLoadEvent(object sender, RoutedEventArgs e)
        {
            try
            {
                Synchronizer.StartEngine(configuration, Handle_Cpp_Error);

                //Changing the detection mode and representation
                detection_mode                   = Features.Detection_Status.Running;
                this.detection_status.Text       = detection_mode.ToString();
                this.detection_status.Foreground = Brushes.Green;
                no_detection = false;

                //Setting the default current view at start
                current_view = this.device_distribution.Name;

                //Store the activity timeline
                activity_timeline = Log.GetEngineActivityTimeline(configuration, true);
            }
            catch (System.Data.Entity.Core.ProviderIncompatibleException dex)
            {
                Console.WriteLine(dex.StackTrace);
                Console.WriteLine(dex.Message);
                Handle_DB_Error();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);

                //Here I stop the engine of the C++ code
                Synchronizer.StopEngine(configuration);
                MessageBox.Show("An unknown error occur during the initialization of the statistic window!\n" +
                                "The application will be closed!");
                Environment.Exit(-1);
            }

            //Initialization of all the axis and series of the views
            Axis_Initialize();
            LineSeries_Initialize();

            //Here I compute the last activity range
            KeyValuePair <DateTime, TimeSpan> lastActivityRange = activity_timeline.OrderByDescending(t => t.Key).First();

            //Initialize the device monitoring representation
            for (int i = 0; i < configuration_boards.Count; i++)
            {
                DM_polygon.Values.Add(new ObservablePoint(configuration_boards[i].X, configuration_boards[i].Y));
            }
            if (configuration_boards.Count > 2)
            {
                DM_polygon.Values.Add(new ObservablePoint(configuration_boards[0].X, configuration_boards[0].Y));
            }
            Axis_Focus_Point();

            //Only if the mode is Modify or Load we display the previous data detected
            if (opening_mode == Features.Window_Mode.Load || opening_mode == Features.Window_Mode.Modify)
            {
                DateTime lastActivity = activity_timeline.OrderBy(t => t.Key).Last().Key;
                foreach (KeyValuePair <DateTime, TimeSpan> tuple in activity_timeline.OrderBy(t => t.Key))
                {
                    //Initialize all the sliders in the representations
                    DM_slider.Maximum       += tuple.Value.TotalSeconds;
                    CoT_rangeSlider.Maximum += tuple.Value.TotalSeconds;
                    FM_rangeSlider.Maximum  += tuple.Value.TotalSeconds;

                    //Initialize the counting over time representation
                    if (tuple.Key != lastActivity && tuple.Value.TotalSeconds >= Features.delayUpdateGraphs)
                    {
                        int iteration = (int)tuple.Value.TotalSeconds / Features.delayUpdateGraphs;
                        for (int i = 1; i <= iteration; i++)
                        {
                            try
                            {
                                last_detection   = tuple.Key.AddSeconds(i * Features.delayUpdateGraphs);
                                devices_position = dataCaching.LastPosition_List(last_detection);
                                CoT_devices.Values.Add(new DateTimePoint(last_detection, devices_position.Count));
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.StackTrace);
                                Console.WriteLine(ex.Message);
                                Handle_DB_Error();
                            }
                        }
                        CoT_devices.Values.Add(new DateTimePoint(last_detection, double.NaN));
                    }
                }

                //Updating the tick frequency of the sliders
                DM_slider.TickFrequency       = Features.percentageUpgradeSteps * DM_slider.Maximum;
                CoT_rangeSlider.TickFrequency = Features.percentageUpgradeSteps * CoT_rangeSlider.Maximum;
                FM_rangeSlider.TickFrequency  = Features.percentageUpgradeSteps * FM_rangeSlider.Maximum;

                //Here I add the splitters
                Statistic_Auxiliary.SplittersDisplay(this, activity_timeline);

                //Here I initialize the statistics at startup
                try
                {
                    //Here I generate the data needed for update the 3 statistics
                    int totalDistinctMACs, local_MACs, distinct_MACs, percentage_MACs;

                    totalDistinctMACs = dataCaching.TotalMAC_DistinctNumber();
                    local_MACs        = dataCaching.LocalMAC_Number();
                    distinct_MACs     = dataCaching.LocalMAC_DistinctNumber();
                    if (local_MACs == 0)
                    {
                        percentage_MACs = 0;
                    }
                    else
                    {
                        percentage_MACs = (int)(distinct_MACs * 100 / local_MACs);
                    }

                    //Here I update the text of the labels showing the statistics
                    this.total_distinct_MACs.Text   = totalDistinctMACs.ToString();
                    this.local_MACs.Text            = local_MACs.ToString();
                    this.distinct_MACs.Text         = distinct_MACs.ToString();
                    this.percentage_local_MACs.Text = percentage_MACs.ToString() + " %";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                    Console.WriteLine(ex.Message);
                    Handle_DB_Error();
                }
            }
            else
            {
                //Initialize the date of the representations
                double max = activity_timeline.Sum(t => t.Value.TotalSeconds);
                DM_slider.Maximum       = max;
                CoT_rangeSlider.Maximum = max;
                FM_rangeSlider.Maximum  = max;

                //Here I update the Min and Max values of the Axis of the CoT graph at startup
                Statistic_Auxiliary.UpdateCoTAxisConfiguration(this, activity_timeline);
            }

            //Here I update DM_slider thumb
            DM_slider.Value = DM_slider.Maximum;

            //Here I update the CoT and FM slider values
            double sum = activity_timeline.Sum(x => x.Value.TotalSeconds);

            CoT_rangeSlider.HigherValue = CoT_rangeSlider.Maximum;
            CoT_rangeSlider.LowerValue  = sum - lastActivityRange.Value.TotalSeconds;

            DateTime date_min = Statistic_Auxiliary.Translate_Slider_Value(FM_rangeSlider.LowerValue, activity_timeline);
            DateTime date_max = Statistic_Auxiliary.Translate_Slider_Value(FM_rangeSlider.HigherValue, activity_timeline);

            FM_rangeSlider.HigherValue = FM_rangeSlider.Maximum;
            FM_rangeSlider.LowerValue  = sum - lastActivityRange.Value.TotalSeconds;
            FM_date_start.Text         = date_min.ToString();
            FM_date_end.Text           = date_max.ToString();

            last_detection = DateTime.Now;

            //Set the operation for the first update graph event call
            this.ActiveUpdateTimers();

            return;
        }
Beispiel #8
0
        //This method initialize the LineSeries where will be added the points inserted by the user
        private void LineSeries_Initialize()
        {
            //This is the initialization of the serie reguarding the boards polygon
            DM_polygon.DataContext = this;
            DM_polygon.Values      = new ChartValues <ObservablePoint>();
            DM_polygon.LabelPoint  = value =>
            {
                int index;

                if (value.Key < DM_polygon.Values.Count - 1)
                {
                    index = value.Key;
                }
                else
                {
                    index = 0;
                }

                return(configuration_boards[index].BoardID + "\n" +                               //MAC
                       "(" + value.X.ToString("N2") + " ; " + value.Y.ToString("N2") + ")");      //Coordintes
            };

            //This is the initialization of the serie reguarding the devices position
            try
            {
                DM_positions.DataContext = this;
                DM_positions.Values      = new ChartValues <ObservablePoint>();
                DM_positions.LabelPoint  = value =>
                {
                    int      index     = value.Key;
                    DateTime timestamp = devices_position[index].Timestamp;
                    Device   device    = devices_position[index].Device;
                    TimeSpan active;
                    String   message;

                    try
                    {
                        active = device.ContinuativePresence_Last(timestamp);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        Console.WriteLine(ex.Message);
                        throw new Exception("Error during the connection with the DB");
                    }

                    message = Statistic_Auxiliary.Retrieve_Active_Time(active);

                    return(device.DeviceID + "\n" +                                                      //MAC
                           timestamp.ToString(System.Globalization.CultureInfo.CurrentCulture) + "\n" +  //Timestamp
                           message + "\n" +                                                              //Timespan of activity
                           "(" + value.X.ToString("N2") + " ; " + value.Y.ToString("N2") + ")");         //Coordinates
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);
                Synchronizer.StopEngine(configuration);
            }

            //This is the initialization of the serie reguarding the counting over time graph
            CoT_devices.DataContext = this;
            CoT_devices.Values      = new ChartValues <DateTimePoint>();
            CoT_devices.LabelPoint  = value =>
            {
                return("Detected " + ((int)value.Y).ToString() + " devices\n" +                                //Number of Devices
                       new DateTime((long)value.X).ToString(System.Globalization.CultureInfo.CurrentCulture)); //Timestamp
            };

            return;
        }