protected void Page_Load(object sender, EventArgs e)
        {
            page_utilities.Set_titles(this.Page, "Export reports / statistics files");
            permss = check_permissions(this.Page, true);

            if (permss.UserType != UserType.Admin || 
                 Session["from"] == null ||
                Session["until"] == null ||
                Session["ordering"] == null||
                Session["row_number"] == null)
            {
                Response.Redirect("index.aspx", true);
            }

            table_emailerror.Visible = false;

            if (!IsPostBack)
            {
                try
                {
                    InitializeStatisticsValues();
                    pathtotempdir = Server.MapPath(utility.getParameter("path_to_temp"));

                    values = new statistics_values();
                    values.permss_account = permss.EmailAddress;
                    values.permss_user = permss.EmailAddress;
                    values.from = from;
                    values.until = until;
                    values.row_number = row_number;
                    values.ordering = ordering;
                    values.Company_Code = permss.Company_Code; //RFG 2.20
                }
                catch
                {
                    table_emailerror.Visible = true;
                }
                values.pathtotempdir = pathtotempdir;
                mailthread.generate_dataemail(values, true);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// queues up a new emailstatistics
        /// </summary>
        /// <param name="values">settings of the emailstatistics to be generated</param>
        public static void generate_dataemail(statistics_values values, bool useSeparateThread)
        {
            #region checks whether thread has to be started at first...

            if (started_thread == null)
            {
                started_thread = new mailthread(useSeparateThread);
                if (useSeparateThread)
                {
                    started_thread.Start();
                }
            }
            #endregion

            Hashtable h_params = new Hashtable();
            string entry_id = "";            

            h_params.Add("requestor_email", values.permss_user);
            h_params.Add("from", values.from);
            h_params.Add("until", values.until);
            h_params.Add("row_number", values.row_number);
            h_params.Add("ordering", values.ordering);            
            entry_id = DB.execProc("insert_queued_statistics", h_params).Rows[0][0].ToString();
            values.queue_entry_id = entry_id;
            started_thread.emailstatistics.Enqueue(values);

            if (!useSeparateThread)
            {
                started_thread.generate_statisticsemail_processingqueue();
            }
        }
Ejemplo n.º 3
0
        private void send_error_email(statistics_values values, Exception error)
        {
            //.NET 1.1: SmtpMail.SmtpServer = utility.getParameter("smtp");
            SmtpClient smtp = new SmtpClient(utility.getParameter("smtp"));

            //MailMessage msg = new MailMessage(email_from, utility.getParameter("error_email_to"));
            MailMessage msg = new MailMessage();

            string email_from = utility.getParameter("email_sender");
            //email_from = email_from.Create(email_from.IndexOf("@"), ".THREAD");
            //.NET 1.1: msg.From = email_from;
            msg.From = new MailAddress(email_from);

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

            string user = values.permss_user;

            string link_to_RFG = utility.getParameter("UrlToApplication");
            string error_on_platform = utility.getParameter("platform");
            //error_on_platform = error_on_platform.Replace("http://", "");
            //error_on_platform = error_on_platform.Replace("/ePeRFGen/", "");

            string error_msg = String.Format("File error on {0} ({1})", error_on_platform, user);
            error_msg += " - " + error.Message;
            error_msg = error_msg.Replace(System.Environment.NewLine, "").Replace('\t', ' ');
            
            msg.SubjectEncoding = Encoding.ASCII;
            msg.Subject = error_msg;

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

            #region building emails content (information about the error)
            //##########################################

            #region build usual error screen.

            string error_text = @"
            <style>
				body {font-family:""Verdana"";font-weight:normal;font-size: .7em;color:black;} 
        		p {font-family:""Verdana"";font-weight:normal;color:black;margin-top: -5px}
        		b {font-family:""Verdana"";font-weight:bold;color:black;margin-top: -5px}
        		H1 { font-family:""Verdana"";font-weight:normal;font-size:18pt;color:red }
        		H2 { font-family:""Verdana"";font-weight:normal;font-size:14pt;color:maroon }
				H3 { font-family:""Verdana"";font-weight:normal;font-size:14pt;color:darkgreen }
        		pre {font-family:""Lucida Console"";font-size: .9em}
        		.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>
			<span><H1>Server Error in '/ePeRFGen' Application.<hr width=100% size=1 color=silver></H1>";

            error_text = String.Format("{0}<h2> <i>{1}</i> </h2></span>", error_text, error.Message);
            error_text = String.Format("{0}<font face=\"Arial, Helvetica, Geneva, SunSans-Regular, sans-serif \">", error_text);
            error_text = String.Format(@"{0}<b> Description: </b>
                                        An unhandled exception occurred during the execution of the current 
                                        web request. Please review the stack trace for more information about 
                                        the error and where it originated in the code.<br><br>", error_text);


            error_text = String.Format("{0}<b> Exception Details: </b>{1}: {2}<br><br>", error_text, error.GetType().ToString(), error.Message);

            error_text = String.Format(@"{0}<b>Stack Trace:</b><br><br><table width=100% bgcolor=""#ffffcc""><tr><td><code><pre>", error_text);

            string stacktrace = error.StackTrace;

            error_text = String.Format("{0}{1}</pre></code></td></tr></table>", error_text, (stacktrace != "" ? stacktrace : ""));

            error_text = String.Format(@"{0}<br><hr width=100% size=1 color=silver><b>
                                         Version Information:</b>&nbsp;Microsoft .NET Framework Version:1.1.4322.2032; 
                                         ASP.NET Version:1.1.4322.2032</font>
                                         <hr width=100% size=1 color=silver><br>", error_text);


            error_text = String.Format("{0}<i><H3>Platform: <font color=blue>{1}</font>{2}{2}{2}{2}{2}", error_text, error_on_platform, "&nbsp;");
            error_text = String.Format("{0}User: <font color=blue>{1}</font></H3></i>", error_text, user);

            #endregion

            #region build additional data

            error_text = String.Format(@"{0}{1}Inner Exception Details - START", error_text, utility.newline);

            //check the InnerException
            while (error.InnerException != null)
            {
                error_text = String.Format(@"{0}--------------------------------", error_text);
                error_text = String.Format(@"{0}The following InnerException reported: {1}", error_text, error.InnerException.ToString());
                error = error.InnerException;
            }

            error_text = String.Format(@"{0}{1}Inner Exception Details - END", error_text, utility.newline);

            error_text = String.Format(@"{0}<hr width=100% size=1 color=silver><b>Error Site: <FONT color=blue>{1}datamgmt/index_reports_statistics.aspx</FONT></b><BR><BR>", error_text, link_to_RFG);

            error_text = String.Format(@"{0}<b>Requested statistics: </b><BR>---------------------<BR><BR>", error_text);

            error_text = String.Format(@"{0}From: {1}<BR>", error_text, values.from.ToString());
            error_text = String.Format(@"{0}Until: {1}<BR>", error_text, values.until.ToString());
            error_text = String.Format(@"{0}Ordering: {1}<BR>", error_text, values.ordering);
            if (!String.IsNullOrEmpty(values.row_number))
            {
                error_text = String.Format(@"{0}Number of report rows: {1}<BR>", error_text, values.row_number);
            }

            #endregion

            //##########################################

            #endregion

            // Sending error message to administration via e-mail
            msg.Body = error_text;
            // throw new Exception(strError);
            try
            {
                //.NET 1.1: SmtpMail.Send(msg);
                smtp.Send(msg);
                msg.Dispose();
            }
            catch
            {
            }
        }
Ejemplo n.º 4
0
        private void generate_statisticsemail_processingqueue(statistics_values values)
        {
            process_statistics processing_files = new process_statistics();

            processing_files.permss_user = values.permss_user;
            processing_files.permss_admin = values.permss_admin;
            processing_files.from = values.from;
            processing_files.until = values.until;
            processing_files.ordering = values.ordering;
            processing_files.row_number = values.row_number;
            processing_files.pathtotempdir = values.pathtotempdir;
            processing_files.Company_Code = values.Company_Code; //RFG 2.20
            //generate content of the file with statistics
            StringCollection file_names = processing_files.generate();

            int record_counter = Int32.Parse(file_names[0]);
            file_names.RemoveAt(0);

            #region create zip file
            string timeformat = "yyyyMMddHHmm";
            string zip_name = String.Format("RFG_report_statistic_{0}.zip", DateTime.Now.ToString(timeformat));
            utility.createZIP(zip_name, values.pathtotempdir, file_names);

            #endregion

            #region create and send email

            MailMessage msg = new MailMessage();            
            msg.IsBodyHtml = true;            
            msg.From = new MailAddress(email_from);
            utility.set_Mail_address(ref msg, "to", values.permss_user);
            msg.Subject = String.Format("Statistics-Files from {0} until {1}", values.from, values.until);              

            if (record_counter > 0)
            {
                Attachment response_files = new Attachment(values.pathtotempdir + zip_name);
                msg.Attachments.Add(response_files);
            }

            #region building emails content (information about the responsefiles)

            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>";            

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

            if (record_counter > 0)
            {
                mail_text = String.Format("{0}please find attached a zip-archive containing the requested statistics for<br><br><table border=1>", mail_text);
            }
            else
            {
                mail_text = String.Format("{0}there were no records of statistics you have requested for<br><br><table border=1>", mail_text);
            }

            mail_text = String.Format("{0}<tr><td>from: </td><td><b>{1}</b></td></tr>", mail_text, values.from.ToShortDateString());
            mail_text = String.Format("{0}<tr><td>until: </td><td><b>{1}</b></td></tr>", mail_text, values.until.ToShortDateString());
            mail_text = String.Format("{0}<tr><td>ordering: </td><td><b>{1}</b></td></tr>", mail_text, values.ordering);
            mail_text = String.Format("{0}<tr><td>number of records<br>in statistics 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;
            
            SmtpClient smtp = new SmtpClient(utility.getParameter("smtp"));
            smtp.Send(msg);

            msg.Dispose();

            try
            {
                File.Delete(values.pathtotempdir + zip_name);                
            }
            catch
            { }

            #endregion
            
            Hashtable h_params = new Hashtable();
            h_params.Add("entry_id", values.queue_entry_id);
            h_params.Add("status", 3);
            DB.execProc("update_queued_statistics", h_params);
           
        }