예제 #1
0
        public void AddTestHistory( TestHistory testHistory )
        {
            string testHistoryCommand = "INSERT " + TestHistoryTable + " (HistoryID,RunTime,TestID,Status) " + "VALUES ('" +
                                        testHistory.ID + "','" + testHistory.Runtime.ToString( ) + "','" + testHistory.TestID + "','" + testHistory.Status + "')";

            SqlCommand cmd = new SqlCommand( testHistoryCommand, SqlDataConnection );

            cmd.ExecuteNonQuery( );

            return;
        }
예제 #2
0
        public ArrayList RetrieveTestHistories( string testID )
        {
            ArrayList testHistories = new ArrayList( );

            string testHistoryCommand = "SELECT * FROM " + TestHistoryTable + " WHERE TestID='" + testID + "'";

            SqlCommand cmd = new SqlCommand( testHistoryCommand, SqlDataConnection );

            SqlDataReader dataReader = cmd.ExecuteReader( );

            TestHistory retrievedTestHistory = null;

            while ( dataReader.Read( ) )
            {
                retrievedTestHistory = new TestHistory( );

                retrievedTestHistory.ID = dataReader["HistoryID"].ToString( );
                retrievedTestHistory.Runtime = DateTime.Parse( dataReader["RunTime"].ToString( ) );
                retrievedTestHistory.TestID = dataReader["TestID"].ToString( );
                retrievedTestHistory.Status = dataReader["Status"].ToString( );

                testHistories.Add( retrievedTestHistory );
            }

            dataReader.Close( );

            return testHistories;
        }
예제 #3
0
        public TestHistory RetrieveTestHistory( string ID )
        {
            string testHistoryCommand = "SELECT * FROM " + TestHistoryTable + " WHERE HistoryID='" + ID + "'";

            SqlCommand cmd = new SqlCommand( testHistoryCommand, SqlDataConnection );

            SqlDataReader dataReader = cmd.ExecuteReader( );

            dataReader.Read( );

            TestHistory retrievedTestHistory = new TestHistory( );

            retrievedTestHistory.ID = dataReader["HistoryID"].ToString( );
            retrievedTestHistory.Runtime = DateTime.Parse( dataReader["RunTime"].ToString( ) );
            retrievedTestHistory.TestID = dataReader["TestID"].ToString( );
            retrievedTestHistory.Status = dataReader["Status"].ToString( );

            dataReader.Close( );

            return retrievedTestHistory;
        }
예제 #4
0
파일: RunQueue.cs 프로젝트: uvbs/Holodeck
        private void Executer( )
        {
            int exitCode = 0;
            TestHistory testHistory = null;

            for (;;)
            {
                Thread.Sleep( ExecutionDelay );

                // If there are items waiting on the queue, we will remove the first item and begin
                // execution...
                if ( ExecutionQueue.Count > 0 )
                {
                    updateMutex.WaitOne( );         // Start waiting for the mutex...

                    // Pull out the queue entry...
                    QueueEntry entry = (QueueEntry)ExecutionQueue.Dequeue( );

                    // Set a flag on the RunItem to show that it is out of the queue and currently
                    // running.
                    foreach ( RunItem item in RunItems )
                    {
                        if ( item.TestID == entry.TestInformation.ID )
                            item.IsRunning = true;
                    }

                    updateMutex.ReleaseMutex( );    // Release the mutex when done...

                    // Add a new history entry to record that the test is now starting...
                    testHistory = new TestHistory( );
                    testHistory.TestID = entry.TestInformation.ID;
                    testHistory.Runtime = DateTime.Now;
                    testHistory.Status = "STARTED";
                    dbConnection.AddTestHistory( testHistory );

                    // Update the CURRENT state of the test...
                    UpdateTestState( entry.TestInformation.ID, "RUNNING" );

                    // Now, outside the main mutex, we perform our concurrent action for running the
                    // executable, but this time using a different mutex. This makes sure that
                    // each application never runs more than one at a time.
                    executionMutex.WaitOne( );

                    exitCode = ExecuteQueueEntry( entry );

                    executionMutex.ReleaseMutex( );

                    // We must grab the mutex again to mess with the RunItem structure...
                    updateMutex.WaitOne( );

                    // Since the position or location of the RunItem in memory cannot be guaranteed because we
                    // left the mutex for the run of the program, we must go back and find it again...
                    foreach ( RunItem item in RunItems )
                    {
                        if ( item.TestID == entry.TestInformation.ID )
                        {
                            // The application is no longer running, so update that state in the current
                            // memory structure...
                            item.IsRunning = false;

                            // Modify the existing runFrequency trackingItem definition to contain the current
                            // time as the start time...
                            RunFrequency runFrequency = new RunFrequency( item.Frequency );
                            runFrequency.StartDate = DateTime.Now;

                            // If this test is supposed to run a static number of times, we decrement the counter...
                            if ( !runFrequency.RunInfinite )
                                runFrequency.RunNumberOfTimes--;

                            // Update the item already in memory with the new changes...
                            item.Frequency = runFrequency.GetFrequencyString( );

                            // Now, update the SQL database with this information...
                            UpdateRunItemFrequency( item.TestID, runFrequency.GetFrequencyString( ) );

                            // Add a new history entry to record the results of the test...
                            testHistory = new TestHistory( );
                            testHistory.TestID = item.TestID;
                            testHistory.Runtime = runFrequency.StartDate;

                            if ( exitCode == 0 )
                            {
                                testHistory.Status = "SUCCESS";
                                SendEmail( item, true );
                            }
                            else
                            {
                                testHistory.Status = "FAILURE (" + exitCode.ToString( ) + ")";
                                SendEmail( item, false );
                            }

                            // Update the CURRENT state of the test... - SUCCESS or FAILURE (either determines that
                            // the test is no longer running - STOPPED).
                            UpdateTestState( item.TestID, testHistory.Status );

                            dbConnection.AddTestHistory( testHistory );
                        }
                        else
                        {
                            // We should NEVER get here...
                            eventLog.WriteEntry( "An item existed in the execution queue which didn't exist in the database!",
                                                 System.Diagnostics.EventLogEntryType.Error );
                        }
                    }

                    // Release the mutex so that further threads may modify the RunItem structures...
                    updateMutex.ReleaseMutex( );
                }
            }
        }