Esempio n. 1
0
        public void CreateFailedEntry(FailedMasterReportDto dto)
        {
            DbCommand sp = null;
            DbConnection connection = null;
            IDataReader reader = null;
            try
            {
                if (dto.MasterReportId > 0)
                {
                    connection = _dbLayer.GetConnection();
                    sp = connection.CreateCommand();

                    sp.CommandText = "insert_failed_masterreport";
                    sp.CommandType = CommandType.StoredProcedure;
                    _dbLayer.AddInParameter(sp, "master_FK", DbType.Int32, dto.MasterReportId);
                    _dbLayer.AddInParameter(sp, "user_FK", DbType.String, dto.UserId);
                    _dbLayer.AddInParameter(sp, "from", DbType.DateTime, dto.From);
                    _dbLayer.AddInParameter(sp, "until", DbType.DateTime, dto.To);
                    _dbLayer.AddInParameter(sp, "entry_id", DbType.Int32, dto.QueueId);
                    _dbLayer.AddInParameter(sp, "datefailed", DbType.DateTime, dto.FailureDate);
                    _dbLayer.AddInParameter(sp, "error_reason", DbType.String, dto.FailureMessage);
                    _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);
                }
            }
        }
Esempio n. 2
0
		/// <summary>
		/// main method of the thread, generates reports
		/// </summary>
		private void generate_dataemail_processingqueue()
		{

            //Added by Phani on 16-04-2009 for RFG 1.9.2 release CaliberRM #PR126953 
            string myPathToTempDir = "";

			while (emailreports.Count != 0)
			{
				report_values emailreport = null;
                //Added Impersonation for RFG 1.9.2 release CaliberRM #PR141900
                Impersonator impersonate = null;
				try	
				{
                    
					emailreport = (report_values)emailreports.Dequeue();
					//Dequeued a waiting report
                    
                    //Added by Phani on 16-04-2009 for RFG 1.9.2 release CaliberRM #PR126953 
                    myPathToTempDir = emailreport.pathtotempdir;
					
                    //log dequeue in DB
					Hashtable h_params = new Hashtable();
					h_params.Add("entry_id", emailreport.queue_entry_id);
					h_params.Add("status", 2); //2 = dequeued
                    //for master report
                    //if (emailreport.IsMasterReport)
                    //{
                    //    int reportId = 0;
                    //    if (int.TryParse(emailreport.queue_entry_id, out reportId))
                    //    {
                    //        QueueFacade.SetMasterReportStatus(reportId, QueueStatus.Dequeued);
                    //    }
                    //}
                    //else
                    //{
                        DB.execProc("update_queued_report", h_params);
                    //}

                    //Added Impersonation for RFG 1.9.2 release CaliberRM #PR141900  
                    string username = utility.getParameter("cluster_usr_usernam");
                    string password = utility.getParameter("cluster_usr_password");
                    string domain = utility.getParameter("cluster_usr_domaim");

                    impersonate = new Impersonator(username, domain , password);
                    impersonate.Impersonate();
                    //for master report
                    if (!emailreport.IsMasterReport)
                        generate_dataemail_processingfile(emailreport);
                    else
                        generate_dataemail_processingfileMaster(emailreport);

                    impersonate.Undo();
				}
				catch (Exception ex)
				{
                    if (impersonate != null)
                    {
                        impersonate.Undo();
                    }
					if (emailreport != null)
					{
                        if (!emailreport.IsMasterReport && 
                            (ex is SmtpFailedRecipientException || ex is SmtpFailedRecipientsException))
                        {
                            try { processFailedEmails(ex, emailreport); } catch { }
                        }
                        else
                        {
                            send_error_email(emailreport, ex);
                        }

						if(emailreport.IsMasterReport)
                        {
                            int queueId = 0;
                            if (int.TryParse(emailreport.queue_entry_id, out queueId))
                            {
                            FailedMasterReportDto msg = new FailedMasterReportDto(emailreport.Master.Dto.MasterRptId,
                                emailreport.permss_user, emailreport.from, emailreport.until, queueId,
                                DateTime.Now.Date, ex.Message);
                            QueueFacade.SetFailureMessage(msg);
                            }
                        }
                        else
                        {
                            Hashtable h_params = new Hashtable();
						    h_params.Add("questionnaire_FK", emailreport.questionnaire_id);
						    h_params.Add("user_FK", emailreport.permss_user);
						    h_params.Add("from", emailreport.from);
						    h_params.Add("until", emailreport.until);
						    h_params.Add("entry_id", emailreport.queue_entry_id);
						    h_params.Add("error_reason", ex.Message);
                            h_params.Add("schedule_id", emailreport.schedule_id);

						    DB.execProc("insert_failed_report", h_params);
                        }
					}
				}
				Thread.Sleep(500);
			}

            //Added by Phani on 16-04-2009 for RFG 1.9.2 release CaliberRM #PR126953 
            if (dateString != DateTime.Today.ToShortDateString() && !String.IsNullOrEmpty(myPathToTempDir))
            {
                new tasks.DailyTasksRoutine().delete_old_temp_files(myPathToTempDir);
                dateString = DateTime.Today.ToShortDateString();
            }

		}
Esempio n. 3
0
        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);

        }
Esempio n. 4
0
 public static void SetFailureMessage(FailedMasterReportDto dto)
 {
     AdminRegistry.QueueDao.CreateFailedEntry(dto);
 }
Esempio n. 5
0
 private FailedMasterReportDto ReadMasterFailedEntry(IDataReader reader, ref bool alreadyRead)
 {
     FailedMasterReportDto retval = null;
     int pl = reader.GetInt32(0);
     int masterReportId = reader.GetInt32(1);
     string userId = reader.GetString(2);
     DateTime from = reader.GetDateTime(3);
     DateTime to = reader.GetDateTime(4);
     DateTime failureDate = reader.GetDateTime(5);
     string error = reader.GetString(6);
     retval = new FailedMasterReportDto(masterReportId, userId, from, to, pl, failureDate, error);
     alreadyRead = reader.Read();
     return retval;
 }