/// <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;
            }
        }
示例#2
0
        public void GetConnectionNameNoConnectionTest()
        {
            // arrange
            DBWorker.Reset();
            const string expected = "No connection";
            // act
            string actual = DBWorker.GetConnectionName();

            // assert
            Assert.AreEqual(expected, actual);
        }
示例#3
0
        public void MSSQLTests()
        {
            ConnectionParameters 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
            };

            Assert.IsTrue(DBWorker.ConfigureDBConnection(conParams), "MS-SQL connection configured");
            Assert.IsTrue(DBWorker.OpenConnection(), "MS-SQL connection opened");
            Assert.IsTrue(DBWorker.IsOpen(), "MS-SQL connection is currently open");
            Assert.IsFalse(string.IsNullOrEmpty(DBWorker.GetConnectionName()), "MS-SQL connection name correct.");
            Assert.IsTrue(DBWorker.CloseConnection(), "MS-SQL connection closed");
            DBWorker.Reset();
        }
示例#4
0
        public void SQLiteTests()
        {
            // arrange
            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);
            }

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

            Assert.IsTrue(DBWorker.ConfigureDBConnection(conParams), "SQLite connection configured");
            Assert.IsTrue(DBWorker.OpenConnection(), "SQLite connection opened");
            Assert.IsTrue(DBWorker.IsOpen(), "SQLite connection is currently open");
            Assert.IsFalse(string.IsNullOrEmpty(DBWorker.GetConnectionName()), "SQLite connection name correct.");
            Assert.IsTrue(DBWorker.CloseConnection(), "SQLite connection closed");
            DBWorker.Reset();
        }
示例#5
0
        public void OracleTests()
        {
            // arrange
            ConnectionParameters 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
            };

            Assert.IsTrue(DBWorker.ConfigureDBConnection(conParams), "Oracle connection configured");
            Assert.IsTrue(DBWorker.OpenConnection(), "Oracle connection opened");
            Assert.IsTrue(DBWorker.IsOpen(), "Oracle connection is currently open");
            Assert.IsFalse(string.IsNullOrEmpty(DBWorker.GetConnectionName()), "Oracle connection name correct.");
            Assert.IsTrue(DBWorker.CloseConnection(), "Oracle connection closed");
            Assert.IsTrue(DBWorker.TryConnection(), "Try Connection");
            Assert.IsTrue(DBWorker.DisposeConnection(), "Connection disposed");

            DBWorker.Reset();
        }
        /// <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);
        }