//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; }