コード例 #1
0
 public void ConfigureDBConnectionTestFail2()
 {
     // arrange
     DBWorker.CloseConnection();
     ConnectionParameters conParams = new ConnectionParameters("MySQL");
     // act
     DBWorker.ConfigureDBConnection(conParams);
 }
コード例 #2
0
 public void ConfigureDBConnectionTestFail0()
 {
     // arrange
     DBWorker.CloseConnection();
     ConnectionParameters conParams = new ConnectionParameters("non-existingType");
     // act
     DBWorker.ConfigureDBConnection(conParams);
 }
コード例 #3
0
        // --------------------- 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;
        }
コード例 #4
0
 public void databaseTest()
 {
     ConnectionParameters target = new ConnectionParameters();
     string expected = "Teststring";
     string actual;
     target.Database = expected;
     actual = target.Database;
     Assert.AreEqual(expected, actual);
 }
コード例 #5
0
        public MPMMicrosoftSQL(ConnectionParameters conParams, bool noWindowsAuth = true)
            : base(conParams)
        {
            NoWindowsAuth = noWindowsAuth;

            Initialize(BuildConnectionString());

            DBWorker.SqlCreator = new SQLCreatorMicrosoftSQL();
        }
コード例 #6
0
        /// <summary>
        /// Configures and opens a database connection
        /// Builds the metadata repository and loads the xml-serialized metadata-file.
        /// Navigates to page P2Metadata
        /// </summary>
        /// <param name="conParams"></param>
        /// <returns></returns>
        /// <author>Bernhard Bruns, Moritz Eversmann, Bernd Nottbeck</author>
        public static bool EstablishDatabaseConnection(ConnectionParameters conParams)
        {
            try
            {
                if (DBWorker.ConfigureDBConnection(conParams))
                {
                    DBWorker.OpenConnection();

                    MainWindow.ConnectionName = DBWorker.GetConnectionName();

                    DBWorker.BuildMetadataRepository();

                    XMLHelper.SynchronizeFactTableWithXML(conParams);

                    DefaultEventClassifierIsSelected = false;

                    if (DBWorker.MetaData.EventClassifier == "")
                    {
                        DefaultEventClassifierIsSelected = true;
                        if (DBWorker.MetaData.ListOfEventsTableColumnNames.Contains("PROC_DESCRIPTION"))
                            DBWorker.MetaData.EventClassifier = "PROC_DESCRIPTION";
                        else if (DBWorker.MetaData.ListOfEventsTableColumnNames.Contains("activity"))
                            DBWorker.MetaData.EventClassifier = "activity";
                        else if (DBWorker.MetaData.ListOfEventsTableColumnNames.Contains("ACTIVITY"))
                            DBWorker.MetaData.EventClassifier = "ACTIVITY";
                        else DefaultEventClassifierIsSelected = false;
                    }
                    NavigationCommands.GoToPage.Execute("/Pages/P2metadata.xaml", null);
                }

                return true;
            }
            catch (TypeInitializationException ex)
            {
                ErrorHandling.ReportErrorToUser("Error: Type initialization. " + ex.Message);
            }
            catch (NoParamsGivenException)
            {
                ErrorHandling.ReportErrorToUser("Error: No databasefields are filled.");
            }
            catch (DBException ex)
            {
                ErrorHandling.ReportErrorToUser("Database error: " + ex.Message);
            }
            catch (TimeoutException ex)
            {
                ErrorHandling.ReportErrorToUser("Database Timeout: " + ex.Message);
            }
            catch (Exception ex)
            {
                ErrorHandling.ReportErrorToUser("Error: " + ex.Message + " " + ex.StackTrace);
            }
            return false;
        }
コード例 #7
0
        public void SerializeTest1()
        {
            string filename = "Unit.tst";
            ConnectionParameters con = new ConnectionParameters("TestString", "TestString", "TestString", "TestString", "TestString", "TestString", "TestString");

            bool expected = true;
            bool actual;

            actual = Serializer.Serialize(filename, con);
            Assert.AreEqual(expected, actual);
        }
コード例 #8
0
 public void ConnectionParamsConstructorTest1()
 {
     string type = "Teststring";
     string name = "Teststring";
     string host = "Teststring";
     string database = "Teststring";
     string user = "******";
     string password = "******";
     string port = "Teststring";
     ConnectionParameters target = new ConnectionParameters(type, name, host, database, user, password, port);
     Assert.IsNotNull(target);
 }
コード例 #9
0
        public MPMSQLiteConnection(ConnectionParameters conParams, bool _inMemory = false)
            : base(conParams)
        {
            DBWorker.SqlCreator = new SQLCreatorSQLite();

            if (_inMemory)
            {
                //ReInitialize for In-Memory
                this.InMemory = true;
                if (Connection != null) Connection.Close();
                Initialize(BuildConnectionString());
            }
        }
コード例 #10
0
        /// <summary>
        /// Configures a new Database-connection that can be accessed from everywhere.
        /// </summary>
        /// <param name="connectionParameter">An Object that stores the connection-details.</param>
        /// <returns>True if the connection configuration was successful.</returns>
        /// <author>Jannik Arndt, Bernd Nottbeck</author>
        public static bool ConfigureDBConnection(ConnectionParameters connectionParameter)
        {
            if (String.IsNullOrEmpty(connectionParameter.Type))
                throw new ConnectionTypeNotGivenException();

            if (connectionParameter.Type.Equals("SQLite") || connectionParameter.Type.Equals("SQLite In-Memory"))
            {
                if (String.IsNullOrEmpty(connectionParameter.Database))
                    throw new NoParamsGivenException();
            }
            else
            {
                if (String.IsNullOrEmpty(connectionParameter.Database) || String.IsNullOrEmpty(connectionParameter.Host) ||
                String.IsNullOrEmpty(connectionParameter.Name) || String.IsNullOrEmpty(connectionParameter.Port))
                    throw new NoParamsGivenException();
            }

            DbConnectionParameter = connectionParameter;

            switch (connectionParameter.Type)
            {
                case "MySQL":
                    DatabaseConnection = new MPMMySQLConnection(connectionParameter);
                    return true;
                case "Oracle":
                    DatabaseConnection = new MPMOracleSQLConnection(connectionParameter);
                    return true;
                case "PostgreSQL":
                    DatabaseConnection = new MPMPostgreSQLConnection(connectionParameter);
                    return true;
                case "MS-SQL":
                    DatabaseConnection = new MPMMicrosoftSQL(connectionParameter);
                    return true;
                case "MS-SQL Windows Auth":
                    DatabaseConnection = new MPMMicrosoftSQL(connectionParameter, false);
                    return true;
                case "SQLite":
                    DatabaseConnection = new MPMSQLiteConnection(connectionParameter);
                    return true;
                case "SQLite In-Memory":
                    DatabaseConnection = new MPMSQLiteConnection(connectionParameter, true);
                    return true;
                default:
                    throw new DatabaseDoesNotExist();
            }
        }
コード例 #11
0
        public static void MyClassInitialize(TestContext testContext)
        {
            string testDbPath = AppDomain.CurrentDomain.BaseDirectory + @"\Files\test.sqlite.db";

            // To enable tests in a virtual machine (change the letter accordingly)
            if (!Char.IsLetter(testDbPath.First()))
                testDbPath = "Z:" + testDbPath.Substring(10);

            ConParams = new ConnectionParameters("SQLite", "SQLite Connection", "", testDbPath, "", "", "");

            DBWorker.ConfigureDBConnection(ConParams);
            DBWorker.OpenConnection();

            DBWorker.BuildMetadataRepository();

            Model = Serializer.Deserialize<MatrixSelectionModel>(@"Files\SQLiteResults.mpm");
        }
コード例 #12
0
 public static void MyClassInitialize(TestContext testContext)
 {
     ConParams = new ConnectionParameters
     {
         Type = "MS-SQL",
         Name = "MS-SQL Connection",
         Host = Settings.Default.mssql_host,
         Database = Settings.Default.mssql_database,
         Port = Settings.Default.mssql_port,
         User = Settings.Default.mssql_user,
         Password = Settings.Default.mssql_password
     };
     DBWorker.ConfigureDBConnection(ConParams);
     DBWorker.OpenConnection();
     DBWorker.BuildMetadataRepository();
     Model = Serializer.Deserialize<MatrixSelectionModel>(@"Files\MS-SQLResults.mpm");
 }
コード例 #13
0
        public void DeserializeTest()
        {
            string filename = "Unit.tst";
            ConnectionParameters expected = new ConnectionParameters("TestString1", "TestString2", "TestString3", "TestString4", "TestString5", "TestString6", "TestString7");
            ConnectionParameters actual;

            Serializer.Serialize(filename, expected);
            actual = Serializer.Deserialize<ConnectionParameters>(filename);

            Assert.AreEqual(expected.Database, actual.Database);
            Assert.AreEqual(expected.Host, actual.Host);
            Assert.AreEqual(expected.IsLastUsedDatabase , actual.IsLastUsedDatabase);
            Assert.AreEqual(expected.Name , actual.Name );
            Assert.AreEqual(expected.Password, actual.Password);
            Assert.AreEqual(expected.Port , actual.Port);
            Assert.AreEqual(expected.Type , actual.Type);
            Assert.AreEqual(expected.User , actual.User);
        }
コード例 #14
0
        public static void MyClassInitialize(TestContext testContext)
        {
            string testDbPath = AppDomain.CurrentDomain.BaseDirectory + @"\Files\test.sqlite.db";

            // To enable tests in a virtual machine (change the letter accordingly)
            if (!Char.IsLetter(testDbPath.First()))
                testDbPath = "Z:" + testDbPath.Substring(10);

            ConParams = new ConnectionParameters("SQLite", "SQLite Connection", "", testDbPath);

            String dbDatabaseWithoutPathName = ConParams.Database.Substring(ConParams.Database.LastIndexOf(("\\"), StringComparison.Ordinal) + 1);
            Path = AppDomain.CurrentDomain.BaseDirectory + @"\Metadata_" + dbDatabaseWithoutPathName + "@" + ConParams.Host + ".xml";

            DBWorker.ConfigureDBConnection(ConParams);
            DBWorker.OpenConnection();

            DBWorker.BuildMetadataRepository();
            XMLHelper.SerializeObjectToXML(Path, DBWorker.MetaData);

            XmlMetadata = XMLHelper.DeserializeObjectFromXML<MetaDataRepository>(Path);
        }
コード例 #15
0
        public static void MyClassInitialize(TestContext testContext)
        {
            //Assert.Inconclusive("Oracle not yet tested");
            ConParams = new ConnectionParameters
            {
                Type = "Oracle",
                Name = "Oracle Connection",
                Host = Settings.Default.oracle_host,
                Database = Settings.Default.oracle_service,
                Port = Settings.Default.oracle_port,
                User = Settings.Default.oracle_user,
                Password = Settings.Default.oracle_password
            };

            DBWorker.ConfigureDBConnection(ConParams);
            DBWorker.OpenConnection();

            DBWorker.BuildMetadataRepository();

            Model = Serializer.Deserialize<MatrixSelectionModel>(@"Files\OracleResults.mpm");
        }
コード例 #16
0
        /// <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();
        }
コード例 #17
0
        public void LoadLastUsedDatabaseTest2()
        {
            ConnectionParameters expected = new ConnectionParameters("TestString", "TestString", "TestString", "TestString", "TestString", "TestString", "TestString");
            ConnectionParameters actual;

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

            actual = DBConnectionHelpers.LoadLastUsedDatabase();

            Assert.IsNull(actual);
        }
コード例 #18
0
 public void ConnectionParamsConstructorTest()
 {
     ConnectionParameters target = new ConnectionParameters();
     Assert.IsNotNull(target);
 }
コード例 #19
0
 public void UserTest()
 {
     ConnectionParameters target = new ConnectionParameters();
     string expected = "Teststring";
     string actual;
     target.User = expected;
     actual = target.User;
     Assert.AreEqual(expected, actual);
 }
コード例 #20
0
 public void PasswordTest()
 {
     ConnectionParameters target = new ConnectionParameters();
     string expected = "SecretKey4711";
     string actual;
     target.Password = expected;
     actual = target.Password;
     Assert.AreEqual(expected, actual);
 }
コード例 #21
0
 public void IsCompleteTrueTest1()
 {
     string type = "Teststring";
     string name = "Teststring";
     string host = "Teststring";
     string database = "Teststring";
     string user = "******";
     string password = "******";
     string port = "Teststring";
     ConnectionParameters target = new ConnectionParameters(type, name, host, database, user, password, port);
     Assert.IsTrue(target.IsComplete(), "ConnectionParameters Complete");
 }
コード例 #22
0
 public void IsCompleteFalseTest1()
 {
     ConnectionParameters target = new ConnectionParameters();
     Assert.IsFalse(target.IsComplete(),"Connecting String was not Complete");
 }
コード例 #23
0
        /// <summary>
        /// Test the Database-Connection.
        /// </summary>
        /// <param Name="sender"></param>
        /// <param Name="e"></param>
        /// <author>Bernhard Bruns</author>
        private void TestConnectionClick(object sender, RoutedEventArgs e)
        {
            Cursor = Cursors.Wait;

            ConnectionParameters connectionParameters = new ConnectionParameters();
            connectionParameters.Type = DBTypeComboBox.SelectedItem.ToString();
            connectionParameters.Name = DBConnectionnameTextBox.Text;
            connectionParameters.User = DBUsernameTextBox.Text;
            connectionParameters.Password = DBPasswordPasswordBox.Password;
            connectionParameters.Host = DBHostnameTextBox.Text;
            connectionParameters.Database = DBDatabaseTextBox.Text;
            connectionParameters.Port = DBPortTextBox.Text;

            try
            {
                if (DBWorker.ConfigureDBConnection(connectionParameters))
                {
                    if (DBWorker.OpenConnection())
                    {
                        ModernDialog.ShowMessage("The connection to " + connectionParameters.Host + " is established.", "Connection", MessageBoxButton.OK);
                    }
                    else
                        ErrorHandling.ReportErrorToUser("The connection could not be established.");
                }
                else
                    ModernDialog.ShowMessage("The connection could not be established. It's probably not implemented yet.", "Error: Implementation missing", MessageBoxButton.OK);
            }
            catch (NoParamsGivenException ex)
            {
                ModernDialog.ShowMessage(ex.ExceptionMessage, "Error: Missing parameters", MessageBoxButton.OK);
            }
            catch (ConnectionTypeNotGivenException ex)
            {
                ModernDialog.ShowMessage(ex.ExceptionMessage, "Error: No connection Type", MessageBoxButton.OK);
            }
            catch (NoConnectionException ex)
            {
                ModernDialog.ShowMessage(ex.ExceptionMessage, "Error: No connection", MessageBoxButton.OK);
            }

            catch (UnauthorizedAccessException ex)
            {
                ModernDialog.ShowMessage(ex.Message, "Error: Access denied ", MessageBoxButton.OK);
            }

            catch (WrongCredentialsException ex)
            {
                ModernDialog.ShowMessage(ex.ExceptionMessage, "Error: Wrong credentials", MessageBoxButton.OK);
            }
            catch (DatabaseDoesNotExist ex)
            {
                ModernDialog.ShowMessage(ex.ExceptionMessage, "Error: Wrong database", MessageBoxButton.OK);
            }
            catch (TimeoutException ex)
            {
                ModernDialog.ShowMessage(ex.Message, "Error: Timeout", MessageBoxButton.OK);
            }
            catch (DBException ex)
            {
                ModernDialog.ShowMessage(ex.Message, "Error: Unknown", MessageBoxButton.OK);
            }

            finally
            {
                Cursor = Cursors.Arrow;
            }
        }
コード例 #24
0
 public void EmptyPasswordTest()
 {
     ConnectionParameters target = new ConnectionParameters();
     target.Password = "";
     Assert.IsTrue(string.IsNullOrEmpty(target.Password));
 }
コード例 #25
0
        public void CurrentConnectionParametersTest()
        {
            ConnectionParameters expected = new ConnectionParameters("TestString", "TestString", "TestString", "TestString", "TestString", "TestString", "TestString");
            ConnectionParameters actual;

            DBConnectionHelpers.CurrentConnectionParameters = expected;
            actual = DBConnectionHelpers.CurrentConnectionParameters;

            Assert.AreEqual(expected, actual);
        }
コード例 #26
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);
        }
コード例 #27
0
        /// <summary>
        /// If the selectedindex of the listbox changes, the textboxes get refreshed
        /// </summary>
        /// <param Name="sender"></param>
        /// <param Name="e"></param>
        /// <author>Bernhard Bruns</author>
        private void ConnectionsSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (ConnectionsListBox.SelectedIndex >= 0)
                {
                    ConnectionParameters = (ConnectionParameters)ConnectionsListBox.Items[ConnectionsListBox.SelectedIndex];

                    DBTypeComboBox.Text = ConnectionParameters.Type;
                    DBConnectionnameTextBox.Text = ConnectionParameters.Name;
                    DBHostnameTextBox.Text = ConnectionParameters.Host;
                    DBDatabaseTextBox.Text = ConnectionParameters.Database;
                    DBPasswordPasswordBox.Password = ConnectionParameters.Password;
                    DBPortTextBox.Text = ConnectionParameters.Port;
                    DBUsernameTextBox.Text = ConnectionParameters.User;
                }
            }
            catch (Exception ex)
            {
                ModernDialog.ShowMessage(ex.Message, "Error: ", MessageBoxButton.OK);
            }
        }
コード例 #28
0
 //private NpgsqlConnection Connection;
 /// <summary>
 /// Constructor, initializes a new connection from the ConnectionParameters-object.
 /// </summary>
 /// <param name="connectionParameters">The connection parameters.</param>
 public MPMPostgreSQLConnection(ConnectionParameters connectionParameters)
     : base(connectionParameters)
 {
     DBWorker.SqlCreator = new SQLCreatorPostgres();
 }
コード例 #29
0
        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);
        }
コード例 #30
0
        /// <summary>
        /// The selected item will be removed.
        /// </summary>
        /// <param Name="sender"></param>
        /// <param Name="e"></param>
        /// <author>Bernhard Bruns</author>
        private void RemoveConnectionClick(object sender, RoutedEventArgs e)
        {
            if (ConnectionsListBox.Items.Count > 0 && ConnectionsListBox.SelectedIndex >= 0)
            {
                ConnectionParameters = (ConnectionParameters)ConnectionsListBox.Items[ConnectionsListBox.SelectedIndex];

                if (ModernDialog.ShowMessage("Are you sure you want to remove the connection \"" + ConnectionParameters.Name + "\"?", "Remove", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    DBConnectionHelpers.ConnectionParametersList.Remove(ConnectionParameters);
                    ReloadListbox();

                    if (ConnectionsListBox.Items.Count > 0)
                    {
                        ConnectionsListBox.SelectedIndex = 0;
                    }
                    else
                    {
                        DBTypeComboBox.Text = "";
                        DBConnectionnameTextBox.Text = "";
                        DBUsernameTextBox.Text = "";
                        DBPasswordPasswordBox.Password = "";
                        DBHostnameTextBox.Text = "";
                        DBPortTextBox.Text = "";
                        DBDatabaseTextBox.Text = "";
                    }
                }

            }
        }