Esempio n. 1
0
		public static int SendEmail(string from, string subject, string body, Kindred.Common.Security.NameEmailPair[] recipients, ITATSystem system, List<string> roles, List<int> facilityIDs)
		{
			Kindred.Common.Email.Email email = new Kindred.Common.Email.Email();
			string emailBody = System.Web.HttpUtility.HtmlDecode(body);

			string[] overrideRecipients = system.OverrideEmail.Split(new char[] { ',', '|' }, StringSplitOptions.RemoveEmptyEntries);
			string[] ownerRecipients = system.OwnerEmail.Split(new char[] { ',', '|' }, StringSplitOptions.RemoveEmptyEntries);

			//Determine actual recipients and whether to add a "debug" or "recipients not found" message to the email body
			if (recipients.Length > 0)
			{
				if (overrideRecipients.Length > 0)
				{
					emailBody = DebugMessage(recipients) + emailBody;
					AddRecipients(email, overrideRecipients);
				}
				else
				{
					AddRecipients(email, recipients);  
				}
			}
			else
			{
				if (overrideRecipients.Length > 0)
				{
                    emailBody = DebugMessage(recipients) + emailBody + RecipientsNotFoundMessage(system, roles, facilityIDs);
					AddRecipients(email, overrideRecipients);
				}
				else
				{
                    emailBody = emailBody + RecipientsNotFoundMessage(system, roles, facilityIDs);
					AddRecipients(email, ownerRecipients);
				}
			}

			if (string.IsNullOrEmpty(email.To))
			{
                emailBody = emailBody + RecipientsNotFoundMessage(system, roles, facilityIDs);
				AddRecipients(email, ownerRecipients);
				if (string.IsNullOrEmpty(email.To))
				{
					throw new Exception("No e-mail recipients were found.   This should not happen, because the OwnerEmail attribute in the System Def XML should contain at least one e-mail address.  Report this issue to Support.");
				}
			}

			email.Subject = subject;
			email.From = from;
			email.Format = Kindred.Common.Email.EmailFormat.Html;
			email.Body = emailBody;
            email.ApplicationName = EmailName(system.Name);
			return email.Send();
		}
Esempio n. 2
0
 public static void SendNotificationToOwner(ITATSystem system, ManagedItem managedItem, string message, string errorMessage)
 {
     string[] ownerRecipients = system.OwnerEmail.Split(new char[] { ',', '|' }, StringSplitOptions.RemoveEmptyEntries);
     if (ownerRecipients.Length > 0)
     {
         Kindred.Common.Email.Email email = new Kindred.Common.Email.Email();
         foreach (string recipient in ownerRecipients)
             email.AddRecipient(Kindred.Common.Email.EmailRecipientType.To, recipient);
         email.Subject = string.Format("ITAT-{0} -- Unable to send notification for {1} {2}", system.Name, system.ManagedItemName, managedItem.ItemNumber);
         email.From = XMLNames._M_EmailFrom;
         email.Format = Kindred.Common.Email.EmailFormat.Html;
         email.Body = string.Format("<b>ITAT-{0} was unable to send a notification for {1} {2}.<br /><br />{3}</b><br /><br /><br />{4}", system.Name, system.ManagedItemName, managedItem.ItemNumber, errorMessage, message);
         email.ApplicationName = EmailName(system.Name);
         email.Send();
     }
 }
Esempio n. 3
0
        private void ProcessDefinitionErrors(metaStoreDefinition definition, string systemName)
        {
            string errorReport = string.Format("There were a total of {0:D} error(s) reported for {1:D} manageditem(s) out of a total of {2:D} manageditem(s) processed.",
                GetErrorCount(definition),
                definition.dataRows.Count,
                definition.managedItemIDCount - definition.skippedManagedItemIDs.Count);

            if (definition.skippedManagedItemIDs.Count > 0)
                errorReport += string.Format("  {0:D} manageditem(s) were not processed.", definition.skippedManagedItemIDs.Count);

            if (definition.dataStoreDefinition.DataStoreConfig.ErrorLogRecepientEmailList.Count == 0)
            {
                _log.Error(string.Format("Email Not Sent - For System '{0}', Definition '{1}' ... {2}. No email recipents were listed.", systemName, definition.dataStoreDefinition.Name, errorReport));
            }
            else
            {
                _log.Error(string.Format("For System '{0}', Definition '{1}' ... {2}", systemName, definition.dataStoreDefinition.Name, errorReport));
                byte[] output = null;
                using (StringWriter sw = new StringWriter())
                {
                    sw.WriteLine("Template Name,ManagedItem Number,Term Name,Field Name,Error Message");
                    foreach (ManagedItemStore.dataRow dataRow in definition.dataRows)
                    {
                        foreach (ManagedItemStore.rowError rowError in dataRow.rowErrors)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb = sb.Append(TextHelper.CSVFormat(null, rowError.templateName, false));
                            sb = sb.Append(TextHelper.CSVFormat(null, rowError.managedItemNumber, false));
                            sb = sb.Append(TextHelper.CSVFormat(null, rowError.termName, false));
                            sb = sb.Append(TextHelper.CSVFormat(null, rowError.fieldName, false));
                            sb = sb.Append(TextHelper.CSVFormat(null, rowError.message, true));
                            sw.WriteLine(sb.ToString());
                        }
                    }
                    output = Encoding.UTF8.GetBytes(sw.ToString());
                }
                Kindred.Common.Email.Email email = new Kindred.Common.Email.Email();
                email.Subject = string.Format("ITAT System {0} - Validation Errors for Interface '{1}'", systemName, definition.dataStoreDefinition.Name);
                email.Format = Common.Email.EmailFormat.Html;
                email.From = XMLNames._M_EmailFrom;
                foreach (string recipient in definition.dataStoreDefinition.DataStoreConfig.ErrorLogRecepientEmailList)
                    email.AddTo(recipient);
                email.Format = Kindred.Common.Email.EmailFormat.Html;
                email.Body = string.Format("Please find the list of validation errors attached. {0}", errorReport);
                email.ApplicationName = Business.EmailHelper.EmailName(systemName);
                email.Attachments.Add(new Common.Email.EmailAttachment(output, definition.emailAttachmentFileName, definition.emailAttachmentExtension));
                email.Send();
            }
        }