예제 #1
0
        private void AddMessage(int organizationID, string description, MailMessage message, string replyToAddress = null, string[] attachments = null, DateTime?timeToSend = null, Ticket ticket = null)
        {
            Organization organization = Organizations.GetOrganization(LoginUser, organizationID);
            string       replyAddress = organization.GetReplyToAddress(replyToAddress).Trim();
            int          i            = 0;

            while (i < message.To.Count)
            {
                MailAddress address = message.To[i];
                if (address.Address.ToLower().Trim() == message.From.Address.ToLower().Trim() || address.Address.ToLower().Trim() == replyAddress || address.Address.ToLower().Trim() == organization.SystemEmailID.ToString().Trim().ToLower() + "@teamsupport.com")
                {
                    message.To.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }

            if (message.To.Count < 1)
            {
                return;
            }

            StringBuilder builder = new StringBuilder();

            builder.AppendLine(message.Body);
            message.HeadersEncoding = Encoding.UTF8;
            message.Body            = builder.ToString();
            List <MailAddress> addresses        = message.To.ToList();
            string             body             = message.Body;
            string             subject          = message.Subject;
            MailAddress        replyMailAddress = null;

            try
            {
                replyMailAddress = GetMailAddress(replyAddress);
            }
            catch (Exception)
            {
                replyMailAddress = GetMailAddress(organization.GetReplyToAddress());
            }

            Logs.WriteEvent(string.Format("ReplyTo Address[{0}]", replyAddress.Replace("<", "").Replace(">", "")));

            foreach (MailAddress address in addresses)
            {
                try
                {
                    message.To.Clear();
                    message.To.Add(GetMailAddress(address.Address, address.DisplayName));
                    Logs.WriteEvent(string.Format("Successfuly added email address [{0}]", address.ToString()));
                    message.HeadersEncoding = Encoding.UTF8;
                    message.Body            = body;
                    message.Subject         = subject;
                    message.From            = replyMailAddress;
                    EmailTemplates.ReplaceMailAddressParameters(message);
                    Emails.AddEmail(LoginUser, organizationID, null, description, message, attachments, timeToSend);

                    if (message.Subject == null)
                    {
                        message.Subject = "";
                    }
                }
                catch (Exception ex)
                {
                    Log("Error when creating and adding email message.");
                    Log(ex.Message + Environment.NewLine + ex.StackTrace);
                }
            }
        }
        private void ProcessReminder(Reminder reminder)
        {
            Logs.WriteLine();
            Logs.WriteEvent("***********************************************************************************");
            Logs.WriteEvent("Processing Reminder  ReminderID: " + reminder.ReminderID.ToString());
            Logs.WriteData(reminder.Row);
            Logs.WriteLine();
            Logs.WriteEvent("***********************************************************************************");

            MailMessage   message;
            UsersViewItem user = UsersView.GetUsersViewItem(LoginUser, (int)reminder.UserID);

            if (user == null)
            {
                return;
            }
            string description = "";

            switch (reminder.RefType)
            {
            case ReferenceType.Organizations:
                OrganizationsViewItem org = OrganizationsView.GetOrganizationsViewItem(LoginUser, reminder.RefID);
                if (org == null)
                {
                    return;
                }
                message = EmailTemplates.GetReminderCustomerEmail(LoginUser, reminder, user, org);

                description = String.Format("Reminder sent to {0} for Organization {1}", message.To.ToString(), org.Name);
                Logs.WriteEvent(description);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, reminder.RefType, reminder.RefID, description);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Organizations, org.OrganizationID, description);
                break;

            case ReferenceType.Tickets:
                TicketsViewItem ticket = TicketsView.GetTicketsViewItem(LoginUser, reminder.RefID);
                if (ticket == null)
                {
                    return;
                }
                message = EmailTemplates.GetReminderTicketEmail(LoginUser, reminder, user, ticket);
                EmailTemplates.ReplaceEmailRecipientParameters(LoginUser, message, Tickets.GetTicket(LoginUser, ticket.TicketID), reminder.UserID);     //vv

                TeamSupport.Data.Action action = (new Actions(LoginUser)).AddNewAction();
                action.ActionTypeID       = null;
                action.Name               = "Reminder";
                action.ActionSource       = "Reminder";
                action.SystemActionTypeID = SystemActionType.Reminder;
                action.Description        = String.Format("<p>The following is a reminder for {0} {1}:</p><p>&nbsp;</p><p>{2}</p>", user.FirstName, user.LastName, reminder.Description);
                action.IsVisibleOnPortal  = false;
                action.IsKnowledgeBase    = false;
                action.TicketID           = ticket.TicketID;
                action.Collection.Save();

                description = String.Format("Reminder sent to {0} for Ticket {1}", message.To.ToString(), ticket.TicketNumber.ToString());
                Logs.WriteEvent(description);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, reminder.RefType, reminder.RefID, description);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Tickets, ticket.TicketID, description);
                break;

            case ReferenceType.Contacts:
                ContactsViewItem contact = ContactsView.GetContactsViewItem(LoginUser, reminder.RefID);
                if (contact == null)
                {
                    return;
                }
                message     = EmailTemplates.GetReminderContactEmail(LoginUser, reminder, user, contact);
                description = String.Format("Reminder sent to {0} for Contact {1}", message.To.ToString(), contact.FirstName + " " + contact.LastName);
                Logs.WriteEvent(description);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, reminder.RefType, reminder.RefID, description);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Users, contact.UserID, description);
                break;

            case ReferenceType.Tasks:
                TasksViewItem task = TasksView.GetTasksViewItem(LoginUser, reminder.RefID);
                if (task == null || task.IsComplete)
                {
                    reminder.IsDismissed = true;
                    reminder.Collection.Save();
                    return;
                }
                message     = EmailTemplates.GetReminderTaskEmail(LoginUser, reminder, user, task);
                description = String.Format("Reminder sent to {0} for Task {1}", message.To.ToString(), task.Name);
                Logs.WriteEvent("ver. 05162017: " + description);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Tasks, task.TaskID, description);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Users, (int)reminder.UserID, description);

                TaskAssociations taskAssociations = new TaskAssociations(LoginUser);
                taskAssociations.LoadByTaskIDOnly(task.TaskID);

                foreach (TaskAssociation taskAssociation in taskAssociations)
                {
                    if (taskAssociation.RefType == (int)ReferenceType.Tickets)
                    {
                        TeamSupport.Data.Action taskAction = (new Actions(LoginUser)).AddNewAction();
                        taskAction.ActionTypeID       = null;
                        taskAction.Name               = "Reminder";
                        taskAction.ActionSource       = "Reminder";
                        taskAction.SystemActionTypeID = SystemActionType.Reminder;
                        taskAction.Description        = String.Format("<p>The following is a reminder for {0} {1}:</p><p>&nbsp;</p><p>{2}</p>", user.FirstName, user.LastName, reminder.Description);
                        taskAction.IsVisibleOnPortal  = false;
                        taskAction.IsKnowledgeBase    = false;
                        taskAction.TicketID           = taskAssociation.RefID;
                        try
                        {
                            taskAction.Collection.Save();
                        }
                        catch (Exception ex)
                        {
                            Logs.WriteEvent("Ex Reminder Action.Save: " + ex.StackTrace);
                        }
                    }
                }
                break;

            default:
                message = null;
                break;
            }

            if (message == null)
            {
                return;
            }

            reminder.HasEmailSent = true;
            reminder.Collection.Save();

            if (Emails.IsEmailDisabled(LoginUser, user.UserID, "Reminders"))
            {
                Logs.WriteEvent("Message skipped due to disabled user setting.");
            }
            else
            {
                MailAddress address = new MailAddress(user.Email, user.FirstName + " " + user.LastName);
                Logs.WriteEvent("Mail Address: " + address.ToString());
                message.To.Add(address);
                EmailTemplates.ReplaceMailAddressParameters(message);
                Emails.AddEmail(LoginUser, reminder.OrganizationID, null, message.Subject, message);
                Logs.WriteEvent("Message queued");
            }
        }
예제 #3
0
        private void ProcessOldUser(int taskID, int modifierID, int oldUserID)
        {
            TasksViewItem task = TasksView.GetTasksViewItem(LoginUser, taskID);

            try
            {
                User modifier = Users.GetUser(LoginUser, modifierID);
                if (task == null)
                {
                    Logs.WriteEvent("Unable to find Task, TaskID: " + taskID.ToString());
                    return;
                }

                if (modifier == null)
                {
                    Logs.WriteEvent("Unable to find Modifying User, UserID: " + modifierID.ToString());
                    return;
                }

                Organization taskOrganization = Organizations.GetOrganization(LoginUser, task.OrganizationID);

                if (taskOrganization == null)
                {
                    Logs.WriteEvent("Task's Organization IS NULL!!!!");
                    return;
                }

                User oldUser = Users.GetUser(LoginUser, oldUserID);

                UsersViewItem owner = null;

                if (task.UserID != null)
                {
                    owner = UsersView.GetUsersViewItem(LoginUser, (int)task.UserID);
                }

                if (Emails.IsEmailDisabled(LoginUser, oldUser.UserID, "Tasks"))
                {
                    return;
                }

                MailMessage message = EmailTemplates.GetTaskOldUser(LoginUser, UsersView.GetUsersViewItem(LoginUser, modifierID), UsersView.GetUsersViewItem(LoginUser, (int)oldUserID), owner, task);
                //if (oldUser.UserID == modifier.UserID)
                //{
                //    User creator = Users.GetUser(LoginUser, (int)task.CreatorID);
                //    message.To.Add(GetMailAddress(creator.Email, creator.FirstLastName));
                //}
                //else
                //{
                message.To.Add(GetMailAddress(oldUser.Email, oldUser.FirstLastName));
                //}
                //message.Subject = message.Subject + " [pvt]";
                //EmailTemplates.ReplaceEmailRecipientParameters(LoginUser, message, ticket, owner.UserID, owner.OnlyEmailAfterHours);
                EmailTemplates.ReplaceMailAddressParameters(message);

                String description = String.Format("Task old user notification sent to {0} for Task {1}", message.To.ToString(), task.Name);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Tasks, task.TaskID, description);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Users, (int)task.UserID, description);

                //string emailReplyToAddress = GetEmailReplyToAddress(LoginUser, ticket);
                //AddMessage(taskOrganization, "Ticket Update Request [" + ticket.TicketNumber.ToString() + "]", message, emailReplyToAddress);
                Emails.AddEmail(LoginUser, task.OrganizationID, null, message.Subject, message);
                Logs.WriteEvent("Message queued");
            }
            catch (Exception ex)
            {
                Logs.WriteEvent("Error with ProcessTaskComplete");
                Logs.WriteException(ex);
                ExceptionLogs.LogException(LoginUser, ex, "ProcessTaskComplete", task.Row);
            }
        }
예제 #4
0
        private void NotifyViolation(int ticketID, bool useUser, bool useGroup, bool isWarning, SlaViolationType slaViolationType, SlaNotification notification, int?triggerId)
        {
            Users users = new Users(LoginUser);
            User  user  = null;

            Logs.WriteLine();
            Logs.WriteEvent("***** Processing TicketID: " + ticketID.ToString());
            TicketsViewItem ticket = TicketsView.GetTicketsViewItem(LoginUser, ticketID);

            if (ticket == null)
            {
                Logs.WriteEvent("Ticket is NULL, exiting");
                return;
            }

            //Since we are already re-loading the Ticket information we will check again if the SLAs still apply at this point
            string violationType      = "";
            bool   slaNotApplyAnymore = false;

            switch (slaViolationType)
            {
            case SlaViolationType.InitialResponse:
                violationType      = "Initial Response";
                slaNotApplyAnymore = ticket.SlaWarningInitialResponse == null;
                break;

            case SlaViolationType.LastAction:
                violationType      = "Last Action";
                slaNotApplyAnymore = ticket.SlaViolationLastAction == null;
                break;

            case SlaViolationType.TimeClosed:
                violationType      = "Time to Close";
                slaNotApplyAnymore = ticket.SlaViolationTimeClosed == null;
                break;

            default: break;
            }

            if (slaNotApplyAnymore)
            {
                Logs.WriteEvent($"The {((isWarning) ? "warning" : "violation")} for {violationType} does not apply anymore because the Ticket has been updated to satisfy this SLA while it was in process for the notification.");
            }
            else
            {
                if (!isWarning)
                {
                    SlaViolationHistoryItem history = (new SlaViolationHistory(LoginUser)).AddNewSlaViolationHistoryItem();
                    history.DateViolated  = DateTime.UtcNow;
                    history.GroupID       = ticket.GroupID;
                    history.UserID        = ticket.UserID;
                    history.ViolationType = slaViolationType;
                    history.TicketID      = ticket.TicketID;
                    history.SlaTriggerId  = triggerId;
                    history.Collection.Save();
                }

                Actions actions = new Actions(LoginUser);
                actions.LoadLatestByTicket(ticket.TicketID, false);

                ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.Tickets, ticket.TicketID, violationType + " SLA " + (isWarning ? "warning" : "violation") + " occurred");

                MailMessage message = EmailTemplates.GetSlaEmail(LoginUser, ticket, violationType, isWarning);


                if (ticket.GroupID != null && useGroup)
                {
                    users.LoadByGroupID((int)ticket.GroupID);
                }

                if (ticket.UserID != null && useUser && users.FindByUserID((int)ticket.UserID) == null)
                {
                    user = Users.GetUser(LoginUser, (int)ticket.UserID);
                }

                foreach (User item in users)
                {
                    if (Emails.IsEmailDisabled(LoginUser, item.UserID, "SLA"))
                    {
                        continue;
                    }
                    message.To.Add(new MailAddress(item.Email, item.FirstLastName));
                }

                if (user != null)
                {
                    if (!Emails.IsEmailDisabled(LoginUser, user.UserID, "SLA"))
                    {
                        message.To.Add(new MailAddress(user.Email, user.FirstLastName));
                        Logs.WriteEvent(string.Format("Adding Main User, Name:{0}  Email:{1}  UserID:{2}", user.FirstLastName, user.Email, user.UserID.ToString()));
                    }
                }

                if (message.To.Count > 0)
                {
                    Email email = Emails.AddEmail(LoginUser, ticket.OrganizationID, null, "Sla Message", message);
                    Logs.WriteEvent("Email Added (EmailID: " + email.EmailID.ToString() + ")", true);
                }

                try
                {
                    TimeZoneInfo tz  = null;
                    Organization org = Organizations.GetOrganization(LoginUser, ticket.OrganizationID);
                    if (org.TimeZoneID != null)
                    {
                        tz = System.TimeZoneInfo.FindSystemTimeZoneById(org.TimeZoneID);
                    }
                    if (tz == null)
                    {
                        Logs.WriteEvent("Timezone is null, using system's");
                        tz = System.TimeZoneInfo.Local;
                    }
                    Logs.WriteEvent(tz.DisplayName);
                    Logs.WriteEvent("Supports DLS: " + tz.SupportsDaylightSavingTime.ToString());
                    Logs.WriteEvent("Is DLS: " + tz.IsDaylightSavingTime(DateTime.UtcNow).ToString());
                    Logs.WriteEvent("UTC: " + DateTime.UtcNow.ToString());
                    Logs.WriteEvent(string.Format("NOTIFYING TicketID:{0}  TicketNumber:{1}  OrganizationID:{2} ", ticket.TicketID.ToString(), ticket.TicketNumber.ToString(), ticket.OrganizationID.ToString()));
                    Logs.WriteEvent(string.Format("User:{1}  Group:{2}  IsWarning:{3}  NoficationType:{4}", ticketID.ToString(), useUser.ToString(), useGroup.ToString(), isWarning.ToString(), slaViolationType));
                    Logs.WriteEvent("Ticket Data:");
                    Logs.WriteData(ticket.Row);
                    Logs.WriteEvent("Notification Data:");
                    Logs.WriteData(notification.Row);
                    Logs.WriteEvent("Organization Data:");
                    Logs.WriteData(org.Row);
                    Organizations customers = new Organizations(LoginUser);
                    customers.LoadByTicketID(ticket.TicketID);

                    foreach (Organization customer in customers)
                    {
                        Logs.WriteEvent("-- Customer: " + customer.Name);
                        if (customer.SlaLevelID != null)
                        {
                            SlaLevel level = SlaLevels.GetSlaLevel(LoginUser, (int)customer.SlaLevelID);
                            Logs.WriteEvent("SLA Level: " + level.Name);
                            SlaTriggers triggers = new SlaTriggers(LoginUser);
                            triggers.LoadByTicketTypeAndSeverity(level.SlaLevelID, ticket.TicketTypeID, ticket.TicketSeverityID);

                            foreach (SlaTrigger trigger in triggers)
                            {
                                Logs.WriteData(trigger.Row);
                            }
                        }
                        else
                        {
                            Logs.WriteEvent("No SLA Level Assigned to " + customer.Name);
                        }
                    }

                    if (org.InternalSlaLevelID != null)
                    {
                        Logs.WriteEvent("Internal SLA:");

                        SlaTriggers triggers = new SlaTriggers(LoginUser);
                        triggers.LoadByTicketTypeAndSeverity((int)org.InternalSlaLevelID, ticket.TicketTypeID, ticket.TicketSeverityID);
                        foreach (SlaTrigger trigger in triggers)
                        {
                            Logs.WriteData(trigger.Row);
                        }
                    }
                    else
                    {
                        Logs.WriteEvent("No Internal SLA");
                    }
                }
                catch (Exception ex)
                {
                    Logs.WriteEvent("Logging Exception:");
                    Logs.WriteException(ex);
                }
            }
        }
예제 #5
0
        private void ProcessTaskAssigned(int taskID, int modifierID)
        {
            TasksViewItem task = TasksView.GetTasksViewItem(LoginUser, taskID);

            try
            {
                User modifier = Users.GetUser(LoginUser, modifierID);
                if (task == null)
                {
                    Logs.WriteEvent("Unable to find Task, TaskID: " + taskID.ToString());
                    return;
                }

                if (modifier == null)
                {
                    Logs.WriteEvent("Unable to find Modifying User, UserID: " + modifierID.ToString());
                    return;
                }

                if (task.UserID == null)
                {
                    Logs.WriteEvent("Assigned Task User is null");
                    return;
                }

                Organization taskOrganization = Organizations.GetOrganization(LoginUser, task.OrganizationID);

                if (taskOrganization == null)
                {
                    Logs.WriteEvent("Task's Organization IS NULL!!!!");
                    return;
                }

                User owner = Users.GetUser(LoginUser, (int)task.UserID);
                if (owner.UserID == modifier.UserID)
                {
                    Logs.WriteEvent("Modifier and Owner are the same person.");
                    return;
                }

                if (Emails.IsEmailDisabled(LoginUser, owner.UserID, "Tasks"))
                {
                    return;
                }

                MailMessage message = EmailTemplates.GetTaskAssigned(LoginUser, UsersView.GetUsersViewItem(LoginUser, modifierID), UsersView.GetUsersViewItem(LoginUser, (int)task.UserID), task);
                message.To.Add(GetMailAddress(owner.Email, owner.FirstLastName));
                //message.Subject = message.Subject + " [pvt]";
                EmailTemplates.ReplaceMailAddressParameters(message);

                String description = String.Format("Task assigned notification sent to {0} for Task {1}", message.To.ToString(), task.Name);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Tasks, task.TaskID, description);
                ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Users, (int)task.UserID, description);

                //string emailReplyToAddress = GetEmailReplyToAddress(LoginUser, ticket);
                //AddMessage(taskOrganization, "Ticket Update Request [" + ticket.TicketNumber.ToString() + "]", message, emailReplyToAddress);
                Emails.AddEmail(LoginUser, task.OrganizationID, null, message.Subject, message);
                Logs.WriteEvent("Message queued");
            }
            catch (Exception ex)
            {
                Logs.WriteEvent("Error with ProcessTaskAssigned");
                Logs.WriteException(ex);
                ExceptionLogs.LogException(LoginUser, ex, "ProcessTaskModified", task.Row);
            }
        }