//This method manage the start setup operations
        private void StartSetup()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            this.createConfiguration.IsEnabled = false;
            this.loadConfiguration.IsEnabled   = false;
            this.modifyConfiguration.IsEnabled = false;
            this.removeConfiguration.IsEnabled = false;

            Synchronizer.StartSetup((Configuration conf) =>
            {
                this.Hide();
                Setup_Window newSetup = new Setup_Window(Features.Window_Mode.Create, conf);
                newSetup.Show();
                Mouse.OverrideCursor = null;
                this.Close();
            },
                                    (Synchronizer.Reason reason, String message) =>
            {
                Synchronizer.StopSetup();
                Mouse.OverrideCursor     = null;
                MessageBoxResult result2 = MessageBox.Show("There was an error during the listening of the boards\nPlease try again!",
                                                           "Auto-setup error");

                this.createConfiguration.IsEnabled = true;
                this.loadConfiguration.IsEnabled   = true;
                this.modifyConfiguration.IsEnabled = true;
                this.removeConfiguration.IsEnabled = true;

                Console.WriteLine("----------------- ERROR -----------------");
                Console.WriteLine(reason.ToString() + ": " + message);
                Console.WriteLine("-----------------------------------------");
            });
        }
示例#2
0
        //------------------------- CONSTRUCTOR ----------------------------------------------------------------------------------
        public BoardRow(Setup_Window parent, int uid, Boolean blink_mode)
        {
            InitializeComponent();

            this.parent  = parent;
            this.boardId = uid;

            if (!blink_mode)
            {
                this.blink.Visibility = Visibility.Collapsed;
                Canvas.SetLeft(this.up, 15);
                Canvas.SetRight(this.down, 15);
            }
        }
        //This method handle the event raised by the click on the create new configuration button
        private void Create_New_Configuration_button_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("There is the possibility to auto configure the system!\nDo you want to proceed?",
                                                      "Auto-setup option available", MessageBoxButton.YesNo);

            if (result.Equals(MessageBoxResult.Yes))
            {
                try
                {
                    StartSetup();
                }catch (Exception ex)
                {
                    Synchronizer.StopSetup();
                    Mouse.OverrideCursor = null;

                    Console.WriteLine(ex.StackTrace);
                    Console.WriteLine(ex.Message);

                    MessageBoxResult result3 = MessageBox.Show("There was an error during the listening of the boards\nWould you try again?",
                                                               "Auto-setup error", MessageBoxButton.YesNo);
                    if (result3.Equals(MessageBoxResult.Yes))
                    {
                        StartSetup();
                    }
                    else
                    {
                        this.createConfiguration.IsEnabled = true;
                        this.loadConfiguration.IsEnabled   = true;
                        this.modifyConfiguration.IsEnabled = true;
                        this.removeConfiguration.IsEnabled = true;
                    }
                }
            }
            else
            {
                this.Hide();
                Setup_Window nSetup = new Setup_Window(Features.Window_Mode.Create);
                nSetup.Show();
                this.Close();
            }

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