Exemple #1
0
        public DataTable ExecuteUserQuery(int QuestionId, string Query, User User)
        {
            ValidateUserQuery(Query);

            using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.DatabaseDataSourcesConnectionString))
            {
                try
                {
                    conn.Open();
                    var exerciseService             = IocContainer.Container.GetInstance <IExerciseService>();
                    MultipleChoiceExercise exercise = (MultipleChoiceExercise)exerciseService.GetByQuestion(QuestionId, User);
                    var question = exercise.Questions.Single(x => x.ExerciseQuestionId == QuestionId);

                    // Start a transaction first
                    _sourceDA.BeginUserTransaction(conn);
                    IQueryBuilder queryBuilder = QueryBuilderFactory.CreateQueryBuilder(SourceDatabaseType.TSQL);

                    // Do any commands that the user has already ran on this data source (Execute Query type only, not submitted answers)
                    if (User.UserId != -1)
                    {
                        List <UserActionModel> queries = _da.ListQuestionQueries(question.ExerciseQuestionId, User.UserId);

                        foreach (UserActionModel query in queries)
                        {
                            try
                            {
                                String userQuery = queryBuilder.BuildQuery(query.Description, exercise, question);
                                _sourceDA.ExecuteUserQuery(userQuery, conn);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }

                    // Do the commands
                    String builtQuery = queryBuilder.BuildQuery(Query, exercise, question);

                    DataTable results = _sourceDA.GetDataTable(builtQuery, conn, 100);

                    return(results);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    // Roll back the transaction
                    _sourceDA.RollBackUserTransaction(conn);
                }
            }
        }
Exemple #2
0
        public void GetDifferences_should_not_be_slow_on_large_datasets()
        {
            ISourceDataAccess da  = SourceDataAccessFactory.CreateDataAccess(SourceDatabaseType.TSQL);
            DataTable         dt1 = da.GetDataTable("select * FROM SRC_EMARKETING_EMAIL ORDER BY EmailId ASC");
            DataTable         dt2 = da.GetDataTable("select * FROM SRC_EMARKETING_EMAIL ORDER BY EmailId DESC");

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            var results = new DifferenceEngine().GetDifferences(dt1, dt2);

            stopwatch.Stop();

            Assert.IsTrue(stopwatch.ElapsedMilliseconds < 200);
        }
Exemple #3
0
        public void GetDifferences_should_not_be_slow()
        {
            ISourceDataAccess da  = SourceDataAccessFactory.CreateDataAccess(SourceDatabaseType.TSQL);
            DataTable         dt1 = da.GetDataTable("select exq.exq_description, count(exqa.exqa_id) 'times_answered' from src_exercises_questions exq  left join src_exercises_questions_answered exqa on exq.exq_id = exqa.exq_id  group by exq.exq_id, exq.exq_description");
            DataTable         dt2 = da.GetDataTable("select exq.exq_description, count(*) 'times_answered' from src_exercises_questions exq  left join src_exercises_questions_answered exqa on exq.exq_id = exqa.exq_id  group by exq.exq_id, exq.exq_description");

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            var results = new DifferenceEngine().GetDifferences(dt1, dt2);

            stopwatch.Stop();

            Assert.IsTrue(stopwatch.ElapsedMilliseconds < 200);
        }