Exemplo n.º 1
0
        private void FindTasksAndNotifyUsers()
        {
            // Get all the users - 25 user limit.
            DataTable userTable = BCCTaskDataAccess.RetrieveAllUsers(ApplicationName, 0, USER_LIMIT);
            string mailMessage = string.Empty;
            string mailSubject = string.Empty;

            // foreach user in the user table.
            foreach (DataRow dr in userTable.Rows)
            {
                BCCTaskEffort effort = new BCCTaskEffort();

                effort.TaskAssignedToUserName = dr["userName"] as string;
                effort.TaskStatus = null; // has to be null to get all the tasks.

                DataTable taskTable = null;
                try
                {
                    // Get the list of tasks for each user
                    taskTable = BCCTaskEffort.ReportTaskEfforts(effort);
                }
                catch(Exception exception)
                {
                    System.Diagnostics.Debug.Write(exception.Message, "TaskNotifier");
                }

                // Dont send emails when there are no tasks.
                if (taskTable != null && taskTable.Rows != null && taskTable.Rows.Count > 0)
                {
                    EmailHelper helper = new EmailHelper(EmailConfigSpeedCode);

                    helper.EmailRecipient = dr["email"] as string;
                    WriteToEventLog("Sending email to : " + helper.EmailRecipient);

                    // Form the email message for each task
                    mailMessage = HtmlEmailHelper.FormHTMLContent(taskTable, effort.ReportStartDate, effort.ReportEndDate);
                    mailSubject = "(BCC) - Task Status Report - " + DateTime.UtcNow.Date.ToString("MMM-dd-yyyy");
                    helper.SendMail(mailSubject, mailMessage, false);
                }
                else
                {
                    System.Diagnostics.Debug.Write("No tasks found for " + effort.TaskAssignedToUserName, "TaskNotifier");
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Event handler for WMI events
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void monitor_ArtifactStatusChanged(object sender, ArtifactMonitoringEventArgs e)
        {
            try
            {
                int smtp_email_port = 25;
                bool smtp_email_ssl = false;
                string smtp_email_host = string.Empty;
                string smtp_email_username = string.Empty;
                string smtp_email_userpwd = string.Empty;
                string smtp_email_subject = string.Empty;
                string smtp_email_rcpnt = string.Empty;
                string smtp_email_title = "BizTalk Control Center (BCC) - Alert Notification";
                string mailSubject = "BCC Agent notification [" + Environment.MachineName + "]";

                string mailMessage = HtmlEmailHelper.FormatContent(e, smtp_email_title);

                if (!IsLocalEmailFlag)
                {
                    try
                    {
                        // Read monitoring list
                        BCCMonitoringDataAccess da = new BCCMonitoringDataAccess();

                        // Receive Port
                        if (e.ArtifactType == ArtifactType.ReceivePort)
                        {
                            da.LogMonitoringData(e.ArtifactType, e.ReceiveLocationName, e.ArtifactStatus);
                        }
                        // Host Instance
                        else if (e.ArtifactType == ArtifactType.HostInstance)
                        {
                            da.LogMonitoringData(e.ArtifactType, e.HostName, e.ArtifactStatus);
                        }
                        // Service Instance
                        else if (e.ArtifactType == ArtifactType.ServiceInstance)
                        {
                            da.LogMonitoringData(e.ArtifactType, e.ServerName, e.ArtifactStatus);
                        }
                        // Send Port
                        else
                        {
                            da.LogMonitoringData(e.ArtifactType, e.ArtifactName, e.ArtifactStatus);
                        }
                    }
                    catch (Exception exception)
                    {
                        WriteToEventLog(exception.Message + exception.StackTrace);
                    }

                    // Send email
                    EmailHelper helper = new EmailHelper(BCC_AGENT_CONFIG_SPEEDCODE);

                    mailMessage = HtmlEmailHelper.FormatContent(e, helper.EmailTitle);
                    mailSubject = helper.EmailSubject.Replace("$machineName", Environment.MachineName);

                    helper.SendMail(mailSubject, mailMessage, false);

                    WriteToEventLog("Mail message:" + mailMessage);
                }
                else // Use local SMTP settings
                {
                    SmtpSection smtpSection = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;

                    // Get the from email of the config file
                    smtp_email_username = smtpSection.From;
                    // Get the to address from the app settings
                    smtp_email_rcpnt = ConfigurationManager.AppSettings["EmailRecipients"].ToString();
                    // Get the host name from the smtp section
                    smtp_email_host = smtpSection.Network.Host;

                    EmailHelper helper = new EmailHelper(smtp_email_port, smtp_email_ssl, smtp_email_host, smtp_email_username, smtp_email_userpwd, smtp_email_rcpnt, smtp_email_title, false);
                    helper.SendMail(mailSubject, mailMessage, true);
                }
            }
            catch (Exception exception)
            {
                WriteToEventLog(exception.Message + exception.StackTrace);
            }
        }