//This method manage the insertion of splitters in the tickbar
        public static void SplittersDisplay(Statistic_Window window, Dictionary <DateTime, TimeSpan> activity_timeline)
        {
            //Here I clear the entire splitters
            window.DM_splitters.Children.Clear();
            window.CoT_splitters.Children.Clear();
            window.FM_splitters.Children.Clear();

            //Here I create and assign the splitters
            SolidColorBrush splitters_color  = new SolidColorBrush(Color.FromRgb((byte)43, (byte)151, (byte)33));
            Thickness       margin_splitters = new Thickness(0, 0, 0, 5);

            foreach (KeyValuePair <DateTime, TimeSpan> activity in activity_timeline)
            {
                Rectangle DM_splitter = new Rectangle
                {
                    Height = window.DM_splitters.ActualHeight * 3 / 4,
                    Width  = 3,
                    Fill   = splitters_color,
                    //Margin = margin_splitters
                };
                Rectangle CoT_splitter = new Rectangle
                {
                    Height = window.CoT_splitters.ActualHeight * 3 / 4,
                    Width  = 3,
                    Fill   = splitters_color,
                    //Margin = margin_splitters
                };
                Rectangle FM_splitter = new Rectangle
                {
                    Height = window.FM_splitters.ActualHeight * 3 / 4,
                    Width  = 3,
                    Fill   = splitters_color,
                    //Margin = margin_splitters
                };

                //Here I set the DM and CoT splitters
                var timespans = activity_timeline.Where(t => t.Key < activity.Key).Select(t => t.Value);

                if (timespans.Count() != 0)
                {
                    double totSeconds    = timespans.Sum(t => t.TotalSeconds);
                    double DM_leftValue  = (totSeconds * window.DM_splitters.ActualWidth) / window.DM_slider.Maximum;
                    double CoT_leftValue = (totSeconds * window.CoT_splitters.ActualWidth) / window.CoT_rangeSlider.Maximum;
                    double FM_leftValue  = (totSeconds * window.FM_splitters.ActualWidth) / window.FM_rangeSlider.Maximum;

                    window.DM_splitters.Children.Add(DM_splitter);
                    Canvas.SetLeft(DM_splitter, DM_leftValue);
                    Canvas.SetBottom(DM_splitter, 0);

                    window.CoT_splitters.Children.Add(CoT_splitter);
                    Canvas.SetLeft(CoT_splitter, CoT_leftValue);
                    Canvas.SetBottom(CoT_splitter, 0);

                    window.FM_splitters.Children.Add(FM_splitter);
                    Canvas.SetLeft(FM_splitter, FM_leftValue);
                    Canvas.SetBottom(FM_splitter, 0);
                }
            }
        }
        //This method manage the event that arrive on the Start Button
        private void Start_button_Click(object sender, RoutedEventArgs e)
        {
            if (configuration == null)
            {
                MessageBoxResult result = MessageBox.Show("We are sorry!\n" +
                                                          "There was an error during the loading of the configuration\n" +
                                                          "Do you want to restart the application?", "Restart the application", MessageBoxButton.YesNo);

                if (result == MessageBoxResult.No)
                {
                    this.Close();
                    Environment.Exit(-1);
                }
                else
                {
                    this.Hide();
                    MainWindow newMainWindow = new MainWindow();
                    newMainWindow.Show();
                    this.Close();
                    return;
                }
            }
            this.Hide();

            //Start of the critical section in the middle of 2 window
            try
            {
                //Instantiation of the Statistic Window and closing this window
                Statistic_Window newStatisticWindow = new Statistic_Window(configuration, this.mode);
                newStatisticWindow.Show();
                this.Close();
            }
            catch (Exception ex)
            {
                //In case of exception I have to free the lockObject
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Message);

                MessageBox.Show("We are sorry!\n" +
                                "An error occure in the critical section before the opening of the Statistic window!\n");
                Environment.Exit(-1);
            }

            return;
        }
        //------------------------- METHODS -----------------------------------------------------------------------------------------
        //This method admit to update the max and min value of the x and y axis
        public static void UpdateCoTAxisConfiguration(Statistic_Window window, Dictionary <DateTime, TimeSpan> activity_timeline)
        {
            DateTime max = Translate_Slider_Value(window.CoT_rangeSlider.HigherValue, activity_timeline);
            DateTime min = Translate_Slider_Value(window.CoT_rangeSlider.LowerValue, activity_timeline);

            //Update the date labels of the CoT representation
            window.CoT_date_start.Text = min.ToString();
            window.CoT_date_end.Text   = max.ToString();

            //Compute the max values put on the graph
            List <double> maxCoT_Yvalues = window.CoT_devices.Values.GetPoints(window.CoT_devices).Where(t =>
            {
                DateTime date = new DateTime((long)t.X);
                DateTime m    = min.Subtract(new TimeSpan(0, 0, Features.delayUpdateGraphs));
                DateTime M    = max.AddSeconds(Features.delayUpdateGraphs);
                if (date.CompareTo(M) <= 0 && date.CompareTo(m) >= 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }).Select(p => p.Y).ToList();

            //Update the min and max value of the x and y axis of the CoT graph
            window.CoT_Map.AxisX[0].MaxValue = max.AddSeconds(Features.delayUpdateGraphs).Ticks;
            window.CoT_Map.AxisX[0].MinValue = min.Subtract(new TimeSpan(0, 0, Features.delayUpdateGraphs)).Ticks;
            if (maxCoT_Yvalues.Count > 0)
            {
                window.CoT_Map.AxisY[0].MaxValue = maxCoT_Yvalues.Max() + 5;
            }
            else
            {
                window.CoT_Map.AxisY[0].MaxValue = 5;
            }

            return;
        }
        //Display the new MACs on screen
        public static void DisplayNewFrequentMACs(Statistic_Window window, List <FrequentMAC> frequentMACs)
        {
            int index = 1;

            frequentMACs = frequentMACs.OrderByDescending(t => t.TotalSecondsOfActiity).ToList();

            //First clear the values insider the FM graph
            window.FM_Map.Series.Clear();

            //Updating the FM graph
            foreach (FrequentMAC mac in frequentMACs)
            {
                LineSeries serie = new LineSeries
                {
                    DataContext       = window,
                    Fill              = Brushes.Transparent,
                    LineSmoothness    = 0,
                    StrokeThickness   = 3,
                    PointGeometrySize = 11,
                    PointForeground   = Brushes.WhiteSmoke,
                    Stroke            = mac.Color,
                    Title             = "",
                    Values            = new ChartValues <DateTimePoint>()
                };
                foreach (KeyValuePair <DateTime, TimeSpan> tuple in mac.Activity.OrderBy(t => t.Key))
                {
                    serie.LabelPoint = value =>
                    {
                        return("Device " + mac.MAC + "\n" +
                               tuple.Key.ToString(System.Globalization.CultureInfo.CurrentCulture) + " - " +
                               tuple.Key.Add(tuple.Value).ToString(System.Globalization.CultureInfo.CurrentCulture));
                    };
                    serie.Values.Add(new DateTimePoint(tuple.Key, index));
                    serie.Values.Add(new DateTimePoint(tuple.Key.Add(tuple.Value), index));
                    serie.Values.Add(new DateTimePoint(tuple.Key.Add(tuple.Value), double.NaN));
                }
                window.FM_Map.Series.Add(serie);
                index++;
            }

            /*foreach (FrequentMAC mac in frequentMACs.OrderByDescending(t => t.GetTotalSecondsOFActivity()).ToList())
             * {
             *  List<LineSeries> series = new List<LineSeries>();
             *  foreach (KeyValuePair<DateTime, TimeSpan> tuple in mac.Activity.OrderBy(t => t.Key))
             *  {
             *      LineSeries serie = new LineSeries
             *      {
             *          DataContext = window,
             *          Fill = Brushes.Transparent,
             *          LabelPoint = value =>
             *          {
             *              return "Device " + mac.MAC + "\n" +
             *                     tuple.Key.ToString(System.Globalization.CultureInfo.CurrentCulture) + " - " +
             *                     tuple.Key.Add(tuple.Value).ToString(System.Globalization.CultureInfo.CurrentCulture);
             *          },
             *          LineSmoothness = 0,
             *          PointGeometrySize = 11,
             *          PointForeground = Brushes.WhiteSmoke,
             *          Stroke = mac.Color,
             *          StrokeThickness = 3,
             *          Title = "",
             *          Values = new ChartValues<DateTimePoint> {
             *                  new DateTimePoint(tuple.Key, index),
             *                  new DateTimePoint(tuple.Key.Add(tuple.Value), index)
             *          }
             *      };
             *      series.Add(serie);
             *  }
             *  window.FM_Map.Series.AddRange(series);
             *  index++;
             * }*/
        }
        //--------------- This method manage the ok button click event -------------------------------------------
        private void Ok_button_Click(object sender, RoutedEventArgs e)
        {
            //Here there is no need to do something because the value is saved in the attribute of the window
            if (mode == Features.Window_Mode.Load)
            {
                string nameConf = selectedValue;
                if (nameConf != null)
                {
                    Configuration configuration = null;
                    try
                    {
                        configuration = Configuration.LoadConfiguration(nameConf);
                    }
                    catch (Exception)
                    {
                        Handle_DB_Error();
                    }
                    if (configuration == null)
                    {
                        MessageBoxResult result = MessageBox.Show("We are sorry!\n" +
                                                                  "There was an error during the load of the configuration\n" +
                                                                  "Do you want to restart the application?", "Restart the application", MessageBoxButton.YesNo);

                        if (result == MessageBoxResult.No)
                        {
                            this.Close();
                            Environment.Exit(-1);
                        }
                        else
                        {
                            this.Hide();
                            MainWindow newMainWindow = new MainWindow();
                            newMainWindow.Show();
                            this.Close();
                            return;
                        }
                    }
                    this.Hide();

                    //Start of the critical section in the middle of 2 window
                    try
                    {
                        //Instantiation of the Statistic Window and closing this window
                        Statistic_Window newStatisticWindow = new Statistic_Window(configuration, this.mode);
                        newStatisticWindow.Show();
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        //In case of exception I have to free the lockObject
                        Console.WriteLine(ex.StackTrace);
                        Console.WriteLine(ex.Message);

                        MessageBox.Show("We are sorry!\n" +
                                        "An error occure in the critical section before the opening of the Statistic window!\n");
                        Environment.Exit(-1);
                    }
                }
            }
            else if (mode == Features.Window_Mode.Modify)
            {
                string nameConf = selectedValue;
                if (nameConf != null)
                {
                    Configuration configuration = null;

                    //Retrive the configuration from the DB
                    try
                    {
                        configuration = Configuration.LoadConfiguration(nameConf);
                    }
                    catch (Exception)
                    {
                        Handle_DB_Error();
                    }

                    //Managing the case where the configuration is null
                    if (configuration == null)
                    {
                        MessageBoxResult result = MessageBox.Show("We are sorry!\n" +
                                                                  "There was an error during the load of the configuration\n" +
                                                                  "Do you want to restart the application?", "Restart the application", MessageBoxButton.YesNo);

                        if (result == MessageBoxResult.No)
                        {
                            this.Close();
                            Environment.Exit(-1);
                        }
                        else
                        {
                            this.Hide();
                            MainWindow newMainWindow = new MainWindow();
                            newMainWindow.Show();
                            this.Close();
                            return;
                        }
                    }

                    //All is went good so let's go to the setup
                    this.Hide();
                    Setup_Window modifyConfiguration = new Setup_Window(Features.Window_Mode.Modify, configuration);
                    modifyConfiguration.Show();
                    this.Close();
                    return;
                }
            }
            else if (mode == Features.Window_Mode.Remove)
            {
                string configuration_to_remove = selectedValue;
                if (configuration_to_remove != null)
                {
                    try
                    {
                        Configuration.RemoveConfiguration(configuration_to_remove);
                    }
                    catch (Exception)
                    {
                        Handle_DB_Error();
                    }

                    this.Hide();
                    MainWindow mainWindow = new MainWindow();
                    mainWindow.Show();
                    this.Close();
                    return;
                }
            }
        }