public void AddDatabaseConnectionToConnectionListTest()
        {
            DBConnectionHelpers.ConnectionParametersList = new List <ConnectionParameters>();

            DBConnectionHelpers.AddDatabaseConnectionToConnectionList(ConParams);
            Assert.IsTrue(DBConnectionHelpers.ConnectionParametersList.Contains(ConParams));
        }
        /// <summary>
        /// Adds a new/changed connection to the connection list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddConnectionClick(object sender, RoutedEventArgs e)
        {
            ConnectionParameters conParams = new ConnectionParameters(DBTypeComboBox.Text, DBConnectionnameTextBox.Text, DBHostnameTextBox.Text, DBDatabaseTextBox.Text, DBUsernameTextBox.Text, DBPasswordPasswordBox.Password, DBPortTextBox.Text);

            if (conParams.IsComplete())
            {
                if (DBConnectionHelpers.CheckIfDatabaseNameExists(conParams.Name))
                {
                    DBConnectionHelpers.AddDatabaseConnectionToConnectionList(conParams);
                }

                else
                {
                    if (ModernDialog.ShowMessage("Connection Name \"" + conParams.Name + "\" already exists! \r\nDo you want to override the existing connection?", "New Connection", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        DBConnectionHelpers.RemoveConnectionParameter(conParams.Name);
                        DBConnectionHelpers.AddDatabaseConnectionToConnectionList(conParams);
                    }
                }
            }
            else
            {
                ModernDialog.ShowMessage("Please fill out all fields to add the new connection!", "New Connection", MessageBoxButton.OK);
            }

            ReloadListbox();
        }
        /// <summary>
        /// Add a new connection to the DatabaseSettings.xml and connect to the Database
        /// </summary>
        /// <author>Bernhard Bruns</author>
        private void SaveAndConnectClick(object sender, RoutedEventArgs e)
        {
            DBConnectionHelpers.LoadConnectionParameters();

            ConnectionParameters connectionParameters = new ConnectionParameters(DBTypeComboBox.Text, DBConnectionnameTextBox.Text, DBHostnameTextBox.Text, DBDatabaseTextBox.Text, DBUsernameTextBox.Text, DBPasswordTextBox.Password, DBPortTextBox.Text);

            if (connectionParameters.IsComplete())
            {
                if (DBConnectionHelpers.CheckIfDatabaseNameExists(connectionParameters.Name))
                {
                    DBConnectionHelpers.AddDatabaseConnectionToConnectionList(connectionParameters);

                    if (ConnectToDb(connectionParameters))
                    {
                        DBConnectionHelpers.SaveConnectionParameters();
                        DBConnectionHelpers.SaveLastUsedDatabase(connectionParameters);
                        AddConnectionGrid.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        ModernDialog.ShowMessage("Can't connect to database!", "New Connection", MessageBoxButton.OK);
                    }
                }
                else
                {
                    ModernDialog.ShowMessage("Connection Name \"" + connectionParameters.Name + "\" already exists! \r\nPlease choose a new Name for your connection.", "New Connection", MessageBoxButton.OK);
                }
            }
            else
            {
                ModernDialog.ShowMessage("Please fill out all fields to add the new connection!", "New Connection", MessageBoxButton.OK);
            }
        }
        /// <summary>
        /// This function loads the data from the database into the fields and update the user interface
        /// </summary>
        /// <author>Thomas Meents, Bernhard Bruns</author>
        private void LoadDataFromDatabase()
        {
            string connectionName = DBWorker.GetConnectionName();

            Dispatcher.BeginInvoke((Action)(() =>
            {
                MiningInfo.BBCode += "\nLoading data from " + connectionName;
                MiningInfoScrollViewer.ScrollToEnd();
            }));

            if (MainWindow.MatrixSelection.SelectionHasChangedSinceLastLoading || EventSelectionModel.GetInstance().SelectionHasChangedSinceLastLoading)
            {
                foreach (Field field in MainWindow.MatrixSelection.MatrixFields)
                {
                    if (_cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    DBConnectionHelpers.LoadFactsInField(field);

                    Dispatcher.BeginInvoke((Action)(() =>
                    {
                        ProgressBar.Value += 1;
                    }));
                }
                MainWindow.MatrixSelection.SelectionHasChangedSinceLastLoading = false;
                EventSelectionModel.GetInstance().SelectionHasChangedSinceLastLoading = false;
            }
        }
        void IContent.OnNavigatedTo(NavigationEventArgs e)
        {
            InterfaceHelpers.CurrentPage = e.Source.OriginalString;

            FillFavouriteDBConnectionsComboBox();

            // Disable "Reconnect to last used Database" if the connection cannot be found
            DBConnectionHelpers.LoadConnectionParameters();
            if (DBConnectionHelpers.LoadLastUsedDatabase() == null)
            {
                ReconnectToLastUsedConnectionButton.IsEnabled = false;
            }
            else
            {
                ReconnectToLastUsedConnectionButton.IsEnabled = true;
            }

            // Disable "Restore saved results" button if no file exists
            if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\LastMiningResults.mpm"))
            {
                RestoreSavedResultsButton.IsEnabled = false;
            }
            else
            {
                RestoreSavedResultsButton.IsEnabled = true;
            }
        }
        public void RemoveConnectionParameterTest()
        {
            DBConnectionHelpers.ConnectionParametersList = new List <ConnectionParameters>();
            DBConnectionHelpers.AddDatabaseConnectionToConnectionList(ConParams);

            DBConnectionHelpers.RemoveConnectionParameter(ConParams.Name);
            Assert.IsFalse(DBConnectionHelpers.ConnectionParametersList.Contains(ConParams));
        }
        public void SaveConnectionParametersTest()
        {
            DBConnectionHelpers.ConnectionParametersList = new List <ConnectionParameters>();
            DBConnectionHelpers.AddDatabaseConnectionToConnectionList(ConParams);

            DBConnectionHelpers.SaveConnectionParameters();
            Assert.IsTrue(File.Exists(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + "DatabaseSettings.mpm"));
        }
        // --------------------- Functionality ---------------------
        /// <summary>
        /// Connect to the DB
        /// </summary>
        /// <author>Moritz Eversmann, Bernd Nottbeck</author>
        /// <param name="conParams"></param>
        /// <returns></returns>
        public bool ConnectToDb(ConnectionParameters conParams)
        {
            Cursor = Cursors.Wait;
            Boolean connected = DBConnectionHelpers.EstablishDatabaseConnection(conParams);

            Cursor = Cursors.Arrow;

            return(connected);
        }
        /// <summary>
        /// Fills the listbox with saved database connections
        /// </summary>
        /// <author>Bernhard Bruns</author>
        private void FillListboxWithDatabaseConections()
        {
            DBConnectionHelpers.LoadConnectionParameters();
            ConnectionsListBox.ItemsSource = DBConnectionHelpers.ConnectionParametersList;

            if (ConnectionsListBox.Items.Count > 0)
            {
                ConnectionsListBox.SelectedIndex = 0;
            }
        }
        public void CheckIfDBNameAlreadyExistsTest2()
        {
            ConnectionParameters connectionParams = new ConnectionParameters("TestString", "Cname", "TestString", "TestString", "TestString", "TestString", "TestString");
            string connectionName = "OtherName";

            DBConnectionHelpers.ConnectionParametersList = new List <ConnectionParameters>();
            DBConnectionHelpers.ConnectionParametersList.Add(connectionParams);

            bool actual = DBConnectionHelpers.CheckIfDatabaseNameExists(connectionName);

            Assert.IsTrue(actual);
        }
        public void SaveLastUsedDatabaseTest()
        {
            DBConnectionHelpers.ConnectionParametersList = new List <ConnectionParameters>();
            DBConnectionHelpers.AddDatabaseConnectionToConnectionList(ConParams);

            DBConnectionHelpers.SaveLastUsedDatabase(ConParams);
            Assert.IsTrue(DBConnectionHelpers.ConnectionParametersList[0].IsLastUsedDatabase);

            ConnectionParameters c = new ConnectionParameters();

            DBConnectionHelpers.SaveLastUsedDatabase(c);
            Assert.IsTrue(DBConnectionHelpers.ConnectionParametersList[0].IsLastUsedDatabase == false);
        }
        public void LoadLastUsedDatabaseTest()
        {
            ConnectionParameters expected = new ConnectionParameters("TestString", "TestString", "TestString", "TestString", "TestString", "TestString", "TestString");
            ConnectionParameters actual;


            expected.IsLastUsedDatabase = true;
            DBConnectionHelpers.ConnectionParametersList = new List <ConnectionParameters>();
            DBConnectionHelpers.ConnectionParametersList.Add(expected);

            actual = DBConnectionHelpers.LoadLastUsedDatabase();

            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Connect to the chosen favorite-connection
        /// </summary>
        /// <author>Bernhard Bruns</author>
        private void ConnectToFavouriteClick(object sender, RoutedEventArgs e)
        {
            if (FavouriteDBConnectionsComboBox.SelectedIndex == -1)
            {
                ErrorHandling.ReportErrorToUser("Error: No connection is selected.");
            }
            else
            {
                ConnectionParameters connectionParameters = (ConnectionParameters)FavouriteDBConnectionsComboBox.Items[FavouriteDBConnectionsComboBox.SelectedIndex];
                ConnectToDb(connectionParameters);

                DBConnectionHelpers.SaveLastUsedDatabase(connectionParameters);
            }
        }
        public void LoadConnectionParametersTest()
        {
            bool expected;
            bool actual;

            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\DatabaseSettings.mpm"))
            {
                expected = true;
            }
            else
            {
                expected = false;
            }

            actual = DBConnectionHelpers.LoadConnectionParameters();
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Read the DatabaseSettings xml-file and write it in the connectionlist
        /// </summary>
        /// <author>Bernhard Bruns</author>
        public void FillFavouriteDBConnectionsComboBox()
        {
            DBConnectionHelpers.LoadConnectionParameters();

            if (DBConnectionHelpers.ConnectionParametersList != null)
            {
                // Binding
                FavouriteDBConnectionsComboBox.ItemsSource       = DBConnectionHelpers.ConnectionParametersList;
                FavouriteDBConnectionsComboBox.DisplayMemberPath = "Name";

                if (DBConnectionHelpers.ConnectionParametersList.Count == 0)
                {
                    ConnectToFavouriteButton.IsEnabled       = false;
                    FavouriteDBConnectionsComboBox.IsEnabled = false;
                }
                else
                {
                    ConnectToFavouriteButton.IsEnabled           = true;
                    FavouriteDBConnectionsComboBox.IsEnabled     = true;
                    FavouriteDBConnectionsComboBox.SelectedIndex = 0;
                }
            }
        }
        /// <summary>
        /// handle Shortcuts
        /// </summary>
        /// <param Name="sender"></param>
        /// <param Name="e"></param>
        /// <author>Thomas Meents, Bernd Nottbeck, Jannik Arndt</author>
        private void HandleShortcuts(object sender, KeyEventArgs e)
        {
            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
            {
                switch (e.Key)
                {
                case Key.R:
                    Cursor = Cursors.Wait;
                    try
                    {
                        DBConnectionHelpers.LoadConnectionParameters();
                        DBConnectionHelpers.EstablishDatabaseConnection(DBConnectionHelpers.LoadLastUsedDatabase());
                    }
                    finally
                    {
                        Cursor = Cursors.Arrow;
                    }
                    break;
                }
            }
            else
            {
                switch (e.Key)
                {
                case Key.Enter:
                    switch (ContentSource.ToString())
                    {
                    case ("/Pages/P1connection.xaml"):
                        ContentSource = new Uri("/Pages/P2metadata.xaml", UriKind.RelativeOrAbsolute);
                        break;

                    case ("/Pages/P2metadata.xaml"):
                        ContentSource = new Uri("/Pages/P3dimensionselection.xaml", UriKind.RelativeOrAbsolute);
                        break;

                    case ("/Pages/P3dimensionselection.xaml"):
                        ContentSource = new Uri("/Pages/P4eventselection.xaml", UriKind.RelativeOrAbsolute);
                        break;

                    case ("/Pages/P4eventselection.xaml"):
                        ContentSource = new Uri("/Pages/P5configuration.xaml", UriKind.RelativeOrAbsolute);
                        break;

                    case ("/Pages/P5configuration.xaml"):
                        if (MinerSettings.IsAlgorithmSet)
                        {
                            ContentSource = new Uri("/Pages/P6mining.xaml", UriKind.RelativeOrAbsolute);
                        }
                        break;

                    case ("/Pages/P6mining.xaml"):
                        // Start / Continue
                        break;

                    case ("/Pages/P7consolidation.xaml"):
                        ContentSource = new Uri("/Pages/P8results.xaml", UriKind.RelativeOrAbsolute);
                        break;
                    }
                    break;

                case Key.F11:
                    if (WindowState.Equals(WindowState.Maximized))
                    {
                        ViewRegularscreen();
                    }
                    else
                    {
                        ViewFullscreen();
                    }
                    break;
                }
            }
        }
 /// <summary>
 /// Reconnect to the Last used database connection
 /// </summary>
 /// <author>Bernhard Bruns</author>
 private void ReconnectToLastUsedConnectionClick(object sender, RoutedEventArgs e)
 {
     DBConnectionHelpers.LoadConnectionParameters();
     ConnectToDb(DBConnectionHelpers.LoadLastUsedDatabase());
 }
 public void EstablishDatabaseConnectionTest()
 {
     DBConnectionHelpers.EstablishDatabaseConnection(ConParams);
     Assert.IsNotNull(DBWorker.MetaData);
 }
 /// <summary>
 /// Reloads the connection listbox
 /// </summary>
 private void ReloadListbox()
 {
     ConnectionsListBox.ItemsSource = null;
     ConnectionsListBox.ItemsSource = DBConnectionHelpers.ConnectionParametersList;
     DBConnectionHelpers.SaveConnectionParameters();
 }