public void CreateMasterReportEntry(MasterReportQueueEntryDto dto) { DbCommand sp = null; DbConnection connection = null; IDataReader reader = null; try { connection = _dbLayer.GetConnection(); sp = connection.CreateCommand(); //TODO check if MasterReport logic should be refactored! //current logic does not use insert_queued_masterreport... //sp.CommandText = "insert_queued_masterreport"; sp.CommandText = "insert_queued_report"; sp.CommandType = CommandType.StoredProcedure; _dbLayer.AddInParameter(sp, "requestor_email", DbType.String, dto.UserId); //current logic does not use insert_queued_masterreport and hence does not provide master_FK... //_dbLayer.AddInParameter(sp, "master_FK", DbType.Int32, dto.MasterReportId); //current logic does not use insert_queued_masterreport and hence provides a dummy questionnaire_FK to insert_queued_report... _dbLayer.AddInParameter(sp, "questionnaire_FK", DbType.Int32, 9999); _dbLayer.AddInParameter(sp, "from", DbType.DateTime, dto.From); _dbLayer.AddInParameter(sp, "until", DbType.DateTime, dto.To); //current logic does not use insert_queued_masterreport and hence provides a dummy schedule_id to insert_queued_report... _dbLayer.AddInParameter(sp, "schedule_id", DbType.Int32, -1); //current logic does not use insert_queued_masterreport and hence provides the schedule_master_id to insert_queued_report... _dbLayer.AddInParameter(sp, "schedule_master_id", DbType.Int32, dto.MasterReportId); _dbLayer.AddReturnParameter(sp); sp.ExecuteNonQuery(); } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } if (sp != null) { sp.Dispose(); } if (connection != null) { _dbLayer.ReturnConnection(connection); } else { _dbLayer.ReturnConnection(connection, true); } } }
public void TestCheckMasterReportQueue() { MasterReportDto dto = new MasterReportDto(MasterReportDto.TransientId, new List<MasterQuestionnaireDto>(), "", DateTime.Now, new List<Pair<PageElementType, string>>(), ""); MasterReportDto persDto = FormRegistry.MasterReportDao.Create(dto); _createdMasterReports.Add(persDto.MasterRptId); MasterReportQueueEntryDto entry = new MasterReportQueueEntryDto(TestUser, DateTime.Now, DateTime.Now, persDto.MasterRptId); Assert.AreEqual(QueueStatus.NotQueued, entry.QueueStatus); AdminRegistry.QueueDao.CreateMasterReportEntry(entry); //check get //TODO: Masterreport - DBServerTime is UTC, whereas DateTime.Now is local time - hence .ListMasterReportQueue can return null even if successfully entered to DB List<MasterReportQueueEntryDto> list = AdminRegistry.QueueDao.ListMasterReportQueue(DateTime.Now.AddMinutes(-1), DateTime.Now.AddMinutes(1)); Assert.IsNotNull(list); MasterReportQueueEntryDto queueEntry = list.Find(delegate(MasterReportQueueEntryDto cur) { return cur.MasterReportId == persDto.MasterRptId; }); if (list.Count > 0) { Assert.IsNotNull(queueEntry); Assert.AreEqual(QueueStatus.Queued, queueEntry.QueueStatus); //check failed string errorMsg = "error mine"; FailedMasterReportDto failedEntry = new FailedMasterReportDto(persDto.MasterRptId, TestUser, DateTime.Now, DateTime.Now, queueEntry.QueueEntryId, DateTime.Now, errorMsg); AdminRegistry.QueueDao.CreateFailedEntry(failedEntry); list = AdminRegistry.QueueDao.ListMasterReportQueue(DateTime.Now.AddMinutes(-1), DateTime.Now.AddMinutes(1)); Assert.IsNotNull(list); queueEntry = list.Find(delegate(MasterReportQueueEntryDto cur) { return cur.MasterReportId == persDto.MasterRptId; }); Assert.IsNotNull(queueEntry); Assert.AreEqual(QueueStatus.ErrorOccurred, queueEntry.QueueStatus); List<FailedMasterReportDto> failedList = AdminRegistry.QueueDao.ListFailedMasterReports(null, null); FailedMasterReportDto failedEntrySel = failedList.Find(delegate(FailedMasterReportDto cur) { return cur.MasterReportId == persDto.MasterRptId; }); Assert.IsNotNull(failedEntrySel); Assert.AreEqual(errorMsg, failedEntrySel.FailureMessage); //check update AdminRegistry.QueueDao.SetMasterReportStatus(queueEntry.QueueEntryId, QueueStatus.Dequeued); list = AdminRegistry.QueueDao.ListMasterReportQueue(DateTime.Now.AddMinutes(-1), DateTime.Now.AddMinutes(1)); Assert.IsNotNull(list); queueEntry = list.Find(delegate(MasterReportQueueEntryDto cur) { return cur.MasterReportId == persDto.MasterRptId; }); Assert.IsNotNull(queueEntry); Assert.AreEqual(QueueStatus.Dequeued, queueEntry.QueueStatus); //check if master report definition is deleted FormRegistry.MasterReportDao.DeleteMasterReport(persDto.MasterRptId); _createdMasterReports.Remove(persDto.MasterRptId); List<MasterReportDto> list2 = FormRegistry.MasterReportDao.GetMasterReports(null, null, null, null, "ad"); Assert.IsNotNull(list2); Assert.IsFalse(list2.Exists(delegate(MasterReportDto cur) { return cur.MasterRptId == persDto.MasterRptId; })); //do not check if also queue history for deleted master report is deleted as the history is kept //do not check if entry for a failed master report is deleted as this is kept for history/log //failedList = AdminRegistry.QueueDao.ListFailedMasterReports(null, null); //failedEntrySel = failedList.Find(delegate(FailedMasterReportDto cur) { return cur.MasterReportId == persDto.MasterRptId; }); //Assert.IsNull(failedEntrySel); } else Assert.IsNull(queueEntry); }
public static void CreateQueueEntry(MasterReportQueueEntryDto dto) { AdminRegistry.QueueDao.CreateMasterReportEntry(dto); }
private MasterReportQueueEntryDto ReadMasterQueueEntry(IDataReader reader, ref bool alreadyRead) { MasterReportQueueEntryDto retval = null; int queueEntryId = reader.GetInt32(0); string userId = reader.GetString(1); int masterReportId = reader.GetInt32(2); DateTime from = reader.GetDateTime(3); DateTime to = reader.GetDateTime(4); QueueStatus queueStatus = (QueueStatus)reader.GetInt32(5); DateTime requestDate = reader.GetDateTime(6); DateTime? finishDate = GetDateTime(reader, 7); retval = new MasterReportQueueEntryDto(queueEntryId, userId, from, to, masterReportId, requestDate, finishDate, queueStatus); alreadyRead = reader.Read(); return retval; }