예제 #1
0
        /// <summary>
        /// main method of the thread, generates a master report
        /// </summary>
        /// <param name="report_params"></param>
        private void generate_dataemail_processingfileMaster(report_values report_params)
        {
            datamgmt.process_responses processing_files = new datamgmt.process_responses(true);

            processing_files.permss_user = report_params.permss_user;
            processing_files.permss_admin = report_params.permss_admin;
            processing_files.questionnaire_id = report_params.questionnaire_id;
            processing_files.from = report_params.from;
            processing_files.until = report_params.until;
            processing_files.questionnaire_title = report_params.questionnaire_title;
            processing_files.pathtotempdir = report_params.pathtotempdir;

             processing_files.Master = report_params.Master;
             processing_files.IsmasterReport = report_params.IsMasterReport;
            if(report_params.scheduled)
                processing_files.IsMasterFail = processing_files.Master.ValidateMaster();
          

            StringCollection file_names = new StringCollection();
            int record_counter = 0;
            string zip_name = "";
            if (!processing_files.IsMasterFail)
            {
                file_names = processing_files.generate();

                //read number of records and delete entry in file_names
                 record_counter = Int32.Parse(file_names[0]);
                file_names.RemoveAt(0);

                #region create zip file
                string timeformat = "yyyyMMddHHmmss";

                zip_name = String.Format("zip_{0}_{1}.zip", report_params.Master.Dto.MasterRptId, DateTime.Now.ToString(timeformat));


                utility.createZIP(zip_name, report_params.pathtotempdir, file_names);

                #endregion
            }

            #region create and send email

            MailMessage msg = new MailMessage();

            //.NET 1.1: msg.BodyFormat = MailFormat.Html;
            msg.IsBodyHtml = true;

            //.NET 1.1: msg.From = email_from;
            msg.From = new MailAddress(email_from);

            //.NET 1.1: msg.To = report_params.permss_user;
            //MailAddressCollection to = msg.To;
            utility.set_Mail_address(ref msg, "to", report_params.permss_user);
            //to.Add(report_params.permss_user);
            if (processing_files.IsMasterFail)
            {
                msg.Subject = String.Format("RFG - FAILURE - combined response file report for master report {0}", report_params.Master.Dto.MasterName);
            }
            else
            {
                msg.Subject = String.Format("RFG - combined response file report for master report {0}", report_params.Master.Dto.MasterName);

            }

            if (record_counter > 0)
            {
                //.NET 1.1: MailAttachment response_files = new MailAttachment(report_params.pathtotempdir + zip_name);
                Attachment response_files = new Attachment(report_params.pathtotempdir + zip_name);
                msg.Attachments.Add(response_files);
            }

            #region building emails content (information about the responsefiles)
            //††† 20120302 Biju Pattathil | RFG2.7 PR629425:dts email having wrong RFG support link (RFG Support link will change):Start†††
            string support_url = utility.getParameter("support_link"); //+ "live/index.aspx?qid=1493&flexfield1=stop_scheduled_report&flexfield14=qid-" + report_params.questionnaire_id + "-sid-" + report_params.schedule_id + "&flexfield15=" + report_params.permss_user;

            string mail_text = @"
                                <style>
									body {font-family:""Arial"";font-weight:normal;font-size:10pt;color:black;} 
        							table {font-family:""Arial"";font-weight:normal;font-size:10pt;color:black;}
                                    p {font-family:""Arial"";font-weight:normal;color:black;margin-top: -5px}
        							b {font-family:""Arial"";font-weight:bold;color:black;margin-top: -5px}
        							H1 { font-family:""Arial"";font-weight:normal;font-size:14pt;color:black }
        							H2 { font-family:""Arial"";font-weight:normal;font-size:10pt;color:maroon }
									H3 { font-family:""Arial"";font-weight:normal;font-size:10pt;color:darkgreen }
        							pre {font-family:""Arial Console"";font-size: .9em}
                                    .head{ font-family:""Arial"";font-weight:bold;font-size:10pt;color:red }
        							.marker {font-weight: bold; color: black;text-decoration: none;}
        							.version {color: gray;}
        							.error {margin-bottom: 10px;}
        							.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
								</style>";


            if (report_params.scheduled)
            {
                //Commented by Phani for RFG 1.9.4 release 
                //mail_text = String.Format("{0}<span><b>This is a scheduled report!</b></span><br><br>", mail_text);
                mail_text = String.Format("{0}<span class=head>This is an automatically generated scheduled report - please do not reply to this email as answers won't be read!</span><br>", mail_text);
                mail_text = String.Format("{0}<span><i>If you don't need to receive this report any longer please submit your request for the report to stop on the <a href=" + support_url + "> RFG support form</a></i></span><br><br><br>", mail_text);
            }

            mail_text = String.Format("{0}<span><p>Hello {1},<br><br>", mail_text, report_params.permss_user);

            if (record_counter > 0)
            {
                mail_text = String.Format("{0}please find attached a zip-archive containing the requested responses for<br><br><table border=1>", mail_text);
            }
            else
            {
                if (!processing_files.IsMasterFail)
                {
                    mail_text = String.Format("{0}there were no records of responses you have requested for<br><br><table border=1>", mail_text);
                }
                else
                {
                    string txt = "there is a configuration error for the below master report you should receive. Due to this error a report can not be generated.<br><span class=head>Please get in touch with {1} in order to fix the configuration error.</span><br><br><table border=1>";
                    mail_text = String.Format("{0}" + txt, mail_text, report_params.Master.Dto.Creator.ToString());
                }
            }
            //if (!report_params.IsMasterReport)
            //{
            //    mail_text = String.Format("{0}<tr><td width=100>Campaign - Title:</td><td><b>{1} - {2}</b> (qid = {3})&nbsp;</td></tr>", mail_text, report_params.campaign_name, report_params.questionnaire_title, report_params.questionnaire_id);
            //}
            //else
            //{
            if(report_params.Master.Dto.MasterRptId>1)
                mail_text = String.Format("{0}<tr><td width=100>Master Report Name:</td><td><b>{1}(mid = {2})</b> &nbsp;</td></tr>", mail_text, report_params.Master.Dto.MasterName, report_params.Master.Dto.MasterRptId.ToString());
            else
                mail_text = String.Format("{0}<tr><td width=100>Master Report Name:</td><td><b>{1}{2}</b> &nbsp;</td></tr>", mail_text, report_params.Master.Dto.MasterName, "");
            //}
            mail_text = String.Format("{0}<tr><td>from: </td><td><b>{1}</b></td></tr>", mail_text, report_params.from.ToShortDateString());
            mail_text = String.Format("{0}<tr><td>until: </td><td><b>{1}</b></td></tr>", mail_text, report_params.until.AddDays(-1d).ToShortDateString());
            mail_text = String.Format("{0}<tr><td>number of records<br>in response file: </td><td><b>{1}</b></td></tr><br>", mail_text, record_counter.ToString());
                       
            //for master report
            if (report_params.IsMasterReport)
            {
                string str = "";
                report_params.Master.Dto.MasterQ.ForEach(delegate(MasterQuestionnaireDto mq)
                {
                    str = string.Format("{4}{0}-{1}({2}={3})<br>", mq.CName, mq.QName, "qid", mq.QId.ToString(), str);
                });
                mail_text = String.Format("{0}<tr><td>list of questionnaires/<br>processors contained<br>in this master report: </td><td><b>{1}</b></td></tr></table><br>", mail_text, str);

            }
            mail_text = String.Format("{0}<br>Regards,<br>Your RFG-team</p></span>", mail_text);
            #endregion

            msg.Body = mail_text;

            //.NET 1.1: SmtpMail.Send(msg);
            SmtpClient smtp = new SmtpClient(utility.getParameter("smtp"));
            smtp.Send(msg);

            msg.Dispose();

            try
            {
                File.Delete(report_params.pathtotempdir + zip_name);

                //foreach (String file in file_names)
                //{
                //    File.Delete(report_params.pathtotempdir + file);
                //}
            }
            catch
            { }

            #endregion

            //log finish in DB
            int reportId = 0;
            if (int.TryParse(report_params.queue_entry_id, out reportId))
            {
                QueueFacade.SetMasterReportStatus(reportId, QueueStatus.Completed);
            }
        }
예제 #2
0
		/// <summary>
		/// main method of the thread, generates a single report
		/// </summary>
		/// <param name="report_params"></param>
		private void generate_dataemail_processingfile(report_values report_params)
		{
			datamgmt.process_responses processing_files = new datamgmt.process_responses(true);
			
			processing_files.permss_user = report_params.permss_user;
			processing_files.permss_admin = report_params.permss_admin;
			processing_files.questionnaire_id = report_params.questionnaire_id;
			processing_files.from = report_params.from;
			processing_files.until = report_params.until;
			processing_files.questionnaire_title = report_params.questionnaire_title;
			processing_files.pathtotempdir = report_params.pathtotempdir;

           
			StringCollection file_names = processing_files.generate();
            
			//read number of records and delete entry in file_names
			int record_counter = Int32.Parse(file_names[0]);
			file_names.RemoveAt(0);
			
			#region create zip file
			string timeformat = "yyyyMMddHHmmss";
            string zip_name = String.Format("zip_{0}_{1}.zip", report_params.questionnaire_id, DateTime.Now.ToString(timeformat));
            utility.createZIP(zip_name, report_params.pathtotempdir, file_names);

			#endregion

			#region create and send email

            MailMessage msg = new MailMessage();
					
            //.NET 1.1: msg.BodyFormat = MailFormat.Html;
			msg.IsBodyHtml = true;

            //.NET 1.1: msg.From = email_from;
            msg.From = new MailAddress(email_from);

            //.NET 1.1: msg.To = report_params.permss_user;
            //MailAddressCollection to = msg.To;
            utility.set_Mail_address(ref msg, "to", report_params.permss_user); 
            //to.Add(report_params.permss_user);

            msg.Subject = String.Format("Response-Files for campaign {0} - qid {1} (title: {2})", report_params.campaign_name, report_params.questionnaire_id, report_params.questionnaire_title);
			

			if (record_counter > 0)
			{
				//.NET 1.1: MailAttachment response_files = new MailAttachment(report_params.pathtotempdir + zip_name);
                Attachment response_files = new Attachment(report_params.pathtotempdir + zip_name);
                msg.Attachments.Add(response_files);
			}
			
			#region building emails content (information about the responsefiles)
            //††† 20120302 Biju Pattathil | RFG2.7 PR629425:dts email having wrong RFG support link (RFG Support link will change):Start†††
            string support_url = utility.getParameter("support_link"); //+ "live/index.aspx?qid=1493&flexfield1=stop_scheduled_report&flexfield14=qid-"+report_params.questionnaire_id +"-sid-"+ report_params.schedule_id +"&flexfield15="+ report_params.permss_user; 
			
			string mail_text = @"
                                <style>
									body {font-family:""Arial"";font-weight:normal;font-size:10pt;color:black;} 
        							table {font-family:""Arial"";font-weight:normal;font-size:10pt;color:black;}
                                    p {font-family:""Arial"";font-weight:normal;color:black;margin-top: -5px}
        							b {font-family:""Arial"";font-weight:bold;color:black;margin-top: -5px}
        							H1 { font-family:""Arial"";font-weight:normal;font-size:14pt;color:black }
        							H2 { font-family:""Arial"";font-weight:normal;font-size:10pt;color:maroon }
									H3 { font-family:""Arial"";font-weight:normal;font-size:10pt;color:darkgreen }
        							pre {font-family:""Arial Console"";font-size: .9em}
                                    .head{ font-family:""Arial"";font-weight:bold;font-size:10pt;color:red }
        							.marker {font-weight: bold; color: black;text-decoration: none;}
        							.version {color: gray;}
        							.error {margin-bottom: 10px;}
        							.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
								</style>";


			if (report_params.scheduled)
			{
                //Commented by Phani for RFG 1.9.4 release 
				//mail_text = String.Format("{0}<span><b>This is a scheduled report!</b></span><br><br>", mail_text);
                mail_text = String.Format("{0}<span class=head>This is an automatically generated scheduled report - please do not reply to this email as answers won't be read!</span><br>", mail_text);
                mail_text = String.Format("{0}<span><i>If you don't need to receive this report any longer please submit your request for the report to stop on the <a href="+ support_url+"> RFG support form</a></i></span><br><br><br>", mail_text);
			}

            mail_text = String.Format("{0}<span><p>Hello {1},<br><br>", mail_text, report_params.permss_user);

			if (record_counter > 0)
			{
				mail_text  = String.Format("{0}please find attached a zip-archive containing the requested responses for<br><br><table border=1>", mail_text);
			}
			else
			{
				mail_text  = String.Format("{0}there were no records of responses you have requested for<br><br><table border=1>", mail_text);
			}
            
            mail_text = String.Format("{0}<tr><td width=100>Campaign - Title:</td><td><b>{1} - {2}</b> (qid = {3})&nbsp;</td></tr>", mail_text, report_params.campaign_name, report_params.questionnaire_title, report_params.questionnaire_id);
            mail_text  = String.Format("{0}<tr><td>from: </td><td><b>{1}</b></td></tr>", mail_text, report_params.from.ToShortDateString());
			mail_text  = String.Format("{0}<tr><td>until: </td><td><b>{1}</b></td></tr>", mail_text, report_params.until.AddDays(-1d).ToShortDateString());
			mail_text  = String.Format("{0}<tr><td>number of records<br>in response file: </td><td><b>{1}</b></td></tr></table><br>", mail_text, record_counter.ToString());           
            mail_text  = String.Format("{0}<br>Regards,<br>Your RFG-team</p></span>", mail_text);
			#endregion

			msg.Body = mail_text;

            if (report_params.is_incremental_report) // RFG 2.19 | send email if record count > 0 for incremental schedule report
            {
                if (record_counter > 0)
                {
                    //.NET 1.1: SmtpMail.Send(msg);
                    SmtpClient smtp = new SmtpClient(utility.getParameter("smtp"));
                    smtp.Send(msg);
                }
            }
            else
            {
                SmtpClient smtp = new SmtpClient(utility.getParameter("smtp"));
                smtp.Send(msg);
            }

            msg.Dispose();

            try
            {
                File.Delete(report_params.pathtotempdir + zip_name);

                //foreach (String file in file_names)
                //{
                //    File.Delete(report_params.pathtotempdir + file);
                //}
            }
            catch
            { }

			#endregion

			//log finish in DB
			Hashtable h_params = new Hashtable();
			h_params.Add("entry_id", report_params.queue_entry_id);
			h_params.Add("status", 3); //3 = finished/completed
            DB.execProc("update_queued_report", h_params);
           
		}